Skip to content

Instantly share code, notes, and snippets.

@mocchira
Created June 14, 2013 09:07
Show Gist options
  • Save mocchira/5780529 to your computer and use it in GitHub Desktop.
Save mocchira/5780529 to your computer and use it in GitHub Desktop.
-module(test).
-export([start/2, stop/1]).
-export([loop/2, loop_child/1]).
-define(NUM_OF_REC, 256).
-define(INTERVAL, 1).
%% public functions
start(ProcNum, _Table) when ProcNum < 1 ->
{error, badarg};
start(ProcNum, Table) ->
_ = ets:new(Table, [named_table, ordered_set, public, {read_concurrency, true}]),
load_ets(?NUM_OF_REC, Table),
spawn(?MODULE, loop, [ProcNum, Table]).
stop(Pid) ->
Pid ! {stop, self()}.
%% private functions
load_ets(0, _Table) ->
ok;
load_ets(Id, Table) ->
true = ets:insert(Table, {Id, node()}),
load_ets(Id - 1, Table).
loop(ProcNum, Table) ->
loop(ProcNum, Table, []).
loop(0, Table, Acc) ->
receive
{stop, Pid}->
[ChildPid ! stop || ChildPid <- Acc],
Pid ! ok;
Other ->
io:format("[err] received unknown msg:~p table:~p ~n", [Other, Table]),
loop(0, Table, Acc)
end;
loop(ProcNum, Table, Acc) ->
Pid = spawn(?MODULE, loop_child, [Table]),
loop(ProcNum - 1, Table, [Pid|Acc]).
loop_child(Table) ->
receive
stop ->
io:format("[info] received stop msg ~n"),
exit(stop);
Other ->
io:format("[err] received unknown msg:~p ~n", [Other]),
loop_child(Table)
after
?INTERVAL ->
void
end,
case ets:foldl(
fun({_, Member}, Acc) ->
ordsets:add_element(Member, Acc)
end, [], Table) of
[] ->
io:format("[err] succeeded reproducing the bug ets info:~p i:~p ~n",
[ets:info(Table), ets:i()]);
_Members ->
%% always must be reached here
loop_child(Table)
end.
@mocchira
Copy link
Author

In progress

Under high load situations, Occasionary
https://github.com/leo-project/leo_redundant_manager/blob/0.14.3/src/leo_redundant_manager_api.erl#L392 's error occured, This is because failing ets:foldl/3.
So I started to survey how to reproduce this bug in less code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment