[SCM] CTDB repository - branch master updated - ctdb-1.13-3-gf066349

Ronnie Sahlberg sahlberg at samba.org
Mon Mar 12 02:29:42 MDT 2012


The branch, master has been updated
       via  f06634951331232cddf0b48eac3552b92aca5b93 (commit)
      from  68390cb1e8c7f30be034b8ca6c9215b40147305b (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f06634951331232cddf0b48eac3552b92aca5b93
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Mon Mar 12 16:09:32 2012 +1100

    Test: add test tool and test that UPDATE_RECORD works on persistent databases

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

Summary of changes:
 Makefile.in                                        |    5 +
 tests/simple/72_update_record_persistent.sh        |   89 +++++++++++++++++++
 ...only_loop.c => ctdb_update_record_persistent.c} |   91 +++++++++-----------
 3 files changed, 136 insertions(+), 49 deletions(-)
 create mode 100755 tests/simple/72_update_record_persistent.sh
 copy tests/src/{ctdb_fetch_readonly_loop.c => ctdb_update_record_persistent.c} (57%)


Changeset truncated at 500 lines:

diff --git a/Makefile.in b/Makefile.in
index 24283f3..9055a8f 100755
--- a/Makefile.in
+++ b/Makefile.in
@@ -85,6 +85,7 @@ TEST_BINS=tests/bin/ctdb_bench tests/bin/ctdb_fetch tests/bin/ctdb_fetch_one \
 	tests/bin/ctdb_randrec tests/bin/ctdb_persistent \
 	tests/bin/ctdb_traverse tests/bin/rb_test tests/bin/ctdb_transaction \
 	tests/bin/ctdb_takeover_tests tests/bin/ctdb_update_record \
+	tests/bin/ctdb_update_record_persistent \
 	tests/bin/ctdb_tool_libctdb tests/bin/ctdb_tool_stubby \
 	@INFINIBAND_BINS@
 
@@ -215,6 +216,10 @@ tests/bin/ctdb_update_record: $(CTDB_CLIENT_OBJ) tests/src/ctdb_update_record.o
 	@echo Linking $@
 	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_update_record.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
 
+tests/bin/ctdb_update_record_persistent: $(CTDB_CLIENT_OBJ) tests/src/ctdb_update_record_persistent.o 
+	@echo Linking $@
+	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_update_record_persistent.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
+
 tests/bin/ctdb_store: $(CTDB_CLIENT_OBJ) tests/src/ctdb_store.o 
 	@echo Linking $@
 	@$(CC) $(CFLAGS) -o $@ tests/src/ctdb_store.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
diff --git a/tests/simple/72_update_record_persistent.sh b/tests/simple/72_update_record_persistent.sh
new file mode 100755
index 0000000..d232b40
--- /dev/null
+++ b/tests/simple/72_update_record_persistent.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+test_info()
+{
+    cat <<EOF
+UPDATE_RECORD control should be able to create new records and update
+existing records in a persistent database.
+
+Prerequisites:
+
+* An active CTDB cluster with at least one active node.
+
+Steps:
+
+1. Verify that the status on all of the ctdb nodes is 'OK'.
+2. create a persistent test database
+3, wipe the database to make sure it is empty
+4, create a new record
+5, update the record
+
+Expected results:
+
+* 4 created record found in the tdb
+* 5 updated record found in the tdb
+
+EOF
+}
+
+. ctdb_test_functions.bash
+
+ctdb_test_init "$@"
+
+set -e
+
+cluster_is_healthy
+
+try_command_on_node 0 "$CTDB listnodes"
+num_nodes=$(echo "$out" | wc -l)
+
+# create a temporary persistent database to test with
+echo create persistent test database persistent_test.tdb
+try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb attach persistent_test.tdb persistent
+
+
+# 3,
+echo wipe the persistent test database
+try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb wipedb persistent_test.tdb
+echo force a recovery
+try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb recover
+
+# check that the database is wiped
+num_records=$(try_command_on_node -v -pq 1 $CTDB_TEST_WRAPPER ctdb cattdb persistent_test.tdb | grep key | wc -l)
+[ $num_records != "0" ] && {
+    echo "BAD: we did not end up with an empty database"
+    exit 1
+}
+echo "OK. database was wiped"
+
+TDB=`try_command_on_node -v -q 0 $CTDB_TEST_WRAPPER ctdb getdbmap | grep persistent_test.tdb | sed -e "s/.*path://" -e "s/ .*//"`
+
+# 4,
+echo Create a new record in the persistent database using UPDATE_RECORD
+try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb_update_record_persistent  --database=persistent_test.tdb --record=Update_Record_Persistent --value=FirstValue
+
+num_records=`tdbdump $TDB | grep "FirstValue" | wc -l`
+[ $num_records != 1 ] && {
+    echo "BAD: we did find the record after the create/update"
+    exit 1
+}
+
+# 5,
+echo Modify an existing record in the persistent database using UPDATE_RECORD
+try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb_update_record_persistent  --database=persistent_test.tdb --record=Update_Record_Persistent --value=SecondValue
+
+num_records=`tdbdump $TDB | grep "FirstValue" | wc -l`
+[ $num_records != 0 ] && {
+    echo "BAD: we still found the old record after the modify/update"
+    exit 1
+}
+
+num_records=`tdbdump $TDB | grep "SecondValue" | wc -l`
+[ $num_records != 1 ] && {
+    echo "BAD: could not find the record after the modify/update"
+    exit 1
+}
+
+
+echo wipe the persistent test databases and clean up
+try_command_on_node -q 0 $CTDB_TEST_WRAPPER ctdb wipedb persistent_test.tdb
diff --git a/tests/src/ctdb_fetch_readonly_loop.c b/tests/src/ctdb_update_record_persistent.c
similarity index 57%
copy from tests/src/ctdb_fetch_readonly_loop.c
copy to tests/src/ctdb_update_record_persistent.c
index d2bf525..c54c0e4 100644
--- a/tests/src/ctdb_fetch_readonly_loop.c
+++ b/tests/src/ctdb_update_record_persistent.c
@@ -1,8 +1,8 @@
 /* 
    simple ctdb test tool
-   This test just fetch_locks a record and releases it in a loop.
+   This test just creates/updates a record in a persistent database
 
-   Copyright (C) Ronnie Sahlberg 2009
+   Copyright (C) Ronnie Sahlberg 2012
 
    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
@@ -18,53 +18,38 @@
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <time.h>
 #include "includes.h"
 #include "lib/tevent/tevent.h"
+#include "lib/util/db_wrap.h"
 #include "system/filesys.h"
 #include "popt.h"
 #include "cmdline.h"
 #include "ctdb_private.h"
 
-static struct ctdb_db_context *ctdb_db;
 
-const char *TESTKEY = "testkey";
-static int count;
-
-/*
-	Just try locking/unlocking a single record once
-*/
-static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev)
+static void update_once(struct ctdb_context *ctdb, struct event_context *ev, struct ctdb_db_context *ctdb_db, char *record, char *value)
 {
-	TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
-	TDB_DATA key, data;
-	struct ctdb_record_handle *h;
-	static time_t t = 0, t2;
+	TDB_DATA key, data, olddata;
+	struct ctdb_ltdb_header header;
 
-	key.dptr = discard_const(TESTKEY);
-	key.dsize = strlen(TESTKEY);
+	memset(&header, sizeof(header), 0);
 
-//	printf("Trying to fetch lock the record ...\n");
+	key.dptr  = (uint8_t *)record;
+	key.dsize = strlen(record);
 
-	h = ctdb_fetch_readonly_lock(ctdb_db, tmp_ctx, key, &data, true);
-	if (h == NULL) {
-		printf("Failed to fetch record '%s' on node %d\n", 
-	       		(const char *)key.dptr, ctdb_get_pnn(ctdb));
-		talloc_free(tmp_ctx);
-		exit(10);
-	}
+	data.dptr  = (uint8_t *)value;
+	data.dsize = strlen(value);
 
-	count++;
-	t2 = time(NULL);
-	if (t != 0 && t != t2) {
-		static int last_count = 0;
-
-		printf("count : %d\n", count - last_count);
-		last_count = count;
+	olddata = tdb_fetch(ctdb_db->ltdb->tdb, key);
+	if (olddata.dsize != 0) {
+		memcpy(&header, olddata.dptr, sizeof(header));
+		header.rsn++;
 	}
-	t = t2;
 
-	talloc_free(tmp_ctx);
+	if (ctdb_ctrl_updaterecord(ctdb, ctdb, timeval_zero(), CTDB_CURRENT_NODE, ctdb_db, key, &header, data) != 0) {
+		printf("Failed to update record\n");
+		exit(1);
+	}
 }
 
 /*
@@ -73,19 +58,25 @@ static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev)
 int main(int argc, const char *argv[])
 {
 	struct ctdb_context *ctdb;
-	TDB_DATA key;
+	char *test_db = NULL;
+	char *record = NULL;
+	char *value = NULL;
+	struct ctdb_db_context *ctdb_db;
+	struct event_context *ev;
 
 	struct poptOption popt_options[] = {
 		POPT_AUTOHELP
 		POPT_CTDB_CMDLINE
-		{ "record",      'r', POPT_ARG_STRING, &TESTKEY, 0, "record", "string" },
+		{ "database",      'D', POPT_ARG_STRING, &test_db, 0, "database", "string" },
+		{ "record",      'R', POPT_ARG_STRING, &record, 0, "record", "string" },
+		{ "value",      'V', POPT_ARG_STRING, &value, 0, "value", "string" },
 		POPT_TABLEEND
 	};
-	int opt, ret;
+	int opt;
 	const char **extra_argv;
 	int extra_argc = 0;
 	poptContext pc;
-	struct event_context *ev;
+
 
 	pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
 
@@ -109,19 +100,23 @@ int main(int argc, const char *argv[])
 
 	ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(5, 0));
 
-	key.dptr  = discard_const(TESTKEY);
-	key.dsize = strlen(TESTKEY);
+	if (test_db == NULL) {
+		fprintf(stderr, "You must specify the database\n");
+		exit(10);
+	}
 
-	ret = ctdb_ctrl_getvnnmap(ctdb, timeval_zero(), CTDB_CURRENT_NODE, ctdb, &ctdb->vnn_map);
-	if (ret != 0) {
-		printf("failed to get vnnmap\n");
+	if (record == NULL) {
+		fprintf(stderr, "You must specify the record\n");
+		exit(10);
+	}
+
+	if (value == NULL) {
+		fprintf(stderr, "You must specify the value\n");
 		exit(10);
 	}
-	printf("Record:%s\n", TESTKEY);
-	printf("Lmaster : %d\n", ctdb_lmaster(ctdb, &key)); 
 
 	/* attach to a specific database */
-	ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(5, 0), "test.tdb", false, 0);
+	ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(5, 0), test_db, true, 0);
 	if (!ctdb_db) {
 		printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
 		exit(1);
@@ -135,9 +130,7 @@ int main(int argc, const char *argv[])
 		event_loop_once(ev);
 	}
 
-	while (1) {
-		fetch_lock_once(ctdb, ev);
-	}
+	update_once(ctdb, ev, ctdb_db, record, value);
 
 	return 0;
 }


-- 
CTDB repository


More information about the samba-cvs mailing list