diff --git a/src/hanoidb_merger.erl b/src/hanoidb_merger.erl index 9699c50..94a106b 100644 --- a/src/hanoidb_merger.erl +++ b/src/hanoidb_merger.erl @@ -135,35 +135,41 @@ scan(BT1, BT2, Out, IsLastLevel, AKVs, [], Step) -> scan_only(BT1, Out, IsLastLevel, AKVs, Step) end; -scan(BT1, BT2, Out, IsLastLevel, [{Key1,Value1}|AT]=AKVs, [{Key2,Value2}|BT]=BKVs, Step) -> - if Key1 < Key2 -> - case ?LOCAL_WRITER of - true -> - {noreply, Out2} = hanoidb_writer:handle_cast({add, Key1, Value1}, Out); - false -> - ok = hanoidb_writer:add(Out2=Out, Key1, Value1) - end, - scan(BT1, BT2, Out2, IsLastLevel, AT, BKVs, step(Step)); - - Key2 < Key1 -> - case ?LOCAL_WRITER of - true -> - {noreply, Out2} = hanoidb_writer:handle_cast({add, Key2, Value2}, Out); - false -> - ok = hanoidb_writer:add(Out2=Out, Key2, Value2) - end, - scan(BT1, BT2, Out2, IsLastLevel, AKVs, BT, step(Step)); - - true -> - case ?LOCAL_WRITER of - true -> - {noreply, Out2} = hanoidb_writer:handle_cast({add, Key2, Value2}, Out); - false -> - ok = hanoidb_writer:add(Out2=Out, Key2, Value2) - end, - scan(BT1, BT2, Out2, IsLastLevel, AT, BT, step(Step, 2)) - end. - +scan(BT1, BT2, Out, IsLastLevel, [{Key1,Value1}|AT]=_AKVs, [{Key2,_Value2}|_BT]=BKVs, Step) + when Key1 < Key2 -> + Out3 = + case ?LOCAL_WRITER of + true -> + {noreply, Out2} = hanoidb_writer:handle_cast({add, Key1, Value1}, Out), + Out2; + false -> + ok = hanoidb_writer:add(Out, Key1, Value1), + Out + end, + scan(BT1, BT2, Out3, IsLastLevel, AT, BKVs, step(Step)); +scan(BT1, BT2, Out, IsLastLevel, [{Key1,_Value1}|_AT]=AKVs, [{Key2,Value2}|BT]=_BKVs, Step) + when Key1 > Key2 -> + Out3 = + case ?LOCAL_WRITER of + true -> + {noreply, Out2} = hanoidb_writer:handle_cast({add, Key2, Value2}, Out), + Out2; + false -> + ok = hanoidb_writer:add(Out, Key2, Value2), + Out + end, + scan(BT1, BT2, Out3, IsLastLevel, AKVs, BT, step(Step)); +scan(BT1, BT2, Out, IsLastLevel, [{_Key1,_Value1}|AT]=_AKVs, [{Key2,Value2}|BT]=_BKVs, Step) -> + Out3 = + case ?LOCAL_WRITER of + true -> + {noreply, Out2} = hanoidb_writer:handle_cast({add, Key2, Value2}, Out), + Out2; + false -> + ok = hanoidb_writer:add(Out, Key2, Value2), + Out + end, + scan(BT1, BT2, Out3, IsLastLevel, AT, BT, step(Step, 2)). hibernate_scan_only(Keep) -> erlang:garbage_collect(), @@ -213,10 +219,13 @@ scan_only(BT, Out, true, [{_,?TOMBSTONE}|Rest], Step) -> scan_only(BT, Out, true, Rest, step(Step)); scan_only(BT, Out, IsLastLevel, [{Key,Value}|Rest], Step) -> - case ?LOCAL_WRITER of - true -> - {noreply, Out2} = hanoidb_writer:handle_cast({add, Key, Value}, Out); - false -> - ok = hanoidb_writer:add(Out2=Out, Key, Value) - end, - scan_only(BT, Out2, IsLastLevel, Rest, step(Step)). + Out3 = + case ?LOCAL_WRITER of + true -> + {noreply, Out2} = hanoidb_writer:handle_cast({add, Key, Value}, Out), + Out2; + false -> + ok = hanoidb_writer:add(Out, Key, Value), + Out + end, + scan_only(BT, Out3, IsLastLevel, Rest, step(Step)). diff --git a/src/hanoidb_nursery.erl b/src/hanoidb_nursery.erl index 64f2daf..914ed1a 100644 --- a/src/hanoidb_nursery.erl +++ b/src/hanoidb_nursery.erl @@ -208,7 +208,7 @@ finish(#nursery{ dir=Dir, cache=Cache, log_file=LogFile, %% Issue some work if this is a top-level inject (blocks until previous such %% incremental merge is finished). - {ok, Nursery2} = do_inc_merge(Nursery, Count, TopLevel); + {ok, _Nursery2} = do_inc_merge(Nursery, Count, TopLevel); _ -> ok diff --git a/src/hanoidb_util.erl b/src/hanoidb_util.erl index 3a53ff3..b8c5fc6 100644 --- a/src/hanoidb_util.erl +++ b/src/hanoidb_util.erl @@ -25,7 +25,20 @@ -module(hanoidb_util). -author('Kresten Krab Thorup '). --compile(export_all). +-export([ compress/2 + , uncompress/1 + , index_file_name/1 + , estimate_node_size_increment/3 + , encode_index_node/2 + , decode_index_node/2 + , crc_encapsulate_kv_entry/2 + , decode_crc_data/3 + , file_exists/1 + , crc_encapsulate_transaction/2 + , tstamp/0 + , expiry_time/1 + , has_expired/1 + , ensure_expiry/1 ]). -include("src/hanoidb.hrl"). @@ -100,14 +113,14 @@ do_compression(gzip, Bin) -> do_compression(_, Bin) -> {?NO_COMPRESSION, Bin}. -decompress(<>) -> +uncompress(<>) -> Data; -decompress(<>) -> +uncompress(<>) -> {ok, UncompressedData} = snappy:decompress(Data), UncompressedData; -%decompress(<>) -> +%uncompress(<>) -> % lz4:uncompress(Data); -decompress(<>) -> +uncompress(<>) -> zlib:gunzip(Data). encode_index_node(KVList, Method) -> @@ -120,7 +133,7 @@ encode_index_node(KVList, Method) -> {ok, [MethodName | OutData]}. decode_index_node(Level, Data) -> - TermData = decompress(Data), + TermData = uncompress(Data), {ok, KVList} = decode_kv_list(TermData), {ok, {node, Level, KVList}}.