/** * Check whether we're seen as coordinator by all the nodes in our clique. * NOTE: This function assumes that we see ourself as coord. * * \return true if the whole clique agrees that we are coord, false otherwise */ static bool clique_sees_self_as_coord(void) { exa_nodeid_t node_id; for (node_id = 0; node_id < self->view.num_seen; node_id++) if (exa_nodeset_contains(&self->view.clique, node_id)) { sup_node_t *node = sup_cluster_node(&cluster, node_id); EXA_ASSERT(node); if (!self_sees(node)) return false; if (!exa_nodeset_equals(&node->view.clique, &self->view.clique)) return false; if (node->view.coord != self->view.coord) return false; } __trace("clique_sees_self_as_coord -> YES"); return true; }
/** * Remove a node from a view's seen nodes. * * \param view View to remove a node from * \param[in] node_id Id of node to remove */ void sup_view_del_node(sup_view_t *view, exa_nodeid_t node_id) { EXA_ASSERT(view); exa_nodeset_del(&view->nodes_seen, node_id); if (node_id == view->num_seen - 1) { while (node_id > 0 && !exa_nodeset_contains(&view->nodes_seen, node_id)) node_id--; if (exa_nodeset_contains(&view->nodes_seen, node_id)) view->num_seen = node_id + 1; else view->num_seen = 0; } }
void algopr_update_client_connections(const exa_nodeset_t *mship) { exa_nodeid_t node_id; os_thread_mutex_lock(&peers_lock); for (node_id = 0; node_id < EXA_MAX_NODES_NUMBER; node_id++) { /* FIXME Handle errors */ if (exa_nodeset_contains(mship, node_id) && !__peer_is_connected(node_id)) { /* Don't connect to self nor to nodes with a higher node id */ if (node_id < this_node_id) __connect_to_peer(node_id); } else if (!exa_nodeset_contains(mship, node_id) && __peer_is_connected(node_id)) __disconnect_from_peer(node_id); } os_thread_mutex_unlock(&peers_lock); }
/** * Dump our view of the cluster in the logs. */ static void dump_view(int sig) { exa_nodeid_t node_id; char known_str[EXA_MAX_NODES_NUMBER + 1]; if (sig) __debug("got signal %d, dumping view", sig); __debug("incarnation: %hu", self->incarnation); exa_nodeset_to_bin(&cluster.known_nodes, known_str); __debug("num_nodes: %u known_nodes: %s", cluster.num_nodes, known_str); for (node_id = 0; node_id < EXA_MAX_NODES_NUMBER; node_id++) if (exa_nodeset_contains(&cluster.known_nodes, node_id)) dump_node(sup_cluster_node(&cluster, node_id)); }
int vrt_node_get_upnode_id(void) { int upnode_id = -1; exa_nodeid_t node; for (node = 0 ; node < EXA_MAX_NODES_NUMBER ; node++) { if (exa_nodeset_contains(&nodes_up, node)) { upnode_id++; if (node == vrt_node_id) return upnode_id; } } EXA_ASSERT_VERBOSE(false, "Upnode ID not found. upnode_id=%d vrt_node_get_upnodes_count=%d vrt_node_id=%d", upnode_id, vrt_node_get_upnodes_count(), vrt_node_id); return 0; }
/** * Check ping validity. * * \param[in] ping Ping to check * \param[in] op Operation checking for: 'S' (sending) or 'R' (receiving) * * \return true if valid, false otherwise */ bool sup_check_ping(const sup_ping_t *ping, char op) { bool ok = true; char suffix[32]; EXA_ASSERT(op == 'S' || op == 'R'); if (op == 'S') os_snprintf(suffix, sizeof(suffix), "sending ping"); else os_snprintf(suffix, sizeof(suffix), "ping from node %u", ping->sender); if (ping->incarnation == 0) { __error("%s: invalid incarnation", suffix); ok = false; } if (!SUP_STATE_CHECK(ping->view.state) || ping->view.state == SUP_STATE_UNKNOWN) { __error("%s: invalid state %d", suffix, ping->view.state); ok = false; } if (ping->view.num_seen == 0) { __error("%s: empty view", suffix); ok = false; } if (!exa_nodeset_contains(&ping->view.nodes_seen, ping->sender)) { __error("%s: view does not contain %u", suffix, ping->sender); ok = false; } return ok; }
/** * Check whether all nodes in our clique have accepted the clique * (aka membership) whose generation is given. * * \param[in] gen Membership generation * * \return true if all have accepted, false otherwise */ static bool clique_has_accepted(sup_gen_t gen) { exa_nodeid_t node_id; for (node_id = 0; node_id < self->view.num_seen; node_id++) if (exa_nodeset_contains(&self->view.clique, node_id)) { sup_node_t *node = sup_cluster_node(&cluster, node_id); EXA_ASSERT(node); if (!self_sees(node)) return false; if (!exa_nodeset_equals(&node->view.clique, &self->view.clique)) return false; if (node->view.accepted != gen) return false; } return true; }