[SCM] Samba Shared Repository - branch master updated

Martin Schwenke martins at samba.org
Fri Aug 25 11:34:03 UTC 2017


The branch, master has been updated
       via  1f7f112 ctdb-client: Fix ctdb_attach() to use database flags
       via  9987fe7 ctdb-client: Optionally return database id from ctdb_ctrl_createdb()
       via  4bd0a20 ctdb-client: Fix ctdb_ctrl_createdb() to use database flags
       via  9a92d71 ctdb-tests: Add a test to check databases are attached with correct flags
       via  9691b72 ctdb-tests: Add functions to start/stop/restart a single local daemon
       via  205969d ctdb-tests: Add functions to start/stop/restart ctdb on single node
      from  27fae4c schannel.idl: Fix a typo

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 1f7f112317e0c33bc088a204b3ee69ba48c3f449
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Fri Aug 18 14:00:47 2017 +1000

    ctdb-client: Fix ctdb_attach() to use database flags
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>
    
    Autobuild-User(master): Martin Schwenke <martins at samba.org>
    Autobuild-Date(master): Fri Aug 25 13:32:58 CEST 2017 on sn-devel-144

commit 9987fe7209c3bd44ea0015d98d0f92b65ec70700
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Wed Aug 23 12:09:22 2017 +1000

    ctdb-client: Optionally return database id from ctdb_ctrl_createdb()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 4bd0a20a75db3b3c409c25a4bc59aed30464f047
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Fri Aug 18 13:50:39 2017 +1000

    ctdb-client: Fix ctdb_ctrl_createdb() to use database flags
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 9a92d712705356d18f70dfb779c18256794966b9
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Fri Aug 18 14:27:10 2017 +1000

    ctdb-tests: Add a test to check databases are attached with correct flags
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 9691b72a8785c2bc2561bd6c897fea3c0cc2cbeb
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Fri Aug 18 14:45:30 2017 +1000

    ctdb-tests: Add functions to start/stop/restart a single local daemon
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 205969dd94f532a157e17a88191863e4af0c012c
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Aug 22 12:53:43 2017 +1000

    ctdb-tests: Add functions to start/stop/restart ctdb on single node
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/client/ctdb_client.c                    |  58 ++++++------
 ctdb/include/ctdb_client.h                   |   4 +-
 ctdb/server/ctdb_recoverd.c                  |  13 +--
 ctdb/tests/complex/34_nfs_tickle_restart.sh  |   2 +-
 ctdb/tests/scripts/integration.bash          |  25 +++++-
 ctdb/tests/simple/21_ctdb_attach.sh          | 127 +++++++++++++++++++++++++++
 ctdb/tests/simple/scripts/local_daemons.bash |  35 ++++++--
 7 files changed, 211 insertions(+), 53 deletions(-)
 create mode 100755 ctdb/tests/simple/21_ctdb_attach.sh


Changeset truncated at 500 lines:

diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c
index 47f99bc..25b9654 100644
--- a/ctdb/client/ctdb_client.c
+++ b/ctdb/client/ctdb_client.c
@@ -1910,37 +1910,42 @@ int ctdb_ctrl_getdbseqnum(struct ctdb_context *ctdb, struct timeval timeout,
 /*
   create a database
  */
-int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, 
-		       TALLOC_CTX *mem_ctx, const char *name, bool persistent)
+int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
+		       uint32_t destnode, TALLOC_CTX *mem_ctx,
+		       const char *name, uint8_t db_flags, uint32_t *db_id)
 {
 	int ret;
 	int32_t res;
 	TDB_DATA data;
-	uint64_t tdb_flags = 0;
+	uint32_t opcode;
 
 	data.dptr = discard_const(name);
 	data.dsize = strlen(name)+1;
 
-	/* Make sure that volatile databases use jenkins hash */
-	if (!persistent) {
-		tdb_flags = TDB_INCOMPATIBLE_HASH;
-	}
-
-#ifdef TDB_MUTEX_LOCKING
-	if (!persistent && ctdb->tunable.mutex_enabled == 1) {
-		tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
+	if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
+		opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
+	} else if (db_flags & CTDB_DB_FLAGS_REPLICATED) {
+		opcode = CTDB_CONTROL_DB_ATTACH_REPLICATED;
+	} else {
+		opcode = CTDB_CONTROL_DB_ATTACH;
 	}
-#endif
 
-	ret = ctdb_control(ctdb, destnode, tdb_flags,
-			   persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH, 
-			   0, data, 
+	ret = ctdb_control(ctdb, destnode, 0, opcode, 0, data,
 			   mem_ctx, &data, &res, &timeout, NULL);
 
 	if (ret != 0 || res != 0) {
 		return -1;
 	}
 
+	if (data.dsize != sizeof(uint32_t)) {
+		TALLOC_FREE(data.dptr);
+		return -1;
+	}
+	if (db_id != NULL) {
+		*db_id = *(uint32_t *)data.dptr;
+	}
+	talloc_free(data.dptr);
+
 	return 0;
 }
 
@@ -2081,12 +2086,10 @@ int ctdb_ctrl_db_open_flags(struct ctdb_context *ctdb, uint32_t db_id,
 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
 				    struct timeval timeout,
 				    const char *name,
-				    bool persistent)
+				    uint8_t db_flags)
 {
 	struct ctdb_db_context *ctdb_db;
-	TDB_DATA data;
 	int ret;
-	int32_t res;
 	int tdb_flags;
 
 	ctdb_db = ctdb_db_handle(ctdb, name);
@@ -2101,22 +2104,15 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
 	ctdb_db->db_name = talloc_strdup(ctdb_db, name);
 	CTDB_NO_MEMORY_NULL(ctdb, ctdb_db->db_name);
 
-	data.dptr = discard_const(name);
-	data.dsize = strlen(name)+1;
-
 	/* tell ctdb daemon to attach */
-	ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0,
-			   persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
-			   0, data, ctdb_db, &data, &res, NULL, NULL);
-	if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
+	ret = ctdb_ctrl_createdb(ctdb, timeout, CTDB_CURRENT_NODE,
+				 ctdb_db, name, db_flags, &ctdb_db->db_id);
+	if (ret != 0) {
 		DEBUG(DEBUG_ERR,("Failed to attach to database '%s'\n", name));
 		talloc_free(ctdb_db);
 		return NULL;
 	}
 
-	ctdb_db->db_id = *(uint32_t *)data.dptr;
-	talloc_free(data.dptr);
-
 	ret = ctdb_ctrl_getdbpath(ctdb, timeout, CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
 	if (ret != 0) {
 		DEBUG(DEBUG_ERR,("Failed to get dbpath for database '%s'\n", name));
@@ -2139,9 +2135,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
 		return NULL;
 	}
 
-	if (persistent) {
-		ctdb_db->db_flags = CTDB_DB_FLAGS_PERSISTENT;
-	}
+	ctdb_db->db_flags = db_flags;
 
 	DLIST_ADD(ctdb->db_list, ctdb_db);
 
@@ -3888,7 +3882,7 @@ struct ctdb_transaction_handle *ctdb_transaction_start(struct ctdb_db_context *c
 	}
 
 	h->g_lock_db = ctdb_attach(h->ctdb_db->ctdb, timeval_current_ofs(3,0),
-				   "g_lock.tdb", false);
+				   "g_lock.tdb", 0);
 	if (!h->g_lock_db) {
 		DEBUG(DEBUG_ERR, (__location__ " unable to attach to g_lock.tdb\n"));
 		talloc_free(h);
diff --git a/ctdb/include/ctdb_client.h b/ctdb/include/ctdb_client.h
index 329e354..1397895 100644
--- a/ctdb/include/ctdb_client.h
+++ b/ctdb/include/ctdb_client.h
@@ -251,7 +251,7 @@ int ctdb_ctrl_getdbseqnum(struct ctdb_context *ctdb, struct timeval timeout,
 
 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
 		       uint32_t destnode, TALLOC_CTX *mem_ctx,
-		       const char *name, bool persistent);
+		       const char *name, uint8_t db_flags, uint32_t *db_id);
 
 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode,
 			     int32_t *level);
@@ -273,7 +273,7 @@ int ctdb_ctrl_db_open_flags(struct ctdb_context *ctdb, uint32_t db_id,
 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
 				    struct timeval timeout,
 				    const char *name,
-				    bool persistent);
+				    uint8_t db_flags);
 
 int ctdb_detach(struct ctdb_context *ctdb, uint32_t db_id);
 
diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c
index b57be06..9488bc2 100644
--- a/ctdb/server/ctdb_recoverd.c
+++ b/ctdb/server/ctdb_recoverd.c
@@ -472,7 +472,7 @@ static int create_missing_remote_databases(struct ctdb_context *ctdb, struct ctd
 			ret = ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(),
 						 nodemap->nodes[j].pnn,
 						 mem_ctx, name,
-						 dbmap->dbs[db].flags & CTDB_DB_FLAGS_PERSISTENT);
+						 dbmap->dbs[db].flags, NULL);
 			if (ret != 0) {
 				DEBUG(DEBUG_ERR, (__location__ " Unable to create remote db:%s\n", name));
 				return -1;
@@ -534,8 +534,9 @@ static int create_missing_local_databases(struct ctdb_context *ctdb, struct ctdb
 					  nodemap->nodes[j].pnn));
 				return -1;
 			}
-			ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), pnn, mem_ctx, name, 
-					   remote_dbmap->dbs[db].flags & CTDB_DB_FLAGS_PERSISTENT);
+			ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), pnn,
+					   mem_ctx, name,
+					   remote_dbmap->dbs[db].flags, NULL);
 			if (ret != 0) {
 				DEBUG(DEBUG_ERR, (__location__ " Unable to create local db:%s\n", name));
 				return -1;
@@ -653,7 +654,7 @@ static void vacuum_fetch_handler(uint64_t srvid, TDB_DATA data,
 	TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
 	const char *name;
 	struct ctdb_dbid_map_old *dbmap=NULL;
-	bool persistent = false;
+	uint8_t db_flags = 0;
 	struct ctdb_db_context *ctdb_db;
 	struct ctdb_rec_data_old *r;
 
@@ -672,7 +673,7 @@ static void vacuum_fetch_handler(uint64_t srvid, TDB_DATA data,
 
 	for (i=0;i<dbmap->num;i++) {
 		if (dbmap->dbs[i].db_id == recs->db_id) {
-			persistent = dbmap->dbs[i].flags & CTDB_DB_FLAGS_PERSISTENT;
+			db_flags = dbmap->dbs[i].flags;
 			break;
 		}
 	}
@@ -688,7 +689,7 @@ static void vacuum_fetch_handler(uint64_t srvid, TDB_DATA data,
 	}
 
 	/* attach to it */
-	ctdb_db = ctdb_attach(ctdb, CONTROL_TIMEOUT(), name, persistent);
+	ctdb_db = ctdb_attach(ctdb, CONTROL_TIMEOUT(), name, db_flags);
 	if (ctdb_db == NULL) {
 		DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
 		goto done;
diff --git a/ctdb/tests/complex/34_nfs_tickle_restart.sh b/ctdb/tests/complex/34_nfs_tickle_restart.sh
index 365a017..6350db6 100755
--- a/ctdb/tests/complex/34_nfs_tickle_restart.sh
+++ b/ctdb/tests/complex/34_nfs_tickle_restart.sh
@@ -71,7 +71,7 @@ rn=$(awk -F'|' -v test_node=$test_node \
     '$2 != test_node { print $2 ; exit }' <<<"$listnodes_output")
 
 echo "Restarting CTDB on node ${rn}"
-try_command_on_node $rn $CTDB_TEST_WRAPPER restart_ctdb_1
+restart_ctdb_1 $rn
 
 # In some theoretical world this is racy.  In practice, the node will
 # take quite a while to become healthy, so this will beat any
diff --git a/ctdb/tests/scripts/integration.bash b/ctdb/tests/scripts/integration.bash
index b2a3451..4f1227f 100644
--- a/ctdb/tests/scripts/integration.bash
+++ b/ctdb/tests/scripts/integration.bash
@@ -524,19 +524,21 @@ wait_until_node_has_some_ips ()
 
 #######################################
 
-restart_ctdb_1 ()
+_service_ctdb ()
 {
+    cmd="$1"
+
     if [ -e /etc/redhat-release ] ; then
-	service ctdb restart
+	service ctdb "$cmd"
     else
-	/etc/init.d/ctdb restart
+	/etc/init.d/ctdb "$cmd"
     fi
 }
 
 # Restart CTDB on all nodes.  Override for local daemons.
 _restart_ctdb_all ()
 {
-    onnode -p all $CTDB_TEST_WRAPPER restart_ctdb_1
+    onnode -p all $CTDB_TEST_WRAPPER _service_ctdb restart
 }
 
 # Nothing needed for a cluster.  Override for local daemons.
@@ -545,6 +547,21 @@ setup_ctdb ()
     :
 }
 
+start_ctdb_1 ()
+{
+    onnode "$1" $CTDB_TEST_WRAPPER _service_ctdb start
+}
+
+stop_ctdb_1 ()
+{
+    onnode "$1" $CTDB_TEST_WRAPPER _service_ctdb stop
+}
+
+restart_ctdb_1 ()
+{
+    onnode "$1" $CTDB_TEST_WRAPPER _service_ctdb restart
+}
+
 restart_ctdb ()
 {
     echo -n "Restarting CTDB"
diff --git a/ctdb/tests/simple/21_ctdb_attach.sh b/ctdb/tests/simple/21_ctdb_attach.sh
new file mode 100755
index 0000000..11b6008
--- /dev/null
+++ b/ctdb/tests/simple/21_ctdb_attach.sh
@@ -0,0 +1,127 @@
+#!/bin/bash
+
+test_info()
+{
+    cat <<EOF
+Verify the operation of 'ctdb attach' command.
+
+Prerequisites:
+
+* An active CTDB cluster with at least 2 active nodes.
+
+Steps:
+
+1. Verify that the status on all of the ctdb nodes is 'OK'.
+2. Shut down one of the nodes
+3. Attach test databases
+4. Start shutdown node
+5. Verify that the databases are attached.
+6. Restart one of the nodes
+7. Verify that the databses are attached.
+
+
+Expected results:
+
+* Command 'ctdb attach' command successfully attaches databases.
+EOF
+}
+
+. "${TEST_SCRIPTS_DIR}/integration.bash"
+
+ctdb_test_init "$@"
+
+set -e
+
+cluster_is_healthy
+
+# Reset configuration
+ctdb_restart_when_done
+
+######################################################################
+
+try_command_on_node 0 "$CTDB listnodes -X"
+listnodes_output="$out"
+numnodes=$(wc -l <<<"$listnodes_output")
+lastnode=$(( numnodes - 1 ))
+
+######################################################################
+
+# Confirm that the database is attached
+check_db ()
+{
+    pnn="$1"
+    db="$2"
+    flag="$3"
+    try_command_on_node $pnn "$CTDB getdbmap | grep $db"
+    if [ -z "$out" ] ; then
+	echo "BAD: database $db is not attached on node $node"
+	echo "$out"
+	exit 1
+    else
+	local flags=$(awk '{print $4}' <<<"$out") || true
+	if [ "$flags" = "$flag" ]; then
+	    echo "GOOD: database $db is attached on node $node with flag $flag"
+	else
+	    echo "BAD: database $db is attached on node $node with wrong flag"
+	    echo "$out"
+	    exit 1
+	fi
+    fi
+}
+
+######################################################################
+
+testdb1="test_volatile.tdb"
+testdb2="test_persistent.tdb"
+testdb3="test_replicated.tdb"
+
+test_node="0"
+
+echo "Shutting down node $test_node"
+stop_ctdb_1 "$test_node"
+sleep 1
+wait_until_node_has_status 1 recovered
+try_command_on_node -v 1 $CTDB status
+
+echo "Create test databases"
+try_command_on_node 1 $CTDB attach "$testdb1"
+try_command_on_node 1 $CTDB attach "$testdb2" persistent
+try_command_on_node 1 $CTDB attach "$testdb3" replicated
+
+echo
+echo "Checking if database is attached with correct flags"
+for node in $(seq 0 $lastnode) ; do
+    if [ $node -ne $test_node ] ; then
+	check_db $node $testdb1 ""
+	check_db $node $testdb2 PERSISTENT
+	check_db $node $testdb3 REPLICATED
+    fi
+done
+
+######################################################################
+
+echo
+echo "Start node $test_node"
+start_ctdb_1 "$test_node"
+sleep 1
+wait_until_ready
+
+echo
+echo "Checking if database is attached with correct flags"
+check_db $test_node $testdb1 ""
+check_db $test_node $testdb2 PERSISTENT
+check_db $test_node $testdb3 REPLICATED
+
+######################################################################
+
+echo
+echo "Restarting node $test_node"
+restart_ctdb_1 "$test_node"
+sleep 1
+wait_until_ready
+
+echo
+echo "Checking if database is attached with correct flags"
+check_db $test_node $testdb1 ""
+check_db $test_node $testdb2 PERSISTENT
+check_db $test_node $testdb3 REPLICATED
diff --git a/ctdb/tests/simple/scripts/local_daemons.bash b/ctdb/tests/simple/scripts/local_daemons.bash
index d7f33b6..b702a3e 100644
--- a/ctdb/tests/simple/scripts/local_daemons.bash
+++ b/ctdb/tests/simple/scripts/local_daemons.bash
@@ -172,12 +172,9 @@ EOF
     done
 }
 
-daemons_start ()
+start_ctdb_1 ()
 {
-    echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
-
-    local pnn
-    for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
+	local pnn="$1"
 	local pidfile=$(node_pidfile "$pnn")
 	local conf=$(node_conf "$pnn")
 
@@ -200,25 +197,47 @@ daemons_start ()
 	if [ -n "$tmp_conf" ] ; then
 		rm -f "$tmp_conf"
 	fi
-    done
+
 }
 
-daemons_stop ()
+daemons_start ()
 {
-    echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
+    echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
 
     local pnn
     for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
+	start_ctdb_1 "$pnn"
+    done
+}
+
+stop_ctdb_1 ()
+{
+	local pnn="$1"
 	local pidfile=$(node_pidfile "$pnn")
 	local conf=$(node_conf "$pnn")
 
 	CTDBD_CONF="$conf" \
 	     ctdbd_wrapper "$pidfile" stop
+}
+
+daemons_stop ()
+{
+    echo "Stopping $TEST_LOCAL_DAEMONS ctdb daemons..."
+
+    local pnn
+    for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
+	stop_ctdb_1 "$pnn"
     done
 
     rm -rf "${TEST_VAR_DIR}/test.db"
 }
 
+restart_ctdb_1 ()
+{
+	stop_ctdb_1 "$1"
+	start_ctdb_1 "$1"
+}
+
 maybe_stop_ctdb ()
 {
     if $TEST_CLEANUP ; then


-- 
Samba Shared Repository



More information about the samba-cvs mailing list