Skip to content

Commit

Permalink
Skip recursive path merging, COUCHDB-968
Browse files Browse the repository at this point in the history
This patch ensures that we only ever merge a linear path into the tree.
It relies on the stemming code to collapse paths that could have been
merged together by a recursive use of merge_one.
  • Loading branch information
kocolosk committed Dec 14, 2010
1 parent 1732246 commit 9e6c3c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/couchdb/couch_key_tree.erl
Expand Up @@ -38,7 +38,7 @@ merge_one([{Start, Tree}|Rest], {StartInsert, TreeInsert}, Acc, HasConflicts) ->
case merge_at([Tree], StartInsert - Start, [TreeInsert]) of
{ok, [Merged], Conflicts} ->
MergedStart = lists:min([Start, StartInsert]),
merge_one(Rest, {MergedStart, Merged}, Acc, Conflicts or HasConflicts);
{ok, Rest ++ [{MergedStart, Merged} | Acc], Conflicts or HasConflicts};
no ->
AccOut = [{Start, Tree} | Acc],
merge_one(Rest, {StartInsert, TreeInsert}, AccOut, HasConflicts)
Expand Down
11 changes: 7 additions & 4 deletions test/etap/060-kt-merging.t
Expand Up @@ -15,7 +15,7 @@

main(_) ->
test_util:init_code_path(),
etap:plan(12),
etap:plan(14),
case (catch test()) of
ok ->
etap:end_tests();
Expand Down Expand Up @@ -106,10 +106,13 @@ test() ->
"Merging should create conflicts."
),

{MultiPaths, NoConflicts} = couch_key_tree:merge(Expect1, TwoChild),
etap:is(NoConflicts, no_conflicts, "Merge should have no conflicts."),
etap:is(length(MultiPaths), 2, "Should have two paths before stemming."),
etap:is(
{[TwoChild], no_conflicts},
couch_key_tree:merge(Expect1, TwoChild),
"Merge should have no conflicts."
couch_key_tree:stem(MultiPaths, 10),
[TwoChild],
"Stemming should collapse the paths."
),

ok.

0 comments on commit 9e6c3c3

Please sign in to comment.