1 | /* |
2 | * exchange.h |
3 | * |
4 | * Copyright (C) 2016 Aerospike, Inc. |
5 | * |
6 | * Portions may be licensed to Aerospike, Inc. under one or more contributor |
7 | * license agreements. |
8 | * |
9 | * This program is free software: you can redistribute it and/or modify it under |
10 | * the terms of the GNU Affero General Public License as published by the Free |
11 | * Software Foundation, either version 3 of the License, or (at your option) any |
12 | * later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
16 | * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
17 | * details. |
18 | * |
19 | * You should have received a copy of the GNU Affero General Public License |
20 | * along with this program. If not, see http://www.gnu.org/licenses/ |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | #include <stdbool.h> |
26 | #include <stdint.h> |
27 | |
28 | #include "citrusleaf/cf_atomic.h" |
29 | #include "citrusleaf/cf_vector.h" |
30 | |
31 | #include "dynbuf.h" |
32 | #include "node.h" |
33 | |
34 | /* |
35 | * ---------------------------------------------------------------------------- |
36 | * Constants |
37 | * ---------------------------------------------------------------------------- |
38 | */ |
39 | |
40 | /** |
41 | * Used by exchange listeners during upgrades for compatibility purposes. |
42 | * |
43 | * 1 - 4.5.1 - for SMD upgrade. |
44 | * 2 - 4.5.2 - for AER-6035 (AP uniform-balance + quiesce bug). |
45 | * 3 - 4.5.3 - for new pickle format. |
46 | * 4 - 4.7.0 - for AER-6128 (AP uniform-balance empty master selection bug). |
47 | * 5 - 4.7.0.3 - for AER-6143 (SC quiesce with non-roster nodes bug). |
48 | */ |
49 | #define AS_EXCHANGE_COMPATIBILITY_ID 5 |
50 | |
51 | /** |
52 | * Number of quantum intervals in orphan state after which client transactions |
53 | * will be blocked. |
54 | */ |
55 | #define AS_EXCHANGE_REVERT_ORPHAN_INTERVALS 5 |
56 | |
57 | /* |
58 | * ---------------------------------------------------------------------------- |
59 | * Typedefs. |
60 | * ---------------------------------------------------------------------------- |
61 | */ |
62 | |
63 | /** |
64 | * Exchange event raised for every well-formed cluster change, after exchange |
65 | * concludes successfully. |
66 | */ |
67 | typedef struct as_exchange_cluster_changed_event_s |
68 | { |
69 | /** |
70 | * The new cluster key. |
71 | */ |
72 | uint64_t cluster_key; |
73 | |
74 | /** |
75 | * The new cluster size. |
76 | */ |
77 | uint32_t cluster_size; |
78 | |
79 | /** |
80 | * The new succession list. |
81 | */ |
82 | cf_node* succession; |
83 | } as_exchange_cluster_changed_event; |
84 | |
85 | /** |
86 | * Cluster change event call back function for cluster changed event listeners. |
87 | */ |
88 | typedef void |
89 | (*as_exchange_cluster_changed_cb)( |
90 | const as_exchange_cluster_changed_event* event, void* udata); |
91 | |
92 | /* |
93 | * ---------------------------------------------------------------------------- |
94 | * Public API. |
95 | * ---------------------------------------------------------------------------- |
96 | */ |
97 | /** |
98 | * Initialize exchange subsystem. |
99 | */ |
100 | void |
101 | as_exchange_init(); |
102 | |
103 | /** |
104 | * Start exchange subsystem. |
105 | */ |
106 | void |
107 | as_exchange_start(); |
108 | |
109 | /** |
110 | * Stop exchange subsystem. |
111 | */ |
112 | void |
113 | as_exchange_stop(); |
114 | |
115 | /** |
116 | * Register to receive cluster-changed events. |
117 | * TODO - may replace with simple static list someday. |
118 | */ |
119 | void |
120 | as_exchange_register_listener(as_exchange_cluster_changed_cb cb, void* udata); |
121 | |
122 | /** |
123 | * Dump exchange state to log. |
124 | */ |
125 | void |
126 | as_exchange_dump(bool verbose); |
127 | |
128 | /** |
129 | * Member-access method. |
130 | */ |
131 | uint64_t |
132 | as_exchange_cluster_key(); |
133 | |
134 | /** |
135 | * Member-access method. |
136 | */ |
137 | uint32_t |
138 | as_exchange_cluster_size(); |
139 | |
140 | /** |
141 | * Copy over the committed succession list. |
142 | * Ensure the input vector has enough capacity. |
143 | */ |
144 | void |
145 | as_exchange_succession(cf_vector* succession); |
146 | |
147 | /** |
148 | * Return the committed succession list as a string in a dyn-buf. |
149 | */ |
150 | void |
151 | as_exchange_info_get_succession(cf_dyn_buf* db); |
152 | |
153 | /** |
154 | * Member-access method. |
155 | */ |
156 | cf_node |
157 | as_exchange_principal(); |
158 | |
159 | /** |
160 | * Used by exchange listeners during upgrades for compatibility purposes. |
161 | */ |
162 | uint32_t* |
163 | as_exchange_compatibility_ids(void); |
164 | |
165 | /** |
166 | * Used by exchange listeners during upgrades for compatibility purposes. |
167 | */ |
168 | uint32_t |
169 | as_exchange_min_compatibility_id(void); |
170 | |
171 | /** |
172 | * Output exchange cluster state for info. |
173 | */ |
174 | void as_exchange_cluster_info(cf_dyn_buf* db); |
175 | |
176 | /** |
177 | * Lock before setting or getting exchanged info from non-exchange thread. |
178 | */ |
179 | void |
180 | as_exchange_info_lock(); |
181 | |
182 | /** |
183 | * Unlock after setting or getting exchanged info from non-exchange thread. |
184 | */ |
185 | void |
186 | as_exchange_info_unlock(); |
187 | |