@@ -806,7 +806,8 @@ void UeberBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t z
806806
807807 d_qtype = qtype.getCode ();
808808
809- d_handle.i = 0 ;
809+ d_handle.parent = this ;
810+ d_handle.backendIndex = 0 ;
810811 d_handle.qtype = s_doANYLookupsOnly ? QType::ANY : qtype;
811812 d_handle.qname = qname;
812813 d_handle.zoneId = zoneId;
@@ -827,8 +828,7 @@ void UeberBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t z
827828 // cout<<"UeberBackend::lookup("<<qname<<"|"<<DNSRecordContent::NumberToType(qtype.getCode())<<"): uncached"<<endl;
828829 d_negcached = d_cached = false ;
829830 d_answers.clear ();
830- (d_handle.d_hinterBackend = backends[d_handle.i ++].get ())->lookup (d_handle.qtype , d_handle.qname , d_handle.zoneId , d_handle.pkt_p );
831- ++(*s_backendQueries);
831+ d_handle.selectNextBackend ();
832832 }
833833 else if (cacheResult == CacheResult::NegativeMatch) {
834834 // cout<<"UeberBackend::lookup("<<qname<<"|"<<DNSRecordContent::NumberToType(qtype.getCode())<<"): NEGcached"<<endl;
@@ -842,8 +842,6 @@ void UeberBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t z
842842 d_cached = true ;
843843 d_cachehandleiter = d_answers.begin ();
844844 }
845-
846- d_handle.parent = this ;
847845}
848846
849847void UeberBackend::getAllDomains (vector<DomainInfo>* domains, bool getSerial, bool include_disabled)
@@ -1078,33 +1076,41 @@ UeberBackend::handle::~handle()
10781076 --instances;
10791077}
10801078
1079+ // Set d_hinterBackend to the next available backend from the parents list,
1080+ // reset it to nullptr if the whole list has been processed.
1081+ // Invokes lookup on behalf of the newly picked backend if successful.
1082+ void UeberBackend::handle::selectNextBackend ()
1083+ {
1084+ if (backendIndex < parent->backends .size ()) {
1085+ d_hinterBackend = parent->backends [backendIndex++].get ();
1086+ d_hinterBackend->lookup (qtype, qname, zoneId, pkt_p);
1087+ ++(*s_backendQueries);
1088+ }
1089+ else {
1090+ d_hinterBackend = nullptr ;
1091+ }
1092+ }
1093+
10811094bool UeberBackend::handle::get (DNSZoneRecord& record)
10821095{
10831096 DLOG (g_log << " Ueber get() was called for a " << qtype << " record" << endl);
10841097 bool isMore = false ;
10851098 while (d_hinterBackend != nullptr && !(isMore = d_hinterBackend->get (record))) { // this backend out of answers
1086- if (i < parent->backends .size ()) {
1087- DLOG (g_log << " Backend #" << i << " of " << parent->backends .size ()
1088- << " out of answers, taking next" << endl);
1089-
1090- d_hinterBackend = parent->backends [i++].get ();
1091- d_hinterBackend->lookup (qtype, qname, zoneId, pkt_p);
1092- ++(*s_backendQueries);
1099+ DLOG (g_log << " Backend #" << backendIndex << " of " << parent->backends .size ()
1100+ << " out of answers, trying next" << endl);
1101+ selectNextBackend ();
1102+ if (d_hinterBackend != nullptr ) {
1103+ DLOG (g_log << " Now asking backend #" << backendIndex << endl);
10931104 }
1094- else {
1095- break ;
1096- }
1097-
1098- DLOG (g_log << " Now asking backend #" << i << endl);
10991105 }
11001106
1101- if (!isMore && i == parent-> backends . size () ) {
1107+ if (d_hinterBackend == nullptr ) {
11021108 DLOG (g_log << " UeberBackend reached end of backends" << endl);
11031109 return false ;
11041110 }
11051111
11061112 DLOG (g_log << " Found an answering backend - will not try another one" << endl);
1107- i = parent->backends .size (); // don't go on to the next backend
1113+ backendIndex = parent->backends .size (); // don't go on to the next backend
11081114 return true ;
11091115}
11101116
0 commit comments