From 5fb94e3efc6efbbee8ce52f6e0146d9571fc5187 Mon Sep 17 00:00:00 2001 From: Gary Lockyer Date: Mon, 30 Mar 2020 12:08:30 +1300 Subject: [PATCH] lib ldb: lmdb clear stale readers on write txn start In use process failures and Bind9 shut downs leave stale entries in the lmdb reader table. This can result in lmdb filling it's database file, as the free list can not be reclaimed due to the stale reader. In this fix we call mdb_reader_check at the start of each transaction, to free any stale readers. As the default maximum number of readers is 127, this should not impact on performance to any great extent. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14330 Signed-off-by: Gary Lockyer Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Tue Mar 31 01:26:07 UTC 2020 on sn-devel-184 (cherry picked from commit 89041a6d18a1d091ea713e6986cac5ca66c2b481) --- lib/ldb/ldb_mdb/ldb_mdb.c | 17 +++++++++++++++++ lib/ldb/tests/ldb_lmdb_free_list_test.c | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ldb/ldb_mdb/ldb_mdb.c b/lib/ldb/ldb_mdb/ldb_mdb.c index 6c679c214b8..1187aba578a 100644 --- a/lib/ldb/ldb_mdb/ldb_mdb.c +++ b/lib/ldb/ldb_mdb/ldb_mdb.c @@ -641,6 +641,23 @@ static int lmdb_transaction_start(struct ldb_kv_private *ldb_kv) return LDB_ERR_PROTOCOL_ERROR; } + /* + * Clear out any stale readers + */ + { + int stale; + mdb_reader_check(lmdb->env, &stale); + if (stale > 0) { + ldb_debug( + lmdb->ldb, + LDB_DEBUG_ERROR, + "LMDB Stale readers, deleted (%d)", + stale); + } + } + + + ltx_head = lmdb_private_trans_head(lmdb); tx_parent = lmdb_trans_get_tx(ltx_head); diff --git a/lib/ldb/tests/ldb_lmdb_free_list_test.c b/lib/ldb/tests/ldb_lmdb_free_list_test.c index fe78e3ab702..9b295460730 100644 --- a/lib/ldb/tests/ldb_lmdb_free_list_test.c +++ b/lib/ldb/tests/ldb_lmdb_free_list_test.c @@ -617,7 +617,12 @@ static void test_free_list_stale_reader(void **state) ret = ldb_kv->kv_ops->finish_write(ldb_kv); assert_int_equal(ret, LDB_SUCCESS); } - assert_int_equal(ret, LDB_ERR_BUSY); + /* + * We now do an explicit clear of stale readers at the start of a + * write transaction so should not get LDB_ERR_BUSY any more + * assert_int_equal(ret, LDB_ERR_BUSY); + */ + assert_int_equal(ret, LDB_SUCCESS); assert_int_not_equal(i, 0); /* -- 2.47.2