Sun Microsystems
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next

Triggering a Failover by Using the cmm_member_setqualif() Function

A failover can be triggered by calling the cmm_member_setqualif() function on the master node. The notifications sent for this scenario are shown in Table 6-16. An example that demonstrates how to trigger a failover using the cmm_member_setqualif() function is shown in Example 7-7.

Example 7-7 Triggering a Failover Using the cmm_member_setqualif() Function

#include <stdio.h>
#include <unistd.h>
#include <cmm.h>
#include "common.h"

/************************************************************/
int main(int argc , char ** argv) {
    cmm_error_t  cmm_diag;
    cmm_nodeid_t curr_node_id;
    cmm_member_t master;
    cmm_member_t vicemaster;

    cmm_diag = cmm_node_getid(&curr_node_id);
    if (cmm_diag != CMM_OK) {
        fprintf(stderr,
            "An error occurred during cmm_node_getid() call \n");
        exit(1);
    }

    printf("My id is %d\n",curr_node_id);


    /* get master/vice master id */
    cmm_diag = cmm_master_getinfo(&master);
    if (cmm_diag != CMM_OK) {
        fprintf(stderr,
            "An error occurred during cmm_master_getinfo call, CR=%d\n",
            cmm_diag);
        exit(1);
    }

    cmm_diag = cmm_vicemaster_getinfo(&vicemaster);
    if (cmm_diag != CMM_OK) {
        fprintf(stderr,
            "An error occurred during cmm_vicemaster_getinfo call, CR=%d\n",
            cmm_diag);
        exit(1);
    }

    printf("master node id is %d\n",master.nodeid);
    printf("vice-master node id is %d\n",vicemaster.nodeid);

    /* the role could be verified by cmm_member_ismaster() */
    if (curr_node_id == master.nodeid) {
        printf("We are the master of the cluster, launch Failover\n");
    } else {
        printf("We are not master, operation will be cancelled\n");
        exit(1);
    }

    /* launch the failover (disqualify the master) */
    cmm_diag = cmm_member_setqualif(curr_node_id,CMM_DISQUALIFIED_MEMBER);
    if (cmm_diag != CMM_OK) {
        fprintf(stderr,
            "An error occurred during cmm_member_setqualif, CR=%d\n",
            cmm_diag);
        exit(1);
    }

    /*the failover is running*/
    /* ... */


    /* on the new master we should run this command to
     * qualify the ex-master to make it the vice-master of the cluster
     *
     *  cmm_diag = cmm_member_setqualif(curr_node_id,CMM_QUALIFIED_MEMBER);
     *  if (cmm_diag != CMM_OK) {
     *      fprintf(stderr,
     *             "An error occurred during cmm_member_setqualif, CR=%d\n",
     *             cmm_diag);
     *      exit(1);
     *  }
     */
    exit(0);
}

When the master node fails, if the vice-master node cannot take over the master role, another master-eligible node must be qualified to become master.

The vice-master node cannot take over the master role if, for example, the vice-master node is not synchronized with the master node. If this is the case, and if no other node in the cluster is qualified to become the master, a master-eligible node must be qualified using the cmm_member_seizequalif() function. For more information about the cmm_member_seizequalif() function, see the cmm_member_seizequalif(3CMM) man page.

The cmm_member_seizequalif() function is used by the cmm_member_setqualif command and the squalif command of the nhcmmstat tool.

Previous Previous     Contents     Index     Next Next