1/*
2 * partition_balance_ce.c
3 *
4 * Copyright (C) 2017-2019 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//==========================================================
24// Includes.
25//
26
27#include "fabric/partition_balance.h"
28
29#include <stdbool.h>
30#include <stdint.h>
31
32#include "citrusleaf/cf_queue.h"
33
34#include "dynbuf.h"
35#include "fault.h"
36#include "node.h"
37
38#include "base/datamodel.h"
39#include "fabric/partition.h"
40#include "fabric/migrate.h"
41
42
43//==========================================================
44// Public API.
45//
46
47void
48as_partition_balance_emigration_yield()
49{
50}
51
52bool
53as_partition_balance_revive(as_namespace* ns)
54{
55 cf_warning(AS_PARTITION, "revive is an enterprise feature");
56 return true;
57}
58
59void
60as_partition_balance_protect_roster_set(as_namespace* ns)
61{
62}
63
64void
65as_partition_balance_effective_rack_ids(cf_dyn_buf* db)
66{
67 cf_crash(AS_PARTITION, "CE code called as_partition_balance_effective_rack_ids()");
68}
69
70bool
71as_partition_pre_emigrate_done(as_namespace* ns, uint32_t pid,
72 uint64_t orig_cluster_key, uint32_t tx_flags)
73{
74 return true;
75}
76
77
78//==========================================================
79// Private API - for enterprise separation only.
80//
81
82void
83partition_balance_init()
84{
85}
86
87void
88balance_namespace(as_namespace* ns, cf_queue* mq)
89{
90 balance_namespace_ap(ns, mq);
91}
92
93void
94prepare_for_appeals()
95{
96}
97
98void
99process_pb_tasks(cf_queue* tq)
100{
101 pb_task task;
102
103 while (cf_queue_pop(tq, &task, CF_QUEUE_NOWAIT) == CF_QUEUE_OK) {
104 as_migrate_emigrate(&task);
105 }
106}
107
108void
109set_active_size(as_namespace* ns)
110{
111 ns->active_size = ns->cluster_size;
112}
113
114uint32_t
115rack_count(const as_namespace* ns)
116{
117 return 1;
118}
119
120void
121init_target_claims_ap(const as_namespace* ns, const int translation[],
122 uint32_t* target_claims)
123{
124 cf_crash(AS_PARTITION, "CE code called init_target_claims_ap()");
125}
126
127void
128quiesce_adjust_row(cf_node* ns_node_seq, sl_ix_t* ns_sl_ix, as_namespace* ns)
129{
130 cf_crash(AS_PARTITION, "CE code called quiesce_adjust_row()");
131}
132
133void
134uniform_adjust_row(cf_node* node_seq, uint32_t n_nodes, sl_ix_t* ns_sl_ix,
135 uint32_t n_replicas, uint32_t* claims, const uint32_t* target_claims,
136 const uint32_t* rack_ids, uint32_t n_racks)
137{
138 cf_crash(AS_PARTITION, "CE code called uniform_adjust_row()");
139}
140
141void
142rack_aware_adjust_row(cf_node* ns_node_seq, sl_ix_t* ns_sl_ix,
143 uint32_t replication_factor, const uint32_t* rack_ids, uint32_t n_ids,
144 uint32_t n_racks, uint32_t start_n)
145{
146 cf_crash(AS_PARTITION, "CE code called rack_aware_adjust_row()");
147}
148
149void
150emig_lead_flags_ap(const as_partition* p, const sl_ix_t* ns_sl_ix,
151 const as_namespace* ns, uint32_t lead_flags[])
152{
153 for (uint32_t repl_ix = 0; repl_ix < ns->replication_factor; repl_ix++) {
154 lead_flags[repl_ix] = TX_FLAGS_LEAD;
155 }
156}
157
158bool
159drop_superfluous_version(as_partition* p, as_namespace* ns)
160{
161 p->version = ZERO_VERSION;
162
163 return true;
164}
165
166bool
167adjust_superfluous_version(as_partition* p, as_namespace* ns)
168{
169 cf_crash(AS_PARTITION, "CE code called adjust_superfluous_version()");
170 return false;
171}
172
173void
174emigrate_done_advance_non_master_version(as_namespace* ns, as_partition* p,
175 uint32_t tx_flags)
176{
177 emigrate_done_advance_non_master_version_ap(ns, p, tx_flags);
178}
179
180void
181immigrate_start_advance_non_master_version(as_namespace* ns, as_partition* p)
182{
183 immigrate_start_advance_non_master_version_ap(p);
184}
185
186void
187immigrate_done_advance_final_master_version(as_namespace* ns, as_partition* p)
188{
189 immigrate_done_advance_final_master_version_ap(ns, p);
190}
191
192bool
193immigrate_yield()
194{
195 return false;
196}
197