From: Vladimír Čunát Date: Mon, 4 Sep 2017 12:48:41 +0000 (+0200) Subject: cache.clear() on LMDB: be more strict about transactions X-Git-Tag: v1.4.0~9^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10691bf05127b815ef832e5f8d8df682e7e4c618;p=thirdparty%2Fknot-resolver.git cache.clear() on LMDB: be more strict about transactions In particular, don't keep even a reset read-only transaction. This doesn't help with that MDB_BAD_TXN, but still it seems better. --- diff --git a/lib/cdb_lmdb.c b/lib/cdb_lmdb.c index 23e2850ac..040ef44b1 100644 --- a/lib/cdb_lmdb.c +++ b/lib/cdb_lmdb.c @@ -326,9 +326,6 @@ static int cdb_count(knot_db_t *db) static int cdb_clear(knot_db_t *db) { struct lmdb_env *env = db; - /* Always attempt to commit write transactions in-flight. */ - (void) cdb_sync(db); - /* First try mdb_drop() to clear the DB; this may fail with ENOSPC. */ { MDB_txn *txn = NULL; @@ -345,6 +342,13 @@ static int cdb_clear(knot_db_t *db) kr_log_info("[cache] clearing error, falling back\n"); } + /* We are about to switch to a different file, so end all txns, to be sure. */ + (void) cdb_sync(db); + if (env->txn.ro) { + mdb_txn_abort(env->txn.ro); + env->txn.ro = NULL; + } + /* Since there is no guarantee that there will be free * pages to hold whole dirtied db for transaction-safe clear, * we simply remove the database files and reopen.