r5101 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Fri Aug 13 11:40:18 CEST 2010


Author: phk
Date: 2010-08-13 11:40:18 +0200 (Fri, 13 Aug 2010)
New Revision: 5101

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
Log:
Rework the FetchHdr() and surroundings a litle bit, to get us a return
value that indicates if a failure should be retried.

Condition for retry is that the connection is recycled and fails before
we receive any data from the other end.

(The actual retry is not implemented yet)




Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2010-08-12 09:48:45 UTC (rev 5100)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2010-08-13 09:40:18 UTC (rev 5101)
@@ -456,6 +456,8 @@
 	struct vdi_simple	*vdis;
 	int			fd;
 
+	uint8_t			recycled;
+
 	/* Timeouts */
 	double			first_byte_timeout;
 	double			between_bytes_timeout;

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-08-12 09:48:45 UTC (rev 5100)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-08-13 09:40:18 UTC (rev 5101)
@@ -94,6 +94,7 @@
 	assert(vc->backend == NULL);
 	assert(vc->fd < 0);
 
+	vc->recycled = 0;
 	if (params->cache_vbcs) {
 		Lck_Lock(&VBE_mtx);
 		VTAILQ_INSERT_HEAD(&vbcs, vc, list);
@@ -364,11 +365,15 @@
 			WSP(sp, SLT_Backend, "%d %s %s",
 			    vc->fd, sp->director->vcl_name, bp->vcl_name);
 			vc->vdis = vs;
+			vc->recycled = 1;
 			return (vc);
 		}
 		VSC_main->backend_toolate++;
-		sp->vbc = vc;
-		VDI_CloseFd(sp);
+		WSL(sp->wrk, SLT_BackendClose, vc->fd, "%s", bp->vcl_name);
+		TCP_close(&vc->fd);
+		VBE_DropRefConn(bp);
+		vc->backend = NULL;
+		VBE_ReleaseConn(vc);
 	}
 
 	if (!vbe_Healthy(sp->t_req, (uintptr_t)sp->objhead, vs)) {

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2010-08-12 09:48:45 UTC (rev 5100)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2010-08-13 09:40:18 UTC (rev 5101)
@@ -324,7 +324,15 @@
 	return (0);
 }
 
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Send request, and receive the HTTP protocol response, but not the
+ * response body.
+ *
+ * Return value:
+ *	-1 failure, not retryable
+ *	 0 success
+ *	 1 failure which can be retried.
+ */
 
 int
 FetchHdr(struct sess *sp)
@@ -333,35 +341,38 @@
 	struct worker *w;
 	char *b;
 	struct http *hp;
+	int retry = -1;
 	int i;
-	double tmo;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
+	w = sp->wrk;
+
 	AN(sp->director);
 	AZ(sp->obj);
+
 	if (sp->objcore != NULL) {		/* pass has no objcore */
 		CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
 		AN(sp->objhead);		/* details in hash_slinger.h */
 		AN(sp->objcore->flags & OC_F_BUSY);
 	}
 
-	/* Transmit request */
-
-	w = sp->wrk;
 	hp = sp->wrk->bereq;
 
 	sp->vbc = VDI_GetFd(NULL, sp);
 	if (sp->vbc == NULL) {
 		WSP(sp, SLT_FetchError, "no backend connection");
-		return (__LINE__);
+		return (-1);
 	}
 	vc = sp->vbc;
+	if (vc->recycled)
+		retry = 1;
+		
 
 	/*
 	 * Now that we know our backend, we can set a default Host:
-	 * header if one is necessary.
-	 * XXX: This possibly ought to go into the default VCL
+	 * header if one is necessary.  This cannot be done in the VCL
+	 * because the backend may be chosen by a director.
 	 */
 	if (!http_GetHdr(hp, H_Host, &b))
 		VDI_AddHostHeader(sp);
@@ -373,10 +384,11 @@
 	/* Deal with any message-body the request might have */
 	i = FetchReqBody(sp);
 	if (WRW_FlushRelease(w) || i > 0) {
-		WSP(sp, SLT_FetchError, "backend write error: %d", errno);
+		WSP(sp, SLT_FetchError, "backend write error: %d (%s)",
+		    errno, strerror(errno));
 		VDI_CloseFd(sp);
 		/* XXX: other cleanup ? */
-		return (__LINE__);
+		return (retry);
 	}
 
 	/* Checkpoint the vsl.here */
@@ -390,31 +402,39 @@
 	HTC_Init(sp->wrk->htc, sp->wrk->ws, vc->fd);
 
 	TCP_set_read_timeout(vc->fd, vc->first_byte_timeout);
-	tmo = vc->first_byte_timeout;
 
-	do {
+	i = HTC_Rx(sp->wrk->htc);
+
+	if (i < 0) {
+		WSP(sp, SLT_FetchError, "http first read error: %d %d (%s)",
+		    i, errno, strerror(errno));
+		VDI_CloseFd(sp);
+		/* XXX: other cleanup ? */
+		/* Retryable if we never received anything */
+		return (i == -1 ? retry : -1);
+	}
+
+	TCP_set_read_timeout(vc->fd, vc->between_bytes_timeout);
+
+	while (i == 0) {
 		i = HTC_Rx(sp->wrk->htc);
 		if (i < 0) {
 			WSP(sp, SLT_FetchError,
-			    "http read error: %d (%s)", errno, strerror(errno));
+			    "http first read error: %d %d (%s)",
+			    i, errno, strerror(errno));
 			VDI_CloseFd(sp);
 			/* XXX: other cleanup ? */
-			return (__LINE__);
+			return (-1);
 		}
+	}
 
-		if (vc->between_bytes_timeout != tmo) {
-			TCP_set_read_timeout(vc->fd, vc->between_bytes_timeout);
-			tmo = vc->between_bytes_timeout;
-		}
-	} while (i == 0);
-
 	hp = sp->wrk->beresp;
 
 	if (http_DissectResponse(sp->wrk, sp->wrk->htc, hp)) {
 		WSP(sp, SLT_FetchError, "http format error");
 		VDI_CloseFd(sp);
 		/* XXX: other cleanup ? */
-		return (__LINE__);
+		return (-1);
 	}
 	return (0);
 }




More information about the varnish-commit mailing list