Improve driver cleanup, implement lookup of existing keys.
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.
This commit is contained in:
parent
372a05619c
commit
fd87d7963a
1 changed files with 12 additions and 3 deletions
|
@ -6,7 +6,9 @@
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0]).
|
-export([start_link/0]).
|
||||||
|
|
||||||
-export([open/1,
|
-export([
|
||||||
|
lookup_exist/2,
|
||||||
|
open/1,
|
||||||
put/3,
|
put/3,
|
||||||
stop/0]).
|
stop/0]).
|
||||||
|
|
||||||
|
@ -27,6 +29,9 @@ start_link() ->
|
||||||
call(X) ->
|
call(X) ->
|
||||||
gen_server:call(?SERVER, X, infinity).
|
gen_server:call(?SERVER, X, infinity).
|
||||||
|
|
||||||
|
lookup_exist(N, K) ->
|
||||||
|
call({lookup_exist, N, K}).
|
||||||
|
|
||||||
open(N) ->
|
open(N) ->
|
||||||
call({open, N}).
|
call({open, N}).
|
||||||
|
|
||||||
|
@ -56,7 +61,12 @@ handle_call({put, N, K, V}, _, #state { btrees = D} = State) ->
|
||||||
Other ->
|
Other ->
|
||||||
{reply, {error, Other}, State}
|
{reply, {error, Other}, State}
|
||||||
end;
|
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) ->
|
handle_call(stop, _, State) ->
|
||||||
|
cleanup_trees(State),
|
||||||
{stop, normal, ok, State};
|
{stop, normal, ok, State};
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
|
@ -68,8 +78,7 @@ handle_cast(_Msg, State) ->
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
terminate(_Reason, State) ->
|
terminate(_Reason, _State) ->
|
||||||
cleanup_trees(State),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
Loading…
Reference in a new issue