Skip to content

Commit

Permalink
Improve driver cleanup, implement lookup of existing keys.
Browse files Browse the repository at this point in the history
If we decide to stop the driver, we should not reply back before we
have a clean state with all BTrees closed.

Also, implement lookup of existing keys in the tree.
  • Loading branch information
jlouis committed Jan 7, 2012
1 parent 372a056 commit fd87d79
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/fractal_btree_drv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
%% API
-export([start_link/0]).

-export([open/1,
-export([
lookup_exist/2,
open/1,
put/3,
stop/0]).

Expand All @@ -27,6 +29,9 @@ start_link() ->
call(X) ->
gen_server:call(?SERVER, X, infinity).

lookup_exist(N, K) ->
call({lookup_exist, N, K}).

open(N) ->
call({open, N}).

Expand Down Expand Up @@ -56,7 +61,12 @@ handle_call({put, N, K, V}, _, #state { btrees = D} = State) ->
Other ->
{reply, {error, Other}, State}
end;
handle_call({lookup_exist, N, K}, _, #state { btrees = D} = State) ->
Tree = dict:fetch(N, D),
Reply = fractal_btree:lookup(Tree, K),
{reply, Reply, State};
handle_call(stop, _, State) ->
cleanup_trees(State),
{stop, normal, ok, State};
handle_call(_Request, _From, State) ->
Reply = ok,
Expand All @@ -68,8 +78,7 @@ handle_cast(_Msg, State) ->
handle_info(_Info, State) ->
{noreply, State}.

terminate(_Reason, State) ->
cleanup_trees(State),
terminate(_Reason, _State) ->
ok.

code_change(_OldVsn, State, _Extra) ->
Expand Down

0 comments on commit fd87d79

Please sign in to comment.