Blame SOURCES/squid-3.5.20-cache-siblings-gw.patch

e6ac7e
diff --git a/src/FwdState.cc b/src/FwdState.cc
e6ac7e
index f16acd0..c1d8a0f 100644
e6ac7e
--- a/src/FwdState.cc
e6ac7e
+++ b/src/FwdState.cc
e6ac7e
@@ -139,7 +139,6 @@ FwdState::FwdState(const Comm::ConnectionPointer &client, StoreEntry * e, HttpRe
e6ac7e
     start_t = squid_curtime;
e6ac7e
     serverDestinations.reserve(Config.forward_max_tries);
e6ac7e
     e->lock("FwdState");
e6ac7e
-    EBIT_SET(e->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
 }
e6ac7e
 
e6ac7e
 // Called once, right after object creation, when it is safe to set self
e6ac7e
@@ -250,7 +249,6 @@ FwdState::completed()
e6ac7e
             }
e6ac7e
 #endif
e6ac7e
         } else {
e6ac7e
-            EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
             entry->complete();
e6ac7e
             entry->releaseRequest();
e6ac7e
         }
e6ac7e
@@ -495,7 +493,6 @@ FwdState::complete()
e6ac7e
             debugs(17, 3, HERE << "server FD " << serverConnection()->fd << " not re-forwarding status " << entry->getReply()->sline.status());
e6ac7e
         else
e6ac7e
             debugs(17, 3, HERE << "server (FD closed) not re-forwarding status " << entry->getReply()->sline.status());
e6ac7e
-        EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
         entry->complete();
e6ac7e
 
e6ac7e
         if (!Comm::IsConnOpen(serverConn))
e6ac7e
diff --git a/src/MemStore.cc b/src/MemStore.cc
e6ac7e
index 86b6024..405b644 100644
e6ac7e
--- a/src/MemStore.cc
e6ac7e
+++ b/src/MemStore.cc
e6ac7e
@@ -402,7 +402,6 @@ MemStore::copyFromShmSlice(StoreEntry &e, const StoreIOBuffer &buf, bool eof)
e6ac7e
         const int result = rep->httpMsgParseStep(mb.buf, buf.length, eof);
e6ac7e
         if (result > 0) {
e6ac7e
             assert(rep->pstate == psParsed);
e6ac7e
-            EBIT_CLR(e.flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
         } else if (result < 0) {
e6ac7e
             debugs(20, DBG_IMPORTANT, "Corrupted mem-cached headers: " << e);
e6ac7e
             return false;
e6ac7e
@@ -508,15 +507,9 @@ MemStore::startCaching(StoreEntry &e)
e6ac7e
 void
e6ac7e
 MemStore::copyToShm(StoreEntry &e)
e6ac7e
 {
e6ac7e
-    // prevents remote readers from getting ENTRY_FWD_HDR_WAIT entries and
e6ac7e
-    // not knowing when the wait is over
e6ac7e
-    if (EBIT_TEST(e.flags, ENTRY_FWD_HDR_WAIT)) {
e6ac7e
-        debugs(20, 5, "postponing copying " << e << " for ENTRY_FWD_HDR_WAIT");
e6ac7e
-        return;
e6ac7e
-    }
e6ac7e
-
e6ac7e
     assert(map);
e6ac7e
     assert(e.mem_obj);
e6ac7e
+    Must(!EBIT_TEST(e.flags, ENTRY_FWD_HDR_WAIT));
e6ac7e
 
e6ac7e
     const int32_t index = e.mem_obj->memCache.index;
e6ac7e
     assert(index >= 0);
e6ac7e
diff --git a/src/client_side_request.cc b/src/client_side_request.cc
e6ac7e
index a824b08..5debc29 100644
e6ac7e
--- a/src/client_side_request.cc
e6ac7e
+++ b/src/client_side_request.cc
e6ac7e
@@ -1919,7 +1919,6 @@ ClientHttpRequest::handleAdaptedHeader(HttpMsg *msg)
e6ac7e
         assert(repContext);
e6ac7e
         repContext->createStoreEntry(request->method, request->flags);
e6ac7e
 
e6ac7e
-        EBIT_CLR(storeEntry()->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
         request_satisfaction_mode = true;
e6ac7e
         request_satisfaction_offset = 0;
e6ac7e
         storeEntry()->replaceHttpReply(new_rep);
e6ac7e
diff --git a/src/clients/FtpGateway.cc b/src/clients/FtpGateway.cc
e6ac7e
index 9c78bbb..4f8319a 100644
e6ac7e
--- a/src/clients/FtpGateway.cc
e6ac7e
+++ b/src/clients/FtpGateway.cc
e6ac7e
@@ -2309,7 +2309,6 @@ Ftp::Gateway::completedListing()
e6ac7e
     ferr.ftp.server_msg = ctrl.message;
e6ac7e
     ctrl.message = NULL;
e6ac7e
     entry->replaceHttpReply( ferr.BuildHttpReply() );
e6ac7e
-    EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
     entry->flush();
e6ac7e
     entry->unlock("Ftp::Gateway");
e6ac7e
 }
e6ac7e
@@ -2588,8 +2587,6 @@ Ftp::Gateway::appendSuccessHeader()
e6ac7e
 
e6ac7e
     assert(entry->isEmpty());
e6ac7e
 
e6ac7e
-    EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
-
e6ac7e
     entry->buffer();    /* released when done processing current data payload */
e6ac7e
 
e6ac7e
     filename = (t = urlpath.rpos('/')) ? t + 1 : urlpath.termedBuf();
e6ac7e
diff --git a/src/clients/FtpRelay.cc b/src/clients/FtpRelay.cc
e6ac7e
index ed498b4..f1d4e9e 100644
e6ac7e
--- a/src/clients/FtpRelay.cc
e6ac7e
+++ b/src/clients/FtpRelay.cc
e6ac7e
@@ -290,7 +290,6 @@ Ftp::Relay::failedErrorMessage(err_type error, int xerrno)
e6ac7e
     const Http::StatusCode httpStatus = failedHttpStatus(error);
e6ac7e
     HttpReply *const reply = createHttpReply(httpStatus);
e6ac7e
     entry->replaceHttpReply(reply);
e6ac7e
-    EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
     fwd->request->detailError(error, xerrno);
e6ac7e
 }
e6ac7e
 
e6ac7e
@@ -373,7 +372,6 @@ void
e6ac7e
 Ftp::Relay::forwardReply()
e6ac7e
 {
e6ac7e
     assert(entry->isEmpty());
e6ac7e
-    EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
 
e6ac7e
     HttpReply *const reply = createHttpReply(Http::scNoContent);
e6ac7e
 
e6ac7e
@@ -448,7 +446,6 @@ Ftp::Relay::startDataDownload()
e6ac7e
            " (" << data.conn->local << ")");
e6ac7e
 
e6ac7e
     HttpReply *const reply = createHttpReply(Http::scOkay, -1);
e6ac7e
-    EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
     setVirginReply(reply);
e6ac7e
     adaptOrFinalizeReply();
e6ac7e
 
e6ac7e
diff --git a/src/enums.h b/src/enums.h
e6ac7e
index 4d04805..50199da 100644
e6ac7e
--- a/src/enums.h
e6ac7e
+++ b/src/enums.h
e6ac7e
@@ -96,12 +96,31 @@ typedef enum {
e6ac7e
 enum {
e6ac7e
     ENTRY_SPECIAL,
e6ac7e
     ENTRY_REVALIDATE,
e6ac7e
+
e6ac7e
+    /// Tiny Store writes are likely. The writes should be aggregated together
e6ac7e
+    /// before Squid announces the new content availability to the store
e6ac7e
+    /// clients. For example, forming a cached HTTP response header may result
e6ac7e
+    /// in dozens of StoreEntry::write() calls, many of which adding as little
e6ac7e
+    /// as two bytes. Sharing those small writes with the store clients
e6ac7e
+    /// increases overhead, especially because the client code can do nothing
e6ac7e
+    /// useful with the written content until the whole response header is
e6ac7e
+    /// stored. Might be combined with ENTRY_FWD_HDR_WAIT. TODO: Rename to
e6ac7e
+    /// ENTRY_DELAY_WHILE_COALESCING to emphasize the difference from and
e6ac7e
+    /// similarity with ENTRY_FWD_HDR_WAIT.
e6ac7e
     DELAY_SENDING,
e6ac7e
     RELEASE_REQUEST,
e6ac7e
     REFRESH_REQUEST,
e6ac7e
     ENTRY_CACHABLE_RESERVED_FOR_FUTURE_USE,
e6ac7e
     ENTRY_DISPATCHED,
e6ac7e
     KEY_PRIVATE,
e6ac7e
+
e6ac7e
+    /// The current entry response may change. The contents of an entry in this
e6ac7e
+    /// state must not be shared with its store clients. For example, Squid
e6ac7e
+    /// receives (and buffers) an HTTP/504 response but may decide to retry that
e6ac7e
+    /// transaction to receive a successful response from another server
e6ac7e
+    /// instead. Might be combined with DELAY_SENDING. TODO: Rename to
e6ac7e
+    /// ENTRY_DELAY_WHILE_WOBBLING to emphasize the difference from and
e6ac7e
+    /// similarity with DELAY_SENDING.
e6ac7e
     ENTRY_FWD_HDR_WAIT,
e6ac7e
     ENTRY_NEGCACHED,
e6ac7e
     ENTRY_VALIDATED,
e6ac7e
diff --git a/src/gopher.cc b/src/gopher.cc
e6ac7e
index d373e8a..6d4ab1e 100644
e6ac7e
--- a/src/gopher.cc
e6ac7e
+++ b/src/gopher.cc
e6ac7e
@@ -233,7 +233,6 @@ gopherMimeCreate(GopherStateData * gopherState)
e6ac7e
     }
e6ac7e
 
e6ac7e
     assert(entry->isEmpty());
e6ac7e
-    EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
 
e6ac7e
     HttpReply *reply = new HttpReply;
e6ac7e
     entry->buffer();
e6ac7e
diff --git a/src/http.cc b/src/http.cc
e6ac7e
index 1dd1e6d..08531dc 100644
e6ac7e
--- a/src/http.cc
e6ac7e
+++ b/src/http.cc
e6ac7e
@@ -932,8 +932,8 @@ HttpStateData::haveParsedReplyHeaders()
e6ac7e
 
e6ac7e
         if (vary.isEmpty()) {
e6ac7e
             entry->makePrivate();
e6ac7e
-            if (!fwd->reforwardableStatus(rep->sline.status()))
e6ac7e
-                EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
+            if (fwd->reforwardableStatus(rep->sline.status()))
e6ac7e
+                EBIT_SET(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
             varyFailure = true;
e6ac7e
         } else {
e6ac7e
             entry->mem_obj->vary_headers = vary;
e6ac7e
@@ -945,8 +945,8 @@ HttpStateData::haveParsedReplyHeaders()
e6ac7e
          * If its not a reply that we will re-forward, then
e6ac7e
          * allow the client to get it.
e6ac7e
          */
e6ac7e
-        if (!fwd->reforwardableStatus(rep->sline.status()))
e6ac7e
-            EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
+        if (fwd->reforwardableStatus(rep->sline.status()))
e6ac7e
+            EBIT_SET(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
 
e6ac7e
         switch (cacheableReply()) {
e6ac7e
 
e6ac7e
diff --git a/src/ipc/Forwarder.cc b/src/ipc/Forwarder.cc
e6ac7e
index bf3c428..116d6f0 100644
e6ac7e
--- a/src/ipc/Forwarder.cc
e6ac7e
+++ b/src/ipc/Forwarder.cc
e6ac7e
@@ -94,8 +94,10 @@ Ipc::Forwarder::handleRemoteAck()
e6ac7e
 {
e6ac7e
     debugs(54, 3, HERE);
e6ac7e
     request->requestId = 0;
e6ac7e
-    // Do not clear ENTRY_FWD_HDR_WAIT or do entry->complete() because
e6ac7e
-    // it will trigger our client side processing. Let job cleanup close.
e6ac7e
+    // Do not do entry->complete() because it will trigger our client side
e6ac7e
+    // processing when we no longer own the client-Squid connection.
e6ac7e
+    // Let job cleanup close the client-Squid connection that Coordinator
e6ac7e
+    // now owns.
e6ac7e
 }
e6ac7e
 
e6ac7e
 /// Ipc::Forwarder::requestTimedOut wrapper
e6ac7e
diff --git a/src/mgr/Forwarder.cc b/src/mgr/Forwarder.cc
e6ac7e
index 3c4e4f3..7d33a9b 100644
e6ac7e
--- a/src/mgr/Forwarder.cc
e6ac7e
+++ b/src/mgr/Forwarder.cc
e6ac7e
@@ -37,7 +37,6 @@ Mgr::Forwarder::Forwarder(const Comm::ConnectionPointer &aConn, const ActionPara
e6ac7e
 
e6ac7e
     HTTPMSGLOCK(httpRequest);
e6ac7e
     entry->lock("Mgr::Forwarder");
e6ac7e
-    EBIT_SET(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
 
e6ac7e
     closer = asyncCall(16, 5, "Mgr::Forwarder::noteCommClosed",
e6ac7e
                        CommCbMemFunT<Forwarder, CommCloseCbParams>(this, &Forwarder::noteCommClosed));
e6ac7e
@@ -122,7 +121,6 @@ Mgr::Forwarder::sendError(ErrorState *error)
e6ac7e
     Must(entry != NULL);
e6ac7e
     Must(httpRequest != NULL);
e6ac7e
 
e6ac7e
-    EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
     entry->buffer();
e6ac7e
     entry->replaceHttpReply(error->BuildHttpReply());
e6ac7e
     entry->expires = squid_curtime;
e6ac7e
diff --git a/src/store.cc b/src/store.cc
e6ac7e
index cbb2676..c5ae817 100644
e6ac7e
--- a/src/store.cc
e6ac7e
+++ b/src/store.cc
e6ac7e
@@ -831,8 +831,12 @@ StoreEntry::write (StoreIOBuffer writeBuffer)
e6ac7e
     storeGetMemSpace(writeBuffer.length);
e6ac7e
     mem_obj->write(writeBuffer);
e6ac7e
 
e6ac7e
-    if (!EBIT_TEST(flags, DELAY_SENDING))
e6ac7e
-        invokeHandlers();
e6ac7e
+    if (EBIT_TEST(flags, ENTRY_FWD_HDR_WAIT) && !mem_obj->readAheadPolicyCanRead()) {
e6ac7e
+        debugs(20, 3, "allow Store clients to get entry content after buffering too much for " << *this);
e6ac7e
+        EBIT_CLR(flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
+    }
e6ac7e
+
e6ac7e
+    invokeHandlers();
e6ac7e
 }
e6ac7e
 
e6ac7e
 /* Append incoming data from a primary server to an entry. */
e6ac7e
@@ -1047,6 +1051,9 @@ StoreEntry::complete()
e6ac7e
 {
e6ac7e
     debugs(20, 3, "storeComplete: '" << getMD5Text() << "'");
e6ac7e
 
e6ac7e
+    // To preserve forwarding retries, call FwdState::complete() instead.
e6ac7e
+    EBIT_CLR(flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
+
e6ac7e
     if (store_status != STORE_PENDING) {
e6ac7e
         /*
e6ac7e
          * if we're not STORE_PENDING, then probably we got aborted
e6ac7e
@@ -1103,6 +1110,9 @@ StoreEntry::abort()
e6ac7e
 
e6ac7e
     EBIT_SET(flags, ENTRY_ABORTED);
e6ac7e
 
e6ac7e
+    // allow the Store clients to be told about the problem
e6ac7e
+    EBIT_CLR(flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
+
e6ac7e
     setMemStatus(NOT_IN_MEMORY);
e6ac7e
 
e6ac7e
     store_status = STORE_OK;
e6ac7e
@@ -1890,7 +1900,6 @@ StoreEntry::startWriting()
e6ac7e
 
e6ac7e
     rep->packHeadersInto(&p);
e6ac7e
     mem_obj->markEndOfReplyHeaders();
e6ac7e
-    EBIT_CLR(flags, ENTRY_FWD_HDR_WAIT);
e6ac7e
 
e6ac7e
     rep->body.packInto(&p);
e6ac7e
 
e6ac7e
diff --git a/src/store_client.cc b/src/store_client.cc
e6ac7e
index 07a05d4..7ee1b10 100644
e6ac7e
--- a/src/store_client.cc
e6ac7e
+++ b/src/store_client.cc
e6ac7e
@@ -282,11 +282,6 @@ storeClientCopy2(StoreEntry * e, store_client * sc)
e6ac7e
         return;
e6ac7e
     }
e6ac7e
 
e6ac7e
-    if (EBIT_TEST(e->flags, ENTRY_FWD_HDR_WAIT)) {
e6ac7e
-        debugs(90, 5, "storeClientCopy2: returning because ENTRY_FWD_HDR_WAIT set");
e6ac7e
-        return;
e6ac7e
-    }
e6ac7e
-
e6ac7e
     if (sc->flags.store_copying) {
e6ac7e
         sc->flags.copy_event_pending = true;
e6ac7e
         debugs(90, 3, "storeClientCopy2: Queueing storeClientCopyEvent()");
e6ac7e
@@ -720,6 +715,15 @@ storeUnregister(store_client * sc, StoreEntry * e, void *data)
e6ac7e
 void
e6ac7e
 StoreEntry::invokeHandlers()
e6ac7e
 {
e6ac7e
+    if (EBIT_TEST(flags, DELAY_SENDING)) {
e6ac7e
+        debugs(90, 3, "DELAY_SENDING is on, exiting " << *this);
e6ac7e
+        return;
e6ac7e
+    }
e6ac7e
+    if (EBIT_TEST(flags, ENTRY_FWD_HDR_WAIT)) {
e6ac7e
+        debugs(90, 3, "ENTRY_FWD_HDR_WAIT is on, exiting " << *this);
e6ac7e
+        return;
e6ac7e
+    }
e6ac7e
+
e6ac7e
     /* Commit what we can to disk, if appropriate */
e6ac7e
     swapOut();
e6ac7e
     int i = 0;