[SCM] CTDB repository - branch master updated - ctdb-1.0.114-274-g292d743

Ronnie Sahlberg sahlberg at samba.org
Tue Aug 24 19:51:07 MDT 2010


The branch, master has been updated
       via  292d7435a360efd7f15a7a99f658a605e07c0a81 (commit)
       via  9999771105d7105efaa232fe2842e21e66f78706 (commit)
       via  c3a816e5174abefb5155f65d8faad7b1e831e481 (commit)
       via  87160c91bfd87e8b9c510dacbf00e5aa481d2305 (commit)
       via  6c93bf5a1219617bfb39b093aee3200c74c2c61a (commit)
       via  6d7e62f5401f0647a519fe0b74ec628418e33231 (commit)
      from  14184ab7c80a3ef16c54b4ab168fd635b7add445 (commit)

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


- Log -----------------------------------------------------------------
commit 292d7435a360efd7f15a7a99f658a605e07c0a81
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 25 11:37:32 2010 +1000

    Add a configuration database, implemented as a persistent database.
    
    This database can be used, as an option, to store
    the public address assignment instead of editing the /etc/ctdb/public-addresses file manually.
    
    This configuration is stored in one record per key, with a key-name of
    public-addresses:node#<pnn>
    where <pnn> is the node number.
    
    The content of this record is the same syntax as the /etc/ctdb/public-addresses file.
    
    When ctdbd starts, if this key exist and contains data. It is extracted from the database and compared with the normal file /etc/ctdb/public-addresses.
    
    If the content differs, the config database "wins" and is used to overwrite/update the /etc/ctdb/public-addresses file, after which ctdbd is restarted.
    
    The main benefit with this option is that it can be used to update the public address configuration for nodes that are offline/unreachable by updating their configuration in the persistent database.
    Once the offline node is available again, it will resync its databases with the rest of the cluster, find out that the config has changed, apply the changes and restart ctdbd automatically.
    
    The command to store the public address configuration for a node into the persistent database is :
    
    ctdb pstore config.tdb public-addresses:node#<pnn> <filename>
    
    where <pnn> is the node# we wish to update the config for, and <filename> is a file containing the new content for  that nodes public address configuration.

commit 9999771105d7105efaa232fe2842e21e66f78706
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 25 11:10:08 2010 +1000

    the tfetch command can be used without the daemon running, so flag it as such.
    
    fix a couple of incorrect settings for "auto-all" for a few of the commands as well.

commit c3a816e5174abefb5155f65d8faad7b1e831e481
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 25 10:53:54 2010 +1000

    add a new command "ctdb tfetch" that can read a record straight out of the
    tdb file.
    
    the command automatically strips off the initial ctdb header off the record so it can only be used on ctdb managed tdb files, not on normal tdb files.

commit 87160c91bfd87e8b9c510dacbf00e5aa481d2305
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 25 09:54:37 2010 +1000

    When "ctdb pfetch" creates a new file, make sure we set some initial sane mode bits

commit 6c93bf5a1219617bfb39b093aee3200c74c2c61a
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 25 08:34:35 2010 +1000

    run the "init" event before we freeze the databases
    so that we can read from databases during this event

commit 6d7e62f5401f0647a519fe0b74ec628418e33231
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Wed Aug 25 08:07:03 2010 +1000

    change "ctdb pfetch" to take an optional third argument
    as a file to store the record in.

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

Summary of changes:
 config/events.d/00.ctdb |   17 +++++++++++
 server/ctdb_daemon.c    |   10 +++---
 tools/ctdb.c            |   70 +++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 87 insertions(+), 10 deletions(-)


Changeset truncated at 500 lines:

diff --git a/config/events.d/00.ctdb b/config/events.d/00.ctdb
index bfebcd2..7e9e386 100755
--- a/config/events.d/00.ctdb
+++ b/config/events.d/00.ctdb
@@ -34,6 +34,23 @@ case "$1" in
 	done || exit 1
 	;;
 
+    startup)
+	# Pull optional ctdb configuration data out of config.tdb
+	PUBLICADDRESSESKEY='public-addresses:node#'`ctdb -t 1 xpnn|sed -e "s/.*://"`
+	rm -f $CTDB_BASE/state/public_addresses
+	ctdb pfetch config.tdb $PUBLICADDRESSESKEY $CTDB_BASE/state/public_addresses
+	[ "$?" = "0" ] && [ `stat --format="%s" /etc/ctdb/state/public_addresses` != "0" ] && [ ! -z "$CTDB_PUBLIC_ADDRESSES" ] && {
+		diff $CTDB_BASE/state/public_addresses $CTDB_PUBLIC_ADDRESSES >/dev/null 2>/dev/null
+		[ $? = "0" ] || {
+			echo CTDB public address configuration had been updated.
+			echo Extracting new configuration from database.
+			diff $CTDB_BASE/state/public_addresses $CTDB_PUBLIC_ADDRESSES
+			cp $CTDB_BASE/state/public_addresses $CTDB_PUBLIC_ADDRESSES
+			echo Restarting CTDB
+			service ctdb restart &
+		}
+	}
+	;;
     monitor)
 	# We should never enter swap, so SwapTotal == SwapFree.
 	[ "$CTDB_CHECK_SWAP_IS_NOT_USED" = "yes" ] && {
diff --git a/server/ctdb_daemon.c b/server/ctdb_daemon.c
index 1d80305..5d73b0d 100644
--- a/server/ctdb_daemon.c
+++ b/server/ctdb_daemon.c
@@ -810,17 +810,17 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
 		ctdb_fatal(ctdb, "Failed to attach to databases\n");
 	}
 
-	/* start frozen, then let the first election sort things out */
-	if (ctdb_blocking_freeze(ctdb)) {
-		ctdb_fatal(ctdb, "Failed to get initial freeze\n");
-	}
-
 	ret = ctdb_event_script(ctdb, CTDB_EVENT_INIT);
 	if (ret != 0) {
 		ctdb_fatal(ctdb, "Failed to run init event\n");
 	}
 	ctdb_run_notification_script(ctdb, "init");
 
+	/* start frozen, then let the first election sort things out */
+	if (ctdb_blocking_freeze(ctdb)) {
+		ctdb_fatal(ctdb, "Failed to get initial freeze\n");
+	}
+
 	/* now start accepting clients, only can do this once frozen */
 	fde = event_add_fd(ctdb->ev, ctdb, ctdb->daemon.sd, 
 			   EVENT_FD_READ,
diff --git a/tools/ctdb.c b/tools/ctdb.c
index b986f4e..076e6d3 100644
--- a/tools/ctdb.c
+++ b/tools/ctdb.c
@@ -2866,7 +2866,7 @@ static int control_pfetch(struct ctdb_context *ctdb, int argc, const char **argv
 	TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
 	struct ctdb_transaction_handle *h;
 	TDB_DATA key, data;
-	int ret;
+	int fd, ret;
 
 	if (argc < 2) {
 		talloc_free(tmp_ctx);
@@ -2912,7 +2912,18 @@ static int control_pfetch(struct ctdb_context *ctdb, int argc, const char **argv
 		return -1;
 	}
 
-	fwrite(data.dptr, data.dsize, 1, stdout);
+	if (argc == 3) {
+	  fd = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0600);
+		if (fd == -1) {
+			DEBUG(DEBUG_ERR,("Failed to open output file %s\n", argv[2]));
+			talloc_free(tmp_ctx);
+			return -1;
+		}
+		write(fd, data.dptr, data.dsize);
+		close(fd);
+	} else {
+		write(1, data.dptr, data.dsize);
+	}
 
 	/* abort the transaction */
 	talloc_free(h);
@@ -2923,6 +2934,54 @@ static int control_pfetch(struct ctdb_context *ctdb, int argc, const char **argv
 }
 
 /*
+  fetch a record from a tdb-file
+ */
+static int control_tfetch(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+	const char *tdb_file;
+	TDB_CONTEXT *tdb;
+	TDB_DATA key, data;
+	int fd;
+
+	if (argc < 2) {
+		usage();
+	}
+
+	tdb_file = argv[0];
+
+	tdb = tdb_open(tdb_file, 0, 0, O_RDONLY, 0);
+	if (tdb == NULL) {
+		DEBUG(DEBUG_ERR,("Failed to open TDB file %s\n", tdb_file));
+		return -1;
+	}
+
+	key.dptr  = discard_const(argv[1]);
+	key.dsize = strlen(argv[1]);
+	data = tdb_fetch(tdb, key);
+	if (data.dptr == NULL || data.dsize < sizeof(struct ctdb_ltdb_header)) {
+		DEBUG(DEBUG_ERR,("Failed to read record %s from tdb %s\n", argv[1], tdb_file));
+		tdb_close(tdb);
+		return -1;
+	}
+
+	tdb_close(tdb);
+
+	if (argc == 3) {
+	  fd = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0600);
+		if (fd == -1) {
+			DEBUG(DEBUG_ERR,("Failed to open output file %s\n", argv[2]));
+			return -1;
+		}
+		write(fd, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
+		close(fd);
+	} else {
+		write(1, data.dptr+sizeof(struct ctdb_ltdb_header), data.dsize-sizeof(struct ctdb_ltdb_header));
+	}
+
+	return 0;
+}
+
+/*
   write a record to a persistent database
  */
 static int control_pstore(struct ctdb_context *ctdb, int argc, const char **argv)
@@ -4696,9 +4755,10 @@ static const struct {
 	{ "getdbprio",        control_getdbprio,	false,	false, "Get DB priority", "<dbid>"},
 	{ "msglisten",        control_msglisten,	false,	false, "Listen on a srvid port for messages", "<msg srvid>"},
 	{ "msgsend",          control_msgsend,	false,	false, "Send a message to srvid", "<srvid> <message>"},
-	{ "sync", 	     control_ipreallocate,      true,	false,  "wait until ctdbd has synced all state changes" },
-	{ "pfetch", 	     control_pfetch,      	true,	false,  "fetch a record from a persistent database", "<db> <key>" },
-	{ "pstore", 	     control_pstore,      	true,	false,  "write a record to a persistent database", "<db> <key> <file containing record>" },
+	{ "sync", 	     control_ipreallocate,      false,	false,  "wait until ctdbd has synced all state changes" },
+	{ "pfetch", 	     control_pfetch,      	false,	false,  "fetch a record from a persistent database", "<db> <key> [<file>]" },
+	{ "pstore", 	     control_pstore,      	false,	false,  "write a record to a persistent database", "<db> <key> <file containing record>" },
+	{ "tfetch", 	     control_tfetch,      	false,	true,  "fetch a record from a [c]tdb-file", "<tdb-file> <key> [<file>]" },
 };
 
 /*


-- 
CTDB repository


More information about the samba-cvs mailing list