r2168 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Oct 24 20:38:18 CEST 2007


Author: phk
Date: 2007-10-24 20:38:17 +0200 (Wed, 24 Oct 2007)
New Revision: 2168

Modified:
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/steps.h
Log:
Split STP_RECV in two:

STP_START is the initial setup of a viable workerthread:  Dissecting
HTTP, getting vcl reference etc.

STP_RECV is invoking vcl_recv() and following orders.



Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2007-10-24 14:32:12 UTC (rev 2167)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2007-10-24 18:38:17 UTC (rev 2168)
@@ -222,7 +222,7 @@
 		SES_Delete(sp);
 		break;
 	case 1:
-		sp->step = STP_RECV;
+		sp->step = STP_START;
 		WRK_QueueSession(sp);
 		break;
 	default:

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2007-10-24 14:32:12 UTC (rev 2167)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2007-10-24 18:38:17 UTC (rev 2168)
@@ -48,12 +48,12 @@
 DOT	size="7.2,10.5"
 DOT	margin="0.5"
 DOT	center="1"
-DOT start [
+DOT acceptor [
 DOT	shape=hexagon
 DOT	label="Request received"
 DOT ]
 DOT ERROR [shape=plaintext]
-DOT start -> recv [style=bold,color=green,weight=4]
+DOT acceptor -> start [style=bold,color=green,weight=4]
  */
 
 #include <stdio.h>
@@ -93,7 +93,7 @@
 	while (i == 0)
 		i = HTC_Rx(sp->htc);
 	if (i == 1) {
-		sp->step = STP_RECV;
+		sp->step = STP_START;
 	} else {
 		vca_close_session(sp, "overflow");
 		sp->step = STP_DONE;
@@ -227,7 +227,7 @@
 	i = HTC_Reinit(sp->htc);
 	if (i == 1) {
 		VSL_stats->sess_pipeline++;
-		sp->step = STP_RECV;
+		sp->step = STP_START;
 		return (0);
 	}
 	if (Tlen(sp->htc->rxbuf)) {
@@ -290,6 +290,7 @@
 DOT }
 DOT fetch_pass -> deliver
 DOT vcl_fetch -> deliver [label="insert",style=bold,color=blue,weight=2]
+DOT vcl_fetch -> recv [label="restart"]
 DOT vcl_fetch -> errfetch [label="error"]
 DOT errfetch [label="ERROR",shape=plaintext]
  */
@@ -386,7 +387,7 @@
 
 	switch (i) {
 	case 1:
-		sp->step = STP_RECV;
+		sp->step = STP_START;
 		break;
 	case -1:
 		vca_close_session(sp, "error");
@@ -700,8 +701,7 @@
 
 /*--------------------------------------------------------------------
  * RECV
- * We have a complete request, get a VCL reference and dispatch it
- * as instructed by vcl_recv{}
+ * We have a complete request, set everything up and start it.
  *
 DOT subgraph xcluster_recv {
 DOT	recv [
@@ -719,56 +719,10 @@
 static int
 cnt_recv(struct sess *sp)
 {
-	int done;
 
 	AZ(sp->obj);
+	AN(sp->vcl);
 
-	if (sp->restarts > params->max_restarts) {
-		sp->step = STP_ERROR;
-		return (0);
-	}
-	if (sp->restarts == 0) {
-		AZ(sp->vcl);
-		/* Update stats of various sorts */
-		VSL_stats->client_req++;			/* XXX not locked */
-		sp->t_req = TIM_real();
-		sp->wrk->used = sp->t_req;
-		sp->wrk->acct.req++;
-
-		/* Assign XID and log */
-		sp->xid = ++xids;				/* XXX not locked */
-		WSP(sp, SLT_ReqStart, "%s %s %u", sp->addr, sp->port,  sp->xid);
-
-		/* Borrow VCL reference from worker thread */
-		VCL_Refresh(&sp->wrk->vcl);
-		sp->vcl = sp->wrk->vcl;
-		sp->wrk->vcl = NULL;
-
-		http_Setup(sp->http, sp->ws);
-		done = http_DissectRequest(sp);
-
-		/* Catch request snapshot */
-		sp->ws_req = WS_Snapshot(sp->ws);
-
-		/* Catch original request, before modification */
-		*sp->http0 = *sp->http;
-
-		if (done != 0) {
-			RES_Error(sp, done, NULL);		/* XXX: STP_ERROR ? */
-			sp->step = STP_DONE;
-			return (0);
-		}
-
-		sp->doclose = http_DoConnection(sp->http);
-
-		/* By default we use the first backend */
-		AZ(sp->backend);
-		sp->backend = sp->vcl->backend[0];
-		CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
-
-		/* XXX: Handle TRACE & OPTIONS of Max-Forwards = 0 */
-	}
-
 	VCL_recv_method(sp);
 
 	sp->wantbody = (strcmp(sp->http->hd[HTTP_HDR_REQ].b, "HEAD") != 0);
@@ -792,7 +746,66 @@
 	}
 }
 
+/*--------------------------------------------------------------------
+ * START
+ * Handle a request, wherever it came from recv/restart.
+ *
+DOT start [shape=box,label="Dissect request"]
+DOT start -> recv 
+ */
 
+static int
+cnt_start(struct sess *sp)
+{
+	int done;
+
+	AZ(sp->restarts);
+	AZ(sp->obj);
+	AZ(sp->vcl);
+
+	/* Update stats of various sorts */
+	VSL_stats->client_req++;			/* XXX not locked */
+	sp->t_req = TIM_real();
+	sp->wrk->used = sp->t_req;
+	sp->wrk->acct.req++;
+
+	/* Assign XID and log */
+	sp->xid = ++xids;				/* XXX not locked */
+	WSP(sp, SLT_ReqStart, "%s %s %u", sp->addr, sp->port,  sp->xid);
+
+	/* Borrow VCL reference from worker thread */
+	VCL_Refresh(&sp->wrk->vcl);
+	sp->vcl = sp->wrk->vcl;
+	sp->wrk->vcl = NULL;
+
+	http_Setup(sp->http, sp->ws);
+	done = http_DissectRequest(sp);
+
+	/* Catch request snapshot */
+	sp->ws_req = WS_Snapshot(sp->ws);
+
+	/* Catch original request, before modification */
+	*sp->http0 = *sp->http;
+
+	if (done != 0) {
+		RES_Error(sp, done, NULL);		/* XXX: STP_ERROR ? */
+		sp->step = STP_DONE;
+		return (0);
+	}
+
+	sp->doclose = http_DoConnection(sp->http);
+
+	/* By default we use the first backend */
+	AZ(sp->backend);
+	sp->backend = sp->vcl->backend[0];
+	CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
+
+	/* XXX: Handle TRACE & OPTIONS of Max-Forwards = 0 */
+
+	sp->step = STP_RECV;
+	return (0);
+}
+
 /*--------------------------------------------------------------------
  * Central state engine dispatcher.
  *

Modified: trunk/varnish-cache/bin/varnishd/steps.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/steps.h	2007-10-24 14:32:12 UTC (rev 2167)
+++ trunk/varnish-cache/bin/varnishd/steps.h	2007-10-24 18:38:17 UTC (rev 2168)
@@ -32,6 +32,7 @@
 STEP(again,	AGAIN)
 STEP(first,	FIRST)
 STEP(recv,	RECV)
+STEP(start,	START)
 STEP(pipe,	PIPE)
 STEP(pass,	PASS)
 STEP(lookup,	LOOKUP)




More information about the varnish-commit mailing list