pytdb: Add support for tdb_enable_seqnum, tdb_get_seqnum and tdb_increment_seqnum_non...
[metze/ctdb/wip.git] / server / ctdb_monitor.c
index 48a3f32ac8a448b62f3c2d635f3f071227acc4ae..dff6f42f86c55d3c3b6173ccb4a0d0ae2b772f7b 100644 (file)
@@ -19,7 +19,7 @@
 */
 
 #include "includes.h"
-#include "lib/events/events.h"
+#include "lib/tevent/tevent.h"
 #include "system/filesys.h"
 #include "system/wait.h"
 #include "../include/ctdb_private.h"
@@ -91,6 +91,7 @@ void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event)
        if (child == 0) {
                int ret;
 
+               debug_extra = talloc_asprintf(NULL, "notification-%s:", event);
                ret = ctdb_run_notification_script_child(ctdb, event);
                if (ret != 0) {
                        DEBUG(DEBUG_ERR,(__location__ " Notification script failed\n"));
@@ -113,6 +114,7 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
        int ret;
        TDB_DATA rddata;
        struct takeover_run_reply rd;
+       const char *state_str = NULL;
 
        c.pnn = ctdb->pnn;
        c.old_flags = node->flags;
@@ -140,28 +142,12 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
                ctdb->monitor->next_interval = 5;
 
                ctdb_run_notification_script(ctdb, "unhealthy");
-
-               /* ask the recmaster to reallocate all addresses */
-               DEBUG(DEBUG_ERR,("Node became UNHEALTHY. Ask recovery master %u to perform ip reallocation\n", ctdb->recovery_master));
-               ret = ctdb_daemon_send_message(ctdb, ctdb->recovery_master, CTDB_SRVID_TAKEOVER_RUN, rddata);
-               if (ret != 0) {
-                       DEBUG(DEBUG_ERR,(__location__ " Failed to send ip takeover run request message to %u\n", ctdb->recovery_master));
-               }
-
        } else if (status == 0 && (node->flags & NODE_FLAGS_UNHEALTHY)) {
                DEBUG(DEBUG_NOTICE,("monitor event OK - node re-enabled\n"));
                node->flags &= ~NODE_FLAGS_UNHEALTHY;
                ctdb->monitor->next_interval = 5;
 
                ctdb_run_notification_script(ctdb, "healthy");
-
-               /* ask the recmaster to reallocate all addresses */
-               DEBUG(DEBUG_ERR,("Node became HEALTHY. Ask recovery master %u to perform ip reallocation\n", ctdb->recovery_master));
-               ret = ctdb_daemon_send_message(ctdb, ctdb->recovery_master, CTDB_SRVID_TAKEOVER_RUN, rddata);
-               if (ret != 0) {
-                       DEBUG(DEBUG_ERR,(__location__ " Failed to send ip takeover run request message to %u\n", ctdb->recovery_master));
-               }
-
        }
 
 after_change_status:
@@ -189,6 +175,19 @@ after_change_status:
        ctdb_daemon_send_message(ctdb, ctdb->pnn,
                                 CTDB_SRVID_PUSH_NODE_FLAGS, data);
 
+       if (c.new_flags & NODE_FLAGS_UNHEALTHY) {
+               state_str = "UNHEALTHY";
+       } else {
+               state_str = "HEALTHY";
+       }
+
+       /* ask the recmaster to reallocate all addresses */
+       DEBUG(DEBUG_ERR,("Node became %s. Ask recovery master %u to perform ip reallocation\n",
+                        state_str, ctdb->recovery_master));
+       ret = ctdb_daemon_send_message(ctdb, ctdb->recovery_master, CTDB_SRVID_TAKEOVER_RUN, rddata);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR,(__location__ " Failed to send ip takeover run request message to %u\n", ctdb->recovery_master));
+       }
 }
 
 
@@ -202,7 +201,7 @@ static void ctdb_startup_callback(struct ctdb_context *ctdb, int status, void *p
        } else if (status == 0) {
                DEBUG(DEBUG_NOTICE,("startup event OK - enabling monitoring\n"));
                ctdb->done_startup = true;
-               ctdb->monitor->next_interval = 5;
+               ctdb->monitor->next_interval = 2;
                ctdb_run_notification_script(ctdb, "startup");
        }
 
@@ -245,7 +244,7 @@ static void ctdb_wait_until_recovered(struct event_context *ev, struct timed_eve
        }
 
 
-       if (timeval_elapsed(&ctdb->last_recovery_finished) < (ctdb->tunable.rerecovery_timeout + 3)) {
+       if (!fast_start && timeval_elapsed(&ctdb->last_recovery_finished) < (ctdb->tunable.rerecovery_timeout + 3)) {
                ctdb->db_persistent_startup_generation = INVALID_GENERATION;
 
                DEBUG(DEBUG_NOTICE,(__location__ " wait for pending recoveries to end. Wait one more second.\n"));
@@ -301,7 +300,7 @@ static void ctdb_wait_until_recovered(struct event_context *ev, struct timed_eve
 
        DEBUG(DEBUG_NOTICE,(__location__ " Recoveries finished. Running the \"startup\" event.\n"));
        event_add_timed(ctdb->ev, ctdb->monitor->monitor_context,
-                            timeval_current_ofs(1, 0), 
+                            timeval_current(),
                             ctdb_check_health, ctdb);
 }
 
@@ -432,7 +431,6 @@ int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata)
        struct ctdb_node_flag_change *c = (struct ctdb_node_flag_change *)indata.dptr;
        struct ctdb_node *node;
        uint32_t old_flags;
-       int i;
 
        if (c->pnn >= ctdb->num_nodes) {
                DEBUG(DEBUG_ERR,(__location__ " Node %d is invalid, num_nodes :%d\n", c->pnn, ctdb->num_nodes));
@@ -482,22 +480,7 @@ int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata)
 
        /* if we have become banned, we should go into recovery mode */
        if ((node->flags & NODE_FLAGS_BANNED) && !(c->old_flags & NODE_FLAGS_BANNED) && (node->pnn == ctdb->pnn)) {
-               /* make sure we are frozen */
-               DEBUG(DEBUG_NOTICE,("This node has been banned - forcing freeze and recovery\n"));
-               /* Reset the generation id to 1 to make us ignore any
-                  REQ/REPLY CALL/DMASTER someone sends to us.
-                  We are now banned so we shouldnt service database calls
-                  anymore.
-               */
-               ctdb->vnn_map->generation = INVALID_GENERATION;
-
-               for (i=1; i<=NUM_DB_PRIORITIES; i++) {
-                       if (ctdb_start_freeze(ctdb, i) != 0) {
-                               DEBUG(DEBUG_ERR,(__location__ " Failed to freeze db priority %u\n", i));
-                       }
-               }
-               ctdb_release_all_ips(ctdb);
-               ctdb->recovery_mode = CTDB_RECOVERY_ACTIVE;
+               return ctdb_local_node_got_banned(ctdb);
        }
        
        return 0;