Changeset 1284

Show
Ignore:
Timestamp:
11/15/08 23:24:17 (16 months ago)
Author:
ahu
Message:

make statbag work with unsigned counters - people are complaining of wraparounds at 2.15 billion packets going wrong! closes ticket 179, thanks Stefan Schmidt

Location:
trunk/pdns/pdns
Files:
7 modified

Legend:

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

    r1281 r1284  
    182182void sendout(const DNSDistributor::AnswerData &AD) 
    183183{ 
    184   static int &numanswered=*S.getPointer("udp-answers"); 
    185   static int &numanswered4=*S.getPointer("udp4-answers"); 
    186   static int &numanswered6=*S.getPointer("udp6-answers"); 
     184  static unsigned int &numanswered=*S.getPointer("udp-answers"); 
     185  static unsigned int &numanswered4=*S.getPointer("udp4-answers"); 
     186  static unsigned int &numanswered6=*S.getPointer("udp6-answers"); 
    187187 
    188188  if(!AD.A) 
     
    214214  DNSPacket cached; 
    215215 
    216   int &numreceived=*S.getPointer("udp-queries"); 
    217   int &numanswered=*S.getPointer("udp-answers"); 
    218  
    219   int &numreceived4=*S.getPointer("udp4-queries"); 
    220   int &numanswered4=*S.getPointer("udp4-answers"); 
    221  
    222   int &numreceived6=*S.getPointer("udp6-queries"); 
    223   int &numanswered6=*S.getPointer("udp6-answers"); 
     216  unsigned int &numreceived=*S.getPointer("udp-queries"); 
     217  unsigned int &numanswered=*S.getPointer("udp-answers"); 
     218 
     219  unsigned int &numreceived4=*S.getPointer("udp4-queries"); 
     220  unsigned int &numanswered4=*S.getPointer("udp4-answers"); 
     221 
     222  unsigned int &numreceived6=*S.getPointer("udp6-queries"); 
     223  unsigned int &numanswered6=*S.getPointer("udp6-answers"); 
    224224  numreceived=-1; 
    225225  int diff; 
  • trunk/pdns/pdns/dnsproxy.hh

    r681 r1284  
    6868  NetmaskGroup d_ng; 
    6969  int d_sock; 
    70   int* d_resanswers; 
    71   int* d_udpanswers; 
    72   int* d_resquestions; 
     70  unsigned int* d_resanswers; 
     71  unsigned int* d_udpanswers; 
     72  unsigned int* d_resquestions; 
    7373  pthread_mutex_t d_lock; 
    7474  uint16_t d_xor; 
  • trunk/pdns/pdns/packetcache.cc

    r1228 r1284  
    3838  S.declare("packetcache-size"); 
    3939 
    40   statnumhit=S.getPointer("packetcache-hit"); 
    41   statnummiss=S.getPointer("packetcache-miss"); 
    42   statnumentries=S.getPointer("packetcache-size"); 
     40  d_statnumhit=S.getPointer("packetcache-hit"); 
     41  d_statnummiss=S.getPointer("packetcache-miss"); 
     42  d_statnumentries=S.getPointer("packetcache-size"); 
    4343} 
    4444 
     
    5555  if(d_doRecursion && p->d.rd) { // wants recursion 
    5656    if(!d_recursivettl) { 
    57       (*statnummiss)++; 
     57      (*d_statnummiss)++; 
    5858      d_miss++; 
    5959      return 0; 
     
    6262  else { // does not 
    6363    if(!d_ttl) { 
    64       (*statnummiss)++; 
     64      (*d_statnummiss)++; 
    6565      d_miss++; 
    6666      return 0; 
     
    8181 
    8282    if(!((d_hit+d_miss)%30000)) { 
    83       *statnumentries=d_map.size(); // needs lock 
     83      *d_statnumentries=d_map.size(); // needs lock 
    8484    } 
    8585    string value; 
     
    8787    if(getEntry(p->qdomain, p->qtype, PacketCache::PACKETCACHE, value, -1, packetMeritsRecursion)) { 
    8888      //      cerr<<"Packet cache hit!"<<endl; 
    89       (*statnumhit)++; 
     89      (*d_statnumhit)++; 
    9090      d_hit++; 
    9191      if(cached->parse(value.c_str(), value.size()) < 0) { 
     
    9797  } 
    9898  //   cerr<<"Packet cache miss"<<endl; 
    99   (*statnummiss)++; 
     99  (*d_statnummiss)++; 
    100100  d_miss++; 
    101101  return 0; // bummer 
     
    164164    delcount = d_map.size(); 
    165165    d_map.clear(); 
    166     *statnumentries=0; 
     166    *d_statnumentries=0; 
    167167    return delcount; 
    168168  } 
     
    239239    } 
    240240  } 
    241   *statnumentries=d_map.size(); 
     241  *d_statnumentries=d_map.size(); 
    242242  return delcount; 
    243243} 
     
    283283  WriteLock l(&d_mut); 
    284284 
    285   *statnumentries=d_map.size(); 
     285  *d_statnumentries=d_map.size(); 
    286286 
    287287  unsigned int maxCached=::arg().asNum("max-cache-entries"); 
    288288  unsigned int toTrim=0; 
    289289   
    290   unsigned int cacheSize=*statnumentries; 
     290  unsigned int cacheSize=*d_statnumentries; 
    291291 
    292292  if(maxCached && cacheSize > maxCached) { 
     
    325325  } 
    326326  //  cerr<<"erased: "<<erased<<endl; 
    327   *statnumentries=d_map.size(); 
     327  *d_statnumentries=d_map.size(); 
    328328  DLOG(L<<"Done with cache clean"<<endl); 
    329329} 
  • trunk/pdns/pdns/packetcache.hh

    r1273 r1284  
    125125  int d_recursivettl; 
    126126  bool d_doRecursion; 
    127   int *statnumhit; 
    128   int *statnummiss; 
    129   int *statnumentries; 
     127  unsigned int *d_statnumhit; 
     128  unsigned int *d_statnummiss; 
     129  unsigned int *d_statnumentries; 
    130130}; 
    131131 
  • trunk/pdns/pdns/statbag.cc

    r681 r1284  
    5252  ostringstream o; 
    5353  lock(); 
    54   for(map<string,int *>::const_iterator i=d_stats.begin(); 
     54  for(map<string, unsigned int *>::const_iterator i=d_stats.begin(); 
    5555      i!=d_stats.end(); 
    5656      i++) 
     
    6868  vector<string> ret; 
    6969  lock(); 
    70   for(map<string,int *>::const_iterator i=d_stats.begin(); 
     70  for(map<string, unsigned int *>::const_iterator i=d_stats.begin(); 
    7171      i!=d_stats.end(); 
    7272      i++) 
     
    8989{ 
    9090  lock(); 
    91   int *i=new int(0); 
     91  unsigned int *i=new unsigned int(0); 
    9292  d_stats[key]=i; 
    9393  d_keyDescrips[key]=descrip; 
     
    158158} 
    159159 
    160 int *StatBag::getPointer(const string &key) 
     160unsigned int *StatBag::getPointer(const string &key) 
    161161{ 
    162162  exists(key); 
     
    166166StatBag::~StatBag() 
    167167{ 
    168   for(map<string,int *>::const_iterator i=d_stats.begin(); 
     168  for(map<string,unsigned int *>::const_iterator i=d_stats.begin(); 
    169169      i!=d_stats.end(); 
    170170      i++) 
  • trunk/pdns/pdns/statbag.hh

    r681 r1284  
    5959class StatBag 
    6060{ 
    61   map<string,int *> d_stats; 
     61  map<string, unsigned int *> d_stats; 
    6262  map<string, string> d_keyDescrips; 
    6363  map<string,StatRing>d_rings; 
     
    9797  int read(const string &key); //!< read the value behind this key 
    9898  int readZero(const string &key); //!< read the value behind this key, and zero it afterwards 
    99   int *getPointer(const string &key); //!< get a direct pointer to the value behind a key. Use this for high performance increments 
     99  unsigned int *getPointer(const string &key); //!< get a direct pointer to the value behind a key. Use this for high performance increments 
    100100  string getValueStr(const string &key); //!< read a value behind a key, and return it as a string 
    101101  string getValueStrZero(const string &key); //!< read a value behind a key, and return it as a string, and zero afterwards 
  • trunk/pdns/pdns/ueberbackend.cc

    r1218 r1284  
    238238{ 
    239239  extern PacketCache PC; 
    240   static int *qcachehit=S.getPointer("query-cache-hit"); 
    241   static int *qcachemiss=S.getPointer("query-cache-miss"); 
     240  static unsigned int *qcachehit=S.getPointer("query-cache-hit"); 
     241  static unsigned int *qcachemiss=S.getPointer("query-cache-miss"); 
    242242 
    243243  static int negqueryttl=::arg().asNum("negquery-cache-ttl");