Hello,
this might be a trivial question for you but I didn't find anything in the documentation nor any mention in the examples.
Basically I need to have an opportunity to call mdb_get while in write transaction. The sequence is smth like: - txn = mdb_txn_begin(flags=0) for i in 0..x: - v = mdb_get(txn, i) - mdb_put(txn, x+i, v) - mdb_put(txn, i, v+1) - mdb_txn_commit(txn)
Will it be always valid data? I'm running a stress test and didn't spot any issues so far. Though I might be extremely lucky today.
The DB is used in multi-threaded environment but the code illustrated above is protected with a mutex.
I tried to dig a bit into the lmdb internals but unfortunately didn't get any glue.
Thanks for your help, Dmytro
Dmytro Milinevskyy wrote:
Hello,
this might be a trivial question for you but I didn't find anything in the documentation nor any mention in the examples.
Which examples did you look at? mtest.c (and others) all operate this way already.
Basically I need to have an opportunity to call mdb_get while in write transaction. The sequence is smth like:
- txn = mdb_txn_begin(flags=0)
for i in 0..x: - v = mdb_get(txn, i) - mdb_put(txn, x+i, v) - mdb_put(txn, i, v+1)
- mdb_txn_commit(txn)
Will it be always valid data?
Yes.
On 12/05/15 19:36, Howard Chu wrote:
Dmytro Milinevskyy wrote:
Basically I need to have an opportunity to call mdb_get while in write transaction. The sequence is smth like:
- txn = mdb_txn_begin(flags=0)
for i in 0..x: - v = mdb_get(txn, i) - mdb_put(txn, x+i, v) - mdb_put(txn, i, v+1)
- mdb_txn_commit(txn)
Will it be always valid data?
Yes.
...No. I expect he means v = the MDB_val returned by mdb_get(). mdb_put() can modify the data it points at.
See the MDB_val documentation in ldmb.h: * 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.
On Mon, 2015-05-18 at 23:03 +0200, Hallvard Breien Furuseth wrote:
On 12/05/15 19:36, Howard Chu wrote:
Dmytro Milinevskyy wrote:
Basically I need to have an opportunity to call mdb_get while in write transaction. The sequence is smth like:
- txn = mdb_txn_begin(flags=0)
for i in 0..x: - v = mdb_get(txn, i) - mdb_put(txn, x+i, v) - mdb_put(txn, i, v+1)
- mdb_txn_commit(txn)
Will it be always valid data?
Yes.
...No. I expect he means v = the MDB_val returned by mdb_get(). mdb_put() can modify the data it points at.
See the MDB_val documentation in ldmb.h:
- 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.
What exactly does a subsequent update operation mean? Overwriting the value of the same key, or any mdb_put or mdb_cursor_put operation at all, regardless of which key they touch?
Timur Kristóf wrote:
On Mon, 2015-05-18 at 23:03 +0200, Hallvard Breien Furuseth wrote:
On 12/05/15 19:36, Howard Chu wrote:
Dmytro Milinevskyy wrote:
Basically I need to have an opportunity to call mdb_get while in write transaction. The sequence is smth like:
- txn = mdb_txn_begin(flags=0)
for i in 0..x: - v = mdb_get(txn, i) - mdb_put(txn, x+i, v) - mdb_put(txn, i, v+1)
- mdb_txn_commit(txn)
Will it be always valid data?
Yes.
...No. I expect he means v = the MDB_val returned by mdb_get(). mdb_put() can modify the data it points at.
Since he's using "v+1" in his example I assumed he's making a local copy of the returned values. Anyway, the plain answer to the question in the Subject is Yes.
See the MDB_val documentation in ldmb.h:
- 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.
What exactly does a subsequent update operation mean? Overwriting the value of the same key,
If we meant "same key" we would have said so.
or any mdb_put or mdb_cursor_put operation at all, regardless of which key they touch?
On Tue, 2015-05-19 at 17:05 +0100, Howard Chu wrote:
Timur Kristóf wrote:
On Mon, 2015-05-18 at 23:03 +0200, Hallvard Breien Furuseth wrote:
On 12/05/15 19:36, Howard Chu wrote:
Dmytro Milinevskyy wrote:
Basically I need to have an opportunity to call mdb_get while in write transaction. The sequence is smth like:
- txn = mdb_txn_begin(flags=0)
for i in 0..x: - v = mdb_get(txn, i) - mdb_put(txn, x+i, v) - mdb_put(txn, i, v+1)
- mdb_txn_commit(txn)
Will it be always valid data?
Yes.
...No. I expect he means v = the MDB_val returned by mdb_get(). mdb_put() can modify the data it points at.
Since he's using "v+1" in his example I assumed he's making a local copy of the returned values. Anyway, the plain answer to the question in the Subject is Yes.
See the MDB_val documentation in ldmb.h:
- 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.
What exactly does a subsequent update operation mean? Overwriting the value of the same key,
If we meant "same key" we would have said so.
Okay, thanks for the clarification!
or any mdb_put or mdb_cursor_put operation at all, regardless of which key they touch?