Getting the status of each node in the cluster


#1

Is there any function in the C client library to find the status of each node in the cluster? Basically, I need the output to have each node’s IP along with it’s status e.g. UP, DOWN.


#2
as_nodes* nodes = as_nodes_reserve(as->cluster);

for (uint32_t i = 0; i < nodes->size; i++) {
    as_node* node = nodes->array[i];
    as_node_reserve(node);
    printf("Node %s active=%d\n", as_node_get_address_string(node), node->active);
    as_node_release(node);
}
as_nodes_release(nodes);

#3

Hi Brian,

Thanks for your response. I tested this code in a cluster of 2 nodes and found that it only gives info about the active node i.e. if I shut down 1 of the 2 nodes, the code gives info about only 1 node. I don’t know what’s missing here, because, node->active seems to be of no use.

In order to get info about the node which is no longer working(down) I used “services-alumni” in aerospike_info_foreach() and by finding the node which was present in it’s output but was absent in the output of your code, I got the node which was down.


#4

The client only tracks active nodes. node->active is only false when the node is marked for deletion, but not deleted yet.

If you just want to know when a node is added or dropped from the cluster, subscribe to cluster event callback.

void my_event_callback(as_cluster_event* ce)
{
  switch (ce->type) {
  case AS_CLUSTER_ADD_NODE:
    printf("Add node %s\n", ce->node_address);
    break;
  case AS_CLUSTER_REMOVE_NODE:
    printf("Remove node %s\n", ce->node_address);
    break;
  case AS_CLUSTER_DISCONNECTED:
    printf("Cluster disconnected\n");
    break;
}

as_config c;
as_config_init(&c);
c.event_callback = my_event_callback;
c.event_callback_udata = NULL;

#5

If ‘services-alumni’ is the command you need, you should also be aware of ‘services-alumni-reset’ which sets the alumni list to the current set of nodes observed by the cluster. If you ever make permanent changes to the cluster membership, you will likely want to run this command to manage the alumni lists on each node.


#6

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.