source: bin/varnishd/cache/cache_backend.h @ 21e653

Revision 21e653, 5.9 KB checked in by Poul-Henning Kamp <phk@…>, 2 years ago (diff)

Use the hash digest as identification instead of the neutered objhead
pointer, in order to not have dependency between trouble entry and
objhead lifetime.

Fixes #1091

  • Property mode set to 100644
Line 
1/*-
2 * Copyright (c) 2006 Verdens Gang AS
3 * Copyright (c) 2006-2011 Varnish Software AS
4 * All rights reserved.
5 *
6 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This is the central switch-board for backend connections and it is
30 * slightly complicated by a number of optimizations.
31 *
32 * The data structures:
33 *
34 *    A vrt_backend is a definition of a backend in a VCL program.
35 *
36 *    A backend is a TCP destination, possibly multi-homed and it has a
37 *    number of associated properties and statistics.
38 *
39 *    A vbc is an open TCP connection to a backend.
40 *
41 *    A bereq is a memory carrier for handling a HTTP transaction with
42 *    a backend over a vbc.
43 *
44 *    A director is a piece of code that selects which backend to use,
45 *    by whatever method or metric it chooses.
46 *
47 * The relationships:
48 *
49 *    Backends and directors get instantiated when VCL's are loaded,
50 *    and this always happen in the CLI thread.
51 *
52 *    When a VCL tries to instantiate a backend, any existing backend
53 *    with the same identity (== definition in VCL) will be used instead
54 *    so that vbc's can be reused across VCL changes.
55 *
56 *    Directors disapper with the VCL that created them.
57 *
58 *    Backends disappear when their reference count drop to zero.
59 *
60 *    Backends have their host/port name looked up to addrinfo structures
61 *    when they are instantiated, and we just cache that result and cycle
62 *    through the entries (for multihomed backends) on failure only.
63 *    XXX: add cli command to redo lookup.
64 *
65 *    bereq is sort of a step-child here, we just manage the pool of them.
66 *
67 */
68
69struct vbp_target;
70struct vbc;
71struct vrt_backend_probe;
72
73/*--------------------------------------------------------------------
74 * A director is a piece of code which selects one of possibly multiple
75 * backends to use.
76 */
77
78typedef struct vbc *vdi_getfd_f(const struct director *, struct sess *sp);
79typedef void vdi_fini_f(const struct director *);
80typedef unsigned vdi_healthy(const struct director *, const struct sess *sp);
81
82struct director {
83        unsigned                magic;
84#define DIRECTOR_MAGIC          0x3336351d
85        const char              *name;
86        char                    *vcl_name;
87        vdi_getfd_f             *getfd;
88        vdi_fini_f              *fini;
89        vdi_healthy             *healthy;
90        void                    *priv;
91};
92
93/*--------------------------------------------------------------------
94 * List of objectheads that have recently been rejected by VCL.
95 */
96
97struct trouble {
98        unsigned                magic;
99#define TROUBLE_MAGIC           0x4211ab21
100        unsigned char           digest[DIGEST_LEN];
101        double                  timeout;
102        VTAILQ_ENTRY(trouble)   list;
103};
104
105/*--------------------------------------------------------------------
106 * An instance of a backend from a VCL program.
107 */
108
109enum admin_health {
110        ah_invalid = 0,
111        ah_healthy,
112        ah_sick,
113        ah_probe
114};
115
116struct backend {
117        unsigned                magic;
118#define BACKEND_MAGIC           0x64c4c7c6
119
120        VTAILQ_ENTRY(backend)   list;
121        int                     refcount;
122        struct lock             mtx;
123
124        char                    *vcl_name;
125        char                    *display_name;
126        char                    *ipv4_addr;
127        char                    *ipv6_addr;
128        char                    *port;
129
130        struct sockaddr_storage *ipv4;
131        socklen_t               ipv4len;
132        struct sockaddr_storage *ipv6;
133        socklen_t               ipv6len;
134
135        unsigned                n_conn;
136        VTAILQ_HEAD(, vbc)      connlist;
137
138        struct vbp_target       *probe;
139        unsigned                healthy;
140        enum admin_health       admin_health;
141        VTAILQ_HEAD(, trouble)  troublelist;
142
143        struct VSC_C_vbe        *vsc;
144};
145
146/* -------------------------------------------------------------------*/
147
148/* Backend connection */
149struct vbc {
150        unsigned                magic;
151#define VBC_MAGIC               0x0c5e6592
152        VTAILQ_ENTRY(vbc)       list;
153        struct backend          *backend;
154        struct vdi_simple       *vdis;
155        struct vsl_log          *vsl;
156        unsigned                orig_vsl_id;
157        unsigned                vsl_id;
158        int                     fd;
159
160        struct sockaddr_storage *addr;
161        socklen_t               addrlen;
162
163        uint8_t                 recycled;
164
165        /* Timeouts */
166        double                  first_byte_timeout;
167        double                  between_bytes_timeout;
168};
169
170/* cache_backend.c */
171void VBE_ReleaseConn(struct vbc *vc);
172struct backend *vdi_get_backend_if_simple(const struct director *d);
173
174/* cache_backend_cfg.c */
175void VBE_DropRefConn(struct backend *);
176void VBE_DropRefVcl(struct backend *);
177void VBE_DropRefLocked(struct backend *b);
178
179/* cache_backend_poll.c */
180void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p,
181    const char *hosthdr);
182void VBP_Remove(struct backend *b, struct vrt_backend_probe const *p);
183void VBP_Use(const struct backend *b, const struct vrt_backend_probe const *p);
184void VBP_Summary(struct cli *cli, const struct vbp_target *vt);
185
186/* Init functions for directors */
187typedef void dir_init_f(struct cli *, struct director **, int , const void*);
188dir_init_f VRT_init_dir_simple;
189dir_init_f VRT_init_dir_dns;
190dir_init_f VRT_init_dir_hash;
191dir_init_f VRT_init_dir_random;
192dir_init_f VRT_init_dir_round_robin;
193dir_init_f VRT_init_dir_fallback;
194dir_init_f VRT_init_dir_client;
Note: See TracBrowser for help on using the repository browser.