- 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
-
- # Upgrade or downgrade schema and compact database.
+ 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"
+
+ # Compact database. This is important if the old schema did not enable
+ # garbage collection (i.e. if it did not have any tables with "isRoot":
+ # true) but the new schema does. In that situation the old database
+ # may contain a transaction that creates a record followed by a
+ # transaction that creates the first use of the record. Replaying that
+ # series of transactions against the new database schema (as "convert"
+ # does) would cause the record to be dropped by the first transaction,
+ # then the second transaction would cause a referential integrity
+ # failure (for a strong reference).
+ $ovsdb_tool -vANY:console:emer compact "$OVSDB_SERVER_DB"
+
+ # Upgrade or downgrade schema.