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 */
67typedef 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 */
88typedef 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 */
100void
101as_exchange_init();
102
103/**
104 * Start exchange subsystem.
105 */
106void
107as_exchange_start();
108
109/**
110 * Stop exchange subsystem.
111 */
112void
113as_exchange_stop();
114
115/**
116 * Register to receive cluster-changed events.
117 * TODO - may replace with simple static list someday.
118 */
119void
120as_exchange_register_listener(as_exchange_cluster_changed_cb cb, void* udata);
121
122/**
123 * Dump exchange state to log.
124 */
125void
126as_exchange_dump(bool verbose);
127
128/**
129 * Member-access method.
130 */
131uint64_t
132as_exchange_cluster_key();
133
134/**
135 * Member-access method.
136 */
137uint32_t
138as_exchange_cluster_size();
139
140/**
141 * Copy over the committed succession list.
142 * Ensure the input vector has enough capacity.
143 */
144void
145as_exchange_succession(cf_vector* succession);
146
147/**
148 * Return the committed succession list as a string in a dyn-buf.
149 */
150void
151as_exchange_info_get_succession(cf_dyn_buf* db);
152
153/**
154 * Member-access method.
155 */
156cf_node
157as_exchange_principal();
158
159/**
160 * Used by exchange listeners during upgrades for compatibility purposes.
161 */
162uint32_t*
163as_exchange_compatibility_ids(void);
164
165/**
166 * Used by exchange listeners during upgrades for compatibility purposes.
167 */
168uint32_t
169as_exchange_min_compatibility_id(void);
170
171/**
172 * Output exchange cluster state for info.
173 */
174void as_exchange_cluster_info(cf_dyn_buf* db);
175
176/**
177 * Lock before setting or getting exchanged info from non-exchange thread.
178 */
179void
180as_exchange_info_lock();
181
182/**
183 * Unlock after setting or getting exchanged info from non-exchange thread.
184 */
185void
186as_exchange_info_unlock();
187