[experimental-ims] 4c4d6f6 Make sure that all sessions, requests and busyobj's have a unique transaction id 'vxid'

Poul-Henning Kamp phk at FreeBSD.org
Thu Dec 18 10:27:50 CET 2014


commit 4c4d6f652d0b96aba584575e692a913172146168
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jul 2 10:37:36 2012 +0000

    Make sure that all sessions, requests and busyobj's have a
    unique transaction id 'vxid'

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index d19dc32..ae42dd0 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -259,7 +259,7 @@ struct vsl_log {
 
 /*--------------------------------------------------------------------*/
 
-struct vxid {
+struct vxid_pool {
 	uint32_t		next;
 	uint32_t		count;
 };
@@ -275,7 +275,6 @@ struct wrk_accept {
 	socklen_t		acceptaddrlen;
 	int			acceptsock;
 	struct listen_sock	*acceptlsock;
-	uint32_t		vxid;
 };
 
 /* Worker pool stuff -------------------------------------------------*/
@@ -319,6 +318,7 @@ struct worker {
 
 	struct ws		aws[1];
 
+	struct vxid_pool	vxid_pool;
 
 	/* Temporary accounting */
 	struct acct		acct_tmp;
@@ -472,6 +472,7 @@ struct busyobj {
 	 * is recycled.
 	 */
 	unsigned		refcount;
+	uint32_t		vxid;
 
 	uint8_t			*vary;
 	unsigned		is_gzip;
@@ -560,6 +561,7 @@ struct req {
 	unsigned		magic;
 #define REQ_MAGIC		0x2751aaa1
 
+	uint32_t		vxid;
 	unsigned		xid;
 	int			restarts;
 	int			esi_level;
@@ -655,7 +657,6 @@ struct sess {
 	int			fd;
 	unsigned		vsl_id;
 	uint32_t		vxid;
-	uint32_t		vseq;
 
 	/* Cross references ------------------------------------------*/
 
@@ -857,7 +858,7 @@ int HTC_Complete(struct http_conn *htc);
 #undef HTTPH
 
 /* cache_main.c */
-uint32_t VXID_Get(struct vxid *v);
+uint32_t VXID_Get(struct vxid_pool *v);
 extern volatile struct params * cache_param;
 void THR_SetName(const char *name);
 const char* THR_GetName(void);
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 5e71d00..bbec54f 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -248,8 +248,6 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp)
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CAST_OBJ_NOTNULL(wa, (void*)wrk->aws->f, WRK_ACCEPT_MAGIC);
-	sp->vxid = wa->vxid;
-	sp->vseq = 0;
 	sp->fd = wa->acceptsock;
 	sp->vsl_id = wa->acceptsock | VSL_CLIENTMARKER ;
 	wa->acceptsock = -1;
diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 48efe08..8f0cc50 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -108,6 +108,7 @@ VBO_GetBusyObj(struct worker *wrk)
 	AZ(bo->refcount);
 
 	bo->refcount = 1;
+	bo->vxid = VXID_Get(&wrk->vxid_pool);
 
 	p = (void*)(bo + 1);
 	p = (void*)PRNDUP(p);
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 84fc3ea..c50d503 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -277,6 +277,7 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req)
 
 	WS_Reset(req->ws, NULL);
 	WS_Reset(wrk->aws, NULL);
+	req->vxid = VXID_Get(&wrk->vxid_pool);
 
 	i = HTC_Reinit(req->htc);
 	if (i == 1) {
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index dcb3cb1..94f2c8f 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -85,13 +85,15 @@ THR_GetName(void)
 }
 
 /*--------------------------------------------------------------------
+ * VXID's are unique transaction numbers allocated with a minimum of
+ * locking overhead via pools in the worker threads.
  */
 
 static uint32_t vxid_base;
 static struct lock vxid_lock;
 
 static void
-vxid_More(struct vxid *v)
+vxid_More(struct vxid_pool *v)
 {
 
 	Lck_Lock(&vxid_lock);
@@ -102,7 +104,7 @@ vxid_More(struct vxid *v)
 }
 
 uint32_t
-VXID_Get(struct vxid *v)
+VXID_Get(struct vxid_pool *v)
 {
 	if (v->count == 0)
 		vxid_More(v);
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index fa1f401..21a8a31 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -62,8 +62,6 @@ struct pool {
 	pthread_cond_t			herder_cond;
 	pthread_t			herder_thr;
 
-	struct vxid			vxid;
-
 	struct lock			mtx;
 	struct taskhead			idle_queue;
 	struct taskhead			front_queue;
@@ -148,7 +146,6 @@ pool_accept(struct worker *wrk, void *arg)
 		}
 
 		Lck_Lock(&pp->mtx);
-		wa->vxid = VXID_Get(&pp->vxid);
 		wrk2 = pool_getidleworker(pp);
 		if (wrk2 == NULL) {
 			/* No idle threads, do it ourselves */
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 3ed251d..64ee6f5 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -207,12 +207,15 @@ SES_pool_accept_task(struct worker *wrk, void *arg)
 	sp->t_open = VTIM_real();
 	sp->t_rx = sp->t_open;
 	sp->t_idle = sp->t_open;
+	sp->vxid = VXID_Get(&wrk->vxid_pool);
 
 	lsockname = VCA_SetupSess(wrk, sp);
 
 	req = ses_GetReq(sp);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 
+	req->vxid = VXID_Get(&wrk->vxid_pool);
+
 	ses_vsl_socket(req, lsockname);
 
 	wrk->acct_tmp.sess++;
@@ -262,12 +265,16 @@ SES_Handle(struct sess *sp, double now)
 	struct req *req;
 	struct sesspool *pp;
 
+	/* NB: This only works with single-threaded waiters */
+	static struct vxid_pool vxid_pool;
+
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	pp = sp->sesspool;
 	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
 	AN(pp->pool);
 	req = ses_GetReq(sp);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	req->vxid = VXID_Get(&vxid_pool);
 	sp->task.func = ses_pool_task;
 	sp->task.priv = req;
 	sp->sess_step = S_STP_NEWREQ;



More information about the varnish-commit mailing list