From b67d1f8449b416114f8c4aa50ef01841aba85191 Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Sun, 24 Jun 2012 17:16:42 +0530 Subject: [PATCH] WIP: sitll fixing things. --- src/hanoidb_reader.erl | 2 +- src/hanoidb_writer.erl | 45 ++++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/hanoidb_reader.erl b/src/hanoidb_reader.erl index 0cba863..79d5db3 100644 --- a/src/hanoidb_reader.erl +++ b/src/hanoidb_reader.erl @@ -261,7 +261,7 @@ close(#index{file=File}) -> lookup(#index{file=File, root=Node, bloom=Bloom}, Key) -> - case bloom:is_element(Bloom, Key) orelse Key =:= <<>> of + case bloom:is_element(Bloom, Key) of true -> case lookup_in_node(File, Node, Key) of not_found -> diff --git a/src/hanoidb_writer.erl b/src/hanoidb_writer.erl index f1d0433..56873d3 100644 --- a/src/hanoidb_writer.erl +++ b/src/hanoidb_writer.erl @@ -111,16 +111,30 @@ init([Name, Options]) -> handle_cast({add, Key, {?TOMBSTONE, TStamp}}, State) when is_binary(Key) -> - {ok, State2} = add_record(0, Key, {?TOMBSTONE, TStamp}, State), - {noreply, State2}; + NewState = + case hanoidb_util:has_expired(TStamp) of + true -> + State; + false -> + {ok, State2} = add_record(0, Key, {?TOMBSTONE, TStamp}, State), + State2 + end, + {noreply, NewState}; handle_cast({add, Key, ?TOMBSTONE}, State) when is_binary(Key) -> - {ok, State2} = add_record(0, Key, ?TOMBSTONE, State), - {noreply, State2}; + {ok, NewState} = add_record(0, Key, ?TOMBSTONE, State), + {noreply, NewState}; handle_cast({add, Key, {Value, TStamp}}, State) when is_binary(Key), is_binary(Value) -> - {ok, State2} = add_record(0, Key, {Value, TStamp}, State), - {noreply, State2}; + NewState = + case hanoidb_util:has_expired(TStamp) of + true -> + State; + false -> + {ok, State2} = add_record(0, Key, {Value, TStamp}, State), + State2 + end, + {noreply, NewState}; handle_cast({add, Key, Value}, State) when is_binary(Key), is_binary(Value) -> {ok, State2} = add_record(0, Key, Value, State), @@ -182,13 +196,13 @@ flush_nodes(#state{ nodes=[], last_node_pos=LastNodePos, last_node_size=_LastNod IdxFile = State#state.index_file, RootPos = - case LastNodePos =:= undefined of - true -> - LastNodePos; - false -> + case LastNodePos of + undefined -> %% store contains no entries ok = file:write(IdxFile, <<0:32,0:16>>), - ?FIRST_BLOCK_POS + ?FIRST_BLOCK_POS; + _ -> + LastNodePos end, BloomBin = hanoidb_util:encode_bloom(Bloom), @@ -228,10 +242,11 @@ add_record(Level, Key, Value, #state{ nodes=[ #node{level=Level, members=List, s NewSize = NodeSize + hanoidb_util:estimate_node_size_increment(List, Key, Value), - Bloom = case Key of - <<>> -> State#state.bloom; - _ -> bloom:add_element(Key, State#state.bloom) - end, + Bloom = bloom:add_element(Key, State#state.bloom), + %% Bloom = case Key of + %% <<>> -> State#state.bloom; + %% _ -> bloom:add_element(Key, State#state.bloom) + %% end, {TC1, VC1} = case Level of