-
Notifications
You must be signed in to change notification settings - Fork 3
/
ngx_consistent_hash.h
57 lines (45 loc) · 1.72 KB
/
ngx_consistent_hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (C) agile6v
*/
#ifndef _NGX_CONSISTENT_HASH_H_INCLUDED_
#define _NGX_CONSISTENT_HASH_H_INCLUDED_
#include <ngx_http.h>
#define NGX_CONHASH_NAME_SIZE 64
typedef struct ngx_conhash_vnode_s ngx_conhash_vnode_t;
typedef uint32_t (*ngx_conhash_hashfunc_pt) (u_char *data, size_t len);
typedef void (*ngx_conhash_oper_pt) (ngx_conhash_vnode_t *, void *);
typedef struct {
ngx_conhash_hashfunc_pt hash_func;
void *data;
} ngx_conhash_ctx_t;
typedef struct {
ngx_rbtree_t vnode_tree;
ngx_rbtree_node_t vnode_sentinel;
ngx_queue_t hnode_queue;
ngx_uint_t vnodes;
} ngx_conhash_sh_t;
typedef struct {
ngx_conhash_sh_t *sh;
ngx_slab_pool_t *shpool;
ngx_conhash_hashfunc_pt hash_func;
ngx_shm_zone_t *shm_zone;
ngx_uint_t vnodecnt;
} ngx_conhash_t;
typedef struct {
ngx_str_t name;
ngx_queue_t queue;
void *data;
} ngx_conhash_node_t;
struct ngx_conhash_vnode_s {
ngx_rbtree_node_t node;
ngx_conhash_node_t *hnode;
ngx_str_t name;
} ;
ngx_int_t ngx_conhash_node_traverse(ngx_conhash_t *conhash, ngx_conhash_oper_pt func, void *data);
ngx_int_t ngx_conhash_add_node(ngx_conhash_t *conhash, u_char *name, size_t len, void *data);
ngx_int_t ngx_conhash_del_node(ngx_conhash_t *conhash, u_char *name, size_t len);
ngx_int_t ngx_conhash_lookup_node(ngx_conhash_t *conhash, u_char *name, size_t len,
ngx_conhash_oper_pt func, void *data);
char *ngx_conhash_shm_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
void ngx_conhash_clear(ngx_conhash_t *conhash);
#endif