extern MemRecursorCache RC;
-map<string,NegCacheEntry> SyncRes::s_negcache;
-map<string,DecayingEwma> SyncRes::s_nsSpeeds;
+SyncRes::negcache_t SyncRes::s_negcache;
+SyncRes::nsspeeds_t SyncRes::s_nsSpeeds;
+
unsigned int SyncRes::s_queries;
unsigned int SyncRes::s_outgoingtimeouts;
unsigned int SyncRes::s_outqueries;
rr.content=toLowerCanonic(k->content);
if(!endsOn(rr.content,subdomain) || RC.get(d_now.tv_sec, rr.content ,QType(QType::A),&aset) > 5) {
bestns.insert(rr);
+
LOG<<prefix<<qname<<": NS (with ip, or non-glue) in cache for '"<<subdomain<<"' -> '"<<rr.content<<"'"<<endl;
LOG<<prefix<<qname<<": within bailiwick: "<<endsOn(rr.content,subdomain);
- if(!aset.empty())
- L<<", in cache, ttl="<<(unsigned int)(((time_t)aset.begin()->ttl- d_now.tv_sec ))<<endl;
- else
- L<<", not in cache"<<endl;
+ if(!aset.empty()) {
+ LOG<<", in cache, ttl="<<(unsigned int)(((time_t)aset.begin()->ttl- d_now.tv_sec ))<<endl;
+ }
+ else {
+ LOG<<", not in cache"<<endl;
+ }
}
else
LOG<<prefix<<qname<<": NS in cache for '"<<subdomain<<"', but needs glue ("<<toLowerCanonic(k->content)<<") which we miss or is expired"<<endl;
if(s_negcache.count(toLower(qname))) {
res=0;
- map<string,NegCacheEntry>::const_iterator ni=s_negcache.find(toLower(qname));
+ negcache_t::const_iterator ni=s_negcache.find(toLower(qname));
if(d_now.tv_sec < ni->second.ttd) {
sttl=ni->second.ttd - d_now.tv_sec;
LOG<<prefix<<qname<<": Entire record '"<<toLower(qname)<<"', is negatively cached for another "<<sttl<<" seconds"<<endl;
}
if(!giveNegative) { // let's try some more
- tuple=toLower(qname)+"|"+qtype.getName();
+ tuple=toLower(qname); tuple.append(1,'|'); tuple+=qtype.getName();
LOG<<prefix<<qname<<": Looking for direct cache hit of '"<<tuple<<"', negative cached: "<<s_negcache.count(tuple)<<endl;
res=0;
- map<string,NegCacheEntry>::const_iterator ni=s_negcache.find(tuple);
+ negcache_t::const_iterator ni=s_negcache.find(tuple);
if(ni!=s_negcache.end()) {
if(d_now.tv_sec < ni->second.ttd) {
sttl=ni->second.ttd - d_now.tv_sec;
#include "misc.hh"
#include "lwres.hh"
#include <boost/utility.hpp>
+#include "recursor_cache.hh"
/* external functions, opaque to us */
void submit(int val, struct timeval*tv = 0)
{
- double now;
+ float now;
if(tv)
now=tv->tv_sec + tv->tv_usec/1000000.0;
else
now=getTime();
- double diff=d_last-now;
+ float diff=d_last-now;
d_last=now;
- double factor=exp(diff)/2.0; // might be '0.5', or 0.0001
+ float factor=exp(diff)/2.0; // might be '0.5', or 0.0001
d_val=(1-factor)*val+ factor*d_val;
}
- double get(struct timeval*tv = 0)
+ float get(struct timeval*tv = 0)
{
- double now;
+ float now;
if(tv)
now=tv->tv_sec + tv->tv_usec/1000000.0;
else
now=getTime();
- double diff=d_lastget-now;
+ float diff=d_lastget-now;
d_lastget=now;
- double factor=exp(diff/60.0); // is 1.0 or less
+ float factor=exp(diff/60.0); // is 1.0 or less
return d_val*=factor;
}
+ bool stale(time_t limit)
+ {
+ return limit > d_lastget;
+ }
+
private:
DecayingEwma& operator=(const DecayingEwma&);
- double d_last;
- double d_lastget;
- double d_val;
+ float d_last;
+ float d_lastget;
+ float d_val;
};
int beginResolve(const string &qname, const QType &qtype, vector<DNSResourceRecord>&ret);
void setId(int id)
{
- d_prefix="["+itoa(id)+"] ";
+ if(s_log)
+ d_prefix="["+itoa(id)+"] ";
}
static void setLog(bool log)
{
unsigned int d_tcpoutqueries;
unsigned int d_throttledqueries;
unsigned int d_timeouts;
- static map<string,NegCacheEntry> s_negcache;
- static map<string,DecayingEwma> s_nsSpeeds;
+ typedef map<string,NegCacheEntry> negcache_t;
+ static negcache_t s_negcache;
+
+ typedef map<string,DecayingEwma> nsspeeds_t;
+ static nsspeeds_t s_nsSpeeds;
+
static Throttle<string> s_throttle;
private:
struct GetBestNSAnswer;