auto-run the vacuum and repack ops every 5 minutes by default
authorAndrew Tridgell <tridge@samba.org>
Wed, 9 Jan 2008 23:04:03 +0000 (10:04 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 9 Jan 2008 23:04:03 +0000 (10:04 +1100)
config/events.d/00.ctdb

index fc82dbfac947857898539db6642e65d32a30e9c6..001544e5e83ba7a85c229c9fa942623301ed0b23 100755 (executable)
@@ -18,6 +18,18 @@ PATH=/bin:/usr/bin:$PATH
 cmd="$1"
 shift
 
+# set default samba cleanup period - in minutes
+[ -z "$CTDB_VACUUM_PERIOD" ] && {
+    CTDB_VACUUM_PERIOD=5
+}
+
+###########################
+# periodic vacuum function
+periodic_vacuum() {
+    # this cleans up dead records and repacks the databases
+    ( time ctdb vacuum 200000 -T 30; time ctdb repack -T 30 ) > $CTDB_BASE/state/vacuum.log 2>&1 &
+}
+
 case $cmd in 
      startup)
         # make sure we have a blank state directory for the scripts to work with
@@ -33,6 +45,19 @@ case $cmd in
            echo "`date` Set $varname to $value"
        done || exit 1
        ;;
+
+    monitor)
+       # Create a dummy file to track when we need to do periodic cleanup
+       # of samba databases
+       [ -f $CTDB_BASE/state/periodic_vacuum ] || {
+               touch $CTDB_BASE/state/periodic_vacuum
+       }
+       [ `/usr/bin/find $CTDB_BASE/state/periodic_vacuum -mmin +$CTDB_VACUUM_PERIOD | wc -l` -eq 1 ] && {
+               # vacuum the databases
+               touch $CTDB_BASE/state/periodic_vacuum
+               periodic_vacuum
+       }
+       
 esac
 
 # all OK