Skip to content

Commit

Permalink
sync dets when registering a new server name
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni Visciano committed May 17, 2024
1 parent 29306c0 commit 57c540f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ra_directory.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ deinit(System) when is_atom(System) ->
deinit(#{directory := Name,
directory_rev := NameRev}) ->
_ = ets:delete(Name),
ok = dets:sync(NameRev),
_ = dets:close(NameRev),
ok.

Expand All @@ -76,12 +77,14 @@ register_name(#{directory := Directory,
ClusterName}),
case uid_of(System, ServerName) of
undefined ->
ok = dets:insert(DirRev, {ServerName, UId});
ok = dets:insert(DirRev, {ServerName, UId}),
ok = dets:sync(DirRev);
UId ->
%% no need to insert into dets table if already there
ok;
OtherUId ->
ok = dets:insert(DirRev, {ServerName, UId}),
ok = dets:sync(DirRev),
?WARN("ra server with name ~ts UId ~s replaces prior UId ~s",
[ServerName, UId, OtherUId]),
ok
Expand All @@ -96,6 +99,7 @@ unregister_name(#{directory := Directory,
[{_, _, _, ServerName, _}] ->
_ = ets:take(Directory, UId),
ok = dets:delete(DirRev, ServerName),
ok = dets:sync(DirRev),
UId;
[] ->
UId
Expand Down

0 comments on commit 57c540f

Please sign in to comment.