Skip to content

Commit

Permalink
De-reference Type/Bucket/Key (#38)
Browse files Browse the repository at this point in the history
* De-reference Type/Bucket/Key

Maybe otherwise small binaries which hold a reference count to a much larger binary

* Only copy if > 64 bytes

Has already been copied to the local heap otherwise
  • Loading branch information
martinsumner authored Jul 7, 2024
1 parent 0c060a3 commit dd57992
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/riak_object.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1237,16 +1237,35 @@ nextgenrepl_binarykey(B, K) ->

%% @doc Deocde for nextgenrepl
-spec nextgenrepl_decode(binary()) -> riak_object()|repl_ref().
nextgenrepl_decode(<<1:4/integer, C:1/integer, R:1/integer, _:2/integer,
0:32/integer, BL:32/integer, B:BL/binary,
KL:32/integer, K:KL/binary,
ObjBin/binary>>) ->
nextgenrepl_decode(B, K, C == 1, R == 1, ObjBin);
nextgenrepl_decode(<<1:4/integer, C:1/integer, R:1/integer, _:2/integer,
TL:32/integer, T:TL/binary, BL:32/integer, B:BL/binary,
KL:32/integer, K:KL/binary,
ObjBin/binary>>) ->
nextgenrepl_decode({T, B}, K, C == 1, R == 1, ObjBin).
nextgenrepl_decode(
<<1:4/integer, C:1/integer, R:1/integer, _:2/integer,
0:32/integer,
BL:32/integer, B:BL/binary, KL:32/integer, K:KL/binary,
ObjBin/binary>>) ->
nextgenrepl_decode(
maybe_copy(B, BL),
maybe_copy(K, KL),
C == 1,
R == 1,
ObjBin
);
nextgenrepl_decode(
<<1:4/integer, C:1/integer, R:1/integer, _:2/integer,
TL:32/integer, T:TL/binary,
BL:32/integer, B:BL/binary, KL:32/integer, K:KL/binary,
ObjBin/binary>>) ->
nextgenrepl_decode(
{maybe_copy(T, TL), maybe_copy(B, BL)},
maybe_copy(K, KL),
C == 1,
R == 1,
ObjBin
).

maybe_copy(B, BL) when BL > 64 ->
binary:copy(B);
maybe_copy(B, _BL) ->
B.

nextgenrepl_decode(B, K, _, true, MetaBin) ->
<<Mega:32/integer, Secs:32/integer, Micro:32/integer, TClockBin/binary>> =
Expand Down

0 comments on commit dd57992

Please sign in to comment.