From 2a9fe3400b1ea044fc563a93eb7dc3dde71dd199 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 29 Jun 2006 13:04:55 +0000 Subject: [PATCH] Add a unique transaction-ID to each request, and register it in the shmlog so we can match backend transactions with client transactions. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@265 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 3 ++- varnish-cache/bin/varnishd/cache_backend.c | 3 ++- varnish-cache/bin/varnishd/cache_fetch.c | 2 +- varnish-cache/bin/varnishd/cache_http.c | 5 ----- varnish-cache/bin/varnishd/cache_pass.c | 2 +- varnish-cache/bin/varnishd/cache_pipe.c | 2 +- varnish-cache/bin/varnishd/cache_pool.c | 10 ++++++++++ varnish-cache/include/shmlog_tags.h | 2 ++ 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index f2861d69..6ebdbfe7 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -92,6 +92,7 @@ struct objhead { struct sess { int fd; + unsigned xid; /* formatted ascii client address */ char addr[VCA_ADDRBUFSIZE]; @@ -143,7 +144,7 @@ void VCA_Init(void); /* cache_backend.c */ void VBE_Init(void); -int VBE_GetFd(struct backend *bp, void **ptr); +int VBE_GetFd(struct backend *bp, void **ptr, unsigned xid); void VBE_ClosedFd(void *ptr); void VBE_RecycleFd(void *ptr); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 951bdfb0..961264e4 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -201,7 +201,7 @@ vbe_main(void *priv __unused) */ int -VBE_GetFd(struct backend *bp, void **ptr) +VBE_GetFd(struct backend *bp, void **ptr, unsigned xid) { struct vbe *vp; struct vbe_conn *vc; @@ -244,6 +244,7 @@ VBE_GetFd(struct backend *bp, void **ptr) event_base_set(vbe_evb, &vc->ev); } *ptr = vc; + VSL(SLT_BackendXID, vc->fd, "%u", xid); return (vc->fd); } diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 4aa1de52..a363e906 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -245,7 +245,7 @@ FetchSession(struct worker *w, struct sess *sp) time_t t_req, t_resp; int body; - fd = VBE_GetFd(sp->backend, &fd_token); + fd = VBE_GetFd(sp->backend, &fd_token, sp->xid); assert(fd != -1); VSL(SLT_Backend, sp->fd, "%d %s", fd, sp->backend->vcl_name); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 37cf0b8f..fa486284 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -335,11 +335,6 @@ http_read_f(int fd, short event, void *arg) } hp->t = ++p; -#if 0 -printf("Head:\n%#H\n", hp->s, hp->t - hp->s); -printf("Tail:\n%#H\n", hp->t, hp->v - hp->t); -#endif - event_del(&hp->ev); if (hp->callback != NULL) hp->callback(hp->arg, 1); diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index 01ef5af3..339f43aa 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -157,7 +157,7 @@ PassSession(struct worker *w, struct sess *sp) char *b; int cls; - fd = VBE_GetFd(sp->backend, &fd_token); + fd = VBE_GetFd(sp->backend, &fd_token, sp->xid); assert(fd != -1); http_BuildSbuf(fd, 1, w->sb, sp->http); diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 68866fc1..6457fc7f 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -48,7 +48,7 @@ PipeSession(struct worker *w, struct sess *sp) void *fd_token; struct edir e1, e2; - fd = VBE_GetFd(sp->backend, &fd_token); + fd = VBE_GetFd(sp->backend, &fd_token, sp->xid); assert(fd != -1); http_BuildSbuf(fd, 0, w->sb, sp->http); /* XXX: 0 ?? */ diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 3fd10e2a..5c02f5fa 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -21,6 +21,7 @@ static TAILQ_HEAD(, sess) shd = TAILQ_HEAD_INITIALIZER(shd); static pthread_cond_t shdcnd; +static unsigned xids; /*--------------------------------------------------------------------*/ @@ -131,6 +132,13 @@ DealWithSession(void *arg, int good) vca_return_session(sp); return; } + + /* + * No locking necessary, we're serialized in the acceptor thread + */ + sp->xid = xids++; + VSL(SLT_XID, sp->fd, "%u", sp->xid); + VSL_stats->client_req++; AZ(pthread_mutex_lock(&sessmtx)); TAILQ_INSERT_TAIL(&shd, sp, list); @@ -149,4 +157,6 @@ CacheInitPool(void) for (i = 0; i < 5; i++) AZ(pthread_create(&tp, NULL, CacheWorker, NULL)); AZ(pthread_detach(tp)); + srandomdev(); + xids = random(); } diff --git a/varnish-cache/include/shmlog_tags.h b/varnish-cache/include/shmlog_tags.h index f2e104ee..bbe13c0c 100644 --- a/varnish-cache/include/shmlog_tags.h +++ b/varnish-cache/include/shmlog_tags.h @@ -13,6 +13,7 @@ SLTM(SessionOpen) SLTM(SessionReuse) SLTM(SessionClose) SLTM(BackendOpen) +SLTM(BackendXID) SLTM(BackendReuse) SLTM(BackendClose) SLTM(HttpError) @@ -32,3 +33,4 @@ SLTM(Header) SLTM(BldHdr) SLTM(LostHeader) SLTM(VCL) +SLTM(XID) -- 2.39.5