简体   繁体   English

从lmdb返回的数据在对数据库进行任何更改后是否无效?

[英]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: lmdb(闪电存储器映射数据库)文档在返回数据的有效性方面提到了以下内容:

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? 在这种情况下,我对“更新操作”指的是有些困惑:“更新操作”是指对数据库的任何更新操作(例如,更改另一个值,可能来自另一个线程),还是仅针对特定的更新操作值?

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). 因此,该值在事务打开时将保持有效,但不要长时间保持只读事务打开,因为它将导致数据库在写入时持续增长(无法重复使用删除操作中的空间)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM