Use not_found uniformly (rather than notfound).
This commit is contained in:
parent
5338a07c54
commit
61d360550e
5 changed files with 15 additions and 14 deletions
|
@ -53,7 +53,7 @@ run(get, KeyGen, _ValueGen, State) ->
|
||||||
case lsm_btree:lookup(State#state.tree, KeyGen()) of
|
case lsm_btree:lookup(State#state.tree, KeyGen()) of
|
||||||
{ok, _Value} ->
|
{ok, _Value} ->
|
||||||
{ok, State};
|
{ok, State};
|
||||||
notfound ->
|
not_found ->
|
||||||
{ok, State};
|
{ok, State};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
open(Dir) ->
|
open(Dir) ->
|
||||||
open(Dir, []).
|
open(Dir, []).
|
||||||
|
|
||||||
open(Dir, Config) -> %TODO Config is currently ignored.
|
open(Dir, _Config) -> %TODO Config is currently ignored.
|
||||||
gen_server:start(?MODULE, [Dir], []).
|
gen_server:start(?MODULE, [Dir], []).
|
||||||
|
|
||||||
close(Ref) ->
|
close(Ref) ->
|
||||||
|
|
|
@ -180,8 +180,8 @@ main_loop(State = #state{ next=Next }) ->
|
||||||
receive
|
receive
|
||||||
?REQ(From, {lookup, Key})=Req ->
|
?REQ(From, {lookup, Key})=Req ->
|
||||||
case do_lookup(Key, [State#state.b, State#state.a, Next]) of
|
case do_lookup(Key, [State#state.b, State#state.a, Next]) of
|
||||||
notfound ->
|
not_found ->
|
||||||
reply(From, notfound);
|
reply(From, not_found);
|
||||||
{found, Result} ->
|
{found, Result} ->
|
||||||
reply(From, {ok, Result});
|
reply(From, {ok, Result});
|
||||||
{delegate, DelegatePid} ->
|
{delegate, DelegatePid} ->
|
||||||
|
@ -355,16 +355,16 @@ main_loop(State = #state{ next=Next }) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_lookup(_Key, []) ->
|
do_lookup(_Key, []) ->
|
||||||
notfound;
|
not_found;
|
||||||
do_lookup(_Key, [Pid]) when is_pid(Pid) ->
|
do_lookup(_Key, [Pid]) when is_pid(Pid) ->
|
||||||
{delegate, Pid};
|
{delegate, Pid};
|
||||||
do_lookup(Key, [undefined|Rest]) ->
|
do_lookup(Key, [undefined|Rest]) ->
|
||||||
do_lookup(Key, Rest);
|
do_lookup(Key, Rest);
|
||||||
do_lookup(Key, [BT|Rest]) ->
|
do_lookup(Key, [BT|Rest]) ->
|
||||||
case lsm_btree_reader:lookup(BT, Key) of
|
case lsm_btree_reader:lookup(BT, Key) of
|
||||||
{ok, ?TOMBSTONE} -> notfound;
|
{ok, ?TOMBSTONE} -> not_found;
|
||||||
{ok, Result} -> {found, Result};
|
{ok, Result} -> {found, Result};
|
||||||
notfound -> do_lookup(Key, Rest)
|
not_found -> do_lookup(Key, Rest)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
close_if_defined(undefined) -> ok;
|
close_if_defined(undefined) -> ok;
|
||||||
|
|
|
@ -130,7 +130,7 @@ lookup_node(File,FromKey,#node{members=Members,level=N},_) ->
|
||||||
eof ->
|
eof ->
|
||||||
none
|
none
|
||||||
end;
|
end;
|
||||||
notfound ->
|
not_found ->
|
||||||
none
|
none
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -161,13 +161,13 @@ lookup(#index{file=File, root=Node, bloom=Bloom}, Key) ->
|
||||||
true ->
|
true ->
|
||||||
lookup_in_node(File,Node,Key);
|
lookup_in_node(File,Node,Key);
|
||||||
false ->
|
false ->
|
||||||
notfound
|
not_found
|
||||||
end.
|
end.
|
||||||
|
|
||||||
lookup_in_node(_File,#node{level=0,members=Members},Key) ->
|
lookup_in_node(_File,#node{level=0,members=Members},Key) ->
|
||||||
case lists:keyfind(Key,1,Members) of
|
case lists:keyfind(Key,1,Members) of
|
||||||
false ->
|
false ->
|
||||||
notfound;
|
not_found;
|
||||||
{_,Value} ->
|
{_,Value} ->
|
||||||
{ok, Value}
|
{ok, Value}
|
||||||
end;
|
end;
|
||||||
|
@ -177,8 +177,8 @@ lookup_in_node(File,#node{members=Members},Key) ->
|
||||||
{ok, {Pos,Size}} ->
|
{ok, {Pos,Size}} ->
|
||||||
{ok, Node} = read_node(File, {Pos,Size}),
|
{ok, Node} = read_node(File, {Pos,Size}),
|
||||||
lookup_in_node(File, Node, Key);
|
lookup_in_node(File, Node, Key);
|
||||||
notfound ->
|
not_found ->
|
||||||
notfound
|
not_found
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,10 +189,11 @@ find(K, [{K1,V}]) when K >= K1 ->
|
||||||
find(K, [_|T]) ->
|
find(K, [_|T]) ->
|
||||||
find(K,T);
|
find(K,T);
|
||||||
find(_, _) ->
|
find(_, _) ->
|
||||||
notfound.
|
not_found.
|
||||||
|
|
||||||
|
|
||||||
read_node(File,{Pos,Size}) ->
|
read_node(File,{Pos,Size}) ->
|
||||||
|
% error_logger:info_msg("read_node ~p ~p ~p~n", [File, Pos, Size]),
|
||||||
{ok, <<_:32, Level:16/unsigned, Data/binary>>} = file:pread(File, Pos, Size),
|
{ok, <<_:32, Level:16/unsigned, Data/binary>>} = file:pread(File, Pos, Size),
|
||||||
lsm_btree_util:decode_index_node(Level, Data);
|
lsm_btree_util:decode_index_node(Level, Data);
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ start(Partition, Config) ->
|
||||||
end,
|
end,
|
||||||
case AppStart of
|
case AppStart of
|
||||||
ok ->
|
ok ->
|
||||||
ok = filelib:ensure_dir(filename:join(DataRoot, "x")),
|
ok = filelib:ensure_dir(filename:join([DataRoot, "x"])),
|
||||||
DbName = filename:join(DataRoot, integer_to_list(Partition)),
|
DbName = filename:join(DataRoot, integer_to_list(Partition)),
|
||||||
case lsm_btree:open(DbName) of
|
case lsm_btree:open(DbName) of
|
||||||
{ok, Tree} ->
|
{ok, Tree} ->
|
||||||
|
|
Loading…
Reference in a new issue