ctdb-daemon: Avoid the use of ctdb->freeze_mode variable
authorAmitay Isaacs <amitay@gmail.com>
Thu, 21 Aug 2014 02:32:02 +0000 (12:32 +1000)
committerAmitay Isaacs <amitay@samba.org>
Wed, 7 Oct 2015 12:53:26 +0000 (14:53 +0200)
Use ctdb->freeze_mode only in ctdb_freeze.c and use the functions to
check if databases are frozen everywhere else.

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

index d8f7ab1b6ff09751459255da7057da8a04f3fbf2..91064b4c516bb49f787a1886f5aa16c16e47a088 100644 (file)
@@ -31,17 +31,9 @@ ctdb_ban_node_event(struct event_context *ev, struct timed_event *te,
                               struct timeval t, void *private_data)
 {
        struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context);
-       bool freeze_failed = false;
-       int i;
 
        /* Make sure we were able to freeze databases during banning */
-       for (i=1; i<=NUM_DB_PRIORITIES; i++) {
-               if (ctdb->freeze_mode[i] != CTDB_FREEZE_FROZEN) {
-                       freeze_failed = true;
-                       break;
-               }
-       }
-       if (freeze_failed) {
+       if (!ctdb_db_all_frozen(ctdb)) {
                DEBUG(DEBUG_ERR, ("Banning timedout, but still unable to freeze databases\n"));
                ctdb_ban_self(ctdb);
                return;
index 2335f06ceeb5243c1563a84e7c56fbe15a6874dd..7b26ff969831a224224800ef734a0d49951f15fa 100644 (file)
@@ -110,16 +110,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        }
 
        case CTDB_CONTROL_STATISTICS: {
-               int i;
                CHECK_CONTROL_DATA_SIZE(0);
                ctdb->statistics.memory_used = talloc_total_size(NULL);
                ctdb->statistics.num_clients = ctdb->num_clients;
-               ctdb->statistics.frozen = 0;
-               for (i=1; i<= NUM_DB_PRIORITIES; i++) {
-                       if (ctdb->freeze_mode[i] == CTDB_FREEZE_FROZEN) {
-                               ctdb->statistics.frozen = 1;
-                       }
-               }
+               ctdb->statistics.frozen = (ctdb_db_all_frozen(ctdb) ? 1 : 0);
                ctdb->statistics.recovering = (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE);
                ctdb->statistics.statistics_current_time = timeval_current();
 
index 9f9710fdbda943bdd59b00d0070b55fd0591c478..6b6a712e91f7286cba1920c207662d136bdde025 100644 (file)
@@ -351,13 +351,12 @@ int32_t ctdb_control_thaw(struct ctdb_context *ctdb, uint32_t priority,
  */
 int32_t ctdb_control_transaction_start(struct ctdb_context *ctdb, uint32_t id)
 {
-       int i, ret;
+       int ret;
 
-       for (i=1;i<=NUM_DB_PRIORITIES; i++) {
-               if (ctdb->freeze_mode[i] != CTDB_FREEZE_FROZEN) {
-                       DEBUG(DEBUG_ERR,(__location__ " Failed transaction_start while not frozen\n"));
-                       return -1;
-               }
+       if (!ctdb_db_all_frozen(ctdb)) {
+               DEBUG(DEBUG_ERR, (__location__
+                     " failing transaction start while not frozen\n"));
+               return -1;
        }
 
        ret = ctdb_db_iterator(ctdb, db_transaction_start_handler,
@@ -394,11 +393,10 @@ int32_t ctdb_control_transaction_commit(struct ctdb_context *ctdb, uint32_t id)
        int healthy_nodes = 0;
        int ret;
 
-       for (i=1;i<=NUM_DB_PRIORITIES; i++) {
-               if (ctdb->freeze_mode[i] != CTDB_FREEZE_FROZEN) {
-                       DEBUG(DEBUG_ERR,(__location__ " Failed transaction_start while not frozen\n"));
-                       return -1;
-               }
+       if (!ctdb_db_all_frozen(ctdb)) {
+               DEBUG(DEBUG_ERR, (__location__
+                     " failing transaction commit while not frozen\n"));
+               return -1;
        }
 
        if (!ctdb->freeze_transaction_started) {
index 2ef5b21464695d190d8d06e02eb6079aa26a87aa..9494f9f14f348f55f84c7e7efe3b0cfdcf217a38 100644 (file)
@@ -196,11 +196,10 @@ int ctdb_lockall_mark_prio(struct ctdb_context *ctdb, uint32_t priority)
        /*
         * This function is only used by the main dameon during recovery.
         * At this stage, the databases have already been locked, by a
-        * dedicated child process. The freeze_mode variable is used to track
-        * whether the actual locks are held by the child process or not.
+        * dedicated child process.
         */
 
-       if (ctdb->freeze_mode[priority] != CTDB_FREEZE_FROZEN) {
+       if (!ctdb_db_prio_frozen(ctdb, priority)) {
                DEBUG(DEBUG_ERR, ("Attempt to mark all databases locked when not frozen\n"));
                return -1;
        }
@@ -256,11 +255,10 @@ int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority)
        /*
         * This function is only used by the main daemon during recovery.
         * At this stage, the databases have already been locked, by a
-        * dedicated child process. The freeze_mode variable is used to track
-        * whether the actual locks are held by the child process or not.
+        * dedicated child process.
         */
 
-       if (ctdb->freeze_mode[priority] != CTDB_FREEZE_FROZEN) {
+       if (!ctdb_db_prio_frozen(ctdb, priority)) {
                DEBUG(DEBUG_ERR, ("Attempt to unmark all databases locked when not frozen\n"));
                return -1;
        }
index 23f793be64fffaa05a0d6c4e97ee1eeac8757c47..3a638fac361a6e435ffa3705466885b7a3cc42f9 100644 (file)
@@ -54,13 +54,10 @@ int
 ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
 {
        struct ctdb_vnn_map_wire *map = (struct ctdb_vnn_map_wire *)indata.dptr;
-       int i;
 
-       for(i=1; i<=NUM_DB_PRIORITIES; i++) {
-               if (ctdb->freeze_mode[i] != CTDB_FREEZE_FROZEN) {
-                       DEBUG(DEBUG_ERR,("Attempt to set vnnmap when not frozen\n"));
-                       return -1;
-               }
+       if (!ctdb_db_all_frozen(ctdb)) {
+               DEBUG(DEBUG_ERR,("Attempt to set vnnmap when not frozen\n"));
+               return -1;
        }
 
        talloc_free(ctdb->vnn_map);
@@ -252,7 +249,7 @@ int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DAT
                return -1;
        }
 
-       if (ctdb->freeze_mode[ctdb_db->priority] != CTDB_FREEZE_FROZEN) {
+       if (!ctdb_db_prio_frozen(ctdb, ctdb_db->priority)) {
                DEBUG(DEBUG_DEBUG,("rejecting ctdb_control_pull_db when not frozen\n"));
                return -1;
        }
@@ -324,7 +321,7 @@ int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata)
                return -1;
        }
 
-       if (ctdb->freeze_mode[ctdb_db->priority] != CTDB_FREEZE_FROZEN) {
+       if (!ctdb_db_prio_frozen(ctdb, ctdb_db->priority)) {
                DEBUG(DEBUG_DEBUG,("rejecting ctdb_control_push_db when not frozen\n"));
                return -1;
        }