[SCM] CTDB repository - branch 1.2 updated - ctdb-1.0.114-279-gbffaece
Ronnie Sahlberg
sahlberg at samba.org
Tue Aug 24 19:51:07 MDT 2010
The branch, 1.2 has been updated
via bffaecee9a91d972a1697101aee7b40fbb87edbf (commit)
via 6b4b754758bde58e04ef6d3b57c723ff4a18e910 (commit)
via 41ab1520ad72e8c7b6b56d5339ada910b63ad713 (commit)
via 16b5586761aeac99524557eaf82019e9f052a9e6 (commit)
via 8aa1d812e09f8059610d28486fb566c783340d3a (commit)
via 796291358b4c5f775f10cb549d09561bf4c9b429 (commit)
via 0383f6cf386ea3738404f3e1446912881b34b9b3 (commit)
from 1d33782334f83aa768d6effc5fa207a52cd29177 (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=1.2
- Log -----------------------------------------------------------------
commit bffaecee9a91d972a1697101aee7b40fbb87edbf
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 6b4b754758bde58e04ef6d3b57c723ff4a18e910
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 41ab1520ad72e8c7b6b56d5339ada910b63ad713
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 16b5586761aeac99524557eaf82019e9f052a9e6
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Wed Aug 25 10:39:33 2010 +1000
Dont initialize the domain socket for commands that do not require/use
the daemon
commit 8aa1d812e09f8059610d28486fb566c783340d3a
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 796291358b4c5f775f10cb549d09561bf4c9b429
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 0383f6cf386ea3738404f3e1446912881b34b9b3
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 | 76 ++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 90 insertions(+), 13 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 37bb557..2a9eb49 100644
--- a/tools/ctdb.c
+++ b/tools/ctdb.c
@@ -2828,7 +2828,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);
@@ -2874,7 +2874,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);
@@ -2885,6 +2896,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)
@@ -4658,9 +4717,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>]" },
};
/*
@@ -4787,12 +4847,12 @@ int main(int argc, const char *argv[])
close(2);
}
- /* initialise ctdb */
- ctdb = ctdb_cmdline_client(ev);
-
if (ctdb_commands[i].without_daemon == false) {
const char *socket_name;
+ /* initialise ctdb */
+ ctdb = ctdb_cmdline_client(ev);
+
if (ctdb == NULL) {
DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));
exit(1);
--
CTDB repository
More information about the samba-cvs
mailing list