Whitespace and comment cleanup.

This commit is contained in:
Gregory Burd 2012-06-11 23:40:07 +01:00
parent acbcf9d601
commit f4eea4a594
2 changed files with 7 additions and 8 deletions

View file

@ -259,7 +259,7 @@ transact(Spec, Nursery=#nursery{ log_file=File, cache=Cache0, total_size=TotalSi
Nursery1 = ensure_space(Nursery, length(Spec), Top), Nursery1 = ensure_space(Nursery, length(Spec), Top),
TStamp = hanoidb_util:tstamp(), 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), ok = file:write(File, Data),
Nursery2 = do_sync(File, Nursery1), Nursery2 = do_sync(File, Nursery1),

View file

@ -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_kv_entry(Key, Value) when is_binary(Value) ->
crc_encapsulate( [?TAG_KV_DATA, <<(byte_size(Key)):32/unsigned>>, Key | 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_kv_entry(Key, {Pos,Len}) when Len < 16#ffffffff ->
crc_encapsulate( [?TAG_POSLEN32, <<Pos:64/unsigned, Len:32/unsigned>>, Key ] ). crc_encapsulate( [?TAG_POSLEN32, <<Pos:64/unsigned, Len:32/unsigned>>, Key] ).
crc_encapsulate_transaction(TransactionSpec, TStamp) -> crc_encapsulate_transaction(TransactionSpec, TStamp) ->
crc_encapsulate( [?TAG_TRANSACT | crc_encapsulate([?TAG_TRANSACT |
lists:map( fun({delete, Key}) -> lists:map(fun({delete, Key}) ->
crc_encapsulate_kv_entry(Key, {?TOMBSTONE, TStamp}); crc_encapsulate_kv_entry(Key, {?TOMBSTONE, TStamp});
({put, Key, Value}) -> ({put, Key, Value}) ->
crc_encapsulate_kv_entry(Key, {Value, TStamp}) crc_encapsulate_kv_entry(Key, {Value, TStamp})
end, end,
TransactionSpec)] ). TransactionSpec)]).
crc_encapsulate(Blob) -> crc_encapsulate(Blob) ->
CRC = erlang:crc32(Blob), CRC = erlang:crc32(Blob),
Size = erlang:iolist_size(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(<<?TAG_END, Custom/binary>>) -> decode_kv_list(<<?TAG_END, Custom/binary>>) ->
decode_crc_data(Custom, [], []); decode_crc_data(Custom, [], []);
@ -171,13 +171,12 @@ decode_crc_data(<<>>, BrokenData, Acc) ->
%% simply returning "the good parts". %% simply returning "the good parts".
%% %%
%% {error, data_corruption}; %% {error, data_corruption};
decode_crc_data(<< BinSize:32/unsigned, CRC:32/unsigned, Bin:BinSize/binary, ?TAG_END, Rest/binary >>, Broken, Acc) -> decode_crc_data(<< BinSize:32/unsigned, CRC:32/unsigned, Bin:BinSize/binary, ?TAG_END, Rest/binary >>, Broken, Acc) ->
CRCTest = erlang:crc32( Bin ), CRCTest = erlang:crc32( Bin ),
if CRC == CRCTest -> if CRC == CRCTest ->
decode_crc_data(Rest, Broken, [ decode_kv_data( Bin ) | Acc ]); decode_crc_data(Rest, Broken, [ decode_kv_data( Bin ) | Acc ]);
true -> 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) decode_crc_data(Rest, [Bin|Broken], Acc)
end; end;