]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache.clear() on LMDB: be more strict about transactions
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 4 Sep 2017 12:48:41 +0000 (14:48 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 4 Sep 2017 12:52:04 +0000 (14:52 +0200)
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.

lib/cdb_lmdb.c

index 23e2850ac36edd1c0c8f95ada66a17dfd7844588..040ef44b1818c5f00ec8145bce836b98461fa490 100644 (file)
@@ -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.