sun.com | docs.sun.com | How To Buy | My Sun | Worldwide Sites |  |

| Previous Contents Index Next
You can trigger a failover by calling the `cmm_member_setqualif()` function from the master node. For more information, see Triggering a Failover by Using the `cmm_member_setqualif()`Function. ### Triggering A Switchover A switchover is usually triggered by the system administrator for maintenance of a node. There are two ways to trigger a switchover: By calling the `cmm_mastership_release()` function. By using the `nhcmmstat` tool. For information about the `nhcmmstat` tool, see the `nhcmmstat`(1M) man page. #### Triggering a Switchover Using `cmm_mastership_release()` The `cmm_mastership_release()` function enables a calling process to trigger a switchover. This function must be called from the master node. If the vice-master node is qualified to be master when the `cmm_mastership_release()` function is called, it becomes the master node. If there is no node qualified to become master when the `cmm_mastership_release()` function is called, the function does not release the mastership from the current master and the function fails. After the `cmm_mastership_release()` function is called, the calling node remains master until the vice-master node has taken the master role. When this happens, the `nhcmmd` daemon issues a notification of the switchover. For information about notifications during a switchover, see Switchover Notifications. For more information about the `nhcmmd` daemon and notifications, see Introduction to Change Notifications. The `cmm_mastership_release()` call is synchronous, that is, it only returns when the switchover has been completed or has failed, or when a timeout occurs. Example 7-5 demonstrates how to use the `cmm_mastership_release()` function to trigger a switchover: Example 7-5 Triggering a Switchover by Using the `cmm_mastership_release()` Function
    #include <cmm.h>
    #include <stdio.h>
    #include "common.h"

    /**************************************************************/
    void main(void)
    {
        cmm_error_t  res;
        cmm_member_t master_info;
        cmm_nodeid_t currnode;

        /* get the current node id */
        if ((res = cmm_node_getid(&currnode))==CMM_OK)
            printf("Current node id is: %d\n", currnode);
        else {
            printf("Error getting info on local node: %s\n",
                cmm_strerror(res));
            exit(1) ;
        }

        /* get the master information */
        if ((res = cmm_master_getinfo(&master_info)) != CMM_OK) {
            printf("Error getting info on master: %s\n",
                cmm_strerror(res));
            exit(1);
        }

        print_member(&master_info);
        /* get the current node id */

        if (master_info.nodeid != currnode)
        {
            printf("you must be on master to execute this command\n") ;
            exit(1);
        }

        /* note that cmm_mastership_release internally checks that
         * the command is executed on master node */
        res = cmm_mastership_release();
        if (res != CMM_OK) {
            printf("Error to release masterhsip: %s\n",
                cmm_strerror(res));
            exit(1) ;
        }
        printf("Switch-over completed successfully\n") ;
        exit(0) ;
    }
Note - Do not trigger a switchover with the `cmm_mastership_release()` function if you are running a separate Netra HA Suite Framework product on your cluster. ### Triggering A Failover A failover can be triggered by removing the master node by using the `cmm_membership_release()` function, or by disqualifying the master node by using the `cmm_member_setqualif()` function. This section contains information about these topics: Triggering a Failover by Using the `cmm_membership_remove()` Function. Triggering a Failover by Using the `cmm_member_setqualif()`Function. Caution - Trigger a failover only for test purposes. #### Triggering a Failover by Using the `cmm_membership_remove()` Function The `cmm_membership_remove()` function removes from the cluster the node from which the `cmm_membership_remove()` function is called. If you call this function from the master when the vice-master is synchronized, you trigger a failover. When the `cmm_membership_remove()` function is called from the master node, the master node stops sending heartbeat information to other nodes in the cluster, which triggers a failover. The notifications sent for this scenario are shown in Failover Due to the Removal or Failure of the Master Node. If there is no vice-master, or the master-eligible nodes are desynchronized, the `CMM_ECANCELLED` error is returned. If a node is not configured to be in any cluster, any subsequent call to the CMM API returns the `CMM_ENOCLUSTER` error. For further information about these and other return values, see Return Values of the CMM API. The only way for a removed node to rejoin the cluster is to restart the `nhprobed` daemon and the CMM service. For further information, see the `cmm_membership_remove`(3CMM) man page and the `nhprobed`(1M) man page. An example that demonstrates how to trigger a failover by using the `cmm_membership_remove()` function is shown in Example 7-6. Example 7-6 Triggering a Failover Using the `cmm_membership_remove()` Function
    #include <cmm.h>
    #include <stdio.h>
    #include "common.h"

    /**************************************************************/
    void main(void)
    {
        cmm_error_t  res;
        cmm_member_t master_info;
        cmm_nodeid_t currnode;

        /* get the current node id */
        if ((res = cmm_node_getid(&currnode))==CMM_OK)
            printf("Current node id is: %d\n", currnode);
        else {
            printf("Error getting info on local node: %s\n",
                cmm_strerror(res));
            exit(1) ;
        }

        /* get the master information */
        if ((res = cmm_master_getinfo(&master_info)) != CMM_OK) {
            printf("Error getting info on master: %s\n",
                cmm_strerror(res));
            exit(1);
        }

        print_member(&master_info);
        /* get the current node id */

        if (master_info.nodeid != currnode)
        {
            printf("you must be on master to trigger a failover
            using the cmm_membership_remove command\n") ;
            exit(1);
        }

        res = cmm_membership_remove();
        if (res != CMM_OK) {
            printf("Error in triggering a failover: %s\n",
                cmm_strerror(res));
            exit(1) ;
        }
        printf("Failover successful\n") ;
        exit(0) ;
    }
Previous Contents Index Next

Copyright 1994-2004 Sun Microsystems