From 5bdb7fd7facc33b447f8914c1e65366c93d5dfcc Mon Sep 17 00:00:00 2001 From: martinsumner Date: Thu, 8 Dec 2016 23:38:50 +0000 Subject: [PATCH] Alter Riak HEAD Change the extract of Riak metadata. In Riak-based volume tests hte writing of SFT files is tanking. Could this be the "extra" metadata. i.e. There are only current plans to look at the vclock. Sibling count is free to fetch, what if we just get these two items, will it be less CPU to extract the metadata, but also will the reduced weight reduce the downstream impact? --- src/leveled_codec.erl | 49 ++++++++----------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/src/leveled_codec.erl b/src/leveled_codec.erl index 8903198..19e9c9f 100644 --- a/src/leveled_codec.erl +++ b/src/leveled_codec.erl @@ -331,8 +331,8 @@ build_metadata_object(PrimaryKey, MD) -> {Tag, _Bucket, _Key, null} = PrimaryKey, case Tag of ?RIAK_TAG -> - {SibMetaBinList, Vclock, _Hash, _Size} = MD, - riak_metadata_to_binary(Vclock, SibMetaBinList); + {SibCount, Vclock, _Hash, _Size} = MD, + riak_metadata_to_binary(Vclock, SibCount); ?STD_TAG -> MD end. @@ -341,55 +341,24 @@ build_metadata_object(PrimaryKey, MD) -> riak_extract_metadata(delete, Size) -> {delete, null, null, Size}; riak_extract_metadata(ObjBin, Size) -> - {Vclock, SibMetaBinList} = riak_metadata_from_binary(ObjBin), - {SibMetaBinList, Vclock, erlang:phash2(ObjBin), Size}. + {Vclock, SibCount} = riak_metadata_from_binary(ObjBin), + {SibCount, Vclock, erlang:phash2(ObjBin), Size}. %% <>. -riak_metadata_to_binary(Vclock, SibMetaBinList) -> +riak_metadata_to_binary(Vclock, SibCount) -> VclockBin = term_to_binary(Vclock), VclockLen = byte_size(VclockBin), - SibCount = length(SibMetaBinList), - SibsBin = slimbin_contents(SibMetaBinList), <>. + VclockBin:VclockLen/binary, SibCount:32/integer>>. -% Fixes the value length for each sibling to be zero, and so includes no value -slimbin_content(MetaBin) -> - MetaLen = byte_size(MetaBin), - <<0:32/integer, MetaLen:32/integer, MetaBin:MetaLen/binary>>. - -slimbin_contents(SibMetaBinList) -> - F = fun(MetaBin, Acc) -> - <> - end, - lists:foldl(F, <<>>, SibMetaBinList). - riak_metadata_from_binary(V1Binary) -> <> = V1Binary, - <> = Rest, - SibMetaBinList = - case SibCount of - 0 -> - []; - SC when is_integer(SC) -> - get_metadata_from_siblings(SibsBin, SibCount, []) - end, - {binary_to_term(VclockBin), SibMetaBinList}. - -get_metadata_from_siblings(<<>>, 0, SibMetaBinList) -> - SibMetaBinList; -get_metadata_from_siblings(<>, - SibCount, - SibMetaBinList) -> - <<_ValBin:ValLen/binary, MetaLen:32/integer, Rest1/binary>> = Rest0, - <> = Rest1, - get_metadata_from_siblings(Rest2, - SibCount - 1, - [MetaBin|SibMetaBinList]). - + <> = Rest, + {binary_to_term(VclockBin), SibCount}. +