Merge branch 'dev' of git://github.com/norton/hanoidb

This commit is contained in:
Kresten Krab Thorup 2012-09-24 17:43:53 +02:00
commit 9006ef037f
7 changed files with 53 additions and 9 deletions

View file

@ -31,6 +31,6 @@
% , {lz4, ".*", {git, "git://github.com/gburd/erlang-lz4.git", {branch, "master"}}} % , {lz4, ".*", {git, "git://github.com/gburd/erlang-lz4.git", {branch, "master"}}}
% , {edown, "0.3.*", {git, "git://github.com/esl/edown.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"}}} % , {asciiedoc, "0.1.*", {git, "git://github.com/norton/asciiedoc.git", {branch, "master"}}}
, {triq, ".*", {git, "git://github.com/krestenkrab/triq.git", {branch, "master"}}} % , {triq, ".*", {git, "git://github.com/krestenkrab/triq.git", {branch, "master"}}}
, {proper, ".*", {git, "git://github.com/manopapad/proper.git", {branch, "master"}}} % , {proper, ".*", {git, "git://github.com/manopapad/proper.git", {branch, "master"}}}
]}. ]}.

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) ->

View file

@ -25,6 +25,8 @@
%% @doc Drive a set of LSM BTrees %% @doc Drive a set of LSM BTrees
-module(hanoidb_drv). -module(hanoidb_drv).
-ifdef(QC_PROPER).
-behaviour(gen_server). -behaviour(gen_server).
%% API %% API
@ -141,3 +143,4 @@ terminate(_Reason, _State) ->
code_change(_OldVsn, State, _Extra) -> code_change(_OldVsn, State, _Extra) ->
{ok, State}. {ok, State}.
-endif. %% -ifdef(QC_PROPER).

View file

@ -24,6 +24,8 @@
-module(hanoidb_merger_tests). -module(hanoidb_merger_tests).
-ifdef(QC_PROPER).
-ifdef(TEST). -ifdef(TEST).
-include_lib("proper/include/proper.hrl"). -include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
@ -62,3 +64,4 @@ merge_test() ->
ok. ok.
-endif. %% -ifdef(QC_PROPER).

View file

@ -24,6 +24,8 @@
-module(hanoidb_tests). -module(hanoidb_tests).
-ifdef(QC_PROPER).
-include("include/hanoidb.hrl"). -include("include/hanoidb.hrl").
-include("src/hanoidb.hrl"). -include("src/hanoidb.hrl").
@ -425,3 +427,5 @@ dict_range_query(Dict, Fun, Acc0, Range) ->
dict_range_query(Dict, Range) -> dict_range_query(Dict, Range) ->
[{K, V} || {K, V} <- dict:to_list(Dict), [{K, V} || {K, V} <- dict:to_list(Dict),
?KEY_IN_RANGE(K, Range)]. ?KEY_IN_RANGE(K, Range)].
-endif. %% -ifdef(QC_PROPER).

View file

@ -24,6 +24,8 @@
-module(hanoidb_writer_tests). -module(hanoidb_writer_tests).
-ifdef(QC_PROPER).
-ifdef(TEST). -ifdef(TEST).
-ifdef(TEST). -ifdef(TEST).
-ifdef(TRIQ). -ifdef(TRIQ).
@ -116,3 +118,4 @@ simple1_test() ->
ok = hanoidb_reader:close(IN). ok = hanoidb_reader:close(IN).
-endif. %% -ifdef(QC_PROPER).