]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache.clear() on LMDB: first try mdb_drop()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 4 Sep 2017 10:51:47 +0000 (12:51 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 4 Sep 2017 10:58:24 +0000 (12:58 +0200)
It's certainly a cleaner way.

lib/cdb_lmdb.c

index 11d0561e79b708e7c6c2335dd8d3cd7e1aaccfb6..ff6c0973373cc6ef3ba92a785d56fd06657eda2a 100644 (file)
@@ -327,6 +327,22 @@ static int cdb_clear(knot_db_t *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;
+               int ret = txn_get(env, &txn, false);
+               if (ret == kr_ok()) {
+                       ret = lmdb_error(mdb_drop(txn, env->dbi, 0));
+                       if (ret == kr_ok()) {
+                               ret = cdb_sync(db);
+                       }
+                       if (ret == kr_ok()) {
+                               return ret;
+                       }
+               }
+               kr_log_info("[cache] clearing error, falling back\n");
+       }
+
        /* 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.