From: bert hubert Date: Thu, 13 Mar 2014 09:08:54 +0000 (+0100) Subject: document new bindbackend semantics, plus fix that we did not learn about slave zones. X-Git-Tag: rec-3.6.0-rc1~138^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d8f47a4a82ff280effc4fc573f039c7de475f31c;p=thirdparty%2Fpdns.git document new bindbackend semantics, plus fix that we did not learn about slave zones. --- diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index f2307cbf33..6c983e6f86 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -49,13 +49,30 @@ #include "pdns/lock.hh" #include "pdns/namespaces.hh" +/* + All instances of this backend share one s_state, which is indexed by zone name and zone id. + The s_state is protected by a read/write lock, and the goal it to only interact with it briefly. + When a query comes in, we take a read lock and COPY the best zone to answer from s_state (BB2DomainInfo object) + All answers are served from this copy. + + To interact with s_state, use safeGetBBDomainInfo (search on name or id), safePutBBDomainInfo (to update) + or safeRemoveBBDomainInfo. These all lock as they should. + + Several functions need to traverse s_state to get data for the rest of PowerDNS. When doing so, + you need to manually take the s_state_lock (read). + + Parsing zones happens with parseZone(), which fills a BB2DomainInfo object. This can then be stored with safePutBBDomainInfo. + + Finally, the BB2DomainInfo contains all records as a LookButDontTouch object. This makes sure you only look, but don't touch, since + the records might be in use in other places. +*/ Bind2Backend::state_t Bind2Backend::s_state; int Bind2Backend::s_first=1; bool Bind2Backend::s_ignore_broken_records=false; pthread_rwlock_t Bind2Backend::s_state_lock=PTHREAD_RWLOCK_INITIALIZER; -pthread_mutex_t Bind2Backend::s_supermaster_config_lock=PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t Bind2Backend::s_supermaster_config_lock=PTHREAD_MUTEX_INITIALIZER; // protects writes to config file pthread_mutex_t Bind2Backend::s_startup_lock=PTHREAD_MUTEX_INITIALIZER; string Bind2Backend::s_binddirectory; @@ -144,7 +161,6 @@ bool Bind2Backend::safeRemoveBBDomainInfo(const std::string& name) return true; } - void Bind2Backend::safePutBBDomainInfo(const BB2DomainInfo& bbd) { WriteLock rl(&s_state_lock); @@ -348,7 +364,7 @@ void Bind2Backend::getUnfreshSlaveInfos(vector *unfreshDomains) } catch(...){} sd.serial=soadata.serial; - if(sd.last_check+soadata.refresh<(unsigned int)time(0)) + if(sd.last_check+soadata.refresh < (unsigned int)time(0)) unfreshDomains->push_back(sd); } } @@ -554,8 +570,7 @@ string Bind2Backend::DLAddDomainHandler(const vector&parts, Utility::pid BB2DomainInfo bbd; if(safeGetBBDomainInfo(domainname, &bbd)) return "Already loaded"; - - Bind2Backend bb2; // XXX do we need this? + Bind2Backend bb2; // createdomainentry needs access to our configuration bbd=bb2.createDomainEntry(domainname, filename); bbd.d_filename=filename; bbd.d_checknow=true; @@ -772,7 +787,7 @@ void Bind2Backend::loadConfig(string* status) try { parseZoneFile(&bbd); - safePutBBDomainInfo(bbd); + } catch(PDNSException &ae) { ostringstream msg; @@ -795,6 +810,7 @@ void Bind2Backend::loadConfig(string* status) L< alsoNotify; //!< this is used to store the also-notify list of interested peers. - BB2DomainInfo createDomainEntry(const string &domain, const string &filename); + BB2DomainInfo createDomainEntry(const string &domain, const string &filename); //!< does not insert in s_state int d_transaction_id; string d_transaction_tmpname;