]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add support for opening the LMDB database with `MDB_NOLOCK`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 25 Jun 2021 10:06:42 +0000 (12:06 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 25 Jun 2021 10:06:42 +0000 (12:06 +0200)
pdns/dnsdist-console.cc
pdns/dnsdistdist/dnsdist-kvs.hh
pdns/dnsdistdist/dnsdist-lua-bindings-kvs.cc
pdns/dnsdistdist/docs/reference/kvs.rst

index c3bd5e20c4e0318e881bbe25cb9ff27dccb05c3f..b4b616c118637a6da1b42614d6af4e1008926e7b 100644 (file)
@@ -518,7 +518,7 @@ const std::vector<ConsoleKeyword> 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" },
index d75972b3673241fd14d04b8e14dd7bbdada5b6a7..37ac34cab3ffa85dcff7c9b8464f5e1162e20602 100644 (file)
@@ -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)
   {
   }
 
index bf26914bc7e4f3a83a75ab595152447c49573bd2..fd7b827e00782d774f5836315f0e493e5bacd4be 100644 (file)
@@ -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<bool> noLock) {
     if (client) {
       return std::shared_ptr<KeyValueStore>(nullptr);
     }
-    return std::shared_ptr<KeyValueStore>(new LMDBKVStore(fname, dbName));
+    return std::shared_ptr<KeyValueStore>(new LMDBKVStore(fname, dbName, noLock.get_value_or(false)));
   });
 #endif /* HAVE_LMDB */
 
index 8519c8828501eb2094c153be8dc0c8ec805e8c2c..dbdfaacdec7cbdd455d8eefb9d8cee275fcb5c01 100644 (file)
@@ -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