diff --git a/rebar.config b/rebar.config index fc64dbf..a08116c 100644 --- a/rebar.config +++ b/rebar.config @@ -31,6 +31,6 @@ % , {lz4, ".*", {git, "git://github.com/gburd/erlang-lz4.git", {branch, "master"}}} % , {edown, "0.3.*", {git, "git://github.com/esl/edown.git", {branch, "master"}}} % , {asciiedoc, "0.1.*", {git, "git://github.com/norton/asciiedoc.git", {branch, "master"}}} - , {triq, ".*", {git, "git://github.com/krestenkrab/triq.git", {branch, "master"}}} - , {proper, ".*", {git, "git://github.com/manopapad/proper.git", {branch, "master"}}} +% , {triq, ".*", {git, "git://github.com/krestenkrab/triq.git", {branch, "master"}}} +% , {proper, ".*", {git, "git://github.com/manopapad/proper.git", {branch, "master"}}} ]}. diff --git a/src/hanoidb.erl b/src/hanoidb.erl index 3798834..53c09db 100644 --- a/src/hanoidb.erl +++ b/src/hanoidb.erl @@ -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]). @@ -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. @@ -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} = @@ -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}; @@ -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; diff --git a/src/hanoidb_nursery.erl b/src/hanoidb_nursery.erl index ebdbf61..8594223 100644 --- a/src/hanoidb_nursery.erl +++ b/src/hanoidb_nursery.erl @@ -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) -> diff --git a/test/hanoidb_drv.erl b/test/hanoidb_drv.erl index bfa9cb6..0649801 100644 --- a/test/hanoidb_drv.erl +++ b/test/hanoidb_drv.erl @@ -25,6 +25,8 @@ %% @doc Drive a set of LSM BTrees -module(hanoidb_drv). +-ifdef(QC_PROPER). + -behaviour(gen_server). %% API @@ -141,3 +143,4 @@ terminate(_Reason, _State) -> code_change(_OldVsn, State, _Extra) -> {ok, State}. +-endif. %% -ifdef(QC_PROPER). diff --git a/test/hanoidb_merger_tests.erl b/test/hanoidb_merger_tests.erl index 287c782..69b8a80 100644 --- a/test/hanoidb_merger_tests.erl +++ b/test/hanoidb_merger_tests.erl @@ -24,6 +24,8 @@ -module(hanoidb_merger_tests). +-ifdef(QC_PROPER). + -ifdef(TEST). -include_lib("proper/include/proper.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -62,3 +64,4 @@ merge_test() -> ok. +-endif. %% -ifdef(QC_PROPER). diff --git a/test/hanoidb_tests.erl b/test/hanoidb_tests.erl index dac859d..8a8750d 100644 --- a/test/hanoidb_tests.erl +++ b/test/hanoidb_tests.erl @@ -24,6 +24,8 @@ -module(hanoidb_tests). +-ifdef(QC_PROPER). + -include("include/hanoidb.hrl"). -include("src/hanoidb.hrl"). @@ -425,3 +427,5 @@ dict_range_query(Dict, Fun, Acc0, Range) -> dict_range_query(Dict, Range) -> [{K, V} || {K, V} <- dict:to_list(Dict), ?KEY_IN_RANGE(K, Range)]. + +-endif. %% -ifdef(QC_PROPER). diff --git a/test/hanoidb_writer_tests.erl b/test/hanoidb_writer_tests.erl index f01ac20..024b177 100644 --- a/test/hanoidb_writer_tests.erl +++ b/test/hanoidb_writer_tests.erl @@ -24,6 +24,8 @@ -module(hanoidb_writer_tests). +-ifdef(QC_PROPER). + -ifdef(TEST). -ifdef(TEST). -ifdef(TRIQ). @@ -116,3 +118,4 @@ simple1_test() -> ok = hanoidb_reader:close(IN). +-endif. %% -ifdef(QC_PROPER).