2 monitoring links to all other nodes to detect dead nodes
5 Copyright (C) Ronnie Sahlberg 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "lib/events/events.h"
24 #include "system/filesys.h"
25 #include "system/wait.h"
26 #include "../include/ctdb_private.h"
29 see if any nodes are dead
31 static void ctdb_check_for_dead_nodes(struct event_context *ev, struct timed_event *te,
32 struct timeval t, void *private_data)
34 struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context);
37 if (ctdb->monitoring_mode == CTDB_MONITORING_DISABLED) {
38 event_add_timed(ctdb->ev, ctdb,
39 timeval_current_ofs(ctdb->tunable.keepalive_interval, 0),
40 ctdb_check_for_dead_nodes, ctdb);
44 /* send a keepalive to all other nodes, unless */
45 for (i=0;i<ctdb->num_nodes;i++) {
46 struct ctdb_node *node = ctdb->nodes[i];
47 if (node->vnn == ctdb->vnn) {
51 if (!(node->flags & NODE_FLAGS_CONNECTED)) {
52 /* it might have come alive again */
53 if (node->rx_cnt != 0) {
54 ctdb_node_connected(node);
60 if (node->rx_cnt == 0) {
68 if (node->dead_count >= ctdb->tunable.keepalive_limit) {
69 DEBUG(0,("dead count reached for node %u\n", node->vnn));
71 ctdb_send_keepalive(ctdb, node->vnn);
72 /* maybe tell the transport layer to kill the
78 if (node->tx_cnt == 0) {
79 DEBUG(5,("sending keepalive to %u\n", node->vnn));
80 ctdb_send_keepalive(ctdb, node->vnn);
86 event_add_timed(ctdb->ev, ctdb,
87 timeval_current_ofs(ctdb->tunable.keepalive_interval, 0),
88 ctdb_check_for_dead_nodes, ctdb);
91 static void ctdb_check_health(struct event_context *ev, struct timed_event *te,
92 struct timeval t, void *private_data);
95 called when a health monitoring event script finishes
97 static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
99 struct ctdb_node *node = ctdb->nodes[ctdb->vnn];
101 struct ctdb_node_flag_change c;
103 event_add_timed(ctdb->ev, ctdb,
104 timeval_current_ofs(ctdb->tunable.monitor_interval, 0),
105 ctdb_check_health, ctdb);
107 if (status != 0 && !(node->flags & NODE_FLAGS_DISABLED)) {
108 DEBUG(0,("monitor event failed - disabling node\n"));
109 node->flags |= NODE_FLAGS_DISABLED;
110 } else if (status == 0 && (node->flags & NODE_FLAGS_DISABLED)) {
111 DEBUG(0,("monitor event OK - node re-enabled\n"));
112 ctdb->nodes[ctdb->vnn]->flags &= ~NODE_FLAGS_DISABLED;
119 c.flags = node->flags;
121 data.dptr = (uint8_t *)&c;
122 data.dsize = sizeof(c);
124 /* tell the recmaster that something has changed */
125 ctdb_send_message(ctdb, ctdb->recovery_master, CTDB_SRVID_NODE_FLAGS_CHANGED, data);
130 see if the event scripts think we are healthy
132 static void ctdb_check_health(struct event_context *ev, struct timed_event *te,
133 struct timeval t, void *private_data)
135 struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context);
138 if (ctdb->monitoring_mode == CTDB_MONITORING_DISABLED) {
139 event_add_timed(ctdb->ev, ctdb,
140 timeval_current_ofs(ctdb->tunable.monitor_interval, 0),
141 ctdb_check_health, ctdb);
145 ret = ctdb_event_script_callback(ctdb, ctdb, ctdb_health_callback, ctdb, "monitor");
147 DEBUG(0,("Unable to launch monitor event script\n"));
148 event_add_timed(ctdb->ev, ctdb,
149 timeval_current_ofs(ctdb->tunable.monitor_interval, 0),
150 ctdb_check_health, ctdb);
156 start watching for nodes that might be dead
158 int ctdb_start_monitoring(struct ctdb_context *ctdb)
160 event_add_timed(ctdb->ev, ctdb,
161 timeval_current_ofs(ctdb->tunable.keepalive_interval, 0),
162 ctdb_check_for_dead_nodes, ctdb);
163 event_add_timed(ctdb->ev, ctdb,
164 timeval_current_ofs(ctdb->tunable.monitor_interval, 0),
165 ctdb_check_health, ctdb);