Skip to content

Commit 8e87d24

Browse files
committed
Fix replication job rewinds
This is due to #5869 (Faster selector execution by pre-parsing fields) where normalized form changed which results in all the replication jobs with selector to change their IDs and rewind. To fix, bring back the binary dotted format.
1 parent 25b1b9a commit 8e87d24

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/couch_replicator/src/couch_replicator_filters.erl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ parse(Options) ->
5252
{undefined, _, undefined} ->
5353
{ok, {docids, DocIds}};
5454
{undefined, undefined, _} ->
55-
{ok, {mango, ejsort(mango_selector:normalize(Selector))}};
55+
% We need paths to hashed with <<"a.b">> form not the new
56+
% normalized [<<"a">>, <<"b">>] form
57+
Normalized = mango_util:join_keys(mango_selector:normalize(Selector)),
58+
{ok, {mango, ejsort(Normalized)}};
5659
_ ->
5760
Err = "`selector`, `filter` and `doc_ids` are mutually exclusive",
5861
{error, list_to_binary(Err)}
@@ -217,4 +220,20 @@ ejsort_compound_values_test() ->
217220
{[{<<"x">>, Ej1s}, {<<"y">>, [Ej1s, Ej1s]}, {<<"z">>, Ej1s}]}
218221
).
219222

223+
% Regression tests for replication checkpoint stability. The hashed mango
224+
% selector must use field paths with dots: <<"a.b">> or we get rewinds!
225+
mango_selector_single_field_path_test() ->
226+
Sel = {[{<<"name">>, <<"x">>}]},
227+
?assertEqual(
228+
{ok, {mango, {[{<<"name">>, {[{<<"$eq">>, <<"x">>}]}}]}}},
229+
parse([{selector, Sel}])
230+
).
231+
232+
mango_selector_nested_field_path_test() ->
233+
Sel = {[{<<"a">>, {[{<<"b">>, 1}]}}]},
234+
?assertEqual(
235+
{ok, {mango, {[{<<"a.b">>, {[{<<"$eq">>, 1}]}}]}}},
236+
parse([{selector, Sel}])
237+
).
238+
220239
-endif.

0 commit comments

Comments
 (0)