Skip to content

Commit

Permalink
MB-46279 make sure that file:rename doesn't happen when we wait
Browse files Browse the repository at this point in the history
...for memcached to complete configuration request

This is needed because memcached configuration request might lock
the file causing simultaneous rename to fail

Change-Id: I4d853273f959eb7f9f14b5503ef03412baff4210
Reviewed-on: http://review.couchbase.org/c/ns_server/+/156369
Well-Formed: Build Bot <build@couchbase.com>
Tested-by: Artem Stemkovski <artem@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Steve Watanabe <steve.watanabe@couchbase.com>
  • Loading branch information
vzasade committed Jun 24, 2021
1 parent c36a760 commit 3af37ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/memcached_cfg.erl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ write_cfg(#state{path = Path,
rename_and_refresh(#state{path = Path,
tmp_path = TmpPath,
module = Module}, Tries, SleepTime) ->
case file:rename(TmpPath, Path) of
case memcached_refresh:apply_to_file(TmpPath, Path) of
ok ->
ok = Module:refresh(),
?log_debug("Successfully renamed ~p to ~p", [TmpPath, Path]);
Expand Down
8 changes: 7 additions & 1 deletion src/memcached_refresh.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

-behaviour(gen_server).

-export([start_link/0, refresh/1]).
-export([start_link/0, refresh/1, apply_to_file/2]).

-include("ns_common.hrl").

Expand All @@ -27,6 +27,9 @@ start_link() ->
refresh(Item) ->
gen_server:cast(?MODULE, {refresh, Item}).

apply_to_file(TmpPath, Path) ->
gen_server:call(?MODULE, {apply_to_file, TmpPath, Path}).

init([]) ->
ToRestart =
case ns_ports_manager:find_port(ns_server:get_babysitter_node(), memcached) of
Expand All @@ -42,6 +45,9 @@ init([]) ->
code_change(_OldVsn, State, _) -> {ok, State}.
terminate(_Reason, _State) -> ok.

handle_call({apply_to_file, TmpPath, Path}, _From, State) ->
?log_debug("File rename from ~p to ~p is requested", [TmpPath, Path]),
{reply, file:rename(TmpPath, Path), State};
handle_call(_Msg, _From, State) ->
{reply, not_implemented, State}.

Expand Down

0 comments on commit 3af37ea

Please sign in to comment.