From b5c7b8bcfff3e361507b8ddb64edc94f90c13514 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Fri, 23 May 2008 16:51:46 +0000 Subject: fix for bug with reusing map btree indexes when multiple views have the same map function git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@659596 13f79535-47bb-0310-9956-ffa450edef68 --- share/server/main.js | 5 ++-- src/couchdb/couch_btree.erl | 56 +++++++++++++++++++++++---------------------- src/couchdb/couch_view.erl | 4 ++-- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/share/server/main.js b/share/server/main.js index 43660c7b..a62ed1ff 100644 --- a/share/server/main.js +++ b/share/server/main.js @@ -104,11 +104,12 @@ while (cmd = eval(readline())) { var values = null; var reduceFuns = cmd[1]; var is_combine = false; + if (cmd[0] == "reduce") { var kvs = cmd[2]; keys = new Array(kvs.length); values = new Array(kvs.length); - for (var i = 0; i < kvs.length; i++) { + for(var i = 0; i < kvs.length; i++) { keys[i] = kvs[i][0]; values[i] = kvs[i][1]; } @@ -122,7 +123,7 @@ while (cmd = eval(readline())) { } var reductions = new Array(funs.length); - for (var i = 0; i < reduceFuns.length; i++) { + for(var i = 0; i < reduceFuns.length; i++) { try { reductions[i] = reduceFuns[i](keys, values, is_combine); } catch (err) { diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl index 57013ee9..3d95ae5c 100644 --- a/src/couchdb/couch_btree.erl +++ b/src/couchdb/couch_btree.erl @@ -390,40 +390,42 @@ modify_kvnode(Bt, [{Key, Value} | RestKVs], [{ActionType, ActionKey, ActionValue end. +collect_node(_Bt, {P, R}, nil, nil) -> + {[], [{nil, {P,R}}]}; collect_node(Bt, {P, R}, KeyStart, KeyEnd) -> case get_node(Bt, P) of {kp_node, NodeList} -> collect_kp_node(Bt, NodeList, KeyStart, KeyEnd); {kv_node, KVs} -> - GTEKeyStartKVs = - case KeyStart of - nil -> - KVs; - _ -> - lists:dropwhile( - fun({Key,_}) -> - less(Bt, Key, KeyStart) - end, KVs) - end, - KVs2 = - case KeyEnd of - nil -> - GTEKeyStartKVs; - _ -> - lists:dropwhile( - fun({Key,_}) -> - less(Bt, KeyEnd, Key) - end, lists:reverse(GTEKeyStartKVs)) - end, - case length(KVs2) == length(KVs) of - true -> % got full node, return the already calculated reduction - {[], [{nil, {P, R}}]}; - false -> % otherwise return the keyvalues for later reduction - {[assemble(Bt,K,V) || {K,V} <- KVs2], []} - end + collect_kv_node(Bt, {P,R}, KVs, KeyStart, KeyEnd) end. - +collect_kv_node(Bt, {P,R}, KVs, KeyStart, KeyEnd) -> + GTEKeyStartKVs = + case KeyStart of + nil -> + KVs; + _ -> + lists:dropwhile(fun({Key,_}) -> less(Bt, Key, KeyStart) end, KVs) + end, + KVs2 = + case KeyEnd of + nil -> + GTEKeyStartKVs; + _ -> + lists:dropwhile( + fun({Key,_}) -> + less(Bt, KeyEnd, Key) + end, lists:reverse(GTEKeyStartKVs)) + end, + case length(KVs2) == length(KVs) of + true -> % got full node, return the already calculated reduction + {[], [{nil, {P, R}}]}; + false -> % otherwise return the keyvalues for later reduction + {[assemble(Bt,K,V) || {K,V} <- KVs2], []} + end. + + collect_kp_node(Bt, NodeList, KeyStart, KeyEnd) -> Nodes = case KeyStart of diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl index b14f4564..d106fdc2 100644 --- a/src/couchdb/couch_view.erl +++ b/src/couchdb/couch_view.erl @@ -116,8 +116,8 @@ reduce({reduce, NthRed, Lang, #view{btree=Bt, reduce_funs=RedFuns}}, Key1, Key2) {ok, Reduced} = couch_query_servers:combine(Lang, [FunSrc], UserReds), {0, PreResultPadding ++ Reduced ++ PostResultPadding} end, - {_, [FinalReduction]} = couch_btree:final_reduce(ReduceFun, PartialReductions), - {ok, FinalReduction}. + {_, FinalReds} = couch_btree:final_reduce(ReduceFun, PartialReductions), + {ok, lists:nth(NthRed, FinalReds)}. get_key_pos(_Key, [], _N) -> 0; -- cgit v1.2.3