From: Vladimír Čunát Date: Mon, 4 Sep 2017 10:51:47 +0000 (+0200) Subject: cache.clear() on LMDB: first try mdb_drop() X-Git-Tag: v1.4.0~9^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4356f93579982b0f59feaa269f1aa2bf2cefa7be;p=thirdparty%2Fknot-resolver.git cache.clear() on LMDB: first try mdb_drop() It's certainly a cleaner way. --- diff --git a/lib/cdb_lmdb.c b/lib/cdb_lmdb.c index 11d0561e7..ff6c09733 100644 --- a/lib/cdb_lmdb.c +++ b/lib/cdb_lmdb.c @@ -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.