[SCM] CTDB repository - branch master updated -
181318fea6886c40d0aff02d0de777f28ffeddce
Ronnie Sahlberg
sahlberg at samba.org
Tue Jun 3 08:24:44 GMT 2008
The branch, master has been updated
via 181318fea6886c40d0aff02d0de777f28ffeddce (commit)
via 00006222ece63ae3b7f3477646232ae5bbeee6f4 (commit)
via dfe0c44c1e8e9dab790686c5ba798986d04bf218 (commit)
from f0b55adae450cac3cf925e111e1dc9628cff4525 (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 181318fea6886c40d0aff02d0de777f28ffeddce
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue Jun 3 18:19:48 2008 +1000
run the persistent write test with 4 nodes by default
use the timelimit argument to the persistent writer to run the test for
30 seconds by default
commit 00006222ece63ae3b7f3477646232ae5bbeee6f4
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue Jun 3 18:18:28 2008 +1000
redesign the test of persistent writes
so that we have n persistent writers on n nodes,
all writers writing persistently to the same record.
each writer on a node has its own "counter" in this record that is incremented by one in each iteration.
the persistent writer on node 0 also checks that all the counters in the record are increasing monotonically and if they are not, flagging it as an ERROR.
commit dfe0c44c1e8e9dab790686c5ba798986d04bf218
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue Jun 3 18:14:54 2008 +1000
create the nodes file in a 'test' subdirectory and not the current directory
delete all persistent databases when the test starts
(the tests only uses test databases in a special test directory)
do not set up any public addresses in the tests
wait until there are no disconnected or unhealthy nodes when starting the
test daemons instead of waiting for the recovery mode to change.
we do want to wait until the system has recovered and ALL nodes are ok.
-----------------------------------------------------------------------
Summary of changes:
tests/ctdb_persistent.c | 139 ++++++++++++++++++++++++++++++++++++++++-------
tests/persistent.sh | 8 ++-
tests/start_daemons.sh | 20 ++++---
3 files changed, 135 insertions(+), 32 deletions(-)
Changeset truncated at 500 lines:
diff --git a/tests/ctdb_persistent.c b/tests/ctdb_persistent.c
index dd0e27c..b98e662 100644
--- a/tests/ctdb_persistent.c
+++ b/tests/ctdb_persistent.c
@@ -27,21 +27,88 @@
#include <sys/time.h>
#include <time.h>
+static struct timeval tp1,tp2;
+
+static void start_timer(void)
+{
+ gettimeofday(&tp1,NULL);
+}
+
+static double end_timer(void)
+{
+ gettimeofday(&tp2,NULL);
+ return (tp2.tv_sec + (tp2.tv_usec*1.0e-6)) -
+ (tp1.tv_sec + (tp1.tv_usec*1.0e-6));
+}
+
+static int timelimit = 10;
+
+static unsigned int pnn;
+
+static TDB_DATA old_data;
+
+static int success = true;
+
+static void each_second(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);
+ int i;
+ uint32_t *old_counters;
+
+
+ printf("Counters: ");
+ old_counters = (uint32_t *)old_data.dptr;
+ for (i=0;i<old_data.dsize/sizeof(uint32_t); i++) {
+ printf("%6u ", old_counters[i]);
+ }
+ printf("\n");
+
+ event_add_timed(ev, ctdb, timeval_current_ofs(1, 0), each_second, ctdb);
+}
+
+static void check_counters(struct ctdb_context *ctdb, TDB_DATA data)
+{
+ int i;
+ uint32_t *counters, *old_counters;
+
+ counters = (uint32_t *)data.dptr;
+ old_counters = (uint32_t *)old_data.dptr;
+
+ /* check that all the counters are monotonic increasing */
+ for (i=0; i<old_data.dsize/sizeof(uint32_t); i++) {
+ if (counters[i]<old_counters[i]) {
+ printf("ERROR: counters has decreased for node %u From %u to %u\n", i, old_counters[i], counters[i]);
+ success = false;
+ }
+ }
+
+ if (old_data.dsize != data.dsize) {
+ old_data.dsize = data.dsize;
+ old_data.dptr = talloc_realloc_size(ctdb, old_data.dptr, old_data.dsize);
+ }
+
+ memcpy(old_data.dptr, data.dptr, data.dsize);
+}
+
+
+
static void test_store_records(struct ctdb_context *ctdb, struct event_context *ev)
{
TDB_DATA key, data;
struct ctdb_db_context *ctdb_db;
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
- int ret, i;
+ int ret;
struct ctdb_record_handle *h;
- unsigned node=0, count=0;
-
+ uint32_t *counters;
+ int first_time = true;
ctdb_db = ctdb_db_handle(ctdb, "persistent.tdb");
key.dptr = discard_const("testkey");
key.dsize = strlen((const char *)key.dptr)+1;
- for (i=0;i<10;i++) {
+ start_timer();
+ while (end_timer() < timelimit) {
h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
if (h == NULL) {
printf("Failed to fetch record '%s' on node %d\n",
@@ -49,27 +116,44 @@ static void test_store_records(struct ctdb_context *ctdb, struct event_context *
talloc_free(tmp_ctx);
return;
}
-
- printf("Current value: %*.*s\n", (int)data.dsize, (int)data.dsize, data.dptr);
-
- if (data.dsize != 0) {
- if (sscanf((char *)data.dptr, "Node %u Count %u", &node, &count) != 2) {
- printf("Badly formatted node data!\n");
- exit(1);
- }
+
+ if (data.dsize < sizeof(uint32_t) * (pnn+1)) {
+ unsigned char *ptr = data.dptr;
+
+ data.dptr = talloc_zero_size(tmp_ctx, sizeof(uint32_t) * (pnn+1));
+ memcpy(data.dptr, ptr, data.dsize);
+ talloc_free(ptr);
+
+ data.dsize = sizeof(uint32_t) * (pnn+1);
+ }
+
+ if (data.dptr == NULL) {
+ printf("Failed to realloc array\n");
+ talloc_free(tmp_ctx);
+ return;
}
-
- node = ctdb_get_pnn(ctdb);
- count++;
-
- data.dptr = (uint8_t *)talloc_asprintf(h, "Node %u Count %u", node, count);
- data.dsize = strlen((char *)data.dptr)+1;
-
+
+ counters = (uint32_t *)data.dptr;
+
+ if (first_time) {
+ counters[pnn] = 0;
+ first_time = false;
+ }
+
+ /* bump our counter */
+ counters[pnn]++;
+
ret = ctdb_record_store(h, data);
if (ret != 0) {
DEBUG(DEBUG_ERR,("Failed to store record\n"));
exit(1);
}
+
+ /* store the counters and verify that they are sane */
+ if (pnn == 0) {
+ check_counters(ctdb, data);
+ }
+
talloc_free(h);
}
@@ -87,6 +171,7 @@ int main(int argc, const char *argv[])
struct poptOption popt_options[] = {
POPT_AUTOHELP
POPT_CTDB_CMDLINE
+ { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
POPT_TABLEEND
};
int opt;
@@ -132,8 +217,22 @@ int main(int argc, const char *argv[])
event_loop_once(ev);
}
- printf("Starting test\n");
+ pnn = ctdb_get_pnn(ctdb);
+ printf("Starting test on node %u. running for %u seconds\n", pnn, timelimit);
+
+ if (pnn == 0) {
+ event_add_timed(ev, ctdb, timeval_current_ofs(1, 0), each_second, ctdb);
+ }
+
test_store_records(ctdb, ev);
+ if (pnn == 0) {
+ if (success != true) {
+ printf("The test FAILED\n");
+ return 1;
+ } else {
+ printf("SUCCESS!\n");
+ }
+ }
return 0;
}
diff --git a/tests/persistent.sh b/tests/persistent.sh
index 1ea3d03..d952786 100755
--- a/tests/persistent.sh
+++ b/tests/persistent.sh
@@ -1,19 +1,21 @@
#!/bin/sh
-NUMNODES=2
+NUMNODES=4
if [ $# -gt 0 ]; then
NUMNODES=$1
fi
+echo "Starting $NUMNODES daemons"
tests/start_daemons.sh $NUMNODES || exit 1
-
killall -9 -q ctdb_persistent
+
for i in `seq 1 $NUMNODES`; do
- $VALGRIND bin/ctdb_persistent --socket sock.$i $* &
+ $VALGRIND bin/ctdb_persistent --timelimit 30 --socket sock.$i $* &
done
wait
echo "Shutting down"
bin/ctdb shutdown -n all --socket=sock.1
+
exit 0
diff --git a/tests/start_daemons.sh b/tests/start_daemons.sh
index 980dfc5..afcf23e 100755
--- a/tests/start_daemons.sh
+++ b/tests/start_daemons.sh
@@ -4,28 +4,30 @@ NUMNODES=2
if [ $# -gt 0 ]; then
NUMNODES=$1
fi
-NODES="nodes.txt"
+NODES="./tests/nodes.txt"
shift
-rm -f nodes.txt
+rm -f $NODES
for i in `seq 1 $NUMNODES`; do
- echo 127.0.0.$i >> nodes.txt
+ echo 127.0.0.$i >> $NODES
done
killall -q ctdbd
-
-CTDB_OPTIONS="--reclock=rec.lock --nlist $NODES --event-script-dir=tests/events.d --logfile=- --dbdir=test.db --dbdir-persistent=test.db/persistent $*"
-if [ `id -u` -eq 0 ]; then
- CTDB_OPTIONS="$CTDB_OPTIONS --public-addresses=tests/public_addresses --public-interface=lo"
-fi
+rm -rf test.db/persistent/*
+
+CTDB_OPTIONS="--reclock=rec.lock --nlist $NODES --event-script-dir=tests/events.d --logfile=- -d 0 --dbdir=test.db --dbdir-persistent=test.db/persistent $*"
echo "Starting $NUMNODES ctdb daemons"
for i in `seq 1 $NUMNODES`; do
+ if [ `id -u` -eq 0 ]; then
+ CTDB_OPTIONS="$CTDB_OPTIONS --public-interface=lo"
+ fi
+
$VALGRIND bin/ctdbd --socket=sock.$i $CTDB_OPTIONS || exit 1
done
ln -sf $PWD/sock.1 /tmp/ctdb.socket || exit 1
-while bin/ctdb status | grep RECOVERY > /dev/null; do
+while bin/ctdb status | egrep "DISCONNECTED|UNHEALTHY" > /dev/null; do
echo "`date` Waiting for recovery"
sleep 1;
done
--
CTDB repository
More information about the samba-cvs
mailing list