store icon indicating copy to clipboard operation
store copied to clipboard

provide method to test if an entity instance is stored

Open nimo23 opened this issue 1 year ago • 5 comments

Is your feature request related to a problem? Please describe.

I want to write test cases to check if an entity instance is stored. However, it seems that there is no method in eclipse-store to check if an entity instance is stored. Such method can be also useful for other cases.

Describe the solution you'd like

Please provide a method something like

long StorageManager#isStored(Object o), which returns

  • 0 if entity instance is not stored
  • a UTC timestamp in milliseconds indicating when the data was last saved (or updated).

nimo23 avatar Oct 16 '24 16:10 nimo23

Small tip: You can use storageManager.persistenceManager().objectRegistry().lookupObjectId(s);. This returns the objectId if the object is stored, and -1 if the object is not in storage yet.

zdenek-jonas avatar Oct 16 '24 17:10 zdenek-jonas

@zdenek-jonas Thanks! I think this solves this issue, but we should keep in mind that in case of lazy storage (which is the default), the object ID is not always returned immediately. However, that's okay as I can switch to eager storage for test cases.

Is there a way to get a UTC timestamp in milliseconds indicating when the data was last saved (or updated) by eclipse-store? Maybe it's already stored somewhere internally for administration.

nimo23 avatar Oct 16 '24 22:10 nimo23

There is a time stamp but no simple way to get that. We write a time stamp to the storage transaction log file at every store. The time stamp is produced by a org.eclipse.store.storage.types.StorageTimestampProvider. The default implementation is org.eclipse.store.storage.types.StorageTimestampProvider.MonotonicTime. You may replace that with a custom implementation that allows you to get the last generated value. The StorageFoundation has a setter to setup that custom one:

EmbeddedStorageFoundation.New()
.setTimestampProvider(...)

hg-ms avatar Oct 17 '24 08:10 hg-ms

There is a time stamp but no simple way to get that.

It would be good if it could be done in a simpler way, for example with a method in storageManger#persistenceManager().objectRegistry():

lastStored(Object o) or getLastSync(Object o) with

  • 0 if entity instance is currently not stored
  • a UTC timestamp in milliseconds indicating when the data was last saved (or updated).

What do you think?

nimo23 avatar Oct 17 '24 13:10 nimo23

Many thanks for your proposal.

Adding an object specific time stamp would be a bigger feature that requires a detailed requirement analysis, I doubt that we will implement that in the near future.

I’m not sure if it helps but there is a logger available that can log every object store. To do so you need to enable the ‘org.eclipse.serializer.persistence.binary.types.BinaryStorer’ logger with log level ‘debug’

hg-ms avatar Oct 18 '24 10:10 hg-ms