Changeset 1484

Show
Ignore:
Timestamp:
01/02/10 20:30:14 (8 months ago)
Author:
ahu
Message:

remove last traces of locking in recursor cache, plus reinstate cache aging, plus properly zero counters

Location:
trunk/pdns/pdns
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/recursor_cache.cc

    r1472 r1484  
    66#include "arguments.hh" 
    77#include "syncres.hh" 
    8 #include "lock.hh" 
    98#include "recursor_cache.hh" 
    109 
     
    106105{ 
    107106  unsigned int ttd=0; 
    108   { 
    109     WriteLock wl(&d_rwlock); 
    110     //  cerr<<"looking up "<< qname+"|"+qt.getName()<<"\n"; 
    111  
    112     if(!d_cachecachevalid || !pdns_iequals(d_cachedqname, qname)) { 
    113       //    cerr<<"had cache cache miss"<<endl; 
    114       d_cachedqname=qname; 
    115       d_cachecache=d_cache.equal_range(tie(qname)); 
    116       d_cachecachevalid=true; 
    117     } 
    118     else 
    119       //    cerr<<"had cache cache hit!"<<endl; 
    120       ; 
    121   } 
    122   ReadLock l(&d_rwlock); 
     107  //  cerr<<"looking up "<< qname+"|"+qt.getName()<<"\n"; 
     108 
     109  if(!d_cachecachevalid || !pdns_iequals(d_cachedqname, qname)) { 
     110    //    cerr<<"had cache cache miss"<<endl; 
     111    d_cachedqname=qname; 
     112    d_cachecache=d_cache.equal_range(tie(qname)); 
     113    d_cachecachevalid=true; 
     114  } 
     115  else 
     116    //    cerr<<"had cache cache hit!"<<endl; 
     117    ; 
    123118 
    124119  if(res) 
     
    131126         ) { 
    132127        typedef cache_t::nth_index<1>::type sequence_t; 
    133         //      sequence_t& sidx=d_cache.get<1>(); 
     128        sequence_t& sidx=d_cache.get<1>(); 
    134129        sequence_t::iterator si=d_cache.project<1>(i); 
    135130         
     
    144139        } 
    145140        if(res) { 
    146  
    147  
    148 #if 0 // XXX FIXME removed because of threading - sidx should not be touched holding just a readlock! 
    149141          if(res->empty()) 
    150142            sidx.relocate(sidx.begin(), si);  
    151143          else 
    152144            sidx.relocate(sidx.end(), si);  
    153 #endif 
    154145        } 
    155146        if(qt.getCode()!=QType::ANY && qt.getCode()!=QType::ADDR) // normally if we have a hit, we are done 
     
    167158bool MemRecursorCache::attemptToRefreshNSTTL(const QType& qt, const set<DNSResourceRecord>& content, const CacheEntry& stored) 
    168159{ 
    169   //  WriteLock wl(&d_rwlock); (holds the lock already) 
    170160  if(!stored.d_auth) { 
    171161//    cerr<<"feel free to scribble non-auth data!"<<endl; 
     
    199189void MemRecursorCache::replace(time_t now, const string &qname, const QType& qt,  const set<DNSResourceRecord>& content, bool auth) 
    200190{ 
    201   WriteLock wl(&d_rwlock); 
    202191  d_cachecachevalid=false; 
    203192  tuple<string, uint16_t> key=make_tuple(qname, qt.getCode()); 
     
    296285int MemRecursorCache::doWipeCache(const string& name, uint16_t qtype) 
    297286{ 
    298   WriteLock wl(&d_rwlock); 
    299287  int count=0; 
    300288  d_cachecachevalid=false; 
     
    314302bool MemRecursorCache::doAgeCache(time_t now, const string& name, uint16_t qtype, int32_t newTTL) 
    315303{ 
    316   WriteLock wl(&d_rwlock); 
    317304  cache_t::iterator iter = d_cache.find(tie(name, qtype)); 
    318305  if(iter == d_cache.end())  
     
    343330void MemRecursorCache::doDumpAndClose(int fd) 
    344331{ 
    345   WriteLock wl(&d_rwlock); 
    346332  FILE* fp=fdopen(fd, "w"); 
    347333  if(!fp) { 
     
    375361void MemRecursorCache::doPrune(void) 
    376362{ 
    377   WriteLock wl(&d_rwlock); 
    378363  uint32_t now=(uint32_t)time(0); 
    379364  d_cachecachevalid=false; 
  • trunk/pdns/pdns/recursor_cache.hh

    r1472 r1484  
    2929  MemRecursorCache() : d_followRFC2181(false), d_cachecachevalid(false) 
    3030  { 
    31     pthread_rwlock_init(&d_rwlock, 0); 
    32     //    cerr<<"ce: "<<sizeof(CacheEntry)<<", sr: "<<sizeof(struct StoredRecord)<<endl; 
     31    cacheHits = cacheMisses = 0; 
    3332  } 
    3433  unsigned int size(); 
     
    110109  bool d_cachecachevalid; 
    111110  bool attemptToRefreshNSTTL(const QType& qt, const set<DNSResourceRecord>& content, const CacheEntry& stored); 
    112  
    113   pthread_rwlock_t d_rwlock; 
    114   // boost::shared_mutex d_smutex; 
    115111}; 
    116112string DNSRR2String(const DNSResourceRecord& rr);