ctdb-daemon: Consolidate basic CTDB context initialisation
authorMartin Schwenke <martin@meltin.net>
Wed, 18 Apr 2018 04:44:01 +0000 (14:44 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 1 May 2018 11:31:19 +0000 (13:31 +0200)
None of this initialisation needs configuration options, so centralise
it with the context initialisation.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdbd.c

index 20f82d771f27c1ded7995fe6ea0b5c7eb3642229..f0f0dc913196aea5782ddecbf556a0aadc49b3f5 100644 (file)
@@ -129,8 +129,33 @@ static struct ctdb_context *ctdb_init(struct tevent_context *ev)
                return NULL;
        }
 
+       gettimeofday(&ctdb->ctdbd_start_time, NULL);
+
+       gettimeofday(&ctdb->last_recovery_started, NULL);
+       gettimeofday(&ctdb->last_recovery_finished, NULL);
+
+       ctdb->recovery_mode    = CTDB_RECOVERY_NORMAL;
+       ctdb->recovery_master  = (uint32_t)-1;
+
+       ctdb->upcalls = &ctdb_upcalls;
+
        ctdb->statistics.statistics_start_time = timeval_current();
 
+       ctdb->capabilities = CTDB_CAP_DEFAULT;
+
+       /*
+        * Initialise this node's PNN to the unknown value.  This will
+        * be set to the correct value by either ctdb_add_node() as
+        * part of loading the nodes file or by
+        * ctdb_tcp_listen_automatic() when the transport is
+        * initialised.  At some point we should de-optimise this and
+        * pull it out into ctdb_start_daemon() so it is done clearly
+        * and only in one place.
+        */
+       ctdb->pnn = CTDB_UNKNOWN_PNN;
+
+       ctdb->do_checkpublicip = true;
+
        return ctdb;
 }
 
@@ -248,13 +273,6 @@ int main(int argc, const char *argv[])
 
        DEBUG(DEBUG_NOTICE,("CTDB starting on node\n"));
 
-       gettimeofday(&ctdb->ctdbd_start_time, NULL);
-       gettimeofday(&ctdb->last_recovery_started, NULL);
-       gettimeofday(&ctdb->last_recovery_finished, NULL);
-       ctdb->recovery_mode    = CTDB_RECOVERY_NORMAL;
-       ctdb->recovery_master  = (uint32_t)-1;
-       ctdb->upcalls          = &ctdb_upcalls;
-
        if (options.recovery_lock == NULL) {
                DEBUG(DEBUG_WARNING, ("Recovery lock not set\n"));
        }
@@ -280,7 +298,6 @@ int main(int argc, const char *argv[])
        }
 
        /* set ctdbd capabilities */
-       ctdb->capabilities = CTDB_CAP_DEFAULT;
        if (options.no_lmaster != 0) {
                ctdb->capabilities &= ~CTDB_CAP_LMASTER;
        }
@@ -288,16 +305,6 @@ int main(int argc, const char *argv[])
                ctdb->capabilities &= ~CTDB_CAP_RECMASTER;
        }
 
-       /* Initialise this node's PNN to the unknown value.  This will
-        * be set to the correct value by either ctdb_add_node() as
-        * part of loading the nodes file or by
-        * ctdb_tcp_listen_automatic() when the transport is
-        * initialised.  At some point we should de-optimise this and
-        * pull it out into ctdb_start_daemon() so it is done clearly
-        * and only in one place.
-        */
-       ctdb->pnn = -1;
-
        /* Default value for CTDB_BASE - don't override */
        setenv("CTDB_BASE", CTDB_ETCDIR, 0);
        ctdb_base = getenv("CTDB_BASE");
@@ -341,8 +348,6 @@ int main(int argc, const char *argv[])
 
        ctdb->do_setsched = (options.nosetsched != 1);
 
-       ctdb->do_checkpublicip = true;
-
        t = getenv("CTDB_TEST_MODE");
        if (t != NULL) {
                ctdb->do_setsched = false;