From d88bdf77038b932cdadbb16da27e1608d939231f Mon Sep 17 00:00:00 2001 From: Giovanni Visciano Date: Thu, 16 May 2024 21:31:12 +0200 Subject: [PATCH 1/3] sync DETS to disk --- src/ra_directory.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ra_directory.erl b/src/ra_directory.erl index 7df026cd..1e0339e0 100644 --- a/src/ra_directory.erl +++ b/src/ra_directory.erl @@ -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. @@ -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 @@ -96,6 +99,7 @@ unregister_name(#{directory := Directory, [{_, _, _, ServerName, _}] -> _ = ets:take(Directory, UId), ok = dets:delete(DirRev, ServerName), + ok = dets:sync(DirRev), UId; [] -> UId From 5fafc73809abe1c1ede29153393099f48b4e061d Mon Sep 17 00:00:00 2001 From: Giovanni Visciano Date: Sat, 18 May 2024 09:00:08 +0200 Subject: [PATCH 2/3] already taken out in the case target --- src/ra_directory.erl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ra_directory.erl b/src/ra_directory.erl index 1e0339e0..db7f010b 100644 --- a/src/ra_directory.erl +++ b/src/ra_directory.erl @@ -97,7 +97,6 @@ unregister_name(#{directory := Directory, directory_rev := DirRev}, UId) -> case ets:take(Directory, UId) of [{_, _, _, ServerName, _}] -> - _ = ets:take(Directory, UId), ok = dets:delete(DirRev, ServerName), ok = dets:sync(DirRev), UId; From e46055728831cad766a704eba0bf6304d08093ae Mon Sep 17 00:00:00 2001 From: Giovanni Visciano Date: Mon, 20 May 2024 10:53:12 +0200 Subject: [PATCH 3/3] dets:sync/1 only in deinit stage --- src/ra_directory.erl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ra_directory.erl b/src/ra_directory.erl index db7f010b..bf96c71d 100644 --- a/src/ra_directory.erl +++ b/src/ra_directory.erl @@ -77,14 +77,12 @@ register_name(#{directory := Directory, ClusterName}), case uid_of(System, ServerName) of undefined -> - ok = dets:insert(DirRev, {ServerName, UId}), - ok = dets:sync(DirRev); + ok = dets:insert(DirRev, {ServerName, UId}); 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 @@ -98,7 +96,6 @@ unregister_name(#{directory := Directory, case ets:take(Directory, UId) of [{_, _, _, ServerName, _}] -> ok = dets:delete(DirRev, ServerName), - ok = dets:sync(DirRev), UId; [] -> UId