Changeset 1399 for trunk/pdns/pdns/packetcache.cc
- Timestamp:
- 08/22/09 21:20:17 (4 years ago)
- Files:
-
- 1 modified
-
trunk/pdns/pdns/packetcache.cc (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/packetcache.cc
r1365 r1399 29 29 { 30 30 pthread_rwlock_init(&d_mut,0); 31 d_ hit=d_miss=0;31 d_ops = 0; 32 32 33 33 d_ttl=-1; … … 51 51 { 52 52 extern StatBag S; 53 if(!((d_hit+d_miss)%150000)) {54 cleanup();55 }56 53 57 54 if(d_ttl<0) 58 55 getTTLS(); 56 57 if(!((d_ops++) % 300000)) { 58 cleanup(); 59 } 60 59 61 60 62 if(d_doRecursion && p->d.rd) { // wants recursion 61 63 if(!d_recursivettl) { 62 64 (*d_statnummiss)++; 63 d_miss++;64 65 return 0; 65 66 } … … 68 69 if(!d_ttl) { 69 70 (*d_statnummiss)++; 70 d_miss++;71 71 return 0; 72 72 } … … 86 86 } 87 87 88 if(!((d_hit+d_miss)%30000)) { 89 *d_statnumentries=d_map.size(); // needs lock 90 } 91 haveSomething=getEntry(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion); 88 haveSomething=getEntryLocked(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion); 92 89 } 93 90 if(haveSomething) { 94 91 (*d_statnumhit)++; 95 d_hit++;96 92 if(cached->noparse(value.c_str(), value.size()) < 0) { 97 93 return 0; … … 103 99 // cerr<<"Packet cache miss for '"<<p->qdomain<<"', merits: "<<packetMeritsRecursion<<endl; 104 100 (*d_statnummiss)++; 105 d_miss++;106 101 return 0; // bummer 107 102 } … … 133 128 void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType cet, const string& value, unsigned int ttl, int zoneID, bool meritsRecursion) 134 129 { 130 if(!((d_ops++) % 300000)) { 131 cleanup(); 132 } 133 135 134 if(!ttl) 136 135 return; … … 249 248 bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion) 250 249 { 250 if(d_ttl<0) 251 getTTLS(); 252 253 if(!((d_ops++) % 300000)) { 254 cleanup(); 255 } 256 251 257 TryReadLock l(&d_mut); // take a readlock here 252 258 if(!l.gotIt()) { … … 254 260 return false; 255 261 } 262 return getEntryLocked(qname, qtype, cet, value, zoneID, meritsRecursion); 263 } 264 265 bool PacketCache::getEntryLocked(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion) 266 { 256 267 257 268 uint16_t qt = qtype.getCode(); … … 261 272 if(ret) 262 273 value = i->value; 263 264 // cerr<<"Cache hit: "<<(int)cet<<", "<<ret<<endl;265 274 266 275 return ret; … … 317 326 318 327 unsigned int lookAt=0; 319 // two modes - if toTrim is 0, just look through 10 000 recordsand nuke everything that is expired328 // two modes - if toTrim is 0, just look through 10% of the cache and nuke everything that is expired 320 329 // otherwise, scan first 5*toTrim records, and stop once we've nuked enough 321 330 if(toTrim) … … 333 342 typedef cmap_t::nth_index<1>::type sequence_t; 334 343 sequence_t& sidx=d_map.get<1>(); 335 unsigned int erased=0 ;336 for(sequence_t::iterator i=sidx.begin(); i != sidx.end(); ) {344 unsigned int erased=0, lookedAt=0; 345 for(sequence_t::iterator i=sidx.begin(); i != sidx.end(); lookedAt++) { 337 346 if(i->ttd < now) { 338 347 sidx.erase(i++); … … 345 354 break; 346 355 356 if(lookedAt > lookAt) 357 break; 347 358 } 348 359 // cerr<<"erased: "<<erased<<endl;