ctdb-daemon: Move VNN map initialisation out of node loading
authorMartin Schwenke <martin@meltin.net>
Tue, 17 Feb 2015 01:34:41 +0000 (12:34 +1100)
committerAmitay Isaacs <amitay@samba.org>
Mon, 23 Mar 2015 11:23:12 +0000 (12:23 +0100)
Each node reload unnecessarily and incorrectly resets the VNN map,
causing a potentially unnecessary recovery.  When nodes are reloaded
any newly deleted nodes should already be disconnected and any newly
added nodes should also be disconnected.  This means that reloading
the nodes file should not cause a change in the VNN map.

The current implementation also leaks memory every time the nodes are
reloaded.

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

index aac507cab5cce496e0b4c0b184b215ae0bc98fdb..5a0bde2a868c8ff4a9176e3c8a2822885d44e067 100644 (file)
@@ -1139,6 +1139,35 @@ static void ctdb_create_pidfile(pid_t pid)
        }
 }
 
+static void ctdb_initialise_vnn_map(struct ctdb_context *ctdb)
+{
+       int i, j, count;
+
+       /* initialize the vnn mapping table, skipping any deleted nodes */
+       ctdb->vnn_map = talloc(ctdb, struct ctdb_vnn_map);
+       CTDB_NO_MEMORY_FATAL(ctdb, ctdb->vnn_map);
+
+       count = 0;
+       for (i = 0; i < ctdb->num_nodes; i++) {
+               if ((ctdb->nodes[i]->flags & NODE_FLAGS_DELETED) == 0) {
+                       count++;
+               }
+       }
+
+       ctdb->vnn_map->generation = INVALID_GENERATION;
+       ctdb->vnn_map->size = count;
+       ctdb->vnn_map->map = talloc_array(ctdb->vnn_map, uint32_t, ctdb->vnn_map->size);
+       CTDB_NO_MEMORY_FATAL(ctdb, ctdb->vnn_map->map);
+
+       for(i=0, j=0; i < ctdb->vnn_map->size; i++) {
+               if (ctdb->nodes[i]->flags & NODE_FLAGS_DELETED) {
+                       continue;
+               }
+               ctdb->vnn_map->map[j] = i;
+               j++;
+       }
+}
+
 /*
   start the protocol going as a daemon
 */
@@ -1265,6 +1294,7 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
                }
        }
 
+       ctdb_initialise_vnn_map(ctdb);
 
        /* attach to existing databases */
        if (ctdb_attach_databases(ctdb) != 0) {
index 2598c4cb5b3aa41220501606d5eab89591b0b32a..8b4960a1087e29c38bb0ce78d01e3de40628f9e9 100644 (file)
@@ -164,7 +164,7 @@ static int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist)
 {
        char **lines;
        int nlines;
-       int i, j, num_present;
+       int i;
 
        talloc_free(ctdb->nodes);
        ctdb->nodes     = NULL;
@@ -179,7 +179,6 @@ static int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist)
                nlines--;
        }
 
-       num_present = 0;
        for (i=0; i < nlines; i++) {
                char *node;
 
@@ -202,28 +201,8 @@ static int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist)
                        talloc_free(lines);
                        return -1;
                }
-               num_present++;
        }
 
-       /* initialize the vnn mapping table now that we have the nodes list,
-          skipping any deleted nodes
-       */
-       ctdb->vnn_map = talloc(ctdb, struct ctdb_vnn_map);
-       CTDB_NO_MEMORY(ctdb, ctdb->vnn_map);
-
-       ctdb->vnn_map->generation = INVALID_GENERATION;
-       ctdb->vnn_map->size = num_present;
-       ctdb->vnn_map->map = talloc_array(ctdb->vnn_map, uint32_t, ctdb->vnn_map->size);
-       CTDB_NO_MEMORY(ctdb, ctdb->vnn_map->map);
-
-       for(i=0, j=0; i < ctdb->vnn_map->size; i++) {
-               if (ctdb->nodes[i]->flags & NODE_FLAGS_DELETED) {
-                       continue;
-               }
-               ctdb->vnn_map->map[j] = i;
-               j++;
-       }
-       
        talloc_free(lines);
        return 0;
 }