]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
AutoDoc and debugs the refresh_pattern algorithm and reply logic.
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 16 Jan 2009 10:11:45 +0000 (23:11 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 16 Jan 2009 10:11:45 +0000 (23:11 +1300)
Also throws in some extra assertions to draw out bug 2491 earlier.

src/client_side_reply.cc
src/refresh.cc

index c6f92167188f07df2fe61252fbd2388c01959a86..f449f65742f927a0af6d2175160b25210f317c72 100644 (file)
@@ -400,8 +400,8 @@ clientReplyContext::handleIMSReply(StoreIOBuffer result)
 extern "C" CSR clientGetMoreData;
 extern "C" CSD clientReplyDetach;
 
-/*
- * clientCacheHit should only be called until the HTTP reply headers
+/**
+ * clientReplyContext::cacheHit Should only be called until the HTTP reply headers
  * have been parsed.  Normally this should be a single call, but
  * it might take more than one.  As soon as we have the headers,
  * we hand off to clientSendMoreData, processExpired, or
@@ -411,12 +411,16 @@ void
 clientReplyContext::CacheHit(void *data, StoreIOBuffer result)
 {
     clientReplyContext *context = (clientReplyContext *)data;
-    context->cacheHit (result);
+    context->cacheHit(result);
 }
 
+/**
+ * Process a possible cache HIT.
+ */
 void
 clientReplyContext::cacheHit(StoreIOBuffer result)
 {
+    /** Ignore if the HIT object is being deleted. */
     if (deleting)
         return;
 
@@ -603,7 +607,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result)
     }
 }
 
-/*
+/**
  * Prepare to fetch the object as it's a cache miss of some kind.
  */
 void
@@ -613,11 +617,11 @@ clientReplyContext::processMiss()
     HttpRequest *r = http->request;
     ErrorState *err = NULL;
     debugs(88, 4, "clientProcessMiss: '" << RequestMethodStr(r->method) << " " << url << "'");
-    /*
+
+    /**
      * We might have a left-over StoreEntry from a failed cache hit
      * or IMS request.
      */
-
     if (http->storeEntry()) {
         if (EBIT_TEST(http->storeEntry()->flags, ENTRY_SPECIAL)) {
             debugs(88, 0, "clientProcessMiss: miss on a special object (" << url << ").");
@@ -628,22 +632,24 @@ clientReplyContext::processMiss()
         removeClientStoreReference(&sc, http);
     }
 
+    /** Check if its a PURGE request to be actioned. */
     if (r->method == METHOD_PURGE) {
         purgeRequest();
         return;
     }
 
+    /** Check if its an 'OTHER' request. Purge all cached entries if so and continue. */
     if (r->method == METHOD_OTHER) {
-        // invalidate all cache entries
         purgeAllCached();
     }
 
+    /** Check if 'only-if-cached' flag is set. Action if so. */
     if (http->onlyIfCached()) {
         processOnlyIfCachedMiss();
         return;
     }
 
-    /*
+    /**
      * Deny loops when running in accelerator/transproxy mode.
      */
     if (http->flags.accel && r->flags.loopdetect) {
@@ -672,16 +678,18 @@ clientReplyContext::processMiss()
             return;
         }
 
+        /** Check for internal requests. Update Protocol info if so. */
         if (http->flags.internal)
             r->protocol = PROTO_INTERNAL;
 
+        /** Start forwarding to get the new object from network */
         FwdState::fwdStart(http->getConn() != NULL ? http->getConn()->fd : -1,
                            http->storeEntry(),
                            r);
     }
 }
 
-/*
+/**
  * client issued a request with an only-if-cached cache-control directive;
  * we did not find a cached object that can be returned without
  *     contacting other servers;
@@ -1439,12 +1447,17 @@ clientReplyContext::identifyStoreObject()
     }
 }
 
+/**
+ * Check state of the current StoreEntry object.
+ * to see if we can determine the final status of the request.
+ */
 void
 clientReplyContext::identifyFoundObject(StoreEntry *newEntry)
 {
     StoreEntry *e = newEntry;
     HttpRequest *r = http->request;
 
+    /** \item  If the entry received isNull() then we ignore it. */
     if (e->isNull()) {
         http->storeEntry(NULL);
     } else {
@@ -1452,8 +1465,11 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry)
     }
 
     e = http->storeEntry();
-    /* Release IP-cache entries on reload */
 
+    /* Release IP-cache entries on reload */
+    /** \item If the request has no-cache flag set or some no_cache HACK in operation we
+      * 'invalidate' the cached IP entries for this request ???
+      */
     if (r->flags.nocache) {
 
 #if USE_DNSSERVERS
@@ -1492,14 +1508,15 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry)
 #endif
 
     if (NULL == http->storeEntry()) {
-        /* this object isn't in the cache */
-        debugs(85, 3, "clientProcessRequest2: storeGet() MISS");
+        /** \item If no StoreEntry object is current assume this object isn't in the cache set MISS*/
+        debugs(85, 3, "clientProcessRequest2: StoreEntry is NULL -  MISS");
         http->logType = LOG_TCP_MISS;
         doGetMoreData();
         return;
     }
 
     if (Config.onoff.offline) {
+        /** \item If we are running in offline mode set to HIT */
         debugs(85, 3, "clientProcessRequest2: offline HIT");
         http->logType = LOG_TCP_HIT;
         doGetMoreData();
@@ -1507,7 +1524,8 @@ clientReplyContext::identifyFoundObject(StoreEntry *newEntry)
     }
 
     if (http->redirect.status) {
-        /* force this to be a miss */
+        /** \item If redirection status is True force this to be a MISS */
+        debugs(85, 3, "clientProcessRequest2: redirectStatus forced StoreEntry to NULL -  MISS");
         http->storeEntry(NULL);
         http->logType = LOG_TCP_MISS;
         doGetMoreData();
@@ -1619,8 +1637,7 @@ clientReplyContext::doGetMoreData()
              * the method as GET.
              */
             http->storeEntry()->createMemObject(http->uri, http->log_uri);
-            http->storeEntry()->mem_obj->method =
-                http->request->method;
+            http->storeEntry()->mem_obj->method = http->request->method;
         }
 
         sc = storeClientListAdd(http->storeEntry(), this);
index 2fd40fba2551ba7ce638d4d1fa03ab61bd5671ce..5f2a2e10f057cfa7fd16c1ff34405809f25f6de3 100644 (file)
@@ -139,14 +139,15 @@ refreshUncompiledPattern(const char *pat)
     return NULL;
 }
 
-/*
+/**
  * Calculate how stale the response is (or will be at the check_time).
  * Staleness calculation is based on the following: (1) response
  * expiration time, (2) age greater than configured maximum, (3)
  * last-modified factor, and (4) age less than configured minimum.
  *
- * If the response is fresh, return -1.  Otherwise return its
- * staleness.  NOTE return value of 0 means the response is stale.
+ * \retval -1  If the response is fresh.
+ * \retval >0  Otherwise return it's staleness.
+ * \retval 0   NOTE return value of 0 means the response is stale.
  *
  * The 'stale_flags' structure is used to tell the calling function
  * _why_ this response is fresh or stale.  Its used, for example,
@@ -156,8 +157,8 @@ refreshUncompiledPattern(const char *pat)
 static int
 refreshStaleness(const StoreEntry * entry, time_t check_time, time_t age, const refresh_t * R, stale_flags * sf)
 {
-    /*
-     * Check for an explicit expiration time.
+    /** \par
+     * Check for an explicit expiration time (Expires: header).
      */
 
     if (entry->expires > -1) {
@@ -177,7 +178,7 @@ refreshStaleness(const StoreEntry * entry, time_t check_time, time_t age, const
     }
 
     assert(age >= 0);
-    /*
+    /** \par
      * Use local heuristics to determine staleness.  Start with the
      * max age from the refresh_pattern rule.
      */
@@ -188,8 +189,8 @@ refreshStaleness(const StoreEntry * entry, time_t check_time, time_t age, const
         return (age - R->max);
     }
 
-    /*
-     * Try the last-modified factor algorithm.
+    /** \par
+     * Try the last-modified factor algorithm:  refresh_pattern n% percentage of Last-Modified: age.
      */
     if (entry->lastmod > -1 && entry->timestamp > entry->lastmod) {
         /*
@@ -208,8 +209,8 @@ refreshStaleness(const StoreEntry * entry, time_t check_time, time_t age, const
         }
     }
 
-    /*
-     * If we are here, staleness is determined by the refresh_pattern
+    /** \par
+     * Finally, if all else fails;  staleness is determined by the refresh_pattern
      * configured minimum age.
      */
     if (age < R->min) {
@@ -222,8 +223,9 @@ refreshStaleness(const StoreEntry * entry, time_t check_time, time_t age, const
     return (age - R->min);
 }
 
-/*  return 1 if the entry must be revalidated within delta seconds
- *         0 otherwise
+/**
+ * \retval 1 if the entry must be revalidated within delta seconds
+ * \retval 0 otherwise
  *
  *  note: request maybe null (e.g. for cache digests build)
  */
@@ -244,9 +246,11 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
 
     debugs(22, 3, "refreshCheck: '" << (uri ? uri : "<none>") << "'");
 
+    assert(age >= 0);
     if (check_time > entry->timestamp)
         age = check_time - entry->timestamp;
 
+    assert(age >= 0);
     R = uri ? refreshLimits(uri) : refreshUncompiledPattern(".");
 
     if (NULL == R)
@@ -254,6 +258,7 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta)
 
     memset(&sf, '\0', sizeof(sf));
 
+    assert(age >= 0);
     staleness = refreshStaleness(entry, check_time, age, R, &sf);
 
     debugs(22, 3, "Staleness = " << staleness);