ConETS table consistency while entries are deleted from 2 processes
Frank Muller
frank.muller.erl@REDACTED
Sun Dec 8 09:29:36 CET 2019
Hi all
Lets assume a public ETS table of type ‘ordered_set’.
Every minute, a process A is deleting expired entries from it (see below).
In the same time, another process B can delete any entry (ex. randomly)
from this table.
I’ve implemented two strategies which can be used by process A:
_________________________________________
-spec purge1(pos_integer()) -> ok.
purge1(Now) ->
Key = ets:first(?MODULE),
purge1(Now, Key).
purge1(Now, Key) when Key =< Now ->
true = ets:delete(?MODULE, Key), %% idempotent call
purge1(Now);
purge1(_, _) -> %% '$end_of_table’ or Key > Now
ok.
or:
_________________________________________
-spec purge2(pos_integer()) -> ok.
purge2(Now) ->
Key = ets:first(?MODULE),
purge2(Now, Key).
purge2(Now, Key) when Key =< Now ->
Next = ets:next(?MODULE, Key),
true = ets:delete(?MODULE, Key), %% idempotent call
purge2(Now, Next);
purge2(_, _) -> %% '$end_of_table’ or Key > Now
ok.
_________________________________________
Question: is it safe in general to have process B deleting entries while A
is running?
Which strategy is more consistent: purge1/1 or purge2/1?
Best
/Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20191208/87ab46d1/attachment.htm>
More information about the erlang-questions
mailing list