recoverd: Delay the initial election if node is started in stopped state
authorAmitay Isaacs <amitay@gmail.com>
Thu, 27 Jun 2013 05:44:27 +0000 (15:44 +1000)
committerMichael Adam <obnox@samba.org>
Mon, 26 Aug 2013 11:35:54 +0000 (13:35 +0200)
Since there is an early exit if a node is stopped or banned, we can wait till
the node becomes active to start initial election.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit 593a17678fbd3109e118154b034d43b852659518)

server/ctdb_recoverd.c

index f902366417be351a96215542c52193dc5c3703af..153ba564196de0ab844be78cf445c4bb62d34a3e 100644 (file)
@@ -2958,28 +2958,6 @@ static void main_loop(struct ctdb_context *ctdb, struct ctdb_recoverd *rec,
        /* remember our own node flags */
        rec->node_flags = nodemap->nodes[pnn].flags;
 
-       /* check which node is the recovery master */
-       ret = ctdb_ctrl_getrecmaster(ctdb, mem_ctx, CONTROL_TIMEOUT(), pnn, &rec->recmaster);
-       if (ret != 0) {
-               DEBUG(DEBUG_ERR, (__location__ " Unable to get recmaster from node %u\n", pnn));
-               return;
-       }
-
-       /* if we are not the recmaster we can safely ignore any ip reallocate requests */
-       if (rec->recmaster != pnn) {
-               if (rec->ip_reallocate_ctx != NULL) {
-                       talloc_free(rec->ip_reallocate_ctx);
-                       rec->ip_reallocate_ctx = NULL;
-                       rec->reallocate_callers = NULL;
-               }
-       }
-
-       if (rec->recmaster == (uint32_t)-1) {
-               DEBUG(DEBUG_NOTICE,(__location__ " Initial recovery master set - forcing election\n"));
-               force_election(rec, pnn, nodemap);
-               return;
-       }
-
        /* if the local daemon is STOPPED or BANNED, we verify that the databases are
           also frozen and thet the recmode is set to active.
        */
@@ -3011,6 +2989,32 @@ static void main_loop(struct ctdb_context *ctdb, struct ctdb_recoverd *rec,
                return;
        }
 
+       /* check which node is the recovery master */
+       ret = ctdb_ctrl_getrecmaster(ctdb, mem_ctx, CONTROL_TIMEOUT(), pnn, &rec->recmaster);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR, (__location__ " Unable to get recmaster from node %u\n", pnn));
+               return;
+       }
+
+       /* if we are not the recmaster we can safely ignore any ip reallocate requests */
+       if (rec->recmaster != pnn) {
+               if (rec->ip_reallocate_ctx != NULL) {
+                       talloc_free(rec->ip_reallocate_ctx);
+                       rec->ip_reallocate_ctx = NULL;
+                       rec->reallocate_callers = NULL;
+               }
+       }
+
+       /* This is a special case.  When recovery daemon is started, recmaster
+        * is set to -1.  If a node is not started in stopped state, then
+        * start election to decide recovery master
+        */
+       if (rec->recmaster == (uint32_t)-1) {
+               DEBUG(DEBUG_NOTICE,(__location__ " Initial recovery master set - forcing election\n"));
+               force_election(rec, pnn, nodemap);
+               return;
+       }
+
        /* update the capabilities for all nodes */
        ret = update_capabilities(ctdb, nodemap);
        if (ret != 0) {