Skip to content

Commit f8186f2

Browse files
committed
Avoid unneeded database compaction at startup, and improve backups.
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.
1 parent 403e3a2 commit f8186f2

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

debian/openvswitch-switch.init

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,11 @@ case "$1" in
226226
if test ! -e $conf_file; then
227227
# Create configuration database.
228228
ovsdb-tool -vANY:console:emer create $conf_file $schema_file
229-
else
230-
# If schema version changed, then back up the old version.
231-
old_ver=`ovsdb-tool db-version "$conf_file"`
232-
if test "X$old_ver" != "X$schema_ver"; then
233-
cp "$conf_file" "$conf_file.backup$old_ver"
234-
fi
229+
elif test "X`ovsdb-tool needs-conversion $conf_file $schema_file`" != Xno; then
230+
# Back up the old version.
231+
version=`ovsdb-tool db-version "$conf_file"`
232+
cksum=`ovsdb-tool db-cksum "$conf_file" | awk '{print $1}'`
233+
cp "$conf_file" "$conf_file.backup$version-$cksum"
235234

236235
# Upgrade or downgrade schema and compact database.
237236
ovsdb-tool -vANY:console:emer convert $conf_file $schema_file

xenserver/etc_init.d_openvswitch

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,11 @@ function start {
335335

336336
action "Creating empty database $OVSDB_SERVER_DB" true
337337
$ovsdb_tool -vANY:console:emer create "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"
338-
else
339-
# If schema version changed, then back up the old version.
340-
oldver=`$ovsdb_tool db-version "$OVSDB_SERVER_DB"`
341-
if test "X$oldver" != "X$schemaver"; then
342-
backup=$OVSDB_SERVER_DB.backup$oldver
343-
action "Backing up $OVSDB_SERVER_DB in $backup before converting from schema version \"$oldver\" to \"$schemaver\"" true
344-
cp "$OVSDB_SERVER_DB" "$backup"
345-
fi
338+
elif test "X`$ovsdb_tool needs-conversion "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"`" != Xno; then
339+
# Back up the old version.
340+
version=`$ovsdb_tool db-version "$OVSDB_SERVER_DB"`
341+
cksum=`$ovsdb_tool db-cksum "$OVSDB_SERVER_DB" | awk '{print $1}'`
342+
cp "$OVSDB_SERVER_DB" "$OVSDB_SERVER_DB.backup$version-$cksum"
346343

347344
# Upgrade or downgrade schema and compact database.
348345
$ovsdb_tool -vANY:console:emer convert "$OVSDB_SERVER_DB" "$VSWITCHD_OVSDB_SCHEMA"

0 commit comments

Comments
 (0)