Makes the transaction's writes durable and visible to other readers, and ends the transaction.
Arguments
- txn
An
mdbx_txnobject, frommdbx_txn_begin().
Details
Unlike mdbx_txn_abort(), this is not idempotent: committing an already-finished
transaction is an error, because the second call cannot do what it appears
to. Note also that a commit which cannot complete is turned into an abort by
'libmdbx' — if this raises an error, the transaction has still ended, and its
writes are gone.
Some failures inside a transaction end it there and then. A rejected key or
value size (mdbx_put() returning MDBX_BAD_VALSIZE) is just that one
operation failing, and the transaction carries on. A failure that exhausts
the map (MDBX_MAP_FULL) instead marks the transaction unusable: every later
operation fails with MDBX_BAD_TXN, and the commit reports that the whole
transaction was rolled back rather than committed. mdbx_txn_state() reads
"failed" from the moment that happens, and "aborted" once the rollback
has ended it.
Examples
path <- tempfile(fileext = ".mdbx")
env <- mdbx_env_open(path)
txn <- mdbx_txn_begin(env, write = TRUE)
mdbx_txn_commit(txn)
mdbx_txn_state(txn)
#> [1] "committed"
mdbx_env_close(env)
unlink(c(path, paste0(path, "-lck")))