ctdbd: Initialise the node flags in just one place
authorMartin Schwenke <martin@meltin.net>
Tue, 4 Dec 2012 03:28:06 +0000 (14:28 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Sun, 6 Jan 2013 23:35:39 +0000 (10:35 +1100)
Currently flags are initialised in 2 places.  One of them is in
ctdb_tcp_listen_automatic(), which just seems wrong.  This makes the
code easier to follow by just doing it in ctdb_start_daemon().

This means that the flags are now initialised later than previously.
However, it is still done before the transport is started and before
clients can connect.

In future it might make sense to do a similar thing with setting the
PNN.  However, the current optimisation is reasonably obvious...

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>

(This used to be ctdb commit 2bbee8ac23ad5b7adf7122d8c91d5f0d54582507)

ctdb/server/ctdb_daemon.c
ctdb/server/ctdb_server.c
ctdb/server/ctdbd.c
ctdb/tcp/tcp_connect.c

index 13ea3192fecd617aa92d5ece9743fc19feaad2cf..623e623cca8ddfd366aea06c63ea347ff5f380d0 100644 (file)
@@ -1029,6 +1029,26 @@ failed:
        return -1;      
 }
 
+static void initialise_node_flags (struct ctdb_context *ctdb)
+{
+       if (ctdb->pnn == -1) {
+               ctdb_fatal(ctdb, "PNN is set to -1 (unknown value)");
+       }
+
+       ctdb->nodes[ctdb->pnn]->flags &= ~NODE_FLAGS_DISCONNECTED;
+
+       /* do we start out in DISABLED mode? */
+       if (ctdb->start_as_disabled != 0) {
+               DEBUG(DEBUG_INFO, ("This node is configured to start in DISABLED state\n"));
+               ctdb->nodes[ctdb->pnn]->flags |= NODE_FLAGS_DISABLED;
+       }
+       /* do we start out in STOPPED mode? */
+       if (ctdb->start_as_stopped != 0) {
+               DEBUG(DEBUG_INFO, ("This node is configured to start in STOPPED state\n"));
+               ctdb->nodes[ctdb->pnn]->flags |= NODE_FLAGS_STOPPED;
+       }
+}
+
 static void ctdb_setup_event_callback(struct ctdb_context *ctdb, int status,
                                      void *private_data)
 {
@@ -1189,6 +1209,9 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog,
        if (ctdb->methods->initialise(ctdb) != 0) {
                ctdb_fatal(ctdb, "transport failed to initialise");
        }
+
+       initialise_node_flags(ctdb);
+
        if (public_address_list) {
                ctdb->public_addresses_file = public_address_list;
                ret = ctdb_set_public_addresses(ctdb, true);
index ec608cfa56a3cae3fc0d95e4ac8762c6be3a10ca..de3c6901d76ef1148c6e50b7a1c13316325251ee 100644 (file)
@@ -146,18 +146,6 @@ static int ctdb_add_node(struct ctdb_context *ctdb, char *nstr)
            ctdb_same_address(&ctdb->address, &node->address)) {
                /* for automatic binding to interfaces, see tcp_connect.c */
                ctdb->pnn = node->pnn;
-               node->flags &= ~NODE_FLAGS_DISCONNECTED;
-
-               /* do we start out in DISABLED mode? */
-               if (ctdb->start_as_disabled != 0) {
-                       DEBUG(DEBUG_INFO, ("This node is configured to start in DISABLED state\n"));
-                       node->flags |= NODE_FLAGS_DISABLED;
-               }
-               /* do we start out in STOPPED mode? */
-               if (ctdb->start_as_stopped != 0) {
-                       DEBUG(DEBUG_INFO, ("This node is configured to start in STOPPED state\n"));
-                       node->flags |= NODE_FLAGS_STOPPED;
-               }
        }
 
        ctdb->num_nodes++;
index bcc950266a46201b46cea9dc78d15d29dc076dc2..491b4a2ff14eb1efe5043ca5b995df6a238643f3 100644 (file)
@@ -242,6 +242,16 @@ int main(int argc, const char *argv[])
                ctdb->capabilities |= CTDB_CAP_LVS;
        }
 
+       /* 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;
+
        /* tell ctdb what nodes are available */
        ctdb_load_nodes_file(ctdb);
 
index 26a280e30ba4a5d73c592278696250555e00343d..93111f37aa3b23623149d5df84dde939150c1460 100644 (file)
@@ -374,21 +374,10 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
                                     ctdb->address.address, 
                                     ctdb->address.port);
        ctdb->pnn = ctdb->nodes[i]->pnn;
-       ctdb->nodes[i]->flags &= ~NODE_FLAGS_DISCONNECTED;
        DEBUG(DEBUG_INFO,("ctdb chose network address %s:%u pnn %u\n", 
                 ctdb->address.address, 
                 ctdb->address.port, 
                 ctdb->pnn));
-       /* do we start out in DISABLED mode? */
-       if (ctdb->start_as_disabled != 0) {
-               DEBUG(DEBUG_INFO, ("This node is configured to start in DISABLED state\n"));
-               ctdb->nodes[i]->flags |= NODE_FLAGS_DISABLED;
-       }
-       /* do we start out in STOPPED mode? */
-       if (ctdb->start_as_stopped != 0) {
-               DEBUG(DEBUG_INFO, ("This node is configured to start in STOPPED state\n"));
-               ctdb->nodes[i]->flags |= NODE_FLAGS_STOPPED;
-       }
        
        if (listen(ctcp->listen_fd, 10) == -1) {
                goto failed;