From 5acf2b126f4d2d2c4e07b2d160276f4729cbdcd2 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Fri, 19 Oct 2018 13:33:27 +0300 Subject: [PATCH] mdbx: backport - fix mdbx_dbi_sequence(). Change-Id: Ic620896ef42c1c2d85c07c146b72e773ab43a67d --- src/mdbx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mdbx.c b/src/mdbx.c index 70dd069b..1751087a 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -12356,6 +12356,15 @@ int mdbx_dbi_sequence(MDBX_txn *txn, MDBX_dbi dbi, uint64_t *result, if (unlikely(TXN_DBI_CHANGED(txn, dbi))) return MDBX_BAD_DBI; + if (unlikely(txn->mt_dbflags[dbi] & DB_STALE)) { + MDBX_cursor mc; + MDBX_xcursor mx; + /* Stale, must read the DB's root. cursor_init does it for us. */ + int rc = mdbx_cursor_init(&mc, txn, dbi, &mx); + if (unlikely(rc != MDBX_SUCCESS)) + return rc; + } + MDBX_db *dbs = &txn->mt_dbs[dbi]; if (likely(result)) *result = dbs->md_seq;