Shutting down DB2 database partitions on an AIX physical node when paging space reaches a certain percentage of fullness, and restarting a DB2 database partition, or initiating a failover operation if a process dies on a given node, are two examples of user-defined events. Examples that illustrate user-defined events, such as shutting down a database partition and forcing a transaction abort to free paging space, can be found in the samples subdirectory.
A rules file, /user/sbin/cluster/events/rules.hacmprd, contains HACMP events. Each event description in this file has the following nine components:
Each object requires one line in the event definition, even if the line is not used. If these lines are removed, HACMP ES Cluster Manager cannot parse the event definition properly, and this may cause the system to hang. Any line beginning with "#" is treated as a comment line.
Note: | The rules file requires exactly nine lines for each event definition, not counting any comment lines. When adding a user-defined event at the bottom of the rules file, it is important to remove the unnecessary empty line at the end of the file, or the node will hang. |
Following is an example of an event definition for node_up:
##### Beginning of the Event Definition: node_up # TE_JOIN_NODE 0 /usr/sbin/cluster/events/node_up.rp 2 0 # 6) Resource variable - only used for event management events # 7) Instance vector - only used for event management events # 8) Predicate - only used for event management events # 9) Rearm predicate - only used for event management events ###### End of the Event Definition: node_up
This example is just one of the event definitions that can be found in the rules.hacmprd file. In this example, the recovery program /usr/sbin/cluster/events/node_up.rp is invoked when the node_up event occurs. Values are specified for the state, recovery type, and recovery level. There are four empty lines for resource variable, instance variable, predicate, and rearm predicate.
You can define other events to react to non-standard HACMP ES events. For example, to define the event that the /tmp file system is over 90 per cent full, the rules.hacmprd file must be modified.
Many events are predefined in the IBM Parallel System Support Program (PSSP). These events can be exploited (when used within user-defined events) as follows:
HACMP ES uses PSSP event detection to treat user-defined events. The PSSP Event Management subsystem provides comprehensive event detection by monitoring various hardware and software resources.
Resource states are represented by resource variables. Resource conditions are represented as expressions called predicates.
Event Management receives resource variables from the Resource Monitor, which observes the state of specific system resources and transforms this state into several resource variables. These variables are periodically passed to Event Management. Event Management applies predicates that are specified by the HACMP ES Cluster Manager in rules.hacmprd for each resource variable. When the predicate is evaluated as being true, an event is generated and sent to the Cluster Manager. Cluster Manager initiates the voting protocol, and the recovery program file (xxx.rp) is run (according to event priority) on a set of nodes specified by "node sets" in the recovery program.
The recovery program file (xxx.rp) is made up of one or more recovery program lines. Each line is declared in the following format:
relationship command_to_run expected_status NULL
There must be at least one space between each value in the line. "Relationship" is a value used to decide which program should run on which kind of node. Three types of relationship are supported:
"Command_to_run" is a quotation mark-delimited string, with or without a full-path specification to an executable program. Only HACMP-delivered event scripts can use a relative-path definition. Other scripts or programs must use the full-path specification, even if they are located in the same directory as the HACMP event scripts.
"Expected_states" is the return code of the specified command or program. It is either an integer value, or an "x". If "x" is used, Cluster Manager does not care about the return code. All other codes must be equal to the expected return code, otherwise Cluster Manager detects the event failure. The handling of this event "hangs" the process until recovery (through manual intervention) occurs. Without manual intervention, the node does not synchronize with the other nodes. Synchronization across all nodes is required for the Cluster Manager to control all the nodes.
"NULL" is a field reserved for future use. The word "NULL" must appear at the end of each line except the barrier line. If you specify multiple recovery commands between two barrier commands, or before the first one, the recovery commands are run in parallel on the node itself, and between the nodes.
The barrier command is used to synchronize all the commands across all the cluster nodes. When a node hits the barrier statement in the recovery program, Cluster Manager initiates the barrier protocol on this node. Since the barrier protocol is a two-phase protocol, all nodes are notified that both phases have completed when all of the nodes have met the barrier in the recovery program, and "voted" to approve the protocol.
The process can be summarized as follows:
The following sample scripts for failover recovery and user-defined events are included with DB2 UDB EEE. The script files are located in the $INSTNAME/sqllib/samples/hacmp/es directory. The scripts will work "as is", or you can customize the recovery action.
The recovery scripts must be installed on each node that will run recovery operations. The script files can be centrally installed from the SP control workstation or other designated SP node:
db2_inst_ha $INSTNAME/sqllib/samples/hacmp/es <nodelist> <DATABASENAME> where $INSTNAME/sqllib/samples/hacmp/es is the directory in which the scripts and the event are located <nodelist> is the pcp or pexec style of the nodes; for example, 1-16 or 1,2,3,4 <DATABASENAME> is the name of the database for regular and failover parameter files.
The reg.parms.SAMPLE and failover.parms.SAMPLE files will be copied to each node and renamed reg.parms.DATABASENAME. db2_inst_ha copies files to each node in /usr/bin, and updates the HACMP event files:
/usr/sbin/cluster/events/rules.hacmprd /usr/sbin/cluster/events/network_up_complete /usr/sbin/cluster/events/network_down_complete
ha_db2stop
Note: | You must wait for the command to return. Exiting by using a ctrl-C interrupt, or by killing the process, may re-enable failover recovery prematurely, and some database partitions may not be stopped. |
HACMP ES invokes the DB2 recovery scripts in the following way:
HACMP runs the node_up sequence, acquiring volume groups, logical volumes, file systems, and IP addresses specified in resource groups that are owned (through cascading) or assigned (through rotating) to this node.
When node_up_local_complete is run, the application server definition that contains rc.db2pe is initiated to start the database partition specified in the application server definitions on this physical node.
Note: | rc.db2pe, when running in start mode, adjusts the DB2 parameters specified in reg.parms.DATABASE for each DATABASE in the database directory that matches a parameter (parms) file. |
Each node follows this sequence when starting. If you have multiple HACMP clusters and start them in parallel, multiple nodes are brought up at once.
HACMP acquires volume groups, logical volumes, file systems, and IP addresses that are specified in the resource group on the designated takeover node.
When node_down_remote_complete is run, HACMP will run rc.db2pe as the application server start script specified in the resource group for this database partition.
Note: | rc.db2pe, when running in mutual takeover mode, stops the DB2 database partition running on it, adjusts the DB2 parameters specified in failover.parms.DATABASE for each DATABASE in the database directory that matches a parameter (parms) file, and then starts both database partitions on the physical takeover node. |
When node_up_remote is run on the old takeover node, the application server definition causes rc.db2pe to be run in stop mode.
Note: | rc.db2pe, when running in a reintegration mode (mutual takeover), stops both of the database partitions running on it, adjust the DB2 parameters specified in reg.parms.DATABASE for each DATABASE in the database directory that matches a parameter (parms) file, and then starts just the database partition to be kept on this physical takeover node. |
The old takeover node releases volume groups, logical volumes, file systems, and IP addresses specified in resource groups that are to be owned by the reintegrating node.
HACMP re-acquires volume groups, logical volumes, file systems, and IP addresses specified in the resource group that is now owned by the reintegrating node.
When node_up_local_complete is run, the application server definition that contains rc.db2pe is initiated to start the DB2 database partition specified in the application server definition on this reintegrating physical node.
Note: | rc.db2pe, when running in start mode, adjusts the DB2 parameters specified in reg.parms.DATABASE for each DATABASE in the database directory that matches a parameter (parms) file. |
When node_down_local is run on the stopping node, the application server definition causes rc.db2pe to be run in stop mode.
Note: | rc.db2pe, when running in stop mode, adjusts the DB2 parameters specified in failover.parms.DATABASE for each DATABASE in the database directory that matches a parameter (parms) file, and then stops the DB2 database partition (this is for takeover). |
HACMP releases volume groups, logical volumes, file systems, and IP addresses specified in resource groups that are now owned by the node.
All nodes run the db2_proc_restart script. The node on which the failure occurred restarts the correct DB2 database partition.
All nodes run the db2_paging_action script. If a node has more than 70 percent of paging space filled, a wall command is issued. If a node has more than 90 percent of paging space filled, DB2 database partitions on this physical node are stopped and then restarted.
All nodes run the rc.db2pe script in NFS mode. If an NFS process stops running, it is restarted. Similarly, if the automount process stops running, it is restarted.
The net_down script is called. This verifies the network as the SP switch network, and verifies that it is down. If that is the case, it waits a user-defined time interval. The default time interval is 100 seconds.
If the SP switch network comes back, as indicated by an network_up_complete event, no recovery is effected.
If the time limit is reached, HACMP is stopped with failover.
Note: | All events can be monitored through SP problem management and the SP Perspectives GUI. |
Other script utilities are available for your use, including:
ha_cmd <noderange> <START|STOP|TAKE|FORCE> where <noderange> is a pcp or pexec style of SP noderange. For example, "ha_cmd 3-6 START" would start HACMP on nodes 3,4,5,6. "ha_cmd 5 TAKE" would shut down HACMP on node 5 for mutual takeover.
ha_mon <node> where <node> is the SP node to be monitored. ha_mon will "tail -f" the /tmp/hacmp.out file on the node you specify.
db2_turnoff_recov <nodelist>
db2_turnon_recov <nodelist>