varnish-cache/lib/libvmod_directors/shard_dir.h
1
/*-
2
 * Copyright 2009-2016 UPLEX - Nils Goroll Systemoptimierung
3
 * All rights reserved.
4
 *
5
 * Authors: Julian Wiesener <jw@uplex.de>
6
 *          Nils Goroll <slink@uplex.de>
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
30
#include "shard_parse_vcc_enums.h"
31
32
struct vbitmap;
33
34
struct shard_circlepoint {
35
        uint32_t                point;
36
        unsigned int            host;
37
};
38
39
struct shard_backend {
40
        VCL_BACKEND             backend;
41
        const char              *ident; // XXX COPY IN !
42
        VCL_DURATION            rampup;
43
        uint32_t                canon_point;
44
};
45
46
#define SHDBG_LOOKUP     1
47
#define SHDBG_CIRCLE    (1<<1)
48
#define SHDBG_RAMPWARM  (1<<2)
49
50
struct sharddir {
51
        unsigned                                magic;
52
#define SHARDDIR_MAGIC                          0xdbb7d59f
53
        uint32_t                                debug_flags;
54
55
        pthread_rwlock_t                        mtx;
56
57
        const char                              *name;
58
59
        unsigned                                n_backend;
60
        unsigned                                l_backend;
61
        struct shard_backend                    *backend;
62
63
        struct shard_circlepoint                *hashcircle;
64
65
        VCL_DURATION                            rampup_duration;
66
        VCL_REAL                                warmup;
67
        VCL_INT                                 replicas;
68
};
69
70
static inline VCL_BACKEND
71 70
sharddir_backend(const struct sharddir *shardd, int id)
72
{
73 70
        assert(id >= 0);
74 70
        assert(id < shardd->n_backend);
75 70
        return (shardd->backend[id].backend);
76
}
77
78
static inline const char *
79
sharddir_backend_ident(const struct sharddir *shardd, int host)
80
{
81
        assert(host >= 0);
82
        assert(host < shardd->n_backend);
83
        return (shardd->backend[host].ident);
84
}
85
86
#define SHDBG(flag, shardd, ...)                                        \
87
        do {                                                            \
88
                if ((shardd)->debug_flags & (flag))                     \
89
                        VSL(SLT_Debug, 0, "shard: " __VA_ARGS__);       \
90
        } while (0)
91
92
#define shard_err(ctx, shardd, fmt, ...)                                \
93
        do {                                                            \
94
                sharddir_err(ctx, SLT_Error, "shard %s: " fmt,          \
95
                    (shardd)->name, __VA_ARGS__);                       \
96
        } while (0)
97
98
#define shard_err0(ctx, shardd, msg)                                    \
99
        do {                                                            \
100
                sharddir_err(ctx, SLT_Error, "shard %s: %s",            \
101
                    (shardd)->name, (msg));                             \
102
        } while (0)
103
104
void sharddir_debug(struct sharddir *shardd, const uint32_t flags);
105
void sharddir_err(VRT_CTX, enum VSL_tag_e tag,  const char *fmt, ...);
106
void sharddir_new(struct sharddir **sharddp, const char *vcl_name);
107
void sharddir_delete(struct sharddir **sharddp);
108
void sharddir_wrlock(struct sharddir *shardd);
109
void sharddir_unlock(struct sharddir *shardd);
110
VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT,
111
   VCL_REAL, VCL_BOOL, enum healthy_e);
112
113
/* in shard_cfg.c */
114
void shardcfg_delete(const struct sharddir *shardd);
115
VCL_DURATION shardcfg_get_rampup(const struct sharddir *shardd, int host);