Skip to content

Commit 3c6d6bc

Browse files
authored
ovn: delete the db file if the node with new empty db file cannot join cluster for more than 120s (#3101)
1 parent 914bf61 commit 3c6d6bc

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

dist/images/start-db.sh

+13-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ function ovn_db_pre_start() {
142142
local db_file="/etc/ovn/ovn${1}_db.db"
143143
if [ -e "$db_file" ]; then
144144
if ovsdb-tool db-is-clustered "$db_file"; then
145+
local msg=$(ovsdb-tool check-cluster "$db_file" 2>&1) || true
146+
if echo $msg | grep -q 'has not joined the cluster'; then
147+
local birth_time=$(stat --format=%W $db_file)
148+
local now=$(date +%s)
149+
if [ $(($now - $birth_time)) -ge 120 ]; then
150+
echo "ovn db file $db_file exists for more than 120s, removing it..."
151+
rm -f "$db_file" || return 1
152+
fi
153+
return
154+
fi
155+
145156
if ! ovsdb-tool check-cluster "$db_file"; then
146157
echo "detected database corruption for file $db_file, rebuild it."
147158
local sid=$(ovsdb-tool db-sid "$db_file")
@@ -164,12 +175,12 @@ function ovn_db_pre_start() {
164175
done
165176
echo "remote addresses: ${remote_addr[*]}"
166177

167-
local db_new="$db_file.init-$(random_str)"
178+
local db_new="$db_file.init-$(date +%s)-$(random_str)"
168179
echo "generating new database file $db_new"
169180
if [ ${#remote_addr[*]} -ne 0 ]; then
170181
ovsdb-tool --sid $sid join-cluster "$db_new" $db $local_addr ${remote_addr[*]} || return 1
171182

172-
local db_bak="$db_file.backup-$(random_str)"
183+
local db_bak="$db_file.backup-$(date +%s)-$(random_str)"
173184
echo "backup $db_file to $db_bak"
174185
mv "$db_file" "$db_bak" || return 1
175186

0 commit comments

Comments
 (0)