Skip to content

Commit

Permalink
Improve emitted change feed sequence after a split
Browse files Browse the repository at this point in the history
 When we get sequence before the split, we'll fill in the missing (now split)
ranges with a special `{split, OldNodeUUid}` marker. However, when sequences
are emitted in the changes API, that will make the N- prefix (SeqSum) bounce
around from higher to lower numbers, while users expect those to be mostly
incrementing. So take a conservative approach and assume it will be full
rewind for that ramge, and use 0 for that range. This is a purely cosmetic
thing, when we decode the sequence that prefix gets thrown away anyway.

Fixes a part of issue: #4640
  • Loading branch information
nickva committed Jun 16, 2023
1 parent bca3ab0 commit ead9f67
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/fabric/src/fabric_view_changes.erl
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@ pack_seqs(Workers) ->
Opaque = couch_util:encodeBase64Url(?term_to_bin(SeqList, [compressed])),
?l2b([integer_to_list(SeqSum), $-, Opaque]).

% When we get sequence before the split, we'll fill in the missing (now split)
% ranges with a special {split, OldNodeUUid} marker. However, when sequences
% are emitted in the changes API, that will make the N- prefix (SeqSum) bounce
% around from higher to lower numbers, while users expect those to be mostly
% incrementing. So take a conservative approach and assume it will be full
% rewind for that ramge, and use 0 for that range. This is a purely cosmetic
% thing, when we decode the sequence that prefix gets thrown away anyway.
%
seq({Seq, {split, <<_/binary>>}, _Node}) when is_integer(Seq) -> 0;
seq({Seq, _Uuid, _Node}) -> Seq;
seq({Seq, _Uuid}) -> Seq;
seq(Seq) -> Seq.
Expand Down Expand Up @@ -1065,4 +1074,18 @@ find_replacement_sequence_test() ->
?assertEqual(0, find_replacement_sequence(Dead4, [0, 10])),
?assertEqual(0, find_replacement_sequence(Dead4, [0, 5])).

pack_split_seq_test() ->
Shards = [{"n1", 0, 10}, {"n2", 11, ?RING_END}],
Workers = mk_workers(Shards, {42, {split, <<"abc1234">>}, '[email protected]'}),
PackedSeq = pack_seqs(Workers),
?assertMatch(<<"0-", _/binary>>, PackedSeq),
DecodedSeq = decode_seq(PackedSeq),
?assertEqual(
[
{n1, [0, 10], {42, {split, <<"abc1234">>}, '[email protected]'}},
{n2, [11, 4294967295], {42, {split, <<"abc1234">>}, '[email protected]'}}
],
DecodedSeq
).

-endif.

0 comments on commit ead9f67

Please sign in to comment.