0

Product name: Open Liberty Product version: 20.0.0.7 Product edition: Open

is it possible to implement persistent ejbtimers on filesystem based default derby DB, using embedded.derby.DB

I installed derby in /tmp/derby, configured server.xml with the following, i don't see any file being created under /tmp when I start the OpenLiberty JVM, what am I missing in this approach?

        <feature>ejbPersistentTimer-3.2</feature>

       <library id="DerbyLib">
            <fileset dir="/tmp/derby/lib" includes="derby.jar"/>
        </library>
        <dataSource id="DefaultDerbyDatasource" jndiName="jdbc/defaultDatasource" statementCacheSize="10" transactional="false">
           <jdbcDriver libraryRef="DerbyLib"/>
           <properties.derby.embedded createDatabase="create" databaseName="/tmp/sample.ejbtimer.db" shutdownDatabase="false"/>
           <containerAuthData user="user1" password="derbyuser" />
        </dataSource>

Daniyal
  • 11
  • 2

2 Answers2

0

Check this book - http://www.redbooks.ibm.com/abstracts/sg248076.html?Open In chapter "5.2.4 Developing applications using timers" you should find all stuff needed.

UPDATE based on comment:

If you look to the book and to the log it shows:

[INFO ] CNTR4000I: The ITSOTimerApp.war EJB module in the ITSOTimerApp
application is starting.
[INFO ] CNTR0167I: The server is binding the com.ibm.itso.timers.TimerBean
interface of the TimerBean enterprise bean in the ITSOTimerApp.war module of
the ITSOTimerApp application. The binding location is:
java:global/ITSOTimerApp/TimerBean!com.ibm.itso.timers.TimerBean
[INFO ] DSRA8203I: Database product name : Apache Derby
[INFO ] DSRA8204I: Database product version : 10.8.2.3 - (1212722)
[INFO ] DSRA8205I: JDBC driver name : Apache Derby Embedded JDBC Driver
[INFO ] DSRA8206I: JDBC driver version : 10.8.2.3 - (1212722)
[INFO ] CNTR0219I: The server created 1 persistent automatic timer or timers
and 0 non-persistent automatic timer or timers for the ITSOTimerApp.war module.
TimerBean initialized

It creates db 'as needed' so if you dont have any persistent timers beans, the service will not be started nor db created.

Liberty in general follows lazy model and doesn't start unneeded services.

So create sample application and then your DB will be created. There is no need to create database nor connection to database when no one is requesting for it.

Gas
  • 17,601
  • 4
  • 46
  • 93
  • my question is this derby DB (would it be a dir on the Filesystem?) if so, shouldn't it get created when i startup the openliberty jvm without having deployed the application? – Daniyal Apr 06 '21 at 12:11
  • DB is critical if you think of any HA solution for your timer tasks to failover. But instead of Derby, I'd suggest to utilize your 'application' database. Check this article that mentions some new features for persistent timers - [Open Liberty 20.0.0.5 brings updates to EJB persistent timers coordination and failover across members](https://developers.redhat.com/blog/2020/05/13/open-liberty-20-0-0-5-brings-updates-to-ejb-persistent-timers-coordination-and-failover-across-members/) – Gas Apr 06 '21 at 15:14
  • I deployed application which uses derby (works on websphere liberty) but i migrated it to new server and deployed the application on openliberty and i don't see derby connection details in the logs during startup... (posted above my setup).. i added the ejb-feature as well... still no luck – Daniyal Apr 29 '21 at 13:09
  • These are `INFO` level messages, by default server is set to `AUDIT`, so make sure you have info logging enabled in `server.xml` like this: `` – Gas Apr 29 '21 at 18:32
0

In general, it is not advisable to use Derby Embedded database for persistent EJB timers due to limitations of Derby Embedded that all connections use the same class loader (implying the same JVM as well). This means you cannot leverage the failover capability (missedTaskThreshold setting) or even have multiple servers connected to the database at all. If you decide to use a Derby Embedded database, it means that you are limiting yourself to a single server. You can decide for yourself if that is acceptable based on what your needs are.

In the case of the example configuration you gave, it doesn't work because the EJB persistent timers feature in Liberty has no way of knowing that you dataSource, "DefaultDerbyDatasource" with jndiName "jdbc/defaultDatasource" is the data source that it ought to use. Also, it is incorrect to specify transactional="false" on the data source that you want EJB persistent timers to use because EJB persistent timers are transactional in nature.

I assume that what you are intending to do is configure the Java EE default data source and expecting EJB persistent timers to use it. That approach will work, except that you'll need to configure the Java EE default data source, you need to specify the id as "DefaultDataSource".

Here is an example that switches your configured data source to the Java EE default data source and removes the transactional="false" config,

  <library id="DerbyLib">
    <fileset dir="/tmp/derby/lib" includes="derby.jar"/>
  </library>
  <dataSource id="DefaultDataSource" jndiName="jdbc/defaultDatasource" statementCacheSize="10">
    <jdbcDriver libraryRef="DerbyLib"/>
    <properties.derby.embedded createDatabase="create" databaseName="/tmp/sample.ejbtimer.db" shutdownDatabase="false"/>
    <containerAuthData user="user1" password="derbyuser" />
  </dataSource>

By default, the EJB persistent timers feature should create database tables once the application runs and the EJB module is used. However, you may be able to verify the configuration prior to that point by running the ddlgen utility (after correcting the configuration as above)

https://www.ibm.com/docs/en/was-liberty/base?topic=line-running-ddlgen-utility

which gives you the opportunity to see the DDL that it will use and optionally to run it manually (which is useful if you turned off automatic table creation via <databaseStore id="defaultDatabaseStore" createTables="false"/> )

njr
  • 3,399
  • 9
  • 7