diff --git a/src/hanoidb_nursery.erl b/src/hanoidb_nursery.erl index c633ddc..d2ab8e7 100644 --- a/src/hanoidb_nursery.erl +++ b/src/hanoidb_nursery.erl @@ -259,7 +259,7 @@ transact(Spec, Nursery=#nursery{ log_file=File, cache=Cache0, total_size=TotalSi Nursery1 = ensure_space(Nursery, length(Spec), Top), TStamp = hanoidb_util:tstamp(), - Data = hanoidb_util:crc_encapsulate_transaction( Spec, TStamp ), + Data = hanoidb_util:crc_encapsulate_transaction(Spec, TStamp), ok = file:write(File, Data), Nursery2 = do_sync(File, Nursery1), diff --git a/src/hanoidb_util.erl b/src/hanoidb_util.erl index 256aec8..5e852f3 100644 --- a/src/hanoidb_util.erl +++ b/src/hanoidb_util.erl @@ -133,22 +133,22 @@ crc_encapsulate_kv_entry(Key, {Value, TStamp}) when is_binary(Value) -> crc_encapsulate_kv_entry(Key, Value) when is_binary(Value) -> crc_encapsulate( [?TAG_KV_DATA, <<(byte_size(Key)):32/unsigned>>, Key | Value] ); crc_encapsulate_kv_entry(Key, {Pos,Len}) when Len < 16#ffffffff -> - crc_encapsulate( [?TAG_POSLEN32, <>, Key ] ). + crc_encapsulate( [?TAG_POSLEN32, <>, Key] ). crc_encapsulate_transaction(TransactionSpec, TStamp) -> - crc_encapsulate( [?TAG_TRANSACT | - lists:map( fun({delete, Key}) -> + crc_encapsulate([?TAG_TRANSACT | + lists:map(fun({delete, Key}) -> crc_encapsulate_kv_entry(Key, {?TOMBSTONE, TStamp}); ({put, Key, Value}) -> crc_encapsulate_kv_entry(Key, {Value, TStamp}) end, - TransactionSpec)] ). + TransactionSpec)]). crc_encapsulate(Blob) -> CRC = erlang:crc32(Blob), Size = erlang:iolist_size(Blob), - [ << (Size):32/unsigned, CRC:32/unsigned >>, Blob, ?TAG_END ]. + [<< (Size):32/unsigned, CRC:32/unsigned >>, Blob, ?TAG_END]. decode_kv_list(<>) -> decode_crc_data(Custom, [], []); @@ -171,13 +171,12 @@ decode_crc_data(<<>>, BrokenData, Acc) -> %% simply returning "the good parts". %% %% {error, data_corruption}; - decode_crc_data(<< BinSize:32/unsigned, CRC:32/unsigned, Bin:BinSize/binary, ?TAG_END, Rest/binary >>, Broken, Acc) -> CRCTest = erlang:crc32( Bin ), if CRC == CRCTest -> decode_crc_data(Rest, Broken, [ decode_kv_data( Bin ) | Acc ]); true -> - %% chunk is broken, ignore it. Maybe we should tell someone? + %% TODO: chunk is broken, ignore it. Maybe we should tell someone? decode_crc_data(Rest, [Bin|Broken], Acc) end;