[master] b81e27708 Ditch the director cooling list and trust the refcounts.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Nov 24 12:33:06 UTC 2021
commit b81e27708a792ce8168476f43b2a87c8beca50d5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Nov 24 12:06:44 2021 +0000
Ditch the director cooling list and trust the refcounts.
(4th part of #3599)
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index dada7f2b7..ebf1b9e3c 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -54,9 +54,6 @@
static const char * const vbe_proto_ident = "HTTP Backend";
-static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends);
-static VTAILQ_HEAD(, backend) cool_backends =
- VTAILQ_HEAD_INITIALIZER(cool_backends);
static struct lock backends_mtx;
/*--------------------------------------------------------------------*/
@@ -426,13 +423,9 @@ vbe_free(struct backend *be)
VSC_vbe_Destroy(&be->vsc_seg);
Lck_Lock(&backends_mtx);
- if (be->cooled > 0)
- VTAILQ_REMOVE(&cool_backends, be, list);
- else
- VTAILQ_REMOVE(&backends, be, list);
VSC_C_main->n_backend--;
- VCP_Rel(&be->conn_pool);
Lck_Unlock(&backends_mtx);
+ VCP_Rel(&be->conn_pool);
#define DA(x) do { if (be->x != NULL) free(be->x); } while (0)
#define DN(x) /**/
@@ -630,21 +623,19 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
}
Lck_Lock(&backends_mtx);
- VTAILQ_INSERT_TAIL(&backends, be, list);
VSC_C_main->n_backend++;
Lck_Unlock(&backends_mtx);
be->director = VRT_AddDirector(ctx, m, be, "%s", vrt->vcl_name);
- if (be->director != NULL) {
- /* for cold VCL, update initial director state */
- if (be->probe != NULL && ! vcl->temp->is_warm)
- VBP_Update_Backend(be->probe);
- return (be->director);
+ if (be->director == NULL) {
+ vbe_free(be);
+ return (NULL);
}
-
- vbe_free(be);
- return (NULL);
+ /* for cold VCL, update initial director state */
+ if (be->probe != NULL)
+ VBP_Update_Backend(be->probe);
+ return (be->director);
}
VCL_BACKEND
@@ -664,47 +655,11 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
void
VRT_delete_backend(VRT_CTX, VCL_BACKEND *dp)
{
- VCL_BACKEND d;
- struct backend *be;
-
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- TAKE_OBJ_NOTNULL(d, dp, DIRECTOR_MAGIC);
- CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
- Lck_Lock(be->director->mtx);
- VRT_DisableDirector(be->director);
- Lck_Unlock(be->director->mtx);
- Lck_Lock(&backends_mtx);
- AZ(be->cooled);
- be->cooled = VTIM_real() + 60.;
- VTAILQ_REMOVE(&backends, be, list);
- VTAILQ_INSERT_TAIL(&cool_backends, be, list);
- Lck_Unlock(&backends_mtx);
- // NB. The backend is still usable for the ongoing transactions,
- // this is why we don't bust the director's magic number.
-}
-
-/*---------------------------------------------------------------------*/
-
-void
-VBE_Poll(void)
-{
- struct backend *be, *be2;
- vtim_real now = VTIM_real();
-
- ASSERT_CLI();
- Lck_Lock(&backends_mtx);
- VTAILQ_FOREACH_SAFE(be, &cool_backends, list, be2) {
- CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
- if (be->cooled > now)
- break;
- if (be->n_conn > 0)
- continue;
- Lck_Unlock(&backends_mtx);
- VRT_DelDirector(&be->director);
- Lck_Lock(&backends_mtx);
- }
- Lck_Unlock(&backends_mtx);
+ (void)ctx;
+ CHECK_OBJ_NOTNULL(*dp, DIRECTOR_MAGIC);
+ VRT_DisableDirector(*dp);
+ VRT_Assign_Backend(dp, NULL);
}
/*---------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 536494f7b..76bc3c07c 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -54,8 +54,6 @@ struct backend {
unsigned n_conn;
- VTAILQ_ENTRY(backend) list;
-
struct vrt_endpoint *endpoint;
VRT_BACKEND_FIELDS()
@@ -71,8 +69,6 @@ struct backend {
struct conn_pool *conn_pool;
VCL_BACKEND director;
-
- vtim_real cooled;
};
/*---------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_cli.c b/bin/varnishd/cache/cache_cli.c
index 85a16a724..06b2e02e6 100644
--- a/bin/varnishd/cache/cache_cli.c
+++ b/bin/varnishd/cache/cache_cli.c
@@ -77,7 +77,6 @@ cli_cb_before(const struct cli *cli)
ASSERT_CLI();
VSL(SLT_CLI, 0, "Rd %s", VSB_data(cli->cmd));
VCL_Poll();
- VBE_Poll();
Lck_Lock(&cli_mtx);
}
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index a3e0b150a..aae9be794 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -256,7 +256,7 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
if (IS_TOPREQ(req))
AZ(req->top->vcl0);
- req->director_hint = NULL;
+ AZ(req->director_hint);
req->restarts = 0;
if (req->vcl != NULL)
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 57294faa9..a4192018f 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -162,7 +162,6 @@ void VCA_Shutdown(void);
/* cache_backend_cfg.c */
void VBE_InitCfg(void);
-void VBE_Poll(void);
void VBP_Init(void);
diff --git a/bin/varnishd/cache/cache_vcl.h b/bin/varnishd/cache/cache_vcl.h
index 355cccf59..ac0d7aa75 100644
--- a/bin/varnishd/cache/cache_vcl.h
+++ b/bin/varnishd/cache/cache_vcl.h
@@ -71,7 +71,6 @@ extern struct lock vcl_mtx;
extern struct vcl *vcl_active; /* protected by vcl_mtx */
struct vcl *vcl_find(const char *);
void VCL_Update(struct vcl **, struct vcl *);
-void vcldir_free(struct vcldir *);
struct vcltemp {
const char * const name;
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 6e4592c06..35e83f3df 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -140,7 +140,7 @@ VCL_Rel(struct vcl **vcc)
/*--------------------------------------------------------------------*/
-void
+static void
vcldir_free(struct vcldir *vdir)
{
More information about the varnish-commit
mailing list