diff options
| -rw-r--r-- | src/rabbit_recovery_terms.erl | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/rabbit_recovery_terms.erl b/src/rabbit_recovery_terms.erl index 41327147d0..9c0559ea16 100644 --- a/src/rabbit_recovery_terms.erl +++ b/src/rabbit_recovery_terms.erl @@ -193,12 +193,37 @@ code_change(_OldVsn, State, _Extra) -> %%---------------------------------------------------------------------------- +-spec open_table(vhost:name()) -> rabbit_types:ok_or_error(any()). + open_table(VHost) -> + open_table(VHost, 10). + +-spec open_table(vhost:name(), non_neg_integer()) -> rabbit_types:ok_or_error(any()). + +open_table(VHost, RetriesLeft) -> VHostDir = rabbit_vhost:msg_store_dir_path(VHost), File = filename:join(VHostDir, "recovery.dets"), - {ok, _} = dets:open_file(VHost, [{file, File}, - {ram_file, true}, - {auto_save, infinity}]). + Opts = [{file, File}, + {ram_file, true}, + {auto_save, infinity}], + case dets:open_file(VHost, Opts) of + {ok, _} -> ok; + {error, Error} -> + case RetriesLeft of + 0 -> + {error, Error}; + N when is_integer(N) -> + _ = file:delete(File), + %% Wait before retrying + DelayInMs = 1000, + rabbit_log:warning("Failed to open a recovery terms DETS file at ~p. Will delete it and retry in ~p ms (~p retries left)", + [File, DelayInMs, RetriesLeft]), + timer:sleep(DelayInMs), + open_table(VHost, RetriesLeft - 1) + end + end. + +-spec flush(vhost:name()) -> rabbit_types:ok_or_error(any()). flush(VHost) -> try @@ -210,6 +235,8 @@ flush(VHost) -> ok end. +-spec close_table(vhost:name()) -> rabbit_types:ok_or_error(any()). + close_table(VHost) -> try ok = flush(VHost), |
