Changeset 2328

Show
Ignore:
Timestamp:
01/04/12 10:42:47 (3 years ago)
Author:
peter
Message:

Implement domainmetadata cache pruning. Change (for ALL caches) meaning of "max-X-entries=0" from unlimited to actually mean 0.

Location:
trunk/pdns/pdns
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/cachecleaner.hh

    r1712 r2328  
    1212  unsigned int cacheSize=collection.size(); 
    1313 
    14   if(maxCached && cacheSize > maxCached) { 
     14  if(cacheSize > maxCached) { 
    1515    toTrim = cacheSize - maxCached; 
    1616  } 
  • trunk/pdns/pdns/dbdnsseckeeper.cc

    r2216 r2328  
    3131#include <boost/assign/list_inserter.hpp> 
    3232#include "base64.hh" 
     33#include "cachecleaner.hh" 
     34#include "arguments.hh" 
    3335 
    3436 
     
    4143pthread_mutex_t DNSSECKeeper::s_metacachelock = PTHREAD_MUTEX_INITIALIZER; 
    4244pthread_mutex_t DNSSECKeeper::s_keycachelock = PTHREAD_MUTEX_INITIALIZER; 
     45unsigned int DNSSECKeeper::s_ops; 
     46time_t DNSSECKeeper::s_last_prune; 
    4347 
    4448bool DNSSECKeeper::isSecuredZone(const std::string& zone)  
     
    4751    return true; 
    4852   
     53  if(!((s_ops++) % 100000)) { 
     54    cleanup(); 
     55  } 
     56 
    4957  { 
    5058    Lock l(&s_keycachelock); 
     
    178186  value.clear(); 
    179187  unsigned int now = time(0); 
     188 
     189  if(!((s_ops++) % 100000)) { 
     190    cleanup(); 
     191  } 
     192 
    180193  { 
    181194    Lock l(&s_metacachelock);  
     
    265278{ 
    266279  unsigned int now = time(0); 
     280 
     281  if(!((s_ops++) % 100000)) { 
     282    cleanup(); 
     283  } 
     284 
    267285  { 
    268286    Lock l(&s_keycachelock); 
     
    371389  return false; 
    372390} 
     391 
     392void DNSSECKeeper::cleanup() 
     393{ 
     394  struct timeval now; 
     395  Utility::gettimeofday(&now, 0); 
     396 
     397  if(now.tv_sec - s_last_prune > (time_t)(30)) { 
     398    { 
     399        Lock l(&s_metacachelock); 
     400        pruneCollection(s_metacache, ::arg().asNum("max-cache-entries")); 
     401    } 
     402    { 
     403        Lock l(&s_keycachelock); 
     404        pruneCollection(s_keycache, ::arg().asNum("max-cache-entries")); 
     405    } 
     406    s_last_prune=time(0); 
     407  } 
     408} 
  • trunk/pdns/pdns/dnsseckeeper.hh

    r2153 r2328  
    152152  > metacache_t; 
    153153 
     154  void cleanup(); 
     155 
    154156  static keycache_t s_keycache; 
    155157  static metacache_t s_metacache; 
    156158  static pthread_mutex_t s_metacachelock; 
    157159  static pthread_mutex_t s_keycachelock; 
     160  static unsigned int s_ops; 
     161  static time_t s_last_prune; 
    158162}; 
    159163