microsoft / ManagedEsent

MIT License
244 stars 36 forks source link

Figuring out when PersistentDictionary is flushed to disk #17

Open Astralking opened 5 years ago

Astralking commented 5 years ago

So we have been having an issue in production with user sessions not being present in the PersistentDictionary after an obscure exception crashed the API.

After exhausting almost every avenue possible the only thing I'm left with is that whatever changes are made to the dictionary do not have a chance to be persisted to disk before the process Is terminated. Is there any way to tell, via logging or otherwise, when a none manual flush occurs? Please correct me if this isn't how it works but that's what I gather from the docs.

Thanks in advance

michaelthorp commented 5 years ago

You are likely correct in what is happening. PersistentDictionary uses lazy transactions (i.e. specifies the CommitTransactionGrbit.LazyFlush, which returns before it flushes the transaction to the log file. So a crash before this flush may lose whatever was not flushed.

The underlying database (ESENT) does have an option to do a callback when a flush to log happens, but PersistentDictionary does not use the callbacks.