root/trunk/pdns/pdns/slavecommunicator.cc @ 1639

Revision 1639, 6.2 KB (checked in by ahu, 3 years ago)

add dummy 'reportTimeout' to slavecommunicator so things compile again

Line 
1/*
2    PowerDNS Versatile Database Driven Nameserver
3    Copyright (C) 2002-2009  PowerDNS.COM BV
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License version 2 as
7    published by the Free Software Foundation;
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17*/
18#include "packetcache.hh"
19#include "utility.hh"
20#include <errno.h>
21#include "communicator.hh"
22#include <set>
23#include <boost/utility.hpp>
24#include "dnsbackend.hh"
25#include "ueberbackend.hh"
26#include "packethandler.hh"
27#include "resolver.hh"
28#include "logger.hh"
29#include "dns.hh"
30#include "arguments.hh"
31#include "session.hh"
32#include "packetcache.hh"
33#include <boost/foreach.hpp>
34#include <boost/lexical_cast.hpp>
35#include "inflighter.cc"
36
37#include "namespaces.hh"
38
39void CommunicatorClass::addSuckRequest(const string &domain, const string &master, bool priority)
40{
41  Lock l(&d_lock);
42 
43  SuckRequest sr;
44  sr.domain = domain;
45  sr.master = master;
46
47  if(priority) {
48    d_suckdomains.push_front(sr);
49    //  d_havepriosuckrequest=true;
50  }
51  else 
52    d_suckdomains.push_back(sr);
53 
54  d_suck_sem.post();
55  d_any_sem.post();
56}
57
58void CommunicatorClass::suck(const string &domain,const string &remote)
59{
60  L<<Logger::Error<<"Initiating transfer of '"<<domain<<"' from remote '"<<remote<<"'"<<endl;
61  uint32_t domain_id;
62  PacketHandler P;
63
64  DomainInfo di;
65  di.backend=0;
66  bool first=true;   
67  try {
68    Resolver resolver;
69    resolver.axfr(remote, domain.c_str());
70
71    UeberBackend *B=dynamic_cast<UeberBackend *>(P.getBackend());
72
73    if(!B->getDomainInfo(domain, di) || !di.backend) {
74      L<<Logger::Error<<"Can't determine backend for domain '"<<domain<<"'"<<endl;
75      return;
76    }
77    domain_id=di.id;
78
79    Resolver::res_t recs;
80
81    while(resolver.axfrChunk(recs)) {
82      if(first) {
83        L<<Logger::Error<<"AXFR started for '"<<domain<<"', transaction started"<<endl;
84        di.backend->startTransaction(domain, domain_id);
85        first=false;
86      }
87      for(Resolver::res_t::iterator i=recs.begin();i!=recs.end();++i) {
88        if(!endsOn(i->qname, domain)) { 
89          L<<Logger::Error<<"Remote "<<remote<<" tried to sneak in out-of-zone data '"<<i->qname<<"' during AXFR of zone '"<<domain<<"', ignoring"<<endl;
90          continue;
91        }
92        i->domain_id=domain_id;
93        if(i->qtype.getCode()>=1024)
94          throw DBException("Database can't store unknown record type "+lexical_cast<string>(i->qtype.getCode()-1024));
95
96        di.backend->feedRecord(*i);
97      }
98    }
99    di.backend->commitTransaction();
100    di.backend->setFresh(domain_id);
101    L<<Logger::Error<<"AXFR done for '"<<domain<<"', zone committed"<<endl;
102  }
103  catch(DBException &re) {
104    L<<Logger::Error<<"Unable to feed record during incoming AXFR of '"+domain+"': "<<re.reason<<endl;
105    if(di.backend && !first) {
106      L<<Logger::Error<<"Aborting possible open transaction for domain '"<<domain<<"' AXFR"<<endl;
107      di.backend->abortTransaction();
108    }
109  }
110  catch(ResolverException &re) {
111    L<<Logger::Error<<"Unable to AXFR zone '"+domain+"' from remote '"<<remote<<"': "<<re.reason<<endl;
112    if(di.backend && !first) {
113      L<<Logger::Error<<"Aborting possible open transaction for domain '"<<domain<<"' AXFR"<<endl;
114      di.backend->abortTransaction();
115    }
116  }
117}
118struct QueryInfo
119  {
120    struct timeval query_ttd;
121    uint16_t id;
122  };
123
124struct SlaveSenderReceiver
125{
126  typedef pair<string, uint16_t> Identifier;
127  typedef uint32_t Answer;
128 
129  map<uint32_t, uint32_t> d_serials;
130 
131  SlaveSenderReceiver()
132  {
133    d_resolver.makeUDPSocket();
134  }
135 
136  void deliverTimeout(const Identifier& i)
137  {}
138 
139  Identifier send(DomainInfo& di)
140  {
141    random_shuffle(di.masters.begin(), di.masters.end());
142    return make_pair(di.zone, d_resolver.sendResolve(*di.masters.begin(), di.zone.c_str(), QType::SOA));
143  }
144 
145  bool receive(Identifier& id, Answer& a)
146  {
147    if(d_resolver.tryGetSOASerial(&id.first, &a, &id.second)) {
148      return 1;
149    }
150    return 0;
151  }
152 
153  void deliverAnswer(DomainInfo& i, uint32_t serial)
154  {
155    d_serials[i.id]=serial;
156  }
157 
158  Resolver d_resolver;
159
160};
161
162void CommunicatorClass::slaveRefresh(PacketHandler *P)
163{
164  UeberBackend *B=dynamic_cast<UeberBackend *>(P->getBackend());
165  vector<DomainInfo> sdomains;
166  B->getUnfreshSlaveInfos(&sdomains);
167  if(sdomains.empty())
168  {
169    if(d_slaveschanged)
170      L<<Logger::Warning<<"All slave domains are fresh"<<endl;
171    d_slaveschanged=false;
172    return;
173  }
174  else 
175    L<<Logger::Warning<<sdomains.size()<<" slave domain"<<(sdomains.size()>1 ? "s" : "")<<" need"<<
176      (sdomains.size()>1 ? "" : "s")<<
177      " checking"<<endl;
178     
179  SlaveSenderReceiver ssr;
180  Inflighter<vector<DomainInfo>, SlaveSenderReceiver> ifl(sdomains, ssr);
181 
182  ifl.d_maxInFlight = 200;
183
184  for(;;) {
185    try {
186      ifl.run();
187      break;
188    }
189    catch(exception& e) {
190      L<<Logger::Error<<"While checking domain freshness: " << e.what()<<endl;
191    }
192    catch(AhuException &re) { 
193      L<<Logger::Error<<"While checking domain freshness: " << re.reason<<endl;
194    }
195  }
196  L<<Logger::Warning<<"Received serial number updates for "<<ssr.d_serials.size()<<" zones"<<endl;
197
198  BOOST_FOREACH(DomainInfo& di, sdomains) {
199    if(!ssr.d_serials.count(di.id)) 
200      continue;
201    uint32_t theirserial = ssr.d_serials[di.id], ourserial = di.serial;
202   
203    if(theirserial < ourserial) {
204      L<<Logger::Error<<"Domain "<<di.zone<<" more recent than master, our serial " << ourserial << " > their serial "<< theirserial << endl;
205      di.backend->setFresh(di.id);
206    }
207    else if(theirserial == ourserial) {
208      L<<Logger::Warning<<"Domain "<< di.zone<<" is fresh"<<endl;
209      di.backend->setFresh(di.id);
210    }
211    else {
212      L<<Logger::Warning<<"Domain "<< di.zone<<" is stale, master serial "<<theirserial<<", our serial "<< ourserial <<endl;
213      addSuckRequest(di.zone, *di.masters.begin());
214    }
215  }
216} 
217
Note: See TracBrowser for help on using the browser.