Skip to content

Possible inconsistency on persistence layer initialization, #4656

Open
@lo92fr

Description

@lo92fr

Hello All,

I'm currently working on the Linky binding, try to fix a reliability issue I've got with timeseries handling on the binding.

The binding exposes 4 different time series 👍

  • Daily Consumptions
  • Weekly Consumptions
  • Monthly Consumptions
  • Yearly Consumptions.

What I observe is that when I start the binding 👍

  • Sometimes All 4 timeseries are correctly initialized.
  • Sometimes only 1 or 2 timeseries are correctly initialized, over are empty.
  • Sometimes All 4 timeseries are empty.

I first was thinking of course it was an error in my binding.
But after trace the issue, I've found the following issues:

I put a trace on GenericItem::applyTimeSeries(), and one another trace in
PersistenceManageImpl:timeSeriesUpdated().

Normally, appyTimeSeries should called PersistentManagerImple.timeSeriesUpdated().

But what I find is that sometimes, the timeSeriesListeners in applyTimeSeries is not initialize when applyTimeSeries is called. It seems to come mainly of the fact that there is a lot of item in the registry, and the loop in PeristenceManagerImpl:allItemsChaned is not fully end when the timeseries update event occurs.

@OverRide
public void allItemsChanged(Collection oldItemNames) {
itemRegistry.getItems().forEach(this::added);
}

Of course, I can delay a little bit my addon initialization to prevent this condition.
But it seems strange that there is not some sort of locking / protection in the PersistenceManagerImpl to prevent this.

I take a full trace to explain more in details what happened

What we can see is that:

  • at 10:48:41.531 : PersistenceManagerImpl.onReadyMarkerAdded() : the PersistenceManagerImpl is start a little after my binding initialization.
    This function launch the loop to register the persistence listenner on all items.

  • at 10:49:05.305, the loop only end at this point, near the end of the trace. The item registry contains around ~500 entries.

  • at 10:48:44.314 : the binding start to send timeseries update.

  • at 10:48:44.958 : we receive event in the core for timeseries update, but at this point, the timeseries listener is not yet initialized.

  • at 10:48:45.010 : for another timeseries, this time listener is correctly initialized !

  • at 10:48:45.319 : we see that only Month timeseries are correctly handle.

____________________________
Welcome to Apache Felix Gogo

g! 

10:48:27.499 [INFO ] [org.openhab.core.Activator          ] - Starting openHAB 5.0.0 (Unknown Build No.)

...

10:48:32.119 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Linky.items'

...

10:48:37.974 [DEBUG] [rnal.discovery.LinkyDiscoveryService] - Start Linky device background discovery
10:48:37.977 [DEBUG] [nal.handler.BridgeLocalSerialHandler] - isInitialized() = false
10:48:37.985 [DEBUG] [ernal.handler.ThingLinkyLocalHandler] - Initializing Linky handler for 21454992660003
10:48:38.013 [DEBUG] [rnal.handler.BridgeRemoteBaseHandler] - Initializing Linky API bridge handler.


10:48:38.103 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - ThingLinkyRemoteHandler, startLevel: 10

10:48:38.126 [DEBUG] [rnal.handler.ThingLinkyRemoteHandler] - Initializing Linky handler for 21454992660003

10:48:38.126 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - ThingLinkyRemoteHandler.initialize(), startLevel: 10

// PersistenceManagerImpl: onReadyMarkerAdded, line 382
10:48:41.531 [INFO ] [ence.internal.PersistenceManagerImpl] - PersistenceManagerImpl.onReadyMarkerAdded()

10:48:41.593 [INFO ] [openhab.event.StartlevelEvent       ] - Startlevel '20' reached.
10:48:41.594 [INFO ] [openhab.event.StartlevelEvent       ] - Startlevel '30' reached.
10:48:41.594 [INFO ] [openhab.event.StartlevelEvent       ] - Startlevel '40' reached.
10:48:41.594 [INFO ] [openhab.event.StartlevelEvent       ] - Startlevel '50' reached.
10:48:41.594 [INFO ] [openhab.event.StartlevelEvent       ] - Startlevel '70' reached.

// Linky pooling event loop start
10:48:43.131 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - ThingLinkyRemoteHandler.pooling(), startLevel: 70

// And update data
10:48:43.131 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - updateData() called
10:48:43.618 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - updateEnergyData() called

// ========================= Send the timeseries from Linky addon, startLevel = 70
10:48:44.314 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - ThingLinkyRemoteHandler.updateTimeSeries(), startLevel: 70
10:48:44.318 [DEBUG] [rnal.handler.ThingLinkyRemoteHandler] - Send timeseries channel (21454992660003) linky-remote-daily consumption with org.openhab.core.types.TimeSeries@4529b896
10:48:44.441 [INFO ] [openhab.event.ItemTimeSeriesEvent   ] - Item 'Linky_Melody_Daily_Conso_Day' shall process timeseries [Entry[timestamp=2022-03-18T23:00:00Z, state=72.857 kWh],.... ]

10:48:44.545 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - ThingLinkyRemoteHandler.updateTimeSeries(), startLevel: 70
10:48:44.545 [DEBUG] [rnal.handler.ThingLinkyRemoteHandler] - Send timeseries channel (21454992660003) linky-remote-weekly consumption with org.openhab.core.types.TimeSeries@82c686c5
10:48:44.556 [INFO ] [openhab.event.ItemTimeSeriesEvent   ] - Item 'Linky_Melody_Weekly_Conso_Week' shall process timeseries [Entry[timestamp=2022-03-18T23:00:00Z, state=155.284 kWh],... ]

10:48:44.584 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - ThingLinkyRemoteHandler.updateTimeSeries(), startLevel: 70
10:48:44.584 [DEBUG] [rnal.handler.ThingLinkyRemoteHandler] - Send timeseries channel (21454992660003) linky-remote-monthly consumption with org.openhab.core.types.TimeSeries@b2bd36c4

10:48:44.586 [INFO ] [rnal.handler.ThingLinkyRemoteHandler] - ThingLinkyRemoteHandler.updateTimeSeries(), startLevel: 70
10:48:44.586 [DEBUG] [rnal.handler.ThingLinkyRemoteHandler] - Send timeseries channel (21454992660003) linky-remote-yearly consumption with org.openhab.core.types.TimeSeries@c985d64d
10:48:44.590 [INFO ] [openhab.event.ItemTimeSeriesEvent   ] - Item 'Linky_Melody_Monthly_Conso_Month' shall process timeseries [Entry[timestamp=2022-02-28T23:00:00Z, state=838.923 kWh]...]
10:48:44.590 [INFO ] [openhab.event.ItemTimeSeriesEvent   ] - Item 'Linky_Melody_Yearly_Conso_Year' shall process timeseries [Entry[timestamp=2021-12-31T23:00:00Z, state=0 kWh], ...]


// Receive timeseries event on item side and apply



// Persitence listener not registerd for Daily timeseries : GenericItem.applyTimeSeries(), line 308
10:48:44.940 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : Linky_Melody_Daily_Conso_Day
10:48:44.958 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : listenerSize:0
10:48:44.979 [INFO ] [hab.event.ItemTimeSeriesUpdatedEvent] - Item 'Linky_Melody_Daily_Conso_Day' updated timeseries [Entry[timestamp=2022-03-18T23:00:00Z, state=72.857], ...]


// Persitence listener not registerd for Weekly timeseries : GenericItem.applyTimeSeries(), line 308
10:48:44.982 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : Linky_Melody_Weekly_Conso_Week
10:48:44.986 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : listenerSize:0
10:48:44.992 [INFO ] [hab.event.ItemTimeSeriesUpdatedEvent] - Item 'Linky_Melody_Weekly_Conso_Week' updated timeseries [Entry[timestamp=2022-03-18T23:00:00Z, state=155.284],....]


// Persitence listener  registerd for Monthly timeseries : GenericItem.applyTimeSeries(), line 308
10:48:45.008 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : Linky_Melody_Monthly_Conso_Month
10:48:45.010 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : listenerSize:1
10:48:45.014 [INFO ] [hab.event.ItemTimeSeriesUpdatedEvent] - Item 'Linky_Melody_Monthly_Conso_Month' updated timeseries [Entry[timestamp=2022-02-28T23:00:00Z, state=838.923], ...]


// Persistence listener  registerd for Yearly timeseries : GenericItem.applyTimeSeries(), line 308
10:48:45.033 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : Linky_Melody_Yearly_Conso_Year
10:48:45.035 [INFO ] [org.openhab.core.items.GenericItem  ] - GenericItem.applyTimeSeries() : listenerSize:0
10:48:45.037 [INFO ] [hab.event.ItemTimeSeriesUpdatedEvent] - Item 'Linky_Melody_Yearly_Conso_Year' updated timeseries [Entry[timestamp=2021-12-31T23:00:00Z, state=0], ...]


// Only Month timeseries is update because of missing listener
// PersistenceManagerImpl.timeSeriesUpdated, line 338
10:48:45.319 [INFO ] [ence.internal.PersistenceManagerImpl] - PersistenceManagerImpl.timeSeriesUpdated() : Linky_Melody_Monthly_Conso_Month


10:48:46.595 [INFO ] [openhab.event.StartlevelEvent       ] - Startlevel '80' reached.
10:48:46.595 [INFO ] [openhab.event.StartlevelEvent       ] - Startlevel '100' reached.

..

// PersistenceManagerImpl: onReadyMarkerAdded, line 388
10:49:05.305 [INFO ] [ence.internal.PersistenceManagerImpl] - PersistenceManagerImpl.onReadyMarkerAdded():end()

Your Environment

  • Openhab 5.0 snapshoot dev from 18 March
  • Windows OS
  • Eclipse Dev setup
  • Persistence layer is influxdb2 2.7.11 on Fedora 41

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behavior of the Core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions