Search code examples
databaselmdb

is data returned from lmdb invalidated after any change to the database?


the lmdb (Lightning Memory-Mapped Database) documentation mentions the following in regards to the validity of returned data:

Values returned from the database are valid only until a subsequent update operation, or the end of the transaction. Do not modify or free them, they commonly point into the database itself.

i am a bit confused about what "update operation" refers to in this case: does "update operation" mean any update operation on the database (for example changing another value, possibly from another thread), or only an update operation on the specific value?


Solution

  • It should probably say "... valid only until a subsequent update operation on the same transaction, or the end of the transaction."

    If you hold a read-only transaction another thread can't change the value while you hold the transaction, because otherwise it would be impossible to guarantee that you can copy the value successfully before another thread invalidates the value.

    So the value will remain valid while the transaction is opened, but don't keep read-only transactions open for a long time as it will cause the database to continuously grow on writes (space from removals can't be reused).