[master] 925d3f05b Change CLI cmd debug.xid to set the next XID to be used, rather than "one less than the next XID to be used"

Poul-Henning Kamp phk at FreeBSD.org
Tue Jan 17 10:52:08 UTC 2023


commit 925d3f05b9d88cfb759bb6d2b0ec04457a68ee59
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jan 17 10:51:10 2023 +0000

    Change CLI cmd debug.xid to set the next XID to be used, rather than "one less than the next XID to be used"

diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 107506938..ae414bc01 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -179,7 +179,7 @@ THR_Init(void)
  * zero vxid, in order to reserve that for "unassociated" VSL records.
  */
 
-static uint64_t vxid_base;
+static uint64_t vxid_base = 1;
 static uint32_t vxid_chunk = 32768;
 static struct lock vxid_lock;
 
@@ -193,18 +193,20 @@ VXID_Get(const struct worker *wrk, uint32_t mask)
 	CHECK_OBJ_NOTNULL(wrk->wpriv, WORKER_PRIV_MAGIC);
 	v = wrk->wpriv->vxid_pool;
 	AZ(mask & VSL_IDENTMASK);
-	do {
-		if (v->count == 0) {
-			Lck_Lock(&vxid_lock);
-			v->next = vxid_base;
-			v->count = vxid_chunk;
-			vxid_base = (vxid_base + v->count) & VSL_IDENTMASK;
-			Lck_Unlock(&vxid_lock);
-		}
-		v->count--;
-		v->next++;
-	} while (v->next == 0);
+	while (v->count == 0 || v->next >= VSL_CLIENTMARKER) {
+		Lck_Lock(&vxid_lock);
+		v->next = vxid_base;
+		v->count = vxid_chunk;
+		vxid_base += v->count;
+		if (vxid_base >= VSL_CLIENTMARKER)
+			vxid_base = 1;
+		Lck_Unlock(&vxid_lock);
+	}
+	v->count--;
+	assert(v->next > 0);
+	assert(v->next < VSL_CLIENTMARKER);
 	retval.vxid = v->next | mask;
+	v->next++;
 	return (retval);
 }
 
diff --git a/bin/varnishtest/tests/p00000.vtc b/bin/varnishtest/tests/p00000.vtc
index 6956a7562..ea803b524 100644
--- a/bin/varnishtest/tests/p00000.vtc
+++ b/bin/varnishtest/tests/p00000.vtc
@@ -43,7 +43,7 @@ varnish v1 -cliok "debug.persistent s0 sync"
 varnish v1 -stop
 
 varnish v1 -start
-varnish v1 -cliok "debug.xid 1999"
+varnish v1 -cliok "debug.xid 2000"
 
 client c1 {
 	txreq -url "/"
diff --git a/bin/varnishtest/tests/p00004.vtc b/bin/varnishtest/tests/p00004.vtc
index 986f7ec0c..57c30cdd3 100644
--- a/bin/varnishtest/tests/p00004.vtc
+++ b/bin/varnishtest/tests/p00004.vtc
@@ -39,7 +39,7 @@ varnish v1 -expect n_object == 2
 
 varnish v1 -stop
 varnish v1 -start
-varnish v1 -cliok "debug.xid 1999"
+varnish v1 -cliok "debug.xid 2000"
 
 varnish v1 -expect n_vampireobject == 2
 varnish v1 -expect n_object == 0
diff --git a/bin/varnishtest/tests/p00006.vtc b/bin/varnishtest/tests/p00006.vtc
index dfec3571f..b2ddde8bd 100644
--- a/bin/varnishtest/tests/p00006.vtc
+++ b/bin/varnishtest/tests/p00006.vtc
@@ -38,7 +38,7 @@ server s1 -wait
 
 varnish v1 -stop
 varnish v1 -start
-varnish v1 -cliok "debug.xid 1999"
+varnish v1 -cliok "debug.xid 2000"
 
 varnish v1 -expect n_vampireobject == 2
 
diff --git a/bin/varnishtest/tests/r01762.vtc b/bin/varnishtest/tests/r01762.vtc
index 8a3fbd426..5c5b39f2b 100644
--- a/bin/varnishtest/tests/r01762.vtc
+++ b/bin/varnishtest/tests/r01762.vtc
@@ -36,7 +36,7 @@ varnish v1 -cliok "param.set debug +syncvsl"
 varnish v1 -cliok "debug.xid 1073741823"
 
 logexpect l1 -v v1 -g request -T 2 {
-	expect 0 1	Begin		"req 0"
+	expect 0 1	Begin		"req 107374182"
 	expect * =	ReqStart
 	expect 0 =	ReqMethod	GET
 	expect 0 =	ReqURL		/
@@ -80,7 +80,7 @@ varnish v1 -cliok "param.set debug +syncvsl"
 varnish v1 -cliok "debug.xid 1073741823"
 
 logexpect l1 -v v1 -g request {
-	expect 0 1	Begin		"req 0"
+	expect 0 1	Begin		"req 1073741823"
 	expect * =	ReqStart
 	expect 0 =	ReqMethod	GET
 	expect 0 =	ReqURL		/
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index f68ed5d2f..12554b853 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -620,7 +620,7 @@ varnish_start(struct varnish *v)
 	wait_running(v);
 	free(resp);
 	resp = NULL;
-	u = varnish_ask_cli(v, "debug.xid 999", &resp);
+	u = varnish_ask_cli(v, "debug.xid 1000", &resp);
 	if (vtc_error)
 		return;
 	if (u != CLIS_OK)
diff --git a/doc/changes.rst b/doc/changes.rst
index 043ad7f5f..3e47502bf 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -35,6 +35,9 @@ release process.
 Varnish Cache NEXT (2023-03-15)
 ===============================
 
+* The ``debug.xid`` CLI command now sets the next XID to be used,
+  rather than "one less than the next XID to be used"
+
 ================================
 Varnish Cache 7.2.0 (2022-09-15)
 ================================


More information about the varnish-commit mailing list