From 78ca382f7292ed535c8cb19fe94aa3b8e08aa873 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 22 Aug 2017 12:53:43 +1000 Subject: [PATCH 1/6] 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 Reviewed-by: Martin Schwenke (cherry picked from commit 205969dd94f532a157e17a88191863e4af0c012c) --- ctdb/tests/complex/34_nfs_tickle_restart.sh | 2 +- ctdb/tests/scripts/integration.bash | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ctdb/tests/complex/34_nfs_tickle_restart.sh b/ctdb/tests/complex/34_nfs_tickle_restart.sh index 365a0176fc9..6350db68c2e 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 b2a3451049c..4f1227f4393 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" -- 2.13.5 From dce920174e2c9551e5e759e8865e8eb69055d8a1 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 18 Aug 2017 14:45:30 +1000 Subject: [PATCH 2/6] 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 Reviewed-by: Martin Schwenke (cherry picked from commit 9691b72a8785c2bc2561bd6c897fea3c0cc2cbeb) --- ctdb/tests/simple/scripts/local_daemons.bash | 35 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/ctdb/tests/simple/scripts/local_daemons.bash b/ctdb/tests/simple/scripts/local_daemons.bash index d7f33b6804e..b702a3e659f 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 -- 2.13.5 From c3f25c7bf6eb2395dbd1d1fe6d1a03de56e8e5a8 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 18 Aug 2017 14:27:10 +1000 Subject: [PATCH 3/6] 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 Reviewed-by: Martin Schwenke (cherry picked from commit 9a92d712705356d18f70dfb779c18256794966b9) --- ctdb/tests/simple/21_ctdb_attach.sh | 127 ++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100755 ctdb/tests/simple/21_ctdb_attach.sh diff --git a/ctdb/tests/simple/21_ctdb_attach.sh b/ctdb/tests/simple/21_ctdb_attach.sh new file mode 100755 index 00000000000..11b600800a4 --- /dev/null +++ b/ctdb/tests/simple/21_ctdb_attach.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +test_info() +{ + cat < Date: Fri, 18 Aug 2017 13:50:39 +1000 Subject: [PATCH 4/6] 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 Reviewed-by: Martin Schwenke (cherry picked from commit 4bd0a20a75db3b3c409c25a4bc59aed30464f047) --- ctdb/client/ctdb_client.c | 26 +++++++++++--------------- ctdb/include/ctdb_client.h | 2 +- ctdb/server/ctdb_recoverd.c | 7 ++++--- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index 5ec3d0043f3..575ed56ce69 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -1947,31 +1947,27 @@ 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) { 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) { diff --git a/ctdb/include/ctdb_client.h b/ctdb/include/ctdb_client.h index d4fd77142ec..8f270ddaa4e 100644 --- a/ctdb/include/ctdb_client.h +++ b/ctdb/include/ctdb_client.h @@ -254,7 +254,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); int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t *level); diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index b57be0634b8..05aee463bef 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); 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); if (ret != 0) { DEBUG(DEBUG_ERR, (__location__ " Unable to create local db:%s\n", name)); return -1; -- 2.13.5 From f04a19bf1d1ce45dcce61f63d5a01a34a5d5b43f Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 23 Aug 2017 12:09:22 +1000 Subject: [PATCH 5/6] 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 Reviewed-by: Martin Schwenke (cherry picked from commit 9987fe7209c3bd44ea0015d98d0f92b65ec70700) --- ctdb/client/ctdb_client.c | 11 ++++++++++- ctdb/include/ctdb_client.h | 2 +- ctdb/server/ctdb_recoverd.c | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index 575ed56ce69..8b77930adc6 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -1949,7 +1949,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, uint8_t db_flags) + const char *name, uint8_t db_flags, uint32_t *db_id) { int ret; int32_t res; @@ -1974,6 +1974,15 @@ int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, 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; } diff --git a/ctdb/include/ctdb_client.h b/ctdb/include/ctdb_client.h index 8f270ddaa4e..2a19991bc5c 100644 --- a/ctdb/include/ctdb_client.h +++ b/ctdb/include/ctdb_client.h @@ -254,7 +254,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, uint8_t db_flags); + 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); diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index 05aee463bef..386b72065e4 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); + dbmap->dbs[db].flags, NULL); if (ret != 0) { DEBUG(DEBUG_ERR, (__location__ " Unable to create remote db:%s\n", name)); return -1; @@ -536,7 +536,7 @@ static int create_missing_local_databases(struct ctdb_context *ctdb, struct ctdb } ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), pnn, mem_ctx, name, - remote_dbmap->dbs[db].flags); + remote_dbmap->dbs[db].flags, NULL); if (ret != 0) { DEBUG(DEBUG_ERR, (__location__ " Unable to create local db:%s\n", name)); return -1; -- 2.13.5 From c319b98e2704e19b8c2d27acad3dd2d02ebee1cd Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 18 Aug 2017 14:00:47 +1000 Subject: [PATCH 6/6] ctdb-client: Fix ctdb_attach() to use database flags BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke Autobuild-User(master): Martin Schwenke Autobuild-Date(master): Fri Aug 25 13:32:58 CEST 2017 on sn-devel-144 (cherry picked from commit 1f7f112317e0c33bc088a204b3ee69ba48c3f449) --- ctdb/client/ctdb_client.c | 23 ++++++----------------- ctdb/include/ctdb_client.h | 2 +- ctdb/server/ctdb_recoverd.c | 6 +++--- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index 8b77930adc6..b36d46ed79a 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -2123,12 +2123,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); @@ -2143,22 +2141,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)); @@ -2181,9 +2172,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); @@ -3930,7 +3919,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 2a19991bc5c..9ad9bdb24cd 100644 --- a/ctdb/include/ctdb_client.h +++ b/ctdb/include/ctdb_client.h @@ -276,7 +276,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 386b72065e4..9488bc2c842 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -654,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; @@ -673,7 +673,7 @@ static void vacuum_fetch_handler(uint64_t srvid, TDB_DATA data, for (i=0;inum;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; } } @@ -689,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; -- 2.13.5