[SCM] Samba Shared Repository - branch master updated
Martin Schwenke
martins at samba.org
Fri Jul 22 08:32:03 UTC 2016
The branch, master has been updated
via 6bd0f1c ctdb-pcp-pmda: Reimplement using new client API
via 3619a76 ctdb-tests: Add torture test for fetch functions
via b8b6829 ctdb-tests: Remove unused tests code
via 6ad8f46 ctdb-tests: Rename ctdb_porting_tests to porting_tests
via 7ab5605 ctdb-tests: Rename ctdb_lock_tdb to lock_tdb
via e98f7c2 ctdb-tests: Convert rb_test into a unit test
via a76fa36 ctdb-tests: Replace ctdb_update_record_persistent with update_record_persistent
via f6d4f4d ctdb-tests: Replace ctdb_update_record with update_record using new client API
via 8cc069b ctdb-tests: Replace ctdb_transaction with transaction_loop using new client API
via c2e406c ctdb-tests: Replace ctdb_fetch_readonly_loop with fetch_readonly_loop using new client API
via 5a510ec ctdb-tests: Replace ctdb_fetch_readonly_once with fetch_readonly using new client API
via bc157dc ctdb-tests: Replace ctdb_fetch_one with fetch_loop using new client API
via 2c27f300 ctdb-tests: Replace ctdb_fetch with fetch_ring using new client API
via 388fa2c ctdb-tests: Replace ctdb_bench with message_ring using new client API
via 5fe216a ctdb-tests: Add torture test for g_lock functions
via f0395de ctdb-tests: Common code to process commandline options
via 47d95d2 ctdb-tests: Common code to wait for synchronization across cluster
from f757836 WHATSNEW: Add the update for the samba kcc
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 6bd0f1cf4651ad4d8a011398c489bd289cbefd48
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Oct 14 15:49:12 2015 +1100
ctdb-pcp-pmda: Reimplement using new client API
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 Jul 22 10:31:57 CEST 2016 on sn-devel-144
commit 3619a761441f3e633021a114b6492ba3785b639e
Author: Amitay Isaacs <amitay at gmail.com>
Date: Thu May 5 14:51:07 2016 +1000
ctdb-tests: Add torture test for fetch functions
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit b8b6829e2aac61b7b78d3c18ac13ae02a168e580
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Apr 20 18:30:30 2016 +1000
ctdb-tests: Remove unused tests code
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 6ad8f4630bfb4e80101dd6ae3a47eff3e22b103b
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Apr 20 16:14:39 2016 +1000
ctdb-tests: Rename ctdb_porting_tests to porting_tests
and create unit test for it.
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 7ab560527c5028d57034b86bca66d5a17a43440d
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Apr 20 16:03:41 2016 +1000
ctdb-tests: Rename ctdb_lock_tdb to lock_tdb
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit e98f7c264bc01b5e35c28b3b81728b4b01a04521
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Apr 20 15:56:13 2016 +1000
ctdb-tests: Convert rb_test into a unit test
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit a76fa36c2ade44d2f4a8b6343ba12a91941949e6
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Apr 20 14:29:56 2016 +1000
ctdb-tests: Replace ctdb_update_record_persistent with update_record_persistent
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit f6d4f4d9f97c715772ab9d7120e9e069c1c24a40
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Apr 20 14:27:40 2016 +1000
ctdb-tests: Replace ctdb_update_record with update_record using new client API
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 8cc069bd062a16dcbd23be47d1b9d7837e68b835
Author: Amitay Isaacs <amitay at gmail.com>
Date: Mon Apr 18 17:11:36 2016 +1000
ctdb-tests: Replace ctdb_transaction with transaction_loop using new client API
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit c2e406c7feefb31d457f543cc3118d7d9609c0fe
Author: Amitay Isaacs <amitay at gmail.com>
Date: Sat Nov 21 22:50:59 2015 +1100
ctdb-tests: Replace ctdb_fetch_readonly_loop with fetch_readonly_loop using new client API
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 5a510ecbea87b445bcdf3fd8e5baa719e90e0076
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Apr 20 14:49:47 2016 +1000
ctdb-tests: Replace ctdb_fetch_readonly_once with fetch_readonly using new client API
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit bc157dc3d46dde4cbf7c45de1dc65b37526511ae
Author: Amitay Isaacs <amitay at gmail.com>
Date: Fri Nov 20 16:24:34 2015 +1100
ctdb-tests: Replace ctdb_fetch_one with fetch_loop using new client API
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 2c27f3002f77bcc123b85e598527dcf42c5058de
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Nov 18 08:51:41 2015 +1100
ctdb-tests: Replace ctdb_fetch with fetch_ring using new client API
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 388fa2c9b87fddd1ae7345f1f3ee119e16105f14
Author: Amitay Isaacs <amitay at gmail.com>
Date: Tue Nov 10 16:00:07 2015 +1100
ctdb-tests: Replace ctdb_bench with message_ring using new client API
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 5fe216aa3eeead696c5c9e5d1deeea2cfff226e9
Author: Amitay Isaacs <amitay at gmail.com>
Date: Tue Apr 19 16:18:54 2016 +1000
ctdb-tests: Add torture test for g_lock functions
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit f0395deb17e1e5eb6f57a90a46ed824e379607a3
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Nov 18 12:46:08 2015 +1100
ctdb-tests: Common code to process commandline options
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
commit 47d95d2a0b151f7ef93158d979540f38392e6764
Author: Amitay Isaacs <amitay at gmail.com>
Date: Wed Nov 18 12:18:14 2015 +1100
ctdb-tests: Common code to wait for synchronization across cluster
Signed-off-by: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Martin Schwenke <martin at meltin.net>
-----------------------------------------------------------------------
Summary of changes:
ctdb/tests/cunit/porting_tests_001.sh | 20 ++
ctdb/tests/cunit/rb_test_001.sh | 31 ++
ctdb/tests/simple/51_ctdb_bench.sh | 2 +-
ctdb/tests/simple/52_ctdb_fetch.sh | 2 +-
ctdb/tests/simple/53_ctdb_transaction.sh | 9 +-
ctdb/tests/simple/54_ctdb_transaction_recovery.sh | 11 +-
ctdb/tests/simple/72_update_record_persistent.sh | 6 +-
ctdb/tests/simple/75_readonly_records_basic.sh | 22 +-
ctdb/tests/src/cluster_wait.c | 331 +++++++++++++++++
.../dbwrap_rbt.h => ctdb/tests/src/cluster_wait.h | 23 +-
ctdb/tests/src/ctdb_bench.c | 292 ---------------
ctdb/tests/src/ctdb_fetch.c | 312 ----------------
ctdb/tests/src/ctdb_fetch_one.c | 155 --------
ctdb/tests/src/ctdb_fetch_readonly_loop.c | 157 --------
ctdb/tests/src/ctdb_fetch_readonly_once.c | 129 -------
ctdb/tests/src/ctdb_lock_tdb.c | 42 ---
ctdb/tests/src/ctdb_persistent.c | 281 ---------------
ctdb/tests/src/ctdb_randrec.c | 211 -----------
ctdb/tests/src/ctdb_store.c | 172 ---------
ctdb/tests/src/ctdb_trackingdb_test.c | 144 --------
ctdb/tests/src/ctdb_transaction.c | 312 ----------------
ctdb/tests/src/ctdb_traverse.c | 127 -------
ctdb/tests/src/ctdb_update_record.c | 171 ---------
ctdb/tests/src/ctdb_update_record_persistent.c | 150 --------
ctdb/tests/src/fetch_loop.c | 286 +++++++++++++++
ctdb/tests/src/fetch_loop_key.c | 214 +++++++++++
ctdb/tests/src/fetch_readonly.c | 163 +++++++++
ctdb/tests/src/fetch_readonly_loop.c | 270 ++++++++++++++
ctdb/tests/src/fetch_ring.c | 381 ++++++++++++++++++++
ctdb/tests/src/g_lock_loop.c | 271 ++++++++++++++
.../protocol_packet.c => tests/src/lock_tdb.c} | 44 ++-
ctdb/tests/src/message_ring.c | 362 +++++++++++++++++++
.../src/{ctdb_porting_tests.c => porting_tests.c} | 165 ++++-----
ctdb/tests/src/rb_test.c | 171 ++++-----
ctdb/tests/src/test_options.c | 183 ++++++++++
.../protocol_packet.c => tests/src/test_options.h} | 44 +--
ctdb/tests/src/transaction_loop.c | 393 +++++++++++++++++++++
ctdb/tests/src/update_record.c | 233 ++++++++++++
ctdb/tests/src/update_record_persistent.c | 215 +++++++++++
ctdb/utils/pmda/pmda_ctdb.c | 114 +-----
ctdb/wscript | 51 ++-
41 files changed, 3626 insertions(+), 3046 deletions(-)
create mode 100755 ctdb/tests/cunit/porting_tests_001.sh
create mode 100755 ctdb/tests/cunit/rb_test_001.sh
create mode 100644 ctdb/tests/src/cluster_wait.c
copy lib/dbwrap/dbwrap_rbt.h => ctdb/tests/src/cluster_wait.h (56%)
delete mode 100644 ctdb/tests/src/ctdb_bench.c
delete mode 100644 ctdb/tests/src/ctdb_fetch.c
delete mode 100644 ctdb/tests/src/ctdb_fetch_one.c
delete mode 100644 ctdb/tests/src/ctdb_fetch_readonly_loop.c
delete mode 100644 ctdb/tests/src/ctdb_fetch_readonly_once.c
delete mode 100644 ctdb/tests/src/ctdb_lock_tdb.c
delete mode 100644 ctdb/tests/src/ctdb_persistent.c
delete mode 100644 ctdb/tests/src/ctdb_randrec.c
delete mode 100644 ctdb/tests/src/ctdb_store.c
delete mode 100644 ctdb/tests/src/ctdb_trackingdb_test.c
delete mode 100644 ctdb/tests/src/ctdb_transaction.c
delete mode 100644 ctdb/tests/src/ctdb_traverse.c
delete mode 100644 ctdb/tests/src/ctdb_update_record.c
delete mode 100644 ctdb/tests/src/ctdb_update_record_persistent.c
create mode 100644 ctdb/tests/src/fetch_loop.c
create mode 100644 ctdb/tests/src/fetch_loop_key.c
create mode 100644 ctdb/tests/src/fetch_readonly.c
create mode 100644 ctdb/tests/src/fetch_readonly_loop.c
create mode 100644 ctdb/tests/src/fetch_ring.c
create mode 100644 ctdb/tests/src/g_lock_loop.c
copy ctdb/{protocol/protocol_packet.c => tests/src/lock_tdb.c} (53%)
create mode 100644 ctdb/tests/src/message_ring.c
rename ctdb/tests/src/{ctdb_porting_tests.c => porting_tests.c} (56%)
create mode 100644 ctdb/tests/src/test_options.c
copy ctdb/{protocol/protocol_packet.c => tests/src/test_options.h} (55%)
create mode 100644 ctdb/tests/src/transaction_loop.c
create mode 100644 ctdb/tests/src/update_record.c
create mode 100644 ctdb/tests/src/update_record_persistent.c
Changeset truncated at 500 lines:
diff --git a/ctdb/tests/cunit/porting_tests_001.sh b/ctdb/tests/cunit/porting_tests_001.sh
new file mode 100755
index 0000000..5612c99
--- /dev/null
+++ b/ctdb/tests/cunit/porting_tests_001.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+socket="${TEST_VAR_DIR}/test_sock.$$"
+
+remove_socket ()
+{
+ rm -f "$socket"
+}
+
+test_cleanup remove_socket
+
+if [ $EUID -eq 0 ] ; then
+ ok "../common/system_linux.c:607 interface 'fake' not found"
+else
+ ok "../common/system_linux.c:601 failed to open raw socket"
+fi
+
+unit_test porting_tests --socket=${socket}
diff --git a/ctdb/tests/cunit/rb_test_001.sh b/ctdb/tests/cunit/rb_test_001.sh
new file mode 100755
index 0000000..25d3ceb
--- /dev/null
+++ b/ctdb/tests/cunit/rb_test_001.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+output="\
+testing trbt_insertarray32_callback
+traverse data:3
+traverse data:2
+traverse data:1
+
+deleting key4
+traverse data:3
+traverse data:2
+traverse data:1
+
+deleting key2
+traverse data:3
+traverse data:1
+
+deleting key3
+traverse data:3
+
+deleting key1
+
+run random insert and delete for 60 seconds
+
+deleting all entries"
+
+ok "$output"
+
+unit_test rb_test
diff --git a/ctdb/tests/simple/51_ctdb_bench.sh b/ctdb/tests/simple/51_ctdb_bench.sh
index ed39286..b8d6e5a 100755
--- a/ctdb/tests/simple/51_ctdb_bench.sh
+++ b/ctdb/tests/simple/51_ctdb_bench.sh
@@ -38,7 +38,7 @@ try_command_on_node 0 "$CTDB listnodes"
num_nodes=$(echo "$out" | wc -l)
echo "Running ctdb_bench on all $num_nodes nodes."
-try_command_on_node -v -p all $CTDB_TEST_WRAPPER $VALGRIND ctdb_bench -n $num_nodes
+try_command_on_node -v -p all $CTDB_TEST_WRAPPER $VALGRIND message_ring -n $num_nodes
# Get the last line of output.
while read line ; do
diff --git a/ctdb/tests/simple/52_ctdb_fetch.sh b/ctdb/tests/simple/52_ctdb_fetch.sh
index 23c33bf..60beef2 100755
--- a/ctdb/tests/simple/52_ctdb_fetch.sh
+++ b/ctdb/tests/simple/52_ctdb_fetch.sh
@@ -38,7 +38,7 @@ try_command_on_node 0 "$CTDB listnodes"
num_nodes=$(echo "$out" | wc -l)
echo "Running ctdb_fetch on all $num_nodes nodes."
-try_command_on_node -v -p all $CTDB_TEST_WRAPPER $VALGRIND ctdb_fetch -n $num_nodes
+try_command_on_node -v -p all $CTDB_TEST_WRAPPER $VALGRIND fetch_ring -n $num_nodes
pat='^(Fetch: [[:digit:]]+(\.[[:digit:]]+)? msgs/sec[[:space:]]?|msg_count=[[:digit:]]+ on node [[:digit:]]|Fetching final record|DATA:|Test data|Waiting for cluster[[:space:]]?|.*: Reqid wrap!|Sleeping for [[:digit:]]+ seconds|)+$'
sanity_check_output 1 "$pat" "$out"
diff --git a/ctdb/tests/simple/53_ctdb_transaction.sh b/ctdb/tests/simple/53_ctdb_transaction.sh
index aa9202f..de81994 100755
--- a/ctdb/tests/simple/53_ctdb_transaction.sh
+++ b/ctdb/tests/simple/53_ctdb_transaction.sh
@@ -37,11 +37,8 @@ if [ -z "$CTDB_TEST_TIMELIMIT" ] ; then
CTDB_TEST_TIMELIMIT=30
fi
-# Add a timeout command to ensure this test completes if
-# ctdb_transaction gets stuck
-timeout_cmd="timeout $((CTDB_TEST_TIMELIMIT * 2))"
-
-t="$CTDB_TEST_WRAPPER $VALGRIND $timeout_cmd ctdb_transaction --timelimit=${CTDB_TEST_TIMELIMIT}"
+t="$CTDB_TEST_WRAPPER $VALGRIND transaction_loop \
+ -n ${num_nodes} -t ${CTDB_TEST_TIMELIMIT}"
echo "Running ctdb_transaction on all $num_nodes nodes."
-try_command_on_node -v -p all "$t & $t"
+try_command_on_node -v -p all "$t"
diff --git a/ctdb/tests/simple/54_ctdb_transaction_recovery.sh b/ctdb/tests/simple/54_ctdb_transaction_recovery.sh
index 78a6e99..ba04535 100755
--- a/ctdb/tests/simple/54_ctdb_transaction_recovery.sh
+++ b/ctdb/tests/simple/54_ctdb_transaction_recovery.sh
@@ -56,17 +56,12 @@ if [ -z "$CTDB_TEST_TIMELIMIT" ] ; then
CTDB_TEST_TIMELIMIT=30
fi
-# Add a timeout command to ensure this test completes if
-# ctdb_transaction gets stuck. This one can get more "stuck" than the
-# previous test because a recovery can stop it committing a
-# transaction.
-timeout_cmd="timeout 600"
-
-t="$CTDB_TEST_WRAPPER $VALGRIND $timeout_cmd ctdb_transaction --timelimit=${CTDB_TEST_TIMELIMIT}"
+t="$CTDB_TEST_WRAPPER $VALGRIND transaction_loop \
+ -n ${num_nodes} -t ${CTDB_TEST_TIMELIMIT}"
echo "Starting recovery loop"
recovery_loop_start
echo "Running ctdb_transaction on all $num_nodes nodes."
-try_command_on_node -v -p all "$t & $t"
+try_command_on_node -v -p all "$t"
diff --git a/ctdb/tests/simple/72_update_record_persistent.sh b/ctdb/tests/simple/72_update_record_persistent.sh
index f409332..8f028d0 100755
--- a/ctdb/tests/simple/72_update_record_persistent.sh
+++ b/ctdb/tests/simple/72_update_record_persistent.sh
@@ -61,7 +61,8 @@ fi
# 4,
echo "Create a new record in the persistent database using UPDATE_RECORD"
-try_command_on_node 0 $CTDB_TEST_WRAPPER ctdb_update_record_persistent --database="$test_db" --record=Update_Record_Persistent --value=FirstValue
+try_command_on_node 0 $CTDB_TEST_WRAPPER $VALGRIND update_record_persistent \
+ -D "$test_db" -k "Update_Record_Persistent" -v "FirstValue"
try_command_on_node 0 "$CTDB cattdb "$test_db" | grep 'FirstValue' | wc -l"
if [ "$out" = 1 ] ; then
@@ -73,7 +74,8 @@ fi
# 5,
echo Modify an existing record in the persistent database using UPDATE_RECORD
-try_command_on_node 0 $CTDB_TEST_WRAPPER ctdb_update_record_persistent --database="$test_db" --record=Update_Record_Persistent --value=SecondValue
+try_command_on_node 0 $CTDB_TEST_WRAPPER $VALGRIND update_record_persistent \
+ -D "$test_db" -k "Update_Record_Persistent" -v "SecondValue"
try_command_on_node 0 "$CTDB cattdb "$test_db" | grep 'FirstValue' | wc -l"
if [ "$out" = 0 ] ; then
diff --git a/ctdb/tests/simple/75_readonly_records_basic.sh b/ctdb/tests/simple/75_readonly_records_basic.sh
index e4d5708..48e16df 100755
--- a/ctdb/tests/simple/75_readonly_records_basic.sh
+++ b/ctdb/tests/simple/75_readonly_records_basic.sh
@@ -123,12 +123,14 @@ echo "Create test database \"${testdb}\""
try_command_on_node 0 $CTDB attach $testdb
echo "Create some records..."
-try_command_on_node all $CTDB_TEST_WRAPPER ctdb_update_record
+try_command_on_node all $CTDB_TEST_WRAPPER $VALGRIND update_record \
+ -D ${testdb} -k testkey
######################################################################
echo "Try some readonly fetches, these should all be upgraded to full fetchlocks..."
-try_command_on_node all $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null"
+try_command_on_node all $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \
+ -D ${testdb} -k testkey
check_no_readonly
@@ -152,10 +154,12 @@ fi
echo "Create 1 read-only delegation ..."
# dmaster=1
-try_command_on_node 1 $CTDB_TEST_WRAPPER ctdb_update_record
+try_command_on_node 1 $CTDB_TEST_WRAPPER $VALGRIND update_record \
+ -D ${testdb} -k testkey
# Fetch read-only to node 0
-try_command_on_node 0 $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null"
+try_command_on_node 0 $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \
+ -D ${testdb} -k testkey
check_readonly 1 0
@@ -163,7 +167,8 @@ check_readonly 1 0
echo "Verify that a fetchlock revokes read-only delegations..."
# Node 1 becomes dmaster
-try_command_on_node 1 $CTDB_TEST_WRAPPER ctdb_update_record
+try_command_on_node 1 $CTDB_TEST_WRAPPER $VALGRIND update_record \
+ -D ${testdb} -k testkey
check_no_readonly
@@ -171,14 +176,15 @@ check_no_readonly
echo "Create more read-only delegations..."
dmaster=1
-try_command_on_node $dmaster $CTDB_TEST_WRAPPER ctdb_update_record
+try_command_on_node $dmaster $CTDB_TEST_WRAPPER $VALGRIND update_record \
+ -D ${testdb} -k testkey
others=""
for n in $all_nodes ; do
if [ "$n" != "$dmaster" ] ; then
# Fetch read-only copy to this node
- try_command_on_node $n \
- $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null"
+ try_command_on_node $n $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \
+ -D ${testdb} -k testkey
others="${others} ${n}"
fi
done
diff --git a/ctdb/tests/src/cluster_wait.c b/ctdb/tests/src/cluster_wait.c
new file mode 100644
index 0000000..ddc3e02
--- /dev/null
+++ b/ctdb/tests/src/cluster_wait.c
@@ -0,0 +1,331 @@
+/*
+ Cluster wide synchronization
+
+ Copyright (C) Amitay Isaacs 2015
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/network.h"
+
+#include "lib/util/tevent_unix.h"
+
+#include "client/client.h"
+
+#include "tests/src/cluster_wait.h"
+
+#define MSG_ID_JOIN (CTDB_SRVID_TEST_RANGE | 0x1)
+#define MSG_ID_SYNC (CTDB_SRVID_TEST_RANGE | 0x2)
+
+/* Wait for all the clients to initialize */
+
+struct cluster_wait_state {
+ struct tevent_context *ev;
+ struct ctdb_client_context *client;
+ int num_nodes;
+ bool *ready;
+};
+
+static void cluster_wait_join_registered(struct tevent_req *subreq);
+static void cluster_wait_sync_registered(struct tevent_req *subreq);
+static void cluster_wait_join(struct tevent_req *subreq);
+static void cluster_wait_join_sent(struct tevent_req *subreq);
+static void cluster_wait_join_handler(uint64_t srvid, TDB_DATA data,
+ void *private_data);
+static void cluster_wait_sync_sent(struct tevent_req *subreq);
+static void cluster_wait_join_unregistered(struct tevent_req *subreq);
+static void cluster_wait_sync_handler(uint64_t srvid, TDB_DATA data,
+ void *private_data);
+static void cluster_wait_sync_unregistered(struct tevent_req *subreq);
+
+struct tevent_req *cluster_wait_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct ctdb_client_context *client,
+ int num_nodes)
+{
+ struct tevent_req *req, *subreq;
+ struct cluster_wait_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct cluster_wait_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ state->ev = ev;
+ state->client = client;
+ state->num_nodes = num_nodes;
+
+ if (ctdb_client_pnn(client) == 0) {
+ state->ready = talloc_zero_array(state, bool, num_nodes);
+ if (tevent_req_nomem(state->ready, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ subreq = ctdb_client_set_message_handler_send(
+ state, ev, client, MSG_ID_JOIN,
+ cluster_wait_join_handler, req);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, cluster_wait_join_registered,
+ req);
+ }
+
+ subreq = ctdb_client_set_message_handler_send(
+ state, ev, client, MSG_ID_SYNC,
+ cluster_wait_sync_handler, req);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, cluster_wait_sync_registered, req);
+
+ /* If cluster is not synchronized within 30 seconds, time out */
+ tevent_req_set_endtime(req, ev, tevent_timeval_current_ofs(30, 0));
+
+ return req;
+}
+
+static void cluster_wait_join_registered(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ bool status;
+ int ret;
+
+ status = ctdb_client_set_message_handler_recv(subreq, &ret);
+ TALLOC_FREE(subreq);
+ if (! status) {
+ tevent_req_error(req, ret);
+ return;
+ }
+
+ printf("Waiting for cluster\n");
+ fflush(stdout);
+}
+
+static void cluster_wait_sync_registered(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cluster_wait_state *state = tevent_req_data(
+ req, struct cluster_wait_state);
+ bool status;
+ int ret;
+
+ status = ctdb_client_set_message_handler_recv(subreq, &ret);
+ TALLOC_FREE(subreq);
+ if (! status) {
+ tevent_req_error(req, ret);
+ return;
+ }
+
+ subreq = tevent_wakeup_send(state, state->ev,
+ tevent_timeval_current_ofs(1, 0));
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cluster_wait_join, req);
+}
+
+static void cluster_wait_join(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cluster_wait_state *state = tevent_req_data(
+ req, struct cluster_wait_state);
+ struct ctdb_req_message msg;
+ uint32_t pnn;
+ bool status;
+
+ status = tevent_wakeup_recv(subreq);
+ TALLOC_FREE(subreq);
+ if (! status) {
+ tevent_req_error(req, EIO);
+ return;
+ }
+
+ pnn = ctdb_client_pnn(state->client);
+
+ msg.srvid = MSG_ID_JOIN;
+ msg.data.data.dsize = sizeof(pnn);
+ msg.data.data.dptr = (uint8_t *)&pnn;
+
+ subreq = ctdb_client_message_send(state, state->ev, state->client,
+ 0, &msg);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cluster_wait_join_sent, req);
+}
+
+static void cluster_wait_join_sent(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cluster_wait_state *state = tevent_req_data(
+ req, struct cluster_wait_state);
+ bool status;
+ int ret;
+
+ status = ctdb_client_message_recv(subreq, &ret);
+ TALLOC_FREE(subreq);
+ if (! status) {
+ tevent_req_error(req, ret);
+ return;
+ }
+
+ subreq = tevent_wakeup_send(state, state->ev,
+ tevent_timeval_current_ofs(1, 0));
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cluster_wait_join, req);
+}
+
+static void cluster_wait_join_handler(uint64_t srvid, TDB_DATA data,
+ void *private_data)
+{
+ struct tevent_req *req = talloc_get_type_abort(
+ private_data, struct tevent_req);
+ struct cluster_wait_state *state = tevent_req_data(
+ req, struct cluster_wait_state);
+ struct ctdb_req_message msg;
+ struct tevent_req *subreq;
+ uint32_t pnn;
+ int i;
+
+ if (srvid != MSG_ID_JOIN) {
+ return;
+ }
+
+ if (data.dsize != sizeof(uint32_t)) {
+ return;
+ }
+
+ pnn = *(uint32_t *)data.dptr;
+
+ if (pnn > state->num_nodes) {
+ return;
+ }
+
+ state->ready[pnn] = true;
+
+ for (i=0; i<state->num_nodes; i++) {
+ if (! state->ready[i]) {
+ return;
+ }
+ }
+
+ msg.srvid = MSG_ID_SYNC;
+ msg.data.data = tdb_null;
+
+ subreq = ctdb_client_message_send(state, state->ev, state->client,
+ CTDB_BROADCAST_ALL, &msg);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cluster_wait_sync_sent, req);
+}
+
+static void cluster_wait_sync_sent(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cluster_wait_state *state = tevent_req_data(
+ req, struct cluster_wait_state);
+ bool status;
+ int ret;
+
+ status = ctdb_client_message_recv(subreq, &ret);
+ TALLOC_FREE(subreq);
+ if (! status) {
+ tevent_req_error(req, ret);
+ return;
+ }
+
+ subreq = ctdb_client_remove_message_handler_send(
+ state, state->ev, state->client,
+ MSG_ID_JOIN, req);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cluster_wait_join_unregistered, req);
+}
+
+static void cluster_wait_join_unregistered(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ bool status;
+ int ret;
--
Samba Shared Repository
More information about the samba-cvs
mailing list