Skip to content

Commit

Permalink
Add open/3, open_link/1-3, and fix some dialyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
norton committed Sep 24, 2012
1 parent d143637 commit 0be2184
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
43 changes: 37 additions & 6 deletions src/hanoidb.erl
Expand Up @@ -31,7 +31,8 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
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]).

-export([get_opt/2, get_opt/3]).
Expand Down Expand Up @@ -74,16 +75,46 @@
%% Create or open a hanoidb store. Argument `Dir' names a
%% directory in which to keep the data files. By convention, we
%% 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, []).

%% @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) ->
ok = start_app(),
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
%% Close a Hanoi data store.
- spec close(Ref::pid()) -> ok.
Expand Down Expand Up @@ -277,7 +308,7 @@ open_levels(Dir, Options) ->

%% remove old nursery data file
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
{TopLevel, MaxMerge} =
Expand Down Expand Up @@ -314,7 +345,7 @@ handle_info({bottom_level, N}, #state{ nursery=Nursery, top=TopLevel }=State)
State2 = State#state{ max_level = 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};

Expand Down Expand Up @@ -367,7 +398,7 @@ handle_call({get, Key}, From, State=#state{ top=Top, nursery=Nursery } ) when is
{value, Value} when is_binary(Value) ->
{reply, {ok, Value}, State};
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}
end;

Expand Down
2 changes: 1 addition & 1 deletion src/hanoidb_nursery.erl
Expand Up @@ -99,7 +99,7 @@ read_nursery_from_log(Directory, MaxLevel, Config) ->

%% @doc Add a Key/Value to the nursery
%% @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, 0, Top);
do_add(Nursery=#nursery{log_file=File, cache=Cache, total_size=TotalSize, count=Count, config=Config}, Key, Value, KeyExpiryTime, Top) ->
Expand Down

0 comments on commit 0be2184

Please sign in to comment.