Avoid unneeded database compaction at startup, and improve backups.
authorBen Pfaff <blp@nicira.com>
Tue, 15 Feb 2011 18:17:44 +0000 (10:17 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 15 Feb 2011 20:24:29 +0000 (12:24 -0800)
Until now, Open vSwitch "start" has always converted the database to the
current database schema.  This compacts the database, which as a side
effect throws away useful information about the transactions that were
executed to bring the database into its current state.  This can make
debugging database-related problems more difficult.

This commit changes the "start" command to only convert the database if
the database schema has changed.  It also adds the database checksum to
the backup file name, to avoid overwriting backups in the case where the
checksum changed but the developer neglected to update the version number.

I tested an earlier version of the xenserver changes but not any version
of the Debian changes.

debian/openvswitch-switch.init
xenserver/etc_init.d_openvswitch

index 60cc369f54a376bb541cff089ac6645c72e65e86..29c8c655efedaab4b7ac01a6f4c268b91081a76c 100755 (executable)
@@ -226,12 +226,11 @@ case "$1" in
         if test ! -e $conf_file; then
             # Create configuration database.
             ovsdb-tool -vANY:console:emer create $conf_file $schema_file
-        else
-            # If schema version changed, then back up the old version.
-            old_ver=`ovsdb-tool db-version "$conf_file"`
-            if test "X$old_ver" != "X$schema_ver"; then
-                cp "$conf_file" "$conf_file.backup$old_ver"
-            fi
+        elif test "X`ovsdb-tool needs-conversion $conf_file $schema_file`" != Xno; then
+            # Back up the old version.
+            version=`ovsdb-tool db-version "$conf_file"`
+            cksum=`ovsdb-tool db-cksum "$conf_file" | awk '{print $1}'`
+            cp "$conf_file" "$conf_file.backup$version-$cksum"
             
             # Upgrade or downgrade schema and compact database.
             ovsdb-tool -vANY:console:emer convert $conf_file $schema_file
index 34fbc97358d0083c85ab3debdb7a3277b5538c8d..cbd2eee125c7c48fbbefcce447a8843fc183b184 100755 (executable)
@@ -335,14 +335,11 @@ function start {
 
         action "Creating empty database $OVSDB_SERVER_DB" true
         $ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
-    else
-        # If schema version changed, then back up the old version.
-        oldver=`$ovsdb_tool db-version "$OVSDB_SERVER_DB"`
-        if test "X$oldver" != "X$schemaver"; then
-            backup=$OVSDB_SERVER_DB.backup$oldver
-            action "Backing up $OVSDB_SERVER_DB in $backup before converting from schema version \"$oldver\" to \"$schemaver\"" true
-            cp "$OVSDB_SERVER_DB" "$backup"
-        fi
+    elif test "X`$ovsdb_tool needs-conversion "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"`" != Xno; then
+        # Back up the old version.
+        version=`$ovsdb_tool db-version "$OVSDB_SERVER_DB"`
+        cksum=`$ovsdb_tool db-cksum "$OVSDB_SERVER_DB" | awk '{print $1}'`
+        cp "$OVSDB_SERVER_DB" "$OVSDB_SERVER_DB.backup$version-$cksum"
 
         # Upgrade or downgrade schema and compact database.
         $ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"