Rev 330: start ctdb frozen, and let the election sort things out. This prevents a race on startup in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Wed May 23 02:23:07 GMT 2007


------------------------------------------------------------
revno: 330
revision-id: tridge at samba.org-20070523022307-ex37iunuyobmmun3
parent: tridge at samba.org-20070522031451-628wjb3bbna6p4vc
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Wed 2007-05-23 12:23:07 +1000
message:
  start ctdb frozen, and let the election sort things out. This prevents a race on startup
modified:
  common/ctdb_daemon.c           ctdb_daemon.c-20070409200331-3el1kqgdb9m4ib0g-1
  common/ctdb_freeze.c           ctdb_freeze.c-20070512051503-935zdtyuqknqnhmo-1
  include/ctdb_private.h         ctdb_private.h-20061117234101-o3qt14umlg9en8z0-13
=== modified file 'common/ctdb_daemon.c'
--- a/common/ctdb_daemon.c	2007-05-19 03:45:24 +0000
+++ b/common/ctdb_daemon.c	2007-05-23 02:23:07 +0000
@@ -745,12 +745,24 @@
 	talloc_set_destructor(domain_socket_name, unlink_destructor);	
 
 	ctdb->ev = event_context_init(NULL);
-	fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd, EVENT_FD_READ|EVENT_FD_AUTOCLOSE, 
-			   ctdb_accept_client, ctdb);
 
 	/* start monitoring for dead nodes */
 	ctdb_start_monitoring(ctdb);
 
+	/* start frozen, then let the first election sort things out */
+	if (!ctdb_blocking_freeze(ctdb)) {
+		DEBUG(0,("Failed to get initial freeze\n"));
+		exit(12);
+	}
+
+	/* force initial recovery for election */
+	ctdb->recovery_mode = CTDB_RECOVERY_ACTIVE;
+
+	/* now start accepting clients, only can do this once frozen */
+	fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd, 
+			   EVENT_FD_READ|EVENT_FD_AUTOCLOSE, 
+			   ctdb_accept_client, ctdb);
+
 	ctdb_main_loop(ctdb);
 
 	return 0;

=== modified file 'common/ctdb_freeze.c'
--- a/common/ctdb_freeze.c	2007-05-18 14:56:49 +0000
+++ b/common/ctdb_freeze.c	2007-05-23 02:23:07 +0000
@@ -215,6 +215,32 @@
 }
 
 
+/*
+  block until we are frozen, used during daemon startup
+ */
+bool ctdb_blocking_freeze(struct ctdb_context *ctdb)
+{
+	if (ctdb->freeze_mode == CTDB_FREEZE_FROZEN) {
+		/* we're already frozen */
+		return true;
+	}
+
+	/* if there isn't a freeze lock child then create one */
+	if (!ctdb->freeze_handle) {
+		ctdb->freeze_handle = ctdb_freeze_lock(ctdb);
+		CTDB_NO_MEMORY(ctdb, ctdb->freeze_handle);
+		ctdb->freeze_mode = CTDB_FREEZE_PENDING;
+	}
+
+	/* block until frozen */
+	while (ctdb->freeze_mode == CTDB_FREEZE_PENDING) {
+		event_loop_once(ctdb->ev);
+	}
+
+	return ctdb->freeze_mode == CTDB_FREEZE_FROZEN;
+}
+
+
 
 /*
   thaw the databases

=== modified file 'include/ctdb_private.h'
--- a/include/ctdb_private.h	2007-05-19 07:21:58 +0000
+++ b/include/ctdb_private.h	2007-05-23 02:23:07 +0000
@@ -828,5 +828,6 @@
 void ctdb_call_resend_all(struct ctdb_context *ctdb);
 void ctdb_node_dead(struct ctdb_node *node);
 void ctdb_node_connected(struct ctdb_node *node);
+bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
 
 #endif



More information about the samba-cvs mailing list