Consider the nursery full when it is just below the threshold so we don't overflow the bloom filter.

This commit is contained in:
Gregory Burd 2012-06-25 07:26:29 +05:30
parent 5efb09a5f3
commit ba068a3175
2 changed files with 12 additions and 7 deletions

View file

@ -130,15 +130,14 @@ do_add(Nursery=#nursery{log_file=File, cache=Cache, total_size=TotalSize, count=
ok = file:write(File, Data),
Nursery1 = do_sync(File, Nursery),
{ok, Nursery2} = do_inc_merge(Nursery1#nursery{ cache=Cache2,
total_size=TotalSize + erlang:iolist_size(Data),
count=Count + 1 }, 1, Top),
if Count+1 >= ?BTREE_SIZE(?TOP_LEVEL) ->
{full, Nursery2};
true ->
{ok, Nursery2}
case has_room(Nursery2, 1) of
true ->
{ok, Nursery2};
false ->
{full, Nursery2}
end.
do_sync(File, Nursery) ->
@ -257,7 +256,7 @@ flush(Nursery=#nursery{ dir=Dir, max_level=MaxLevel, config=Config }, Top) ->
hanoidb_nursery:new(Dir, MaxLevel, Config).
has_room(#nursery{ count=Count }, N) ->
(Count+N) < ?BTREE_SIZE(?TOP_LEVEL).
(Count + N + 1) < ?BTREE_SIZE(?TOP_LEVEL).
ensure_space(Nursery, NeededRoom, Top) ->
case has_room(Nursery, NeededRoom) of

View file

@ -211,6 +211,12 @@ flush_nodes(#state{ nodes=[], last_node_pos=LastNodePos, last_node_size=_LastNod
ok = file:close(IdxFile),
{ok, State#state{ index_file=undefined, index_file_pos=undefined }};
flush_nodes(State=#state{ nodes=[#node{level=N, members=[{_,{Pos,_Len}}]}], last_node_pos=Pos })
when N > 0 ->
%% Ignore this node, its stack consists of one node with one {pos,len} member
flush_nodes(State#state{ nodes=[] });
flush_nodes(State) ->
{ok, State2} = close_node(State),
flush_nodes(State2).