return true;
}
-static struct ipalloc_state * ipalloc_state_init(struct ctdb_context *ctdb,
- TALLOC_CTX *mem_ctx)
+static enum ipalloc_algorithm
+determine_algorithm(const struct ctdb_tunable_list *tunables)
+{
+ if (1 == tunables->lcp2_public_ip_assignment) {
+ return IPALLOC_LCP2;
+ } else if (1 == tunables->deterministic_public_ips) {
+ return IPALLOC_DETERMINISTIC;
+ } else {
+ return IPALLOC_NONDETERMINISTIC;
+ }
+}
+
+static struct ipalloc_state *
+ipalloc_state_init(TALLOC_CTX *mem_ctx,
+ uint32_t num_nodes,
+ enum ipalloc_algorithm algorithm,
+ bool no_ip_failback,
+ uint32_t *force_rebalance_nodes)
{
struct ipalloc_state *ipalloc_state =
talloc_zero(mem_ctx, struct ipalloc_state);
return NULL;
}
- ipalloc_state->num = ctdb->num_nodes;
+ ipalloc_state->num = num_nodes;
ipalloc_state->noiptakeover =
talloc_zero_array(ipalloc_state,
goto fail;
}
- if (1 == ctdb->tunable.lcp2_public_ip_assignment) {
- ipalloc_state->algorithm = IPALLOC_LCP2;
- } else if (1 == ctdb->tunable.deterministic_public_ips) {
- ipalloc_state->algorithm = IPALLOC_DETERMINISTIC;
- } else {
- ipalloc_state->algorithm = IPALLOC_NONDETERMINISTIC;
- }
-
- ipalloc_state->no_ip_failback = (ctdb->tunable.no_ip_failback != 0);
+ ipalloc_state->algorithm = algorithm;
+ ipalloc_state->no_ip_failback = no_ip_failback;
+ ipalloc_state->force_rebalance_nodes = force_rebalance_nodes;
return ipalloc_state;
fail:
* Recalculate the allocation of public IPs to nodes and have the
* nodes host their allocated addresses.
*
- * - Allocate memory for IP allocation state, including per node
- * arrays
- * - Populate IP allocation algorithm in IP allocation state
- * - Populate local value of tunable NoIPFailback in IP allocation
- state - this is really a cluster-wide configuration variable and
- only the value form the master node is used
+ * - Initialise IP allocation state. Pass:
+ + algorithm to be used;
+ + whether IP rebalancing ("failback") should be done (this uses a
+ cluster-wide configuration variable and only the value form the
+ master node is used); and
+ * + list of nodes to force rebalance (internal structure, currently
+ * no way to fetch, only used by LCP2 for nodes that have had new
+ * IP addresses added).
* - Retrieve tunables NoIPTakeover and NoIPHostOnAllDisabled from all
* connected nodes - this is done separately so tunable values can
* be faked in unit testing
* - Use ipalloc_set_public_ips() to set known and available IP
addresses for allocation
* - If cluster can't host IP addresses then early exit
- * - Populate list of nodes to force rebalance - internal structure,
- * currently no way to fetch, only used by LCP2 for nodes that have
- * had new IP addresses added
* - Run IP allocation algorithm
* - Send RELEASE_IP to all nodes for IPs they should not host
* - Send TAKE_IP to all nodes for IPs they should host
goto ipreallocated;
}
- ipalloc_state = ipalloc_state_init(ctdb, tmp_ctx);
+ ipalloc_state = ipalloc_state_init(tmp_ctx, ctdb->num_nodes,
+ determine_algorithm(&ctdb->tunable),
+ (ctdb->tunable.no_ip_failback != 0),
+ force_rebalance_nodes);
if (ipalloc_state == NULL) {
talloc_free(tmp_ctx);
return -1;
goto ipreallocated;
}
- ipalloc_state->force_rebalance_nodes = force_rebalance_nodes;
-
/* Do the IP reassignment calculations */
ipalloc(ipalloc_state);
if (ipalloc_state->all_ips == NULL) {
(*ctdb)->tunable.lcp2_public_ip_assignment = 1;
(*ctdb)->tunable.deterministic_public_ips = 0;
(*ctdb)->tunable.disable_ip_failover = 0;
- (*ctdb)->tunable.no_ip_failback = 0;
if ((t = getenv("CTDB_IP_ALGORITHM"))) {
if (strcmp(t, "lcp2") == 0) {
(*ctdb)->nodes = talloc_array(*ctdb, struct ctdb_node *, nodemap->num); // FIXME: bogus size, overkill
- *ipalloc_state = ipalloc_state_init(*ctdb, *ctdb);
+ *ipalloc_state = ipalloc_state_init(*ctdb, nodemap->num,
+ determine_algorithm(&((*ctdb)->tunable)),
+ false, NULL);
read_ctdb_public_ip_info(*ctdb, nodemap->num,
read_ips_for_multiple_nodes,
set_ipflags_internal(*ipalloc_state, nodemap,
tval_noiptakeover,
tval_noiptakeoverondisabled);
-
- (*ipalloc_state)->force_rebalance_nodes = NULL;
}
/* IP layout is read from stdin. See comment for ctdb_test_init() for