Add a configuration database, implemented as a persistent database.
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 25 Aug 2010 01:37:32 +0000 (11:37 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 25 Aug 2010 01:49:56 +0000 (11:49 +1000)
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.

config/events.d/00.ctdb

index bfebcd282e0d71899fe4dd5059fb8f1d03fcad91..7e9e3869dfd8155f4ad3d0c6e770877e92670383 100755 (executable)
@@ -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" ] && {