]> granicus.if.org Git - pdns/commitdiff
move (DNSSEC) metadata cache to a read/write lock interface, as suggested in ticket...
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 6 Oct 2012 10:20:14 +0000 (10:20 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 6 Oct 2012 10:20:14 +0000 (10:20 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2768 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dbdnsseckeeper.cc
pdns/dnsseckeeper.hh

index 34c0bf737ae3713d0cbffec6252a8c9588ea754c..04072875775a52297843655b7a1844c18da09b04 100644 (file)
@@ -40,8 +40,8 @@ using namespace boost::assign;
 
 DNSSECKeeper::keycache_t DNSSECKeeper::s_keycache;
 DNSSECKeeper::metacache_t DNSSECKeeper::s_metacache;
-pthread_mutex_t DNSSECKeeper::s_metacachelock = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t DNSSECKeeper::s_keycachelock = PTHREAD_MUTEX_INITIALIZER;
+pthread_rwlock_t DNSSECKeeper::s_metacachelock = PTHREAD_RWLOCK_INITIALIZER;
+pthread_rwlock_t DNSSECKeeper::s_keycachelock = PTHREAD_RWLOCK_INITIALIZER;
 AtomicCounter DNSSECKeeper::s_ops;
 time_t DNSSECKeeper::s_last_prune;
 
@@ -55,7 +55,7 @@ bool DNSSECKeeper::isSecuredZone(const std::string& zone)
   }
 
   {
-    Lock l(&s_keycachelock);
+    ReadLock l(&s_keycachelock);
     keycache_t::const_iterator iter = s_keycache.find(zone);
     if(iter != s_keycache.end() && iter->d_ttd > (unsigned int)time(0)) { 
       if(iter->d_keys.empty())
@@ -109,20 +109,20 @@ bool DNSSECKeeper::addKey(const std::string& name, bool keyOrZone, int algorithm
 
 void DNSSECKeeper::clearAllCaches() {
   {
-    Lock l(&s_keycachelock);
+    WriteLock l(&s_keycachelock);
     s_keycache.clear();
   }
-  Lock l(&s_metacachelock);
+  WriteLock l(&s_metacachelock);
   s_metacache.clear();
 }
 
 void DNSSECKeeper::clearCaches(const std::string& name)
 {
   {
-    Lock l(&s_keycachelock);
+    WriteLock l(&s_keycachelock);
     s_keycache.erase(name); 
   }
-  Lock l(&s_metacachelock);
+  WriteLock l(&s_metacachelock);
   pair<metacache_t::iterator, metacache_t::iterator> range = s_metacache.equal_range(name);
   while(range.first != range.second)
     s_metacache.erase(range.first++);
@@ -200,7 +200,7 @@ void DNSSECKeeper::getFromMeta(const std::string& zname, const std::string& key,
   }
 
   {
-    Lock l(&s_metacachelock); 
+    ReadLock l(&s_metacachelock); 
     
     metacache_t::const_iterator iter = s_metacache.find(tie(zname, key));
     if(iter != s_metacache.end() && iter->d_ttd > now) {
@@ -219,7 +219,7 @@ void DNSSECKeeper::getFromMeta(const std::string& zname, const std::string& key,
   nce.d_key= key;
   nce.d_value = value;
   { 
-    Lock l(&s_metacachelock);
+    WriteLock l(&s_metacachelock);
     replacing_insert(s_metacache, nce);
   }
 }
@@ -292,7 +292,7 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const std::string& zone, boost::tri
   }
 
   {
-    Lock l(&s_keycachelock);
+    ReadLock l(&s_keycachelock);
     keycache_t::const_iterator iter = s_keycache.find(zone);
       
     if(iter != s_keycache.end() && iter->d_ttd > now) { 
@@ -340,7 +340,7 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const std::string& zone, boost::tri
   kce.d_keys = allkeyset;
   kce.d_ttd = now + 30;
   {
-    Lock l(&s_keycachelock);
+    WriteLock l(&s_keycachelock);
     replacing_insert(s_keycache, kce);
   }
   
@@ -411,11 +411,11 @@ void DNSSECKeeper::cleanup()
 
   if(now.tv_sec - s_last_prune > (time_t)(30)) {
     {
-        Lock l(&s_metacachelock);
+        WriteLock l(&s_metacachelock);
         pruneCollection(s_metacache, ::arg().asNum("max-cache-entries"));
     }
     {
-        Lock l(&s_keycachelock);
+        WriteLock l(&s_keycachelock);
         pruneCollection(s_keycache, ::arg().asNum("max-cache-entries"));
     }
     s_last_prune=time(0);
index 0ef9e8b3d5da0ec15a390efd622eb9551ef1eb4c..9eb16b310e04de0ab61715817aee778290a422da 100644 (file)
@@ -156,8 +156,8 @@ private:
 
   static keycache_t s_keycache;
   static metacache_t s_metacache;
-  static pthread_mutex_t s_metacachelock;
-  static pthread_mutex_t s_keycachelock;
+  static pthread_rwlock_t s_metacachelock;
+  static pthread_rwlock_t s_keycachelock;
   static AtomicCounter s_ops;
   static time_t s_last_prune;
 };