OH3 Test for completion of restoreOnStartup

I have a rule that I want to make sure does not run until AFTER my persistence services (a combination of rrd4j and mapdb) have completed the restoreOnStartup process.

Is there a way I can query the service to determine if it has finished restoring items on startup?


If you have installed mapdb, use it to restore everything that is wanted. It is purpose made for the job. Configure other services not to restore.

Nope. Using mapdb should ensure it completes quite promptly.

I use rrd4j for historical data for chart items. I use mapdb because rrd4j does not persist strings (and mapdb does not do historical data for charts). Ideally, I would only use one persistence service to do both jobs. Should I be using a different persistence service?

The issue I have, is that restoreOnStartup is not complete by the time my cron-based rule executes and lots of items are still NULL. If I could detect that restoreOnStartup is still going, my cron-based rule could just wait.

Not at all. As you say, some are better at one thing than another; use a combination.

But manage your chosen combination.

Mapdb is good at restore - use it to restore everything that you want restored. It doesn’t matter if any of those Items are being also persisted by other services.

rrd4j is good for charting, use it for that. But by default it persists everything numeric. This slows it down. Ease some load by choosing what to persist carefully. Save some startup confusion by not letting it restore Items (Mapdb already doing that for you)

This stuff does require some thought and manual configuring, once you have grown beyond a trivial configuration.

You can write rules to detect and avoid processing NULL states. That should be sifficient for periodic cron rules.
It’s one-time startup rules are the nuisance - if its not yet ready, you might have to reschedule a retry somehow.

OK. Thanks. I think I get it now - I had to turn my thinking on its head.

I use mapdb to persist all items and perform the restoreOnStartup function. I then use rrd4j to persist just those items I need to chart (I added those items to a group called gRRD4j).

My mapdb.persist now looks like:

Strategies {
  default = everyChange

Items {
  * : strategy = everyChange, restoreOnStartup

And my rrd4j.persist looks like:

Strategies {
  everyMinute : "30 * * * * ?"
  default = everyChange

Items {
  gRRD4j* : strategy = everyChange, everyMinute

For my rules, all my targeted items have names that start with “MP” and should never be NULL, so my cron-based rule now checks all my items and returns if any of them are NULL (which indicates that restoreOnStartup is still going). The check I am doing is:

        // Make sure all the items that start with MP are not NULL
        // If any are NULL, it probably means that startup is not complete
        // and we need to wait until the Persistence Service doing restoreOnStartup completes
        var Number i = 0
        ScriptServiceUtil.getItemRegistry.getItems().forEach[ item |
                if (item.name.startsWith("MP") && item.state === NULL) {
                        i = i + 1
                        logDebug("MP","ManagePower: #" + i + " " + item.name + " is " + item.state)
        if (i > 0) {
                logDebug("MP","ManagePower: There are " + i + " items which start with MP and are NULL - startup not complete")
                logDebug("MP","ManagePower: Early return")

Works for me!!!

1 Like