Parcourir la source

[trac491] Also cache intermediate results

Added some extensive dlog() calls for testing while we are building this
Jelte Jansen il y a 14 ans
Parent
commit
f59af8201a
2 fichiers modifiés avec 34 ajouts et 7 suppressions
  1. 31 6
      src/lib/asiolink/recursive_query.cc
  2. 3 1
      src/lib/cache/message_cache.cc

+ 31 - 6
src/lib/asiolink/recursive_query.cc

@@ -138,6 +138,24 @@ private:
     // Reference to our cache
     isc::cache::ResolverCache& cache_;
 
+    // perform a single lookup; first we check the cache to see
+    // if we have a response for our query stored already. if
+    // so, call handlerecursiveresponse(), if not, we call send()
+    void doLookup() {
+        dlog("doLookup: try cache");
+        Message cached_message(Message::RENDER);
+        cached_message.addQuestion(question_);
+        cached_message.setOpcode(Opcode::QUERY());
+        if (cache_.lookup(question_.getName(), question_.getType(),
+                          question_.getClass(), cached_message)) {
+            dlog("Message found in cache, returning that");
+            handleRecursiveAnswer(cached_message);
+        } else {
+            send();
+        }
+        
+    }
+
     // (re)send the query to the server.
     void send() {
         const int uc = upstream_->size();
@@ -219,7 +237,7 @@ private:
                                  question_.getType());
 
             dlog("Following CNAME chain to " + question_.toText());
-            send();
+            doLookup();
             return false;
             break;
         case isc::resolve::ResponseClassifier::NXDOMAIN:
@@ -256,6 +274,10 @@ private:
             }
             if (found_ns_address) {
                 // next resolver round
+                // we do NOT use doLookup() here, but send() (i.e. we
+                // skip the cache), since if we had the final answer
+                // instead of a delegation cached, we would have been
+                // there by now.
                 send();
                 return false;
             } else {
@@ -336,7 +358,7 @@ public:
             setZoneServersToRoot();
         }
 
-        send();
+        doLookup();
     }
 
     void setZoneServersToRoot() {
@@ -375,10 +397,10 @@ public:
         done_ = true;
         if (resume && !answer_sent_) {
             // Store the answer we found in our cache
-            std::cout << "[XX] caching our answer:" << std::endl;
-            std::cout << answer_message_->toText();
-            cache_.update(*answer_message_);
-            std::cout << "[XX] done caching our answer" << std::endl;
+            //std::cout << "[XX] caching our answer:" << std::endl;
+            //std::cout << answer_message_->toText();
+            //cache_.update(*answer_message_);
+            //std::cout << "[XX] done caching our answer" << std::endl;
             resolvercallback_->success(answer_message_);
         } else {
             resolvercallback_->failure();
@@ -405,6 +427,9 @@ public:
             InputBuffer ibuf(buffer_->getData(), buffer_->getLength());
             incoming.fromWire(ibuf);
 
+            // let's first dunk it into our cache
+            cache_.update(incoming);
+            
             if (upstream_->size() == 0 &&
                 incoming.getRcode() == Rcode::NOERROR()) {
                 done_ = handleRecursiveAnswer(incoming);

+ 3 - 1
src/lib/cache/message_cache.cc

@@ -60,7 +60,9 @@ bool
 MessageCache::update(const Message& msg) {
     QuestionIterator iter = msg.beginQuestion();
     std::string entry_name = genCacheEntryName((*iter)->getName(), (*iter)->getType());
-    std::cout << "[XX] MESSAGECACHE UDPATE: " << entry_name << std::endl;
+    std::cout << "[XX] MESSAGECACHE UPDATE: " << entry_name << std::endl;
+    std::cout << "[XX] FOR MESSAGE:" << std::endl;
+    std::cout << msg.toText();
     HashKey entry_key = HashKey(entry_name, RRClass(message_class_));
 
     // The simplest way to update is removing the old message entry directly.