add fold/3 to wterl.erl and fix dialyzer warnings
The backend fold_objects was failing because it was trying to use wterl:fold_keys/3, which doesn't fold over values. Add fold/3 to wterl.erl to fix this. Also clean up a few dialyzer warnings.
This commit is contained in:
parent
221df5337d
commit
9c9075e70d
3 changed files with 24 additions and 8 deletions
|
@ -246,7 +246,7 @@ fold_objects(FoldObjectsFun, Acc, Opts, #state{conn=ConnRef, table=Table}) ->
|
|||
{ok, SRef} = wterl:session_open(ConnRef),
|
||||
{ok, Cursor} = wterl:cursor_open(SRef, Table),
|
||||
try
|
||||
wterl:fold_keys(Cursor, FoldFun, Acc)
|
||||
wterl:fold(Cursor, FoldFun, Acc)
|
||||
catch
|
||||
{break, AccFinal} ->
|
||||
AccFinal
|
||||
|
@ -265,8 +265,12 @@ fold_objects(FoldObjectsFun, Acc, Opts, #state{conn=ConnRef, table=Table}) ->
|
|||
%% @doc Delete all objects from this wterl backend
|
||||
-spec drop(state()) -> {ok, state()} | {error, term(), state()}.
|
||||
drop(#state{table=Table, session=SRef}=State) ->
|
||||
ok = wterl:session_truncate(SRef, Table),
|
||||
{ok, State}.
|
||||
case wterl:session_truncate(SRef, Table) of
|
||||
ok ->
|
||||
{ok, State};
|
||||
Error ->
|
||||
{error, Error, State}
|
||||
end.
|
||||
|
||||
%% @doc Returns true if this wterl backend contains any
|
||||
%% non-tombstone values; otherwise returns false.
|
||||
|
|
|
@ -58,7 +58,8 @@
|
|||
session_verify/2,
|
||||
session_verify/3,
|
||||
config_to_bin/1,
|
||||
fold_keys/3]).
|
||||
fold_keys/3,
|
||||
fold/3]).
|
||||
|
||||
-type config() :: binary().
|
||||
-type config_list() :: [{atom(), any()}].
|
||||
|
@ -92,7 +93,7 @@ init() ->
|
|||
Path ->
|
||||
Path
|
||||
end,
|
||||
erlang:load_nif(filename:join(PrivDir, ?MODULE), 0).
|
||||
erlang:load_nif(filename:join(PrivDir, atom_to_list(?MODULE)), 0).
|
||||
|
||||
-spec conn_open(string(), config()) -> {ok, connection()} | {error, term()}.
|
||||
conn_open(_HomeDir, _Config) ->
|
||||
|
@ -102,7 +103,7 @@ conn_open(_HomeDir, _Config) ->
|
|||
conn_close(_ConnRef) ->
|
||||
?nif_stub.
|
||||
|
||||
-spec session_open(connection()) -> {ok, reference()} | {error, term()}.
|
||||
-spec session_open(connection()) -> {ok, session()} | {error, term()}.
|
||||
session_open(_ConnRef) ->
|
||||
?nif_stub.
|
||||
|
||||
|
@ -234,7 +235,9 @@ cursor_update(_Cursor, _Key, _Value) ->
|
|||
cursor_remove(_Cursor, _Key, _Value) ->
|
||||
?nif_stub.
|
||||
|
||||
-spec fold_keys(cursor(), fun(), any()) -> any().
|
||||
-type fold_keys_fun() :: fun((Key::binary(), any()) -> any()).
|
||||
|
||||
-spec fold_keys(cursor(), fold_keys_fun(), any()) -> any().
|
||||
fold_keys(Cursor, Fun, Acc0) ->
|
||||
fold_keys(Cursor, Fun, Acc0, cursor_next_key(Cursor)).
|
||||
fold_keys(_Cursor, _Fun, Acc, not_found) ->
|
||||
|
@ -242,6 +245,15 @@ fold_keys(_Cursor, _Fun, Acc, not_found) ->
|
|||
fold_keys(Cursor, Fun, Acc, {ok, Key}) ->
|
||||
fold_keys(Cursor, Fun, Fun(Key, Acc), cursor_next_key(Cursor)).
|
||||
|
||||
-type fold_fun() :: fun(({Key::binary(), Value::binary()}, any()) -> any()).
|
||||
|
||||
-spec fold(cursor(), fold_fun(), any()) -> any().
|
||||
fold(Cursor, Fun, Acc0) ->
|
||||
fold(Cursor, Fun, Acc0, cursor_next(Cursor)).
|
||||
fold(_Cursor, _Fun, Acc, not_found) ->
|
||||
Acc;
|
||||
fold(Cursor, Fun, Acc, {ok, Key, Value}) ->
|
||||
fold(Cursor, Fun, Fun({Key, Value}, Acc), cursor_next(Cursor)).
|
||||
|
||||
%%
|
||||
%% Configuration type information.
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-record(state, {conn :: reference(),
|
||||
-record(state, {conn :: wterl:connection(),
|
||||
monitors :: ets:tid()}).
|
||||
|
||||
%% ====================================================================
|
||||
|
|
Loading…
Reference in a new issue