ctdb-daemon: Add a function to check if db access is allowed
authorAmitay Isaacs <amitay@gmail.com>
Thu, 7 Sep 2017 07:18:18 +0000 (17:18 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 12 Sep 2017 10:23:18 +0000 (12:23 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13021

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

index 5b95b60fb0ee28447a92d013749e1bc04edf7d16..f5966cd94cdefd18b8752270ec7fd8b681edf680 100644 (file)
@@ -627,6 +627,7 @@ int32_t ctdb_control_wipe_database(struct ctdb_context *ctdb, TDB_DATA indata);
 
 bool ctdb_db_frozen(struct ctdb_db_context *ctdb_db);
 bool ctdb_db_all_frozen(struct ctdb_context *ctdb);
+bool ctdb_db_allow_access(struct ctdb_db_context *ctdb_db);
 
 /* from server/ctdb_keepalive.c */
 
index d92f707b25dc4b45df77df30af8b5cc950d10c5c..c41fc7d53ee7cad35dbb7a8758424013fac06fc6 100644 (file)
@@ -874,3 +874,21 @@ bool ctdb_db_all_frozen(struct ctdb_context *ctdb)
        }
        return true;
 }
+
+bool ctdb_db_allow_access(struct ctdb_db_context *ctdb_db)
+{
+       if (ctdb_db->freeze_mode == CTDB_FREEZE_NONE) {
+               /* If database is not frozen, then allow access. */
+               return true;
+       } else if (ctdb_db->freeze_transaction_started) {
+               /* If database is frozen, allow access only if the
+                * transaction is started.  This is required during
+                * recovery.
+                *
+                * If a node is inactive, then transaction is not started.
+                */
+               return true;
+       }
+
+       return false;
+}