Skip to content

Commit 0d96588

Browse files
MB-68168: Handle exdev rename error when retiring keys
It may happen that data dir and retired keys dir are located on different filesystems. In this case, the rename operation will fail with an exdev error, so we should fall back to copy+delete the file instead of renaming it. Key files are small so the performance impact of this fallback should be negligible. Change-Id: I26a71c4aaa4e65d9a098b167276835708a4bce31 Reviewed-on: https://review.couchbase.org/c/ns_server/+/232659 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Tested-by: Timofey Barmin <[email protected]> Reviewed-by: Navdeep S Boparai <[email protected]>
1 parent 81bd886 commit 0d96588

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

apps/ns_server/src/encryption_service.erl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,28 @@ retire_key(Kind, Filename) ->
978978
ok ->
979979
case misc:atomic_rename(FromPath, ToPath) of
980980
ok -> ok;
981+
{error, exdev} ->
982+
%% Cross-filesystem rename, fall back to copy + delete
983+
?log_debug("Cross-filesystem rename failed, "
984+
"will try copy+delete ~p to ~p",
985+
[FromPath, ToPath]),
986+
case file:copy(FromPath, ToPath) of
987+
{ok, _} -> ok;
988+
{error, CopyReason} ->
989+
%% Copy failed, but it is not critical enough to
990+
%% fail the whole operation, as the reason we keep
991+
%% the keys in retired_keys_dir is "just in case".
992+
%% The system can work without it.
993+
?log_error("Copy failed ~p to ~p: ~p",
994+
[FromPath, ToPath, CopyReason])
995+
end,
996+
case file:delete(FromPath) of
997+
ok -> ok;
998+
{error, DeleteReason} ->
999+
?log_error("Failed to delete file ~p: ~p",
1000+
[FromPath, DeleteReason]),
1001+
{error, DeleteReason}
1002+
end;
9811003
{error, Reason} ->
9821004
?log_error("Failed to retire ~p key ~p (~p): ~p",
9831005
[Kind, Filename, FromPath, Reason]),

0 commit comments

Comments
 (0)