@@ -142,6 +142,17 @@ function ovn_db_pre_start() {
142
142
local db_file=" /etc/ovn/ovn${1} _db.db"
143
143
if [ -e " $db_file " ]; then
144
144
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
+
145
156
if ! ovsdb-tool check-cluster " $db_file " ; then
146
157
echo " detected database corruption for file $db_file , rebuild it."
147
158
local sid=$( ovsdb-tool db-sid " $db_file " )
@@ -164,12 +175,12 @@ function ovn_db_pre_start() {
164
175
done
165
176
echo " remote addresses: ${remote_addr[*]} "
166
177
167
- local db_new=" $db_file .init-$( random_str) "
178
+ local db_new=" $db_file .init-$( date +%s ) - $( random_str) "
168
179
echo " generating new database file $db_new "
169
180
if [ ${# remote_addr[*]} -ne 0 ]; then
170
181
ovsdb-tool --sid $sid join-cluster " $db_new " $db $local_addr ${remote_addr[*]} || return 1
171
182
172
- local db_bak=" $db_file .backup-$( random_str) "
183
+ local db_bak=" $db_file .backup-$( date +%s ) - $( random_str) "
173
184
echo " backup $db_file to $db_bak "
174
185
mv " $db_file " " $db_bak " || return 1
175
186
0 commit comments