@@ -715,6 +715,8 @@ UeberBackend::UeberBackend(const string& pname)
715715 d_negcache_ttl = ::arg ().asNum (" negquery-cache-ttl" );
716716
717717 backends = BackendMakers ().all (pname == " key-only" );
718+
719+ d_handle.setParent (this );
718720}
719721
720722// returns -1 for miss, 0 for negative match, 1 for hit
@@ -806,22 +808,15 @@ void UeberBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t z
806808
807809 d_qtype = qtype.getCode ();
808810
809- d_handle.parent = this ;
810- d_handle.backendIndex = 0 ;
811- d_handle.qtype = s_doANYLookupsOnly ? QType::ANY : qtype;
812- d_handle.qname = qname;
813- d_handle.zoneId = zoneId;
814- d_handle.pkt_p = pkt_p;
811+ d_handle.lookup (qtype, qname, zoneId, pkt_p);
815812
816813 if (backends.empty ()) {
817814 g_log << Logger::Error << " No database backends available - unable to answer questions." << endl;
818815 d_stale = true ; // please recycle us!
819816 throw PDNSException (" We are stale, please recycle" );
820817 }
821818
822- d_question.qtype = d_handle.qtype ;
823- d_question.qname = qname;
824- d_question.zoneId = d_handle.zoneId ;
819+ d_handle.setupQuestion (d_question);
825820
826821 auto cacheResult = cacheHas (d_question, d_answers);
827822 if (cacheResult == CacheResult::Miss) { // nothing
@@ -1063,14 +1058,30 @@ void UeberBackend::flush()
10631058 }
10641059}
10651060
1061+ void UeberBackend::handle::lookup (const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p)
1062+ {
1063+ d_backendIndex = 0 ;
1064+ d_qtype = s_doANYLookupsOnly ? QType::ANY : qtype;
1065+ d_qname = qname;
1066+ d_zoneId = zoneId;
1067+ d_pkt_p = pkt_p;
1068+ }
1069+
1070+ void UeberBackend::handle::setupQuestion (UeberBackend::Question& question) const
1071+ {
1072+ question.qtype = d_qtype;
1073+ question.qname = d_qname;
1074+ question.zoneId = d_zoneId;
1075+ }
1076+
10661077// Set d_hinterBackend to the next available backend from the parents list,
10671078// reset it to nullptr if the whole list has been processed.
10681079// Invokes lookup on behalf of the newly picked backend if successful.
10691080void UeberBackend::handle::selectNextBackend ()
10701081{
1071- if (backendIndex < parent ->backends .size ()) {
1072- d_hinterBackend = parent ->backends [backendIndex ++].get ();
1073- d_hinterBackend->lookup (qtype, qname, zoneId, pkt_p );
1082+ if (d_backendIndex < d_parent ->backends .size ()) {
1083+ d_hinterBackend = d_parent ->backends [d_backendIndex ++].get ();
1084+ d_hinterBackend->lookup (d_qtype, d_qname, d_zoneId, d_pkt_p );
10741085 ++(*s_backendQueries);
10751086 }
10761087 else {
@@ -1082,11 +1093,11 @@ bool UeberBackend::handle::get(DNSZoneRecord& record)
10821093{
10831094 DLOG (g_log << " Ueber get() was called for a " << qtype << " record" << endl);
10841095 while (d_hinterBackend != nullptr && !(d_hinterBackend->get (record))) { // this backend is out of answers
1085- DLOG (g_log << " Backend #" << backendIndex << " of " << parent ->backends .size ()
1096+ DLOG (g_log << " Backend #" << d_backendIndex << " of " << d_parent ->backends .size ()
10861097 << " out of answers, trying next" << endl);
10871098 selectNextBackend ();
10881099 if (d_hinterBackend != nullptr ) {
1089- DLOG (g_log << " Now asking backend #" << backendIndex << endl);
1100+ DLOG (g_log << " Now asking backend #" << d_backendIndex << endl);
10901101 }
10911102 }
10921103
@@ -1096,7 +1107,7 @@ bool UeberBackend::handle::get(DNSZoneRecord& record)
10961107 }
10971108
10981109 DLOG (g_log << " Found an answering backend - will not try another one" << endl);
1099- backendIndex = parent ->backends .size (); // don't go on to the next backend
1110+ d_backendIndex = d_parent ->backends .size (); // don't go on to the next backend
11001111 return true ;
11011112}
11021113
0 commit comments