Rev 147: merge fetch1 changes from ronnie in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Wed Apr 18 02:39:12 GMT 2007


------------------------------------------------------------
revno: 147
revision-id: tridge at samba.org-20070418023912-46efe420d9dd59a1
parent: tridge at samba.org-20070418015554-f1b0faceed62a64b
parent: ronniesahlberg at gmail.com-20070418003811-cpnrrypbovb5er9u
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Wed 2007-04-18 12:39:12 +1000
message:
  merge fetch1 changes from ronnie
modified:
  tests/ctdb_fetch1.c            ctdb_fetch1.c-20070412111848-xawz6wqk9r0v8jdk-1
    ------------------------------------------------------------
    merged: ronniesahlberg at gmail.com-20070418003811-cpnrrypbovb5er9u
    parent: ronniesahlberg at gmail.com-20070417232840-kmcz7vzldyneiw0u
    committer: Ronnie sahlberg <ronniesahlberg at gmail.com>
    branch nick: ctdb
    timestamp: Wed 2007-04-18 10:38:11 +1000
    message:
      enhance fetch1 test to verify that a lock is released when a client terminates while holding the lock  and the next blocked waiting client is assigned the lock
    ------------------------------------------------------------
    merged: ronniesahlberg at gmail.com-20070417232840-kmcz7vzldyneiw0u
    parent: ronniesahlberg at gmail.com-20070417081508-rhx2vqhbqqkyqtdm
    parent: tridge at samba.org-20070417123923-99d9e4b5174f992d
    committer: Ronnie sahlberg <ronniesahlberg at gmail.com>
    branch nick: ctdb
    timestamp: Wed 2007-04-18 09:28:40 +1000
    message:
      merge from tridge
=== modified file 'tests/ctdb_fetch1.c'
--- a/tests/ctdb_fetch1.c	2007-04-17 12:16:50 +0000
+++ b/tests/ctdb_fetch1.c	2007-04-18 00:38:11 +0000
@@ -25,6 +25,7 @@
 #include "ctdb.h"
 #include "ctdb_private.h"
 #include "cmdline.h"
+#include <sys/time.h>
 
 #define PARENT_SRVID	0
 #define CHILD1_SRVID	1
@@ -32,6 +33,20 @@
 
 int num_msg=0;
 
+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 void message_handler(struct ctdb_context *ctdb, uint32_t srvid, 
 			    TDB_DATA data, void *private_data)
 {
@@ -113,17 +128,23 @@
 	/* fetch and lock the record */
 	key.dptr  = discard_const("Record");
 	key.dsize = strlen((const char *)key.dptr)+1;
+	printf("client:%d fetching the record\n",srvid);
 	h = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
+	printf("client:%d the record is fetched and locked\n",srvid);
 	if (h == NULL) {
 		printf("client: ctdb_fetch_lock() failed\n");
 		exit(1);
 	}
 	ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), PARENT_SRVID, data);
-	talloc_free(h);
 
-	while (1) {
+	/* wait until parent tells us to release the lock */
+	while (num_msg==1) {
 		event_loop_once(ev);
 	}
+
+	printf("child %d terminating\n",srvid);
+	exit(10);
+	   
 }
 
 /*
@@ -227,29 +248,48 @@
 	 */
 	data.dptr=discard_const("dummy message");
 	data.dsize=strlen((const char *)data.dptr)+1;
-	printf("Send message to child 1 to fetch_lock the record\n");
 	ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data);
 
 	/* wait for child 1 to complete fetching and locking the record */
 	while (num_msg!=3) {
 		event_loop_once(ev);
 	}
-	printf("Child 1 has fetched and locked the record\n");
 
 	/* now tell child 2 to fetch and lock the same record */
-	printf("Send message to child 2 to fetch_lock the record\n");
 	ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data);
 
-	/* wait for child 2 to complete fetching and locking the record */
+	/* wait a while for child 2 to complete fetching and locking the 
+	   record, this should fail since the record is already locked
+	   by the first child */
+	start_timer();
+	while ( (end_timer() < 1.0) && (num_msg!=4) ) {
+		event_loop_once(ev);
+	}
+	if (num_msg!=4) {
+		printf("Child 2 did not get the lock since it is held by client 1:SUCCESS\n");
+	} else {
+		printf("Child 2 did get the lock:FAILURE\n");
+		exit(10);
+	}
+
+	/* send message to child 1 to terminate, which should let child 2
+	   get the lock.
+	 */
+	ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD1_SRVID, data);
+
+
+	/* wait for a final message from child 2 it has received the lock
+	   which indicates success */
 	while (num_msg!=4) {
 		event_loop_once(ev);
 	}
-	printf("Child 2 has fetched and locked the record\n");
-
-
-	while (1) {
-		event_loop_once(ev);
-	}
+	printf("child 2 aquired the lock after child 1 terminated:SUCCESS\n");
+
+	/* send a message to child 2 to tell it to terminate too */
+	ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), CHILD2_SRVID, data);
+
+
+	printf("Test was SUCCESSFUL\n");
 
 	/* shut it down */
 	talloc_free(ctdb);



More information about the samba-cvs mailing list