Skip to content

Commit 7f111db

Browse files
committed
ovn: fix corrupted database file on start (#3112)
1 parent a11d7e9 commit 7f111db

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

dist/images/Dockerfile.base

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ RUN cd /usr/src/ && \
2828
curl -s https://github.com/kubeovn/ovs/commit/b721a251dadfb0857a2aebe32611d18ca935421f.patch | git apply && \
2929
# ovsdb-tool: add optional server id parameter for "join-cluster" command
3030
curl -s https://github.com/kubeovn/ovs/commit/0664cbe47d1684ca5b7147e3449779635454970e.patch | git apply && \
31+
# ovsdb-tool: add command fix-cluster
32+
curl -s https://github.com/kubeovn/ovs/commit/f52c239f5ded40b503e4d217f916b46ca413da4c.patch | git apply && \
3133
# fix memory leak in qos
3234
curl -s https://github.com/kubeovn/ovs/commit/6a4dd2f4b9311a227cc26fef7c398ae9b241311b.patch | git apply && \
3335
# compile without avx512

dist/images/start-db.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ function ovn_db_pre_start() {
124124
! ovsdb-tool db-is-clustered "$db_file" && return
125125
ovsdb-tool check-cluster "$db_file" && return
126126

127-
echo "detected database corruption for file $db_file, rebuild it."
127+
local db_bak="$db_file.backup-$(date +%s)-$(random_str)"
128+
echo "backup $db_file to $db_bak"
129+
cp "$db_file" "$db_bak" || return 1
130+
131+
echo "detected database corruption for file $db_file, try to fix it."
132+
ovsdb-tool fix-cluster "$db_file" && return
133+
134+
echo "failed to fix database file $db_file, rebuild it."
128135
local sid=$(ovsdb-tool db-sid "$db_file")
129136
if ! echo -n "$sid" | grep -qE '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'; then
130137
echo "failed to get sid from $1 db file $db_file"
@@ -148,10 +155,6 @@ function ovn_db_pre_start() {
148155
echo "generating new database file $db_new"
149156
ovsdb-tool --sid $sid join-cluster "$db_new" $db $local_addr ${remote_addr[*]} || return 1
150157

151-
local db_bak="$db_file.backup-$(random_str)"
152-
echo "backup $db_file to $db_bak"
153-
mv "$db_file" "$db_bak" || return 1
154-
155158
echo "use new database file $db_new"
156159
mv "$db_new" "$db_file"
157160
}

0 commit comments

Comments
 (0)