Changeset 2058

Show
Ignore:
Timestamp:
03/03/11 13:12:24 (2 years ago)
Author:
ahu
Message:

move zone freshness checking on incoming notification away from the main query threads and into the slave communicator loop, improving responsiveness when being mass-notified of changes.
Spotted by Richard Poole.

Location:
trunk/pdns/pdns
Files:
5 modified

Legend:

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

    r2012 r2058  
    7979 
    8080    int rc; 
    81     time_t next; 
    82  
    83     time_t tick; 
     81    time_t next, tick; 
    8482 
    8583    for(;;) { 
    8684      slaveRefresh(&P); 
    8785      masterUpdateCheck(&P); 
    88       tick=doNotifications(); 
     86      tick=doNotifications(); // this processes any notification acknowledgements and actually send out our own notifications 
    8987       
    9088      tick = min (tick, d_tickinterval);  
    91  
    92       //      L<<Logger::Error<<"tick = "<<tick<<", d_tickinterval = "<<d_tickinterval<<endl; 
     89       
    9390      next=time(0)+tick; 
    9491 
     
    9996          Utility::sleep(1); 
    10097        else {  
    101            
     98          break; // something happened 
    10299        } 
    103100        // this gets executed at least once every second 
  • trunk/pdns/pdns/communicator.hh

    r2012 r2058  
    156156  bool justNotified(const string &domain, const string &ip); 
    157157  void addSuckRequest(const string &domain, const string &master, bool priority=false); 
     158  void addSlaveCheckRequest(const DomainInfo& di, const ComboAddress& remote); 
    158159  void notify(const string &domain, const string &ip); 
    159160  void mainloop(); 
     
    190191  NotificationQueue d_nq; 
    191192  bool d_masterschanged, d_slaveschanged; 
     193  set<DomainInfo> d_tocheck; 
    192194}; 
    193195 
  • trunk/pdns/pdns/dnsbackend.hh

    r2024 r2058  
    5252  enum {Master,Slave,Native} kind; 
    5353  DNSBackend *backend; 
     54   
     55  bool operator<(const DomainInfo& rhs) const 
     56  { 
     57    return zone < rhs.zone; 
     58  } 
    5459}; 
    5560 
  • trunk/pdns/pdns/packethandler.cc

    r2050 r2058  
    856856  } 
    857857     
    858   string authServer(p->getRemote()); 
    859858  if(::arg().contains("trusted-notification-proxy", p->getRemote())) { 
    860859    L<<Logger::Error<<"Received NOTIFY for "<<p->qdomain<<" from trusted-notification-proxy "<< p->getRemote()<<endl; 
     
    863862      return RCode::Refused; 
    864863    } 
    865     authServer = *di.masters.begin(); 
    866864  } 
    867865  else if(!db->isMaster(p->qdomain, p->getRemote())) { 
     
    869867    return RCode::Refused; 
    870868  } 
    871   authServer = *di.masters.begin();  // XXX this is actually wrong, we should be picking the master that looks most like the notification! 
    872   uint32_t theirserial=0; 
    873  
    874   Resolver resolver; 
    875   try { 
    876     resolver.getSoaSerial(authServer, p->qdomain, &theirserial); // XXX this should have a _really_ short timeout! 
    877   } 
    878   catch(ResolverException& re) { 
    879     L<<Logger::Error<<re.reason<<endl; 
    880     return RCode::ServFail; 
    881   } 
    882  
    883   if(theirserial<=di.serial) {  
    884     L<<Logger::Error<<"Received NOTIFY for "<<p->qdomain<<" from "<< authServer <<", we are up to date: "<< 
    885       theirserial<<"<="<<di.serial<<endl; 
    886     return RCode::NoError; 
    887   } 
    888   else { 
    889     L<<Logger::Error<<"Received valid NOTIFY for "<<p->qdomain<<" (id="<<di.id<<") from master "<<p->getRemote()<<": "<< 
    890       theirserial<<" > "<<di.serial<<endl; 
    891  
    892     Communicator.addSuckRequest(p->qdomain, authServer, true); // priority 
    893     return 0; 
    894   } 
    895   return -1;  
     869   
     870   
     871  // ok, we've done our checks 
     872  Communicator.addSlaveCheckRequest(di, p->remote); 
     873   
     874  return 0; 
    896875} 
    897876 
  • trunk/pdns/pdns/slavecommunicator.cc

    r2052 r2058  
    5757   
    5858  if(res.second) { 
    59   d_suck_sem.post(); 
     59    d_suck_sem.post(); 
    6060  } 
    6161} 
     
    244244}; 
    245245 
     246void CommunicatorClass::addSlaveCheckRequest(const DomainInfo& di, const ComboAddress& remote) 
     247{ 
     248  Lock l(&d_lock); 
     249  d_tocheck.insert(di); 
     250  d_any_sem.post(); // kick the loop! 
     251} 
     252 
    246253void CommunicatorClass::slaveRefresh(PacketHandler *P) 
    247254{ 
    248255  UeberBackend *B=dynamic_cast<UeberBackend *>(P->getBackend()); 
    249256  vector<DomainInfo> rdomains; 
    250   vector<pair<DomainInfo, bool> > sdomains; 
    251   B->getUnfreshSlaveInfos(&rdomains); 
     257  vector<pair<DomainInfo, bool> > sdomains; // the bool is for 'presigned' 
     258   
     259  { 
     260    Lock l(&d_lock); 
     261    rdomains.insert(rdomains.end(), d_tocheck.begin(), d_tocheck.end()); 
     262    d_tocheck.clear(); 
     263  } 
     264   
     265  if(rdomains.empty()) // if we have priority domains, check them first 
     266    B->getUnfreshSlaveInfos(&rdomains); 
     267     
    252268  DNSSECKeeper dk; 
    253269  {