From 82cc76c8c6dd47a7d1e81b53c69c1ba6fd09638a Mon Sep 17 00:00:00 2001 From: Martin Sumner Date: Fri, 5 Nov 2021 09:15:25 +0000 Subject: [PATCH] Tidy up some undefined functions in dialyzer specs (#368) --- src/leveled_bookie.erl | 14 ++++++++------ src/leveled_cdb.erl | 13 ++++++++----- src/leveled_inker.erl | 14 ++++++++++---- src/leveled_sst.erl | 8 +++++++- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/leveled_bookie.erl b/src/leveled_bookie.erl index 49332c0..6f2fa7c 100644 --- a/src/leveled_bookie.erl +++ b/src/leveled_bookie.erl @@ -638,7 +638,7 @@ book_sqn(Pid, Bucket, Key) -> book_sqn(Pid, Bucket, Key, Tag) -> gen_server:call(Pid, {head, Bucket, Key, Tag, true}, infinity). --spec book_returnfolder(pid(), tuple()) -> {async, fun()}. +-spec book_returnfolder(pid(), tuple()) -> {async, fun(() -> term())}. %% @doc Folds over store - deprecated %% The tuple() is a query, and book_returnfolder will return an {async, Folder} @@ -710,7 +710,7 @@ book_returnfolder(Pid, RunnerType) -> FoldAccT :: {FoldFun, Acc}, Range :: {IndexField, Start, End}, TermHandling :: {ReturnTerms, TermRegex}) -> - {async, Runner::fun()} + {async, Runner::fun(() -> term())} when Bucket::term(), StartKey::term(), FoldFun::fun((Bucket, Key | {IndexVal, Key}, Acc) -> Acc), @@ -1120,7 +1120,7 @@ book_destroy(Pid) -> gen_server:call(Pid, destroy, infinity). --spec book_hotbackup(pid()) -> {async, fun()}. +-spec book_hotbackup(pid()) -> {async, fun(() -> ok)}. %% @doc Backup the Bookie %% Return a function that will take a backup of a snapshot of the Journal. %% The function will be 1-arity, and can be passed the absolute folder name @@ -1808,7 +1808,8 @@ set_options(Opts) -> -spec return_snapfun(book_state(), store|ledger, tuple()|no_lookup|undefined, - boolean(), boolean()) -> fun(). + boolean(), boolean()) + -> fun(() -> {ok, pid(), pid()|null}). %% @doc %% Generates a function from which a snapshot can be created. The primary %% factor here is the SnapPreFold boolean. If this is true then the snapshot @@ -1845,7 +1846,7 @@ snaptype_by_presence(true) -> snaptype_by_presence(false) -> ledger. --spec get_runner(book_state(), tuple()) -> {async, fun()}. +-spec get_runner(book_state(), tuple()) -> {async, fun(() -> term())}. %% @doc %% Get an {async, Runner} for a given fold type. Fold types have different %% tuple inputs @@ -1972,7 +1973,8 @@ get_runner(State, DeprecatedQuery) -> get_deprecatedrunner(State, DeprecatedQuery). --spec get_deprecatedrunner(book_state(), tuple()) -> {async, fun()}. +-spec get_deprecatedrunner(book_state(), tuple()) -> + {async, fun(() -> term())}. %% @doc %% Get an {async, Runner} for a given fold type. Fold types have different %% tuple inputs. These folds are currently used in tests, but are deprecated. diff --git a/src/leveled_cdb.erl b/src/leveled_cdb.erl index 83ac256..de549e6 100644 --- a/src/leveled_cdb.erl +++ b/src/leveled_cdb.erl @@ -175,7 +175,7 @@ fun((any(), binary(), integer(), any(), fun((binary()) -> any())) -> {stop|loop, any()}). - +-export_type([filter_fun/0]). %%%============================================================================ %%% API @@ -1386,8 +1386,8 @@ startup_filter(Key, _ValueAsBin, Position, {Hashtree, _LastKey}, _ExtractFun) -> {loop, {put_hashtree(Key, Position, Hashtree), Key}}. --spec scan_over_file(file:io_device(), file_location(), fun(), any(), any()) - -> {file_location(), any()}. +-spec scan_over_file(file:io_device(), file_location(), + filter_fun(), any(), any()) -> {file_location(), any()}. %% Scan for key changes - scan over file returning applying FilterFun %% The FilterFun should accept as input: %% - Key, ValueBin, Position, Accumulator, Fun (to extract values from Binary) @@ -1500,8 +1500,11 @@ safe_read_next_value(Handle, Length, KeyBin) -> ReadFun = fun(VBin) -> crccheck(VBin, KeyBin) end, safe_read_next(Handle, Length, ReadFun). +-type read_output() :: {term(), binary()}|binary()|term()|false. +-type read_fun() :: fun((binary()) -> read_output()). --spec safe_read_next(file:io_device(), integer(), fun()) -> any(). +-spec safe_read_next(file:io_device(), integer(), read_fun()) + -> read_output(). %% @doc %% Read the next item of length Length %% Previously catching error:badarg was sufficient to capture errors of @@ -1515,7 +1518,7 @@ safe_read_next(Handle, Length, ReadFun) -> false end. --spec loose_read(file:io_device(), integer(), fun()) -> any(). +-spec loose_read(file:io_device(), integer(), read_fun()) -> read_output(). %% @doc %% Read with minimal error handling (only eof) - to be wrapped in %% safe_read_next/3 to catch exceptions. diff --git a/src/leveled_inker.erl b/src/leveled_inker.erl index abd4285..08f1629 100644 --- a/src/leveled_inker.erl +++ b/src/leveled_inker.erl @@ -290,7 +290,12 @@ ink_close(Pid) -> ink_doom(Pid) -> gen_server:call(Pid, doom, infinity). --spec ink_fold(pid(), integer(), {fun(), fun(), fun()}, any()) -> fun(). +-spec ink_fold(pid(), + integer(), + {leveled_cdb:filter_fun(), + fun((string(), leveled_codec:sqn()) -> term()), + fun((term(), term()) -> term())}, + term()) -> fun(() -> term()). %% @doc %% Fold over the journal from a starting sequence number (MinSQN), passing %% in three functions and a snapshot of the penciller. The Fold functions @@ -728,9 +733,9 @@ handle_cast({confirm_delete, ManSQN, CDB}, State) -> CheckSnapshotExpiryFun = fun({_R, TS, _SnapSQN}) -> Expiry = leveled_util:integer_time(TS) + State#state.snap_timeout, - % If Expiry has passed this will be false, and the snapshot - % will be removed from the list of registered snapshots and - % so will not longer block deletes + % If Expiry has passed this will be false, and the snapshot + % will be removed from the list of registered snapshots and + % so will not longer block deletes leveled_util:integer_now() < Expiry end, RegisteredSnapshots0 = @@ -773,6 +778,7 @@ handle_cast({remove_logs, ForcedLogs}, State) -> CDBopts0 = CDBopts#cdb_options{log_options = leveled_log:get_opts()}, {noreply, State#state{cdb_options = CDBopts0}}. + %% handle the bookie stopping and stop this snapshot handle_info({'DOWN', BookieMonRef, process, _BookiePid, _Info}, State=#state{bookie_monref = BookieMonRef}) -> diff --git a/src/leveled_sst.erl b/src/leveled_sst.erl index abb41d7..3e06783 100644 --- a/src/leveled_sst.erl +++ b/src/leveled_sst.erl @@ -1957,7 +1957,13 @@ pointer_mapfun(Pointer) -> SK, EK}. --spec binarysplit_mapfun(binary(), integer()) -> fun(). + +-type slotbin_fun() :: + fun(({non_neg_integer(), non_neg_integer(), non_neg_integer(), + range_endpoint(), range_endpoint()}) -> + {binary(), non_neg_integer(), range_endpoint(), range_endpoint()}). + +-spec binarysplit_mapfun(binary(), integer()) -> slotbin_fun(). %% @doc %% Return a function that can pull individual slot binaries from a binary %% covering multiple slots