Skip to content

Commit

Permalink
Attempt to resolve type confusion
Browse files Browse the repository at this point in the history
Dialyzer doesn't see the fold_option as being a valid Options entry in fold/4, as only the read_options are expected by the iterator functions.  The first_key option will be ignored by the iterator, but may be passed in - so this change reflects this in the spec

Make options explicit

Otherwise issue with detecting option combinations

Update eleveldb.erl

Add first_key to iterator options

The iterator will ignore first_key, but first_key may be present on the options

Update eleveldb.erl
  • Loading branch information
martinsumner committed May 29, 2019
1 parent 55e67e0 commit 72fe697
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ c_src/system
.local_dialyzer_plt
.rebar
_build
.DS_Store
28 changes: 16 additions & 12 deletions src/eleveldb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ init() ->
{whole_file_expiry, boolean()}
].

-type read_option() :: {verify_checksums, boolean()} |
{fill_cache, boolean()} |
{iterator_refresh, boolean()}.
-type read_options() :: [{verify_checksums, boolean()} |
{fill_cache, boolean()} |
{iterator_refresh, boolean()}].

-type read_options() :: [read_option()].

-type fold_option() :: {first_key, Key::binary()}.
-type fold_options() :: [read_option() | fold_option()].
-type fold_options() :: [{verify_checksums, boolean()} |
{fill_cache, boolean()} |
{iterator_refresh, boolean()} |
{first_key, binary()}].

-type write_options() :: [{sync, boolean()}].

Expand Down Expand Up @@ -205,21 +205,25 @@ async_put(Ref, Context, Key, Value, Opts) ->
async_write(_CallerRef, _Ref, _Updates, _Opts) ->
erlang:nif_error({error, not_loaded}).

-spec async_iterator(reference(), db_ref(), read_options()) -> ok.
-spec async_iterator(reference(), db_ref(), fold_options()) -> ok.
async_iterator(_CallerRef, _Ref, _Opts) ->
erlang:nif_error({error, not_loaded}).

-spec async_iterator(reference(), db_ref(), read_options(), keys_only) -> ok.
-spec async_iterator(reference(), db_ref(), fold_options(), keys_only) -> ok.
async_iterator(_CallerRef, _Ref, _Opts, keys_only) ->
erlang:nif_error({error, not_loaded}).

-spec iterator(db_ref(), read_options()) -> {ok, itr_ref()}.
-spec iterator(db_ref(), fold_options()) -> {ok, itr_ref()}.
%% Note that only read_options may influence the iterator, if the first_key
%% is to be set, it must be done through explicitly calling iterator_move
iterator(Ref, Opts) ->
CallerRef = make_ref(),
async_iterator(CallerRef, Ref, Opts),
?WAIT_FOR_REPLY(CallerRef).

-spec iterator(db_ref(), read_options(), keys_only) -> {ok, itr_ref()}.
-spec iterator(db_ref(), fold_options(), keys_only) -> {ok, itr_ref()}.
%% Note that only read_options may influence the iterator, if the first_key
%% is to be set, it must be done through explicitly calling iterator_move
iterator(Ref, Opts, keys_only) ->
CallerRef = make_ref(),
async_iterator(CallerRef, Ref, Opts, keys_only),
Expand Down Expand Up @@ -270,7 +274,7 @@ fold(Ref, Fun, Acc0, Opts) ->

%% Fold over the keys in the database
%% will throw an exception if the database is closed while the fold runs
-spec fold_keys(db_ref(), fold_keys_fun(), any(), read_options()) -> any().
-spec fold_keys(db_ref(), fold_keys_fun(), any(), fold_options()) -> any().
fold_keys(Ref, Fun, Acc0, Opts) ->
{ok, Itr} = iterator(Ref, Opts, keys_only),
do_fold(Itr, Fun, Acc0, Opts).
Expand Down

0 comments on commit 72fe697

Please sign in to comment.