]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth lmdb: serialise LMDBBackend construction 9933/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 11 Jan 2021 11:27:41 +0000 (12:27 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 11 Jan 2021 12:21:35 +0000 (13:21 +0100)
modules/lmdbbackend/lmdbbackend.cc

index 9cf2a90d8d60087cc03a4a5070089e67a3a51294..dea714d4f97090c2d82c28e35bd412e7d5e0c7fa 100644 (file)
@@ -32,6 +32,7 @@
 #include "pdns/logger.hh"
 #include "pdns/version.hh"
 #include "pdns/arguments.hh"
+#include "pdns/lock.hh"
 #include <boost/archive/binary_oarchive.hpp>
 #include <boost/archive/binary_iarchive.hpp>
 #include <boost/serialization/vector.hpp>
 // List the class version here. Default is 0
 BOOST_CLASS_VERSION(LMDBBackend::KeyDataDB, 1)
 
+static std::mutex s_lmdbOpenUpgradeLock;
+
 LMDBBackend::LMDBBackend(const std::string& suffix)
 {
+  // we lock to avoid a race condition when we do a schema upgrade during startup
+  // non-upgrade startups should be very cheap so this lock should not hurt performance
+  std::lock_guard<std::mutex> l(s_lmdbOpenUpgradeLock);
+
   setArgPrefix("lmdb"+suffix);
   
   string syncMode = toLower(getArg("sync-mode"));
@@ -544,6 +551,8 @@ std::shared_ptr<LMDBBackend::RecordsROTransaction> LMDBBackend::getRecordsROTran
 
 bool LMDBBackend::upgradeToSchemav3()
 {
+  g_log << Logger::Info<<"Upgrading LMDB schema"<<endl;
+
   for(auto i = 0; i < d_shards; i++) {
     string filename = getArg("filename")+"-"+std::to_string(i);
     if (rename(filename.c_str(), (filename+"-old").c_str()) < 0) {