Add open/3, open_link/1-3, and fix some dialyzer warnings

This commit is contained in:
Joseph Wayne Norton 2012-09-24 23:25:42 +09:00
parent d143637f98
commit 0be218452a
2 changed files with 38 additions and 7 deletions

View file

@ -31,7 +31,8 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]). terminate/2, code_change/3]).
-export([open/1, open/2, transact/2, close/1, get/2, lookup/2, delete/2, put/3, put/4, -export([open/1, open/2, open/3, open_link/1, open_link/2, open_link/3,
transact/2, close/1, get/2, lookup/2, delete/2, put/3, put/4,
fold/3, fold_range/4, destroy/1]). fold/3, fold_range/4, destroy/1]).
-export([get_opt/2, get_opt/3]). -export([get_opt/2, get_opt/3]).
@ -74,16 +75,46 @@
%% Create or open a hanoidb store. Argument `Dir' names a %% Create or open a hanoidb store. Argument `Dir' names a
%% directory in which to keep the data files. By convention, we %% directory in which to keep the data files. By convention, we
%% name hanoidb data directories with extension ".hanoidb". %% name hanoidb data directories with extension ".hanoidb".
- spec open(Dir::string()) -> hanoidb(). - spec open(Dir::string()) -> {ok, hanoidb()} | ignore | {error, term()}.
open(Dir) -> open(Dir) ->
open(Dir, []). open(Dir, []).
%% @doc Create or open a hanoidb store. %% @doc Create or open a hanoidb store.
- spec open(Dir::string(), Opts::[config_option()]) -> hanoidb(). - spec open(Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open(Dir, Opts) -> open(Dir, Opts) ->
ok = start_app(), ok = start_app(),
gen_server:start(?MODULE, [Dir, Opts], []). gen_server:start(?MODULE, [Dir, Opts], []).
%% @doc Create or open a hanoidb store with a registered name.
- spec open(Name::{local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()},
Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open(Name, Dir, Opts) ->
ok = start_app(),
gen_server:start(Name, ?MODULE, [Dir, Opts], []).
%% @doc
%% Create or open a hanoidb store as part of a supervision tree.
%% Argument `Dir' names a directory in which to keep the data files.
%% By convention, we name hanoidb data directories with extension
%% ".hanoidb".
- spec open_link(Dir::string()) -> {ok, hanoidb()} | ignore | {error, term()}.
open_link(Dir) ->
open_link(Dir, []).
%% @doc Create or open a hanoidb store as part of a supervision tree.
- spec open_link(Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open_link(Dir, Opts) ->
ok = start_app(),
gen_server:start_link(?MODULE, [Dir, Opts], []).
%% @doc Create or open a hanoidb store as part of a supervision tree
%% with a registered name.
- spec open_link(Name::{local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()},
Dir::string(), Opts::[config_option()]) -> {ok, hanoidb()} | ignore | {error, term()}.
open_link(Name, Dir, Opts) ->
ok = start_app(),
gen_server:start_link(Name, ?MODULE, [Dir, Opts], []).
%% @doc %% @doc
%% Close a Hanoi data store. %% Close a Hanoi data store.
- spec close(Ref::pid()) -> ok. - spec close(Ref::pid()) -> ok.
@ -277,7 +308,7 @@ open_levels(Dir, Options) ->
%% remove old nursery data file %% remove old nursery data file
NurseryFileName = filename:join(Dir, "nursery.data"), NurseryFileName = filename:join(Dir, "nursery.data"),
file:delete(NurseryFileName), _ = file:delete(NurseryFileName),
%% Do enough incremental merge to be sure we won't deadlock in insert %% Do enough incremental merge to be sure we won't deadlock in insert
{TopLevel, MaxMerge} = {TopLevel, MaxMerge} =
@ -314,7 +345,7 @@ handle_info({bottom_level, N}, #state{ nursery=Nursery, top=TopLevel }=State)
State2 = State#state{ max_level = N, State2 = State#state{ max_level = N,
nursery= hanoidb_nursery:set_max_level(Nursery, N) }, nursery= hanoidb_nursery:set_max_level(Nursery, N) },
hanoidb_level:set_max_level(TopLevel, N), _ = hanoidb_level:set_max_level(TopLevel, N),
{noreply, State2}; {noreply, State2};
@ -367,7 +398,7 @@ handle_call({get, Key}, From, State=#state{ top=Top, nursery=Nursery } ) when is
{value, Value} when is_binary(Value) -> {value, Value} when is_binary(Value) ->
{reply, {ok, Value}, State}; {reply, {ok, Value}, State};
none -> none ->
hanoidb_level:lookup(Top, Key, fun(Reply) -> gen_server:reply(From, Reply) end), _ = hanoidb_level:lookup(Top, Key, fun(Reply) -> gen_server:reply(From, Reply) end),
{noreply, State} {noreply, State}
end; end;

View file

@ -99,7 +99,7 @@ read_nursery_from_log(Directory, MaxLevel, Config) ->
%% @doc Add a Key/Value to the nursery %% @doc Add a Key/Value to the nursery
%% @end %% @end
-spec do_add(#nursery{}, binary(), binary()|?TOMBSTONE, pos_integer() | infinity, pid()) -> {ok, #nursery{}}. -spec do_add(#nursery{}, binary(), binary()|?TOMBSTONE, non_neg_integer() | infinity, pid()) -> {ok, #nursery{}}.
do_add(Nursery, Key, Value, infinity, Top) -> do_add(Nursery, Key, Value, infinity, Top) ->
do_add(Nursery, Key, Value, 0, Top); do_add(Nursery, Key, Value, 0, Top);
do_add(Nursery=#nursery{log_file=File, cache=Cache, total_size=TotalSize, count=Count, config=Config}, Key, Value, KeyExpiryTime, Top) -> do_add(Nursery=#nursery{log_file=File, cache=Cache, total_size=TotalSize, count=Count, config=Config}, Key, Value, KeyExpiryTime, Top) ->