]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
create a define to represent the 'invalid' generation id we used in two
authorRonnie Sahlberg <sahlberg@ronnie>
Wed, 22 Aug 2007 02:38:31 +0000 (12:38 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Wed, 22 Aug 2007 02:38:31 +0000 (12:38 +1000)
places.

create a new helper function to generate new generation id values that
know about the invalid id and avoids generating it.

update the ctdb status tool to know about the invalid generation id and
print the string INVALID instead

(This used to be ctdb commit 4fbcd189543cb8a92227fdcd3d158472e558ccda)

ctdb/include/ctdb_private.h
ctdb/server/ctdb_monitor.c
ctdb/server/ctdb_recoverd.c
ctdb/server/ctdb_server.c
ctdb/tools/ctdb.c

index 64caeb30ec41c2b97cfd447a019782e0650e3c7d..1338ce79a57b2a18ce361c2c174604ca8facdb4c 100644 (file)
@@ -265,6 +265,8 @@ struct ctdb_statistics {
        double max_lockwait_latency;
 };
 
+
+#define INVALID_GENERATION 1
 /* table that contains the mapping between a hash value and lmaster
  */
 struct ctdb_vnn_map {
index 33c39ec457511c26ee76853eddd4df48950da218..444f6e1f3c68635e8f024b3e4b8e57faa3a90033 100644 (file)
@@ -226,7 +226,7 @@ int32_t ctdb_control_modflags(struct ctdb_context *ctdb, TDB_DATA indata)
                   We are now banned so we shouldnt service database calls
                   anymore.
                */
-               ctdb->vnn_map->generation = 1;
+               ctdb->vnn_map->generation = INVALID_GENERATION;
 
                ctdb_start_freeze(ctdb);
                ctdb_release_all_ips(ctdb);
index 812214088e7876ddcf97007ecab80c5755e58750..d710cd2a2890b8ed5d4de5d5a8f08ec379f41518 100644 (file)
@@ -611,6 +611,24 @@ static void ctdb_wait_timeout(struct ctdb_context *ctdb, uint32_t secs)
        }
 }
 
+/* Create a new random generation ip. 
+   The generation id can not be the INVALID_GENERATION id
+*/
+static uint32_t new_generation(void)
+{
+       uint32_t generation;
+
+       while (1) {
+               generation = random();
+
+               if (generation != INVALID_GENERATION) {
+                       break;
+               }
+       }
+
+       return generation;
+}
+               
 /*
   we are the recmaster, and recovery is needed - start a recovery run
  */
@@ -655,7 +673,7 @@ static int do_recovery(struct ctdb_recoverd *rec,
        DEBUG(0, (__location__ " Recovery initiated due to problem with node %u\n", culprit));
 
        /* pick a new generation number */
-       generation = random();
+       generation = new_generation();
 
        /* change the vnnmap on this node to use the new generation 
           number but not on any other nodes.
@@ -729,7 +747,7 @@ static int do_recovery(struct ctdb_recoverd *rec,
 
        /* build a new vnn map with all the currently active and
           unbanned nodes */
-       generation = random();
+       generation = new_generation();
        vnnmap = talloc(mem_ctx, struct ctdb_vnn_map);
        CTDB_NO_MEMORY(ctdb, vnnmap);
        vnnmap->generation = generation;
index 4fd5b192db9cf51daa5d29e39bd504c4acad3ec0..e9b6a9a2a51c0dee74cae707676386382d96680d 100644 (file)
@@ -151,17 +151,10 @@ int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist)
        }
 
        /* initialize the vnn mapping table now that we have num_nodes setup */
-/*
-XXX we currently initialize it to the maximum number of nodes to 
-XXX make it behave the same way as previously.  
-XXX Once we have recovery working we should initialize this always to 
-XXX generation==0 (==invalid) and let the recovery tool populate this 
-XXX table for the daemons. 
-*/
        ctdb->vnn_map = talloc(ctdb, struct ctdb_vnn_map);
        CTDB_NO_MEMORY(ctdb, ctdb->vnn_map);
 
-       ctdb->vnn_map->generation = 1;
+       ctdb->vnn_map->generation = INVALID_GENERATION;
        ctdb->vnn_map->size = ctdb->num_nodes;
        ctdb->vnn_map->map = talloc_array(ctdb->vnn_map, uint32_t, ctdb->vnn_map->size);
        CTDB_NO_MEMORY(ctdb, ctdb->vnn_map->map);
index 4529f610e5d2c16e9e85df0741aab8683d546425..849b638a95321bbd675ef973f05f9de9b7f9b23c 100644 (file)
@@ -282,7 +282,11 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
                DEBUG(0, ("Unable to get vnnmap from node %u\n", options.vnn));
                return ret;
        }
-       printf("Generation:%d\n",vnnmap->generation);
+       if (vnnmap->generation == INVALID_GENERATION) {
+               printf("Generation:INVALID\n");
+       } else {
+               printf("Generation:%d\n",vnnmap->generation);
+       }
        printf("Size:%d\n",vnnmap->size);
        for(i=0;i<vnnmap->size;i++){
                printf("hash:%d lmaster:%d\n", i, vnnmap->map[i]);