Persistence - I don't get it

Persistence - I don’t get it:

My Groups:

Group 						G_Numbers		"Numbers for Diagramms"
Group 						G_jdbc			"jdbc SQL"

It’s about these representative items

String	 	ActTime			"Zeit: [%s]"							(G_jdbc)
Number 		Presence_Num	"Anwesenheit Num [%s]"					(G_Numbers)
Switch 		Trigger_Debug	"Debug Trigger"							(G_jdbc)

I am using the following jdbc.persist file (on mariaDB):

Strategies {
        every5Minutes : "0 0/5 * * * ?"
        default = everyChange, restoreOnStartup
}

Items {
        G_jdbc* : strategy = everyChange, restoreOnStartup
        G_Numbers* : strategy = everyChange, restoreOnStartup, every5Minutes
}

Loading this persist creates an error:

2018-08-17 17:25:36.663 [ERROR] [.core.internal.folder.FolderObserver] - Error handling update of file '/etc/openhab2/persistence/jdbc.persist': null.
java.lang.NullPointerException: null

and leads to:
ActTime is a string and stored on everyChange = every minute (cron writes in a rule the actual time into this string) - this can be found correctly in the DB - right!
Presence_Num is a Number and should be stored every 5 Minutes into the DB (for Charts) - but it’s not - wrong
Trigger_Debug is a Switch set by cron every 30 min to verify persistence issues - it’s not stored in the DB - wrong

This jdbc.persist config is loaded without issues:

Refreshing model 'jdbc.persist'

Strategies {
        every5Minutes : "0 0/5 * * * ?"
        default = everyChange, restoreOnStartup
}

Items {
        G_jdbc* : strategy =
        G_Numbers* : strategy = every5Minutes
}

but leads to:
ActTime: This time it is stored every 5 minutes only - (the rule still changes this string every minute) - wrong
Presence_Num: Now it’s stored every 5 Minutes in the DB - right
Trigger_Debug is not written into the DB - wrong

This config also loads with an error:

 Error handling update of file '/etc/openhab2/persistence/jdbc.persist': null.
java.lang.NullPointerException: null
Strategies {
        every5Minutes : "0 0/5 * * * ?"
        default = everyChange, restoreOnStartup
}

Items {
        * : strategy = every5Minutes, everyChange, restoreOnStartup
}

and leads to:
ActTime: stored every minute - right
Presence_Num: Not stored - should be stored every 5 minutes according to the persist settings - wrong
Trigger_Debug: Not stored - should be stored every 5 minutes according to the persist settings - wrong

The only thing I want is to store numbers every 5 minutes and the other items (mostly strings and Switches) on changes only and restore on startup…

In my previous installations (1.8 / 2.0 / 2.1 / 2.2) I don’t remember such an inconsistent behaviour.
Any hint into the right direction is greatly appreciated.

Can you post full stack trace?

I use a different persistence so I may be wrong but should the above be everyMinute : “” without the 5 and the s at the end of Minuet.?

G_jdbc* : strategy =
        G_Numbers* : strategy = every5Minutes

G_jdbc* : strategy = " There is nothing here " and the same syntax with the 5 and s on the other item.

This is on purpose because the docs say:

// if no strategy is specified at the items below,
    // the default setting will be used.

every5Minutes is just a definition at the strategy part (I guess).
I must be the same syntax as used below at the items

As I mentioned before, I dont use this persistence, just trying to help if possible.
Here is an example of rrd4j and the reason I noticed the syntax was different.

Strategies {
	// for rrd chart cron strategy every minute
	everyMinute : "0 * * * * ?"
	// get data reduced for older values to keep database small
	everyHour : "0 0 * * * ?"
	everyDay : "0 0 0 * * ?"

	default = everyChange
}

Items {
	// additionally persist Items
	LivingRoom_Light_Temp : strategy = everyUpdate, everyMinute
	LivingRoom_Light_Humidity : strategy = everyUpdate, everyMinute
	Home_Sensor_Chart* : strategy = everyUpdate, everyMinute

Hope it helps, best of luck.

@H102
You don’t need everyHour and everyDay as you already have everyMinute
The rrd4j database will average the older data on it’s own to keep it small

@NCO
Have you tried:

Strategies {
        every5Minutes : "0 0/5 * * * ?"
        default = everyChange
}

Items {
        G_jdbc* : strategy = everyChange, restoreOnStartup
        G_Numbers* : strategy = everyChange, restoreOnStartup, every5Minutes
}

With only ONE parameter on the default?
As you don’t use it, it shouldn’t make a difference but maybe the parser has a different idea about it.

And after changing a .persist file, it is often the case that you need to restart OH for the changes to take effect.

Thanks.
I tried a restart / rebboot more than once.
Either without or with deleting the files in cache and tmp.
After startup Numbers got stored, if they change, but not in a 5 minutes period (for Charts).

This is why I played around with the persist file.

I will use your suggestion above to give it another try.
However, I’m concerned that only a start from scratch might help,
I did this a few times since I started with OH and it always takes ages (VPN, mosquitto, etc.) to get it back to the required state.
This will have a huge impact on the current WAF. :wink:

Sure:

2018-08-18 07:30:08.162 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'jdbc.persist'
2018-08-18 07:30:09.512 [ERROR] [.core.internal.folder.FolderObserver] - Error handling update of file '/etc/openhab2/persistence/jdbc.persist': null.
java.lang.NullPointerException: null
        at org.openhab.persistence.jdbc.db.JdbcBaseDAO.getState(JdbcBaseDAO.java:468) ~[?:?]
        at org.openhab.persistence.jdbc.db.JdbcBaseDAO.doGetHistItemFilterQuery(JdbcBaseDAO.java:343) ~[?:?]
        at org.openhab.persistence.jdbc.internal.JdbcMapper.getHistItemFilterQuery(JdbcMapper.java:154) ~[?:?]
        at org.openhab.persistence.jdbc.internal.JdbcPersistenceService.query(JdbcPersistenceService.java:201) ~[?:?]
        at org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate.query(QueryablePersistenceServiceDelegate.java:47) ~[?:?]
        at org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl.initialize(PersistenceManagerImpl.java:262) ~[?:?]
        at org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl.startEventHandling(PersistenceManagerImpl.java:377) ~[?:?]
        at org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl.addConfig(PersistenceManagerImpl.java:352) ~[?:?]
        at org.eclipse.smarthome.model.persistence.internal.PersistenceModelManager.addModel(PersistenceModelManager.java:110) ~[?:?]
        at org.eclipse.smarthome.model.persistence.internal.PersistenceModelManager.modelChanged(PersistenceModelManager.java:101) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:301) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:139) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:227) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:291) ~[?:?]
        at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3(WatchQueueReader.java:323) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]

I usually ignored these messages after changing something, because I though it might be timing related (like some rules got fired before the items have been declared during startup).

I get closer…

I have just put Presence_Num into a new Group with just this member. Changing the jdbc.persist accordingly lead to constant saving of Presence_Num into the DB every 5 Minutes.

Strategies {
        every5Minutes : "0 0/5 * * * ?"
        default = everyChange, restoreOnStartup
}

Items {
        G_jdbc* : strategy =
        G_Num* : strategy = every5Minutes
}

And I remember an issue from my previous steps into Openhab:
Sometimes I changed an items’ type after using it a while (String to DateTime, or Switch to String / Number or whatever).
This lead to a (obviously) fixed variable type in the DB and no values of the new type have been saved anymore. Unless I used a new item name or deleted the DB entry of this item entirely.
So I assume, that some (type changed) item in my items file is in the Group G_Numbers preventing all the entries.

Question:
Is this issue a case for all persistence solutions (mapdb, rrdj, and SQL DB based stuff) or just limited to SQL DB (in my case jdbc using mariaDB?

I had this same problem with influxdb but not with mapdb.
Inlfux db saves values in a typed database but not mapdb which saves only the last value.
So I assume that will be the case for ALL type databases
rrd4j only saves numbers so will not be affected