Sun Microsystems
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next

Retrieving Information About All Nodes in the Cluster

The cmm_member_getcount() and cmm_member_getall() functions retrieve information for all peer nodes in the cluster.

  • The cmm_member_getcount() function counts the number of peer nodes in the cluster.

  • The cmm_member_getall() function fills a table with the information returned in the cmm_member_t structure.

Using the value returned by the cmm_member_getcount() function, you can dynamically allocate the table. For more information, see the cmm_member_getcount(3CMM) man page.

The following example demonstrates how to retrieve information about all peer nodes in the cluster.

Example 5-6 Retrieving Information About All Nodes in the Cluster

#include <cmm.h>
#include <stdio.h>
#include <stdlib.h>        /* for exit() */
#include <strings.h>        /* for strcpy */
#include "common.h"


/**************************************************************/
void main(void)
{
    cmm_error_t  res;
    cmm_member_t *member_table;
    uint32_t     member_count ;
    uint32_t     index;
    uint32_t     totalitems;
    
    res = cmm_member_getcount(&totalitems);
    if (res != CMM_OK) {
        fprintf(stderr,
        "Failed to count nodes: error %s\n",
        cmm_strerror(res));
       exit(1) ;
        }

member_table = (cmm_member_t *) malloc (totalitems * sizeof(cmm_member_t));

    if (member_table == NULL) {
        printf("Failed to allocate memory for data -> abort\n");
        exit(1);
    }

    res = cmm_member_getall(totalitems,member_table,&member_count)
    if (res != CMM_OK) {
            fprintf(stderr,
            "Failed to get all nodes: error %s\n",
            cmm_strerror(res));
        free(member_table);
        exit(1) ;
    }
    
    for (index=0 ; index<member_count ; index++)
        print_member(&(member_table[index])) ;
    
    free(member_table) ;
}

Following is an example output for a two node cluster:

------------------------------
node_id     = 12
domain_id   = 28
name        = one_node
role        = MASTER
qualified   = YES
synchro.    = READY
frozen      = NO
excluded    = NO
eligible    = YES
incarn.     = 998590675
swload_id   = 1
CGTP @      = 10.28.13.12
------------------------------
node_id     = 14
domain_id   = 28
name        = another_node
role        = VICE-MASTER
qualified   = YES
synchro.    = READY
frozen      = NO
excluded    = NO
eligible    = YES
Incarn.     = 998923673
swload id   = 1
CGTP @      = 10.28.13.14
------------------------------

Identifying the Role of a Node

The cmm_potential_getinfo() and cmm_member_getinfo() functions retrieve information about a node identified by its nodeid. For details on the roles that a node can have, see Membership Roles.

To find the nodeid of a node, see Example 5-1.

The following functions retrieve specific information about the role of a node:

cmm_member_ismaster()

This function tests whether the node identified by the cmm_member_t structure is master. See the cmm_member_ismaster(3CMM) man page.

cmm_member_isvicemaster()

This function tests whether the node identified by the cmm_member_t structure is vice-master. See the cmm_member_isvicemaster(3CMM) man page.

cmm_member_isoutofcluster()

This function tests whether a node is out of the cluster. See the cmm_member_isoutofcluster(3CMM) man page.

If the tested condition is false, the functions in the preceding list return 0. Otherwise, these functions return a value other than 0. These functions are used in Example 4-1.

You can also find the role of a node from the command line by using the nhcmmrole command on the node. For details about this command, see the nhcmmrole(1M) man page.


Note - The role of a node is also specified in the sflag field of the cmm_member_t structure returned by these functions. See Using the sflag Field of the cmm_member_t Structure. To get node information, it is better to use the CMM API. Do not to attempt direct extraction of node information from the sflag field of the cmm_member_t structure.


Previous Previous     Contents     Index     Next Next