This commit is contained in:
Gregory Burd 2012-06-25 11:55:07 +05:30
parent db243b9794
commit 3140f9f281
2 changed files with 12 additions and 10 deletions

View file

@ -252,7 +252,6 @@ lookup_node(File,FromKey,#node{members=Members,level=N},_) ->
end.
first_node(#index{file=File}) ->
case read_node(File, ?FIRST_BLOCK_POS) of
{ok, #node{level=0, members=Members}} ->
@ -376,15 +375,19 @@ read_node(File,{Pos,Size}) ->
hanoidb_util:decode_index_node(Level, Data);
read_node(File, Pos) ->
% error_logger:info_msg("read_node ~p ~p~n", [File, Pos]),
{ok, Pos} = file:position(File, Pos),
Result = read_node(File),
% error_logger:info_msg("decoded ~p ~p~n", [Pos, Result]),
Result.
read_node(File) ->
% error_logger:info_msg("read_node ~p~n", [File]),
{ok, <<Len:32, Level:16/unsigned>>} = file:read(File, 6),
% error_logger:info_msg("decoded ~p ~p~n", [Len, Level]),
case Len of
0 -> eof;
0 ->
eof;
_ ->
{ok, Data} = file:read(File, Len-2),
hanoidb_util:decode_index_node(Level, Data)

View file

@ -93,7 +93,7 @@ init([Name, Options]) ->
case do_open(Name, Options, [exclusive]) of
{ok, IdxFile} ->
file:write(IdxFile, ?FILE_FORMAT),
ok = file:write(IdxFile, ?FILE_FORMAT),
Bloom = bloom:new(erlang:min(Size, 16#ffffffff), 0.001),
BlockSize = hanoidb:get_opt(block_size, Options, ?NODE_SIZE),
{ok, #state{ name=Name,
@ -268,10 +268,9 @@ add_record(Level, Key, Value, #state{ nodes=[ #node{level=Level, members=List, s
{ok, State2}
end.
close_node(#state{nodes=[#node{ level=Level, members=NodeMembers }|RestNodes], compress=Compress} = State) ->
close_node(#state{nodes=[#node{ level=Level, members=NodeMembers }|RestNodes], compress=Compress, index_file_pos=NodePos} = State) ->
OrderedMembers = lists:reverse(NodeMembers),
{ok, BlockData} = hanoidb_util:encode_index_node(OrderedMembers, Compress),
NodePos = State#state.index_file_pos,
BlockSize = erlang:iolist_size(BlockData),
Data = [ <<(BlockSize+2):32/unsigned, Level:16/unsigned>> | BlockData ],