From cc59bce675e62e2b9657b42614ce8be3312cae82 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sun, 25 Jan 2015 16:59:25 +0100 Subject: [PATCH] our houseKeeping mthread could (and would) frequently be run several times simultaneously. It is great that this worked. But let's not ;-) --- pdns/pdns_recursor.cc | 127 ++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 61 deletions(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 0ae585a6c..4065f9cc2 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1221,7 +1221,7 @@ void daemonize(void) } } -uint64_t counter; +AtomicCounter counter; bool statsWanted; void usr1Handler(int) @@ -1279,75 +1279,80 @@ void doStats(void) } static void houseKeeping(void *) -try { static __thread time_t last_stat, last_rootupdate, last_prune, last_secpoll; static __thread int cleanCounter=0; - struct timeval now; - Utility::gettimeofday(&now, 0); - - // clog<<"* "< (time_t)(5 + t_id)) { - DTime dt; - dt.setTimeval(now); - t_RC->doPrune(); // this function is local to a thread, so fine anyhow - t_packetCache->doPruneTo(::arg().asNum("max-packetcache-entries") / g_numThreads); + static __thread bool s_running; // houseKeeping can get suspended in secpoll, and be restarted, which makes us do duplicate work + try { + if(s_running) + return; + s_running=true; - pruneCollection(t_sstorage->negcache, ::arg().asNum("max-cache-entries") / (g_numThreads * 10), 200); + struct timeval now; + Utility::gettimeofday(&now, 0); - if(!((cleanCounter++)%40)) { // this is a full scan! - time_t limit=now.tv_sec-300; - for(SyncRes::nsspeeds_t::iterator i = t_sstorage->nsSpeeds.begin() ; i!= t_sstorage->nsSpeeds.end(); ) - if(i->second.stale(limit)) - t_sstorage->nsSpeeds.erase(i++); - else - ++i; - } -// L< 7200) { - SyncRes sr(now); - sr.setDoEDNS0(true); - vector ret; - - sr.setNoCache(); - int res=-1; - try { - res=sr.beginResolve(".", QType(QType::NS), 1, ret); - } - catch(...) - { - L<negcache, ::arg().asNum("max-cache-entries") / (g_numThreads * 10), 200); + + if(!((cleanCounter++)%40)) { // this is a full scan! + time_t limit=now.tv_sec-300; + for(SyncRes::nsspeeds_t::iterator i = t_sstorage->nsSpeeds.begin() ; i!= t_sstorage->nsSpeeds.end(); ) + if(i->second.stale(limit)) + t_sstorage->nsSpeeds.erase(i++); + else + ++i; + } + last_prune=time(0); } - - if(now.tv_sec - last_secpoll >= 3600) { + + if(now.tv_sec - last_rootupdate > 7200) { + SyncRes sr(now); + sr.setDoEDNS0(true); + vector ret; + + sr.setNoCache(); + int res=-1; try { - doSecPoll(&last_secpoll); + res=sr.beginResolve(".", QType(QType::NS), 1, ret); + } + catch(...) + { + L<schedule(&g_now)); // MTasker letting the mthreads do their thing -- 2.40.0