[SCM] CTDB repository - branch 1.2.40 updated - ctdb-1.2.52-2-g046f879

Amitay Isaacs amitay at samba.org
Thu Oct 25 23:19:34 MDT 2012


The branch, 1.2.40 has been updated
       via  046f8799361794997cedae3d4ff812216661e04e (commit)
       via  f1f2a3b74674120993bf7a51ecb1437095eb9318 (commit)
      from  39196986c69f3a7751f2b3a69f242263d6864514 (commit)

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


- Log -----------------------------------------------------------------
commit 046f8799361794997cedae3d4ff812216661e04e
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Fri Oct 26 16:19:35 2012 +1100

    New version 1.2.53
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>

commit f1f2a3b74674120993bf7a51ecb1437095eb9318
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Mar 28 14:50:36 2012 +1100

    Initscript - add backup of corrupt non-persistent databases
    
    Corrupt non-persistent databases never get analysed because ctdbd
    zeroes them at startup.
    
    Modify the initscript so that corrupt non-persistent databases are
    moved aside to a backup.  If the number of backups for a particular
    database exceeds $CTDB_MAX_CORRUPT_DB_BACKUPS (default 10) then the
    oldest excess backups are garbage collected.
    
    Abstracts from and cleans up the code for checking persistent
    databases.
    
    Logging of related messages is done to syslog or a log file as
    specified.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    
    Cherry-picked-from: 00cd75595685dae829758abf1a4cb644af7ed50e
    
    Conflicts:
    	config/ctdb.init

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

Summary of changes:
 config/ctdb.init           |  156 ++++++++++++++++++++++++++------------------
 packaging/RPM/ctdb.spec.in |    4 +-
 2 files changed, 96 insertions(+), 64 deletions(-)


Changeset truncated at 500 lines:

diff --git a/config/ctdb.init b/config/ctdb.init
index 68850c0..7c75726 100755
--- a/config/ctdb.init
+++ b/config/ctdb.init
@@ -111,85 +111,112 @@ build_ctdb_options () {
     maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
 }
 
-check_tdb () {
-	local PDBASE=$1
-
-	test x"$TDBTOOL_HAS_CHECK" = x"1" && {
-		#
-		# Note tdbtool always exits with 0
-		#
-		local OK=`/usr/bin/tdbtool $PDBASE check | grep "Database integrity is OK" | wc -l`
-		test x"$OK" = x"1" || {
-			return 1;
-		}
-
-		return 0;
-	}
-
-	/usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
-		return $?;
-	}
-
-	return 0;
-}
-
-check_persistent_databases () {
-    PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
-    mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
-    local ERRCOUNT=$CTDB_MAX_PERSISTENT_CHECK_ERRORS
+# Log given message or stdin to either syslog or a CTDB log file
+do_log ()
+{
+    if [ "$CTDB_SYSLOG" = "yes" -o \
+	"${CTDB_OPTIONS#*--syslog}" != "$CTDB_OPTIONS" ] ; then
 
-    test -z "$ERRCOUNT" && {
-	ERRCOUNT="0"
-    }
-    test x"$ERRCOUNT" != x"0" && {
-	return 0;
-    }
-
-    if test -x /usr/bin/tdbtool ; then
-        HAVE_TDBTOOL=1
+	logger -t "ctdb.init" "$@"
     else
-        HAVE_TDBTOOL=0
+	_l="${CTDB_LOGFILE:-/var/log/log.ctdb}"
+	{
+	    date
+	    if [ -n "$*" ] ; then
+		echo "$*"
+	    else
+		cat
+	    fi
+	} >>"$_l"
     fi
+}
 
-    if test x"$HAVE_TDBTOOL" = x"1" ; then
-        TDBTOOL_HAS_CHECK=`echo "help" | /usr/bin/tdbtool | grep check | wc -l`
+select_tdb_checker ()
+{
+    # Find the best TDB consistency check available.
+    use_tdb_tool_check=false
+    if [ -x /usr/bin/tdbtool ] && \
+	echo "help" | /usr/bin/tdbtool | grep -q check ; then
+
+	use_tdb_tool_check=true
+    elif [ -x /usr/bin/tdbtool -a -x /usr/bin/tdbdump ] ; then
+	    do_log <<EOF
+WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
+ Using 'tdbdump' for database checks.
+ Consider updating 'tdbtool' for better checks!
+EOF
+    elif [ -x /usr/bin/tdbdump ] ; then
+	do_log <<EOF
+WARNING: 'tdbtool' is not available.
+ Using 'tdbdump' to check the databases.
+ Consider installing a recent 'tdbtool' for better checks!
+EOF
     else
-        TDBTOOL_HAS_CHECK=0
+	do_log <<EOF
+WARNING: Cannot check databases since neither
+ 'tdbdump' nor 'tdbtool check' is available.
+ Consider installing tdbtool or at least tdbdump!
+EOF
+        return 1
     fi
+}
+
+check_tdb ()
+{
+    _db="$1"
 
-    if test -x /usr/bin/tdbdump ; then
-        HAVE_TDBDUMP=1
+    if $use_tdb_tool_check ; then
+	# tdbtool always exits with 0  :-(
+	if tdbtool "$_db" check 2>/dev/null |
+	    grep -q "Database integrity is OK" ; then
+	    return 0
+	else
+	    return 1
+	fi
     else
-        HAVE_TDBDUMP=0
+	tdbdump "$_db" >/dev/null 2>/dev/null
+	return $?
     fi
+}
 
-    if test x"$HAVE_TDBDUMP" = x"0" -a x"$TDBTOOL_HAS_CHECK" = x"0" ; then
-        echo "WARNING: Cannot check persistent databases since"
-        echo "neither 'tdbdump' nor 'tdbtool check' is available."
-        echo "Consider installing tdbtool or at least tdbdump!"
-        return 0
-    fi
+check_persistent_databases ()
+{
+    _dir="${CTDB_DBDIR_PERSISTENT:-${CTDB_DBDIR:-/var/ctdb}/persistent}"
+    mkdir -p "$_dir" 2>/dev/null
 
-    if test x"$HAVE_TDBDUMP" = x"1" -a x"$TDBTOOL_HAS_CHECK" = x"0" ; then
-        if test x"$HAVE_TDBTOOL" = x"0"; then
-            echo "WARNING: 'tdbtool' is not available. Using 'tdbdump' to"
-            echo "check the persistent databases."
-            echo "Consider installing a recent 'tdbtool' for better checks!"
-        else
-            echo "WARNING: The installed 'tdbtool' does not offer the 'check'"
-            echo "subcommand. Using 'tdbdump' for persistent database checks."
-            echo "Consider updating 'tdbtool' for better checks!"
-        fi
-    fi
+    [ "${CTDB_MAX_PERSISTENT_CHECK_ERRORS:-0}" = "0" ] || return 0
 
-    for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
-	check_tdb $PDBASE || {
-	    echo "Persistent database $PDBASE is corrupted! CTDB will not start."
+    for _db in $(ls "$_dir/"*.tdb.*[0-9] 2>/dev/null) ; do
+	check_tdb $_db || {
+	    do_log "Persistent database $_db is corrupted! CTDB will not start."
 	    return 1
 	}
     done
 }
 
+check_non_persistent_databases ()
+{
+    _dir="${CTDB_DBDIR:-/var/ctdb}"
+    mkdir -p "$_dir" 2>/dev/null
+
+    for _db in $(ls "${_dir}/"*.tdb.*[0-9] 2>/dev/null) ; do
+	check_tdb $_db || {
+	    _backup="${_db}.$(date +'%Y%m%d.%H%M%S.%N').corrupt"
+	    do_log <<EOF
+WARNING: database ${_db} is corrupted.
+ Moving to backup ${_backup} for later analysis.
+EOF
+	    mv "$_db" "$_backup"
+
+	    # Now remove excess backups
+	    ls -td "${_db}."*".corrupt" |
+	    tail -n +$((${CTDB_MAX_CORRUPT_DB_BACKUPS:-10} + 1)) |
+	    xargs rm -f
+	    
+	}
+    done
+}
+
 set_ctdb_variables () {
     # set any tunables from the config file
     set | grep ^CTDB_SET_ | cut -d_ -f3- | 
@@ -249,7 +276,10 @@ start() {
     # instance of ctdb got killed with -9 or similar
     drop_all_public_ips
 
-    check_persistent_databases || return $?
+    if select_tdb_checker ; then
+	check_persistent_databases || return $?
+	check_non_persistent_databases
+    fi
 
     if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
 	ulimit -c 0
diff --git a/packaging/RPM/ctdb.spec.in b/packaging/RPM/ctdb.spec.in
index 73a49b7..0e36858 100644
--- a/packaging/RPM/ctdb.spec.in
+++ b/packaging/RPM/ctdb.spec.in
@@ -3,7 +3,7 @@ Name: ctdb
 Summary: Clustered TDB
 Vendor: Samba Team
 Packager: Samba Team <samba at samba.org>
-Version: 1.2.52
+Version: 1.2.53
 Release: 1GITHASH
 Epoch: 0
 License: GNU GPL version 3
@@ -146,6 +146,8 @@ development libraries for ctdb
 
 %changelog
 
+* Fri Oct 26 2012 : Version 1.2.53
+  - Initscript: backup corrupt non-persistent database before starting CTDB
 * Fri Oct 05 2012 : Version 1.2.52
   - util: ctdb_fork() closes all sockets opened by the main daemon
 * Tue Oct 02 2012 : Version 1.2.51


-- 
CTDB repository


More information about the samba-cvs mailing list