lucaong / cubdb

Elixir embedded key/value database
Apache License 2.0
556 stars 23 forks source link

Add CubDB.Tx.refetch/3 #54

Closed lucaong closed 2 years ago

lucaong commented 2 years ago

The function refetch/3 checks if an entry has been written since the point in time represented by the given snapshot. If not, it returns :unchanged, otherwise it fetches the entry from the transaction.

The check if the entry was written is performed without reading the whole entry from disk, and instead only looking at index pages.

This function can be useful to implement optimistic concurrency control, when one computes the update to an entry outside of a transaction to avoid blocking writers, then opens a transaction and checks if the value changed in the meanwhile (and if so, recomputes the update). In these cases, using refetch/3 can improve performance, especially when the value is large, by avoiding to read the value from disk if CubDB can determine that it was not written by looking just at the index pages.