From: Remi Gacogne Date: Fri, 25 Jun 2021 10:06:42 +0000 (+0200) Subject: dnsdist: Add support for opening the LMDB database with `MDB_NOLOCK` X-Git-Tag: dnsdist-1.7.0-alpha1~87^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bc940e096552c0c7d8ea3e4034ebb216c9874bf;p=thirdparty%2Fpdns.git dnsdist: Add support for opening the LMDB database with `MDB_NOLOCK` --- diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index c3bd5e20c4..b4b616c118 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -518,7 +518,7 @@ const std::vector g_consoleKeywords{ { "newFrameStreamTcpLogger", true, "addr [, options]", "create a FrameStream logger object writing to a TCP address (addr should be ip:port), to use with `DnstapLogAction()` and `DnstapLogResponseAction()`" }, { "newFrameStreamUnixLogger", true, "socket [, options]", "create a FrameStream logger object writing to a local unix socket, to use with `DnstapLogAction()` and `DnstapLogResponseAction()`" }, #ifdef HAVE_LMDB - { "newLMDBKVStore", true, "fname, dbName", "Return a new KeyValueStore object associated to the corresponding LMDB database" }, + { "newLMDBKVStore", true, "fname, dbName [, noLock]", "Return a new KeyValueStore object associated to the corresponding LMDB database" }, #endif { "newNMG", true, "", "Returns a NetmaskGroup" }, { "newPacketCache", true, "maxEntries[, maxTTL=86400, minTTL=0, temporaryFailureTTL=60, staleTTL=60, dontAge=false, numberOfShards=1, deferrableInsertLock=true, options={}]", "return a new Packet Cache" }, diff --git a/pdns/dnsdistdist/dnsdist-kvs.hh b/pdns/dnsdistdist/dnsdist-kvs.hh index d75972b367..37ac34cab3 100644 --- a/pdns/dnsdistdist/dnsdist-kvs.hh +++ b/pdns/dnsdistdist/dnsdist-kvs.hh @@ -165,7 +165,7 @@ public: class LMDBKVStore: public KeyValueStore { public: - LMDBKVStore(const std::string& fname, const std::string& dbName): d_env(fname.c_str(), MDB_NOSUBDIR|MDB_RDONLY, 0600), d_dbi(d_env.openDB(dbName, 0)), d_fname(fname), d_dbName(dbName) + LMDBKVStore(const std::string& fname, const std::string& dbName, bool noLock=false): d_env(fname.c_str(), noLock ? MDB_NOSUBDIR|MDB_RDONLY|MDB_NOLOCK : MDB_NOSUBDIR|MDB_RDONLY, 0600), d_dbi(d_env.openDB(dbName, 0)), d_fname(fname), d_dbName(dbName) { } diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-kvs.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-kvs.cc index bf26914bc7..fd7b827e00 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-kvs.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-kvs.cc @@ -40,11 +40,11 @@ void setupLuaBindingsKVS(LuaContext& luaCtx, bool client) }); #ifdef HAVE_LMDB - luaCtx.writeFunction("newLMDBKVStore", [client](const std::string& fname, const std::string& dbName) { + luaCtx.writeFunction("newLMDBKVStore", [client](const std::string& fname, const std::string& dbName, boost::optional noLock) { if (client) { return std::shared_ptr(nullptr); } - return std::shared_ptr(new LMDBKVStore(fname, dbName)); + return std::shared_ptr(new LMDBKVStore(fname, dbName, noLock.get_value_or(false))); }); #endif /* HAVE_LMDB */ diff --git a/pdns/dnsdistdist/docs/reference/kvs.rst b/pdns/dnsdistdist/docs/reference/kvs.rst index 8519c88285..dbdfaacdec 100644 --- a/pdns/dnsdistdist/docs/reference/kvs.rst +++ b/pdns/dnsdistdist/docs/reference/kvs.rst @@ -129,12 +129,16 @@ If the value found in the LMDB database for the key '\\8powerdns\\3com\\0' was ' :param string filename: The path to an existing CDB database :param int refreshDelays: The delay in seconds between two checks of the database modification time. 0 means disabled -.. function:: newLMDBKVStore(filename, dbName) -> KeyValueStore +.. function:: newLMDBKVStore(filename, dbName [, noLock]) -> KeyValueStore .. versionadded:: 1.4.0 + .. versionchanged:: 1.7.0 + Added the optional parameter ``noLock``. + Return a new KeyValueStore object associated to the corresponding LMDB database. The database must have been created - with the ``MDB_NOSUBDIR`` flag. + with the ``MDB_NOSUBDIR`` flag. Since 1.7.0, the database is opened with the ``MDB_READONLY`` flag, and optionally with ``MDB_NOLOCK`` if ``noLock`` is set to true. :param string filename: The path to an existing LMDB database created with ``MDB_NOSUBDIR`` :param string dbName: The name of the database to use + :param bool noLock: Whether to open the database with the ``MDB_NOLOCK`` flag. Default is false