2012-01-07 16:17:48 +00:00
|
|
|
-module(basho_bench_driver_lsm_btree).
|
2012-01-05 14:28:39 +00:00
|
|
|
|
|
|
|
-record(state, { tree,
|
|
|
|
filename,
|
|
|
|
flags,
|
|
|
|
sync_interval,
|
|
|
|
last_sync }).
|
|
|
|
|
|
|
|
-export([new/1,
|
|
|
|
run/4]).
|
|
|
|
|
|
|
|
-include_lib("basho_bench/include/basho_bench.hrl").
|
|
|
|
|
|
|
|
|
|
|
|
%% ====================================================================
|
|
|
|
%% API
|
|
|
|
%% ====================================================================
|
|
|
|
|
|
|
|
new(_Id) ->
|
|
|
|
%% Make sure bitcask is available
|
2012-01-07 16:17:48 +00:00
|
|
|
case code:which(lsm_btree) of
|
2012-01-05 14:28:39 +00:00
|
|
|
non_existing ->
|
2012-01-07 16:17:48 +00:00
|
|
|
?FAIL_MSG("~s requires lsm_btree to be available on code path.\n",
|
2012-01-05 14:28:39 +00:00
|
|
|
[?MODULE]);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
|
|
|
|
%% Get the target directory
|
2012-01-07 16:17:48 +00:00
|
|
|
Dir = basho_bench_config:get(lsm_btree_dir, "."),
|
2012-04-15 14:35:39 +00:00
|
|
|
Filename = filename:join(Dir, "test.lsm_btree"),
|
2012-01-05 14:28:39 +00:00
|
|
|
|
|
|
|
%% Look for sync interval config
|
2012-01-07 16:17:48 +00:00
|
|
|
case basho_bench_config:get(lsm_btree_sync_interval, infinity) of
|
2012-01-05 14:28:39 +00:00
|
|
|
Value when is_integer(Value) ->
|
|
|
|
SyncInterval = Value;
|
|
|
|
infinity ->
|
|
|
|
SyncInterval = infinity
|
|
|
|
end,
|
|
|
|
|
|
|
|
%% Get any bitcask flags
|
2012-01-07 16:17:48 +00:00
|
|
|
case lsm_btree:open(Filename) of
|
2012-01-05 14:28:39 +00:00
|
|
|
{error, Reason} ->
|
2012-01-07 16:17:48 +00:00
|
|
|
?FAIL_MSG("Failed to open lsm btree in ~s: ~p\n", [Filename, Reason]);
|
2012-01-05 14:28:39 +00:00
|
|
|
{ok, FBTree} ->
|
|
|
|
{ok, #state { tree = FBTree,
|
|
|
|
filename = Filename,
|
|
|
|
sync_interval = SyncInterval,
|
|
|
|
last_sync = os:timestamp() }}
|
|
|
|
end.
|
|
|
|
|
|
|
|
run(get, KeyGen, _ValueGen, State) ->
|
2012-01-07 16:17:48 +00:00
|
|
|
case lsm_btree:lookup(State#state.tree, KeyGen()) of
|
2012-01-05 14:28:39 +00:00
|
|
|
{ok, _Value} ->
|
|
|
|
{ok, State};
|
|
|
|
notfound ->
|
|
|
|
{ok, State};
|
|
|
|
{error, Reason} ->
|
|
|
|
{error, Reason}
|
|
|
|
end;
|
|
|
|
run(put, KeyGen, ValueGen, State) ->
|
2012-01-07 16:17:48 +00:00
|
|
|
case lsm_btree:put(State#state.tree, KeyGen(), ValueGen()) of
|
2012-01-05 14:28:39 +00:00
|
|
|
ok ->
|
|
|
|
{ok, State};
|
|
|
|
{error, Reason} ->
|
|
|
|
{error, Reason}
|
|
|
|
end;
|
|
|
|
run(delete, KeyGen, _ValueGen, State) ->
|
2012-01-07 16:17:48 +00:00
|
|
|
case lsm_btree:delete(State#state.tree, KeyGen()) of
|
2012-01-05 14:28:39 +00:00
|
|
|
ok ->
|
|
|
|
{ok, State};
|
|
|
|
{error, Reason} ->
|
|
|
|
{error, Reason}
|
|
|
|
end.
|