Ported thrash test to new bdberl API.
This commit is contained in:
parent
ab3162d47c
commit
e6f0cba53d
|
@ -39,60 +39,42 @@ thrash_run(Owner) ->
|
||||||
random:seed(A1, A2, A3),
|
random:seed(A1, A2, A3),
|
||||||
|
|
||||||
%% Open up a port and database
|
%% Open up a port and database
|
||||||
{ok, P} = bdberl_port:new(),
|
{ok, 0} = bdberl:open("thrash", btree),
|
||||||
{ok, 0} = bdberl_port:open_database(P, "thrash", btree),
|
|
||||||
|
|
||||||
%% Start thrashing
|
%% Start thrashing
|
||||||
thrash_incr_loop(P, Owner, 1000).
|
thrash_incr_loop(Owner, 1000).
|
||||||
|
|
||||||
|
thrash_incr_loop(Owner, 0) ->
|
||||||
|
|
||||||
thrash_incr_loop(Port, Owner, 0) ->
|
|
||||||
Owner ! {finished, self()};
|
Owner ! {finished, self()};
|
||||||
thrash_incr_loop(Port, Owner, Count) ->
|
thrash_incr_loop(Owner, Count) ->
|
||||||
ct:print("~p\n", [Count]),
|
ct:print("~p\n", [Count]),
|
||||||
%% Choose random key
|
%% Choose random key
|
||||||
Key = random:uniform(1200),
|
Key = random:uniform(1200),
|
||||||
|
|
||||||
%% Start a txn that will read the current value of the key and increment by 1
|
%% Start a txn that will read the current value of the key and increment by 1
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
case get_or_die(Port, 0, Key) of
|
case bdberl:get(0, Key, [rmw]) of
|
||||||
not_found ->
|
not_found ->
|
||||||
Value = 0;
|
Value = 0;
|
||||||
|
|
||||||
Value ->
|
{ok, Value} ->
|
||||||
Value
|
Value
|
||||||
end,
|
end,
|
||||||
put_or_die(Port, 0, Key, Value)
|
ok = bdberl:put(0, Key, Value)
|
||||||
end,
|
end,
|
||||||
ok = do_txn(Port, F, 0),
|
ok = do_txn(F, 0),
|
||||||
thrash_incr_loop(Port, Owner, Count-1).
|
thrash_incr_loop(Owner, Count-1).
|
||||||
|
|
||||||
|
do_txn(F, Count) ->
|
||||||
|
case bdberl:txn_begin() of
|
||||||
get_or_die(Port, DbRef, Key) ->
|
|
||||||
case bdberl_port:get(Port, DbRef, Key, [rmw]) of
|
|
||||||
not_found ->
|
|
||||||
not_found;
|
|
||||||
{ok, Value} ->
|
|
||||||
Value
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
put_or_die(Port, DbRef, Key, Value) ->
|
|
||||||
ok = bdberl_port:put(Port, DbRef, Key, Value).
|
|
||||||
|
|
||||||
|
|
||||||
do_txn(Port, F, Count) ->
|
|
||||||
case bdberl_port:txn_begin(Port) of
|
|
||||||
ok ->
|
ok ->
|
||||||
case catch(F()) of
|
case catch(F()) of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', _Reason} ->
|
||||||
io:format("Txn attempt ~p failed; retrying", [Count]),
|
io:format("Txn attempt ~p failed; retrying", [Count]),
|
||||||
do_txn(Port, F, Count+1);
|
do_txn(F, Count+1);
|
||||||
Other ->
|
_Other ->
|
||||||
ok = bdberl_port:txn_commit(Port)
|
ok = bdberl:txn_commit()
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, _Reason} ->
|
||||||
do_txn(Port, F, Count+1)
|
do_txn(F, Count+1)
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in a new issue