couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bbast...@apache.org
Subject [03/41] couch-mrview commit: updated refs/heads/master to 28e51f3
Date Fri, 31 Oct 2014 19:53:18 GMT
couch_mrview: fix purge when seq_indexed=true

This change makes tsure to also purge the log btree and related btrees
in views when seqs_indexed is set to true.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/deb8139b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/deb8139b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/deb8139b

Branch: refs/heads/master
Commit: deb8139b8ce94965abba6beb842b9579b569bd2a
Parents: 44c07c3
Author: benoitc <benoitc@apache.org>
Authored: Mon Jan 27 10:14:59 2014 +0100
Committer: Benjamin Bastian <benjamin.bastian@gmail.com>
Committed: Thu Oct 30 13:38:32 2014 -0700

----------------------------------------------------------------------
 src/couch_mrview.erl         |  1 -
 src/couch_mrview_updater.erl | 57 ++++++++++++++++++++++++++++-----------
 2 files changed, 41 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/deb8139b/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index afb6f1e..343b91a 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -150,7 +150,6 @@ view_changes_since(Db, DDoc, VName, StartSeq, Fun, Options, Acc) ->
                 true -> View#mrview.key_byseq_btree;
                 _ -> View#mrview.seq_btree
             end,
-            io:format("opt list ~p~n", [OptList]),
             AccOut = lists:foldl(fun(Opts, Acc0) ->
                         {ok, _R, A} = couch_mrview_util:fold_changes(
                                     Btree, Fun, Acc0, Opts),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/deb8139b/src/couch_mrview_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_updater.erl b/src/couch_mrview_updater.erl
index eb06c92..27cf795 100644
--- a/src/couch_mrview_updater.erl
+++ b/src/couch_mrview_updater.erl
@@ -55,40 +55,66 @@ start_update(Partial, State, NumChanges) ->
 purge(_Db, PurgeSeq, PurgedIdRevs, State) ->
     #mrst{
         id_btree=IdBtree,
+        log_btree=LogBtree,
         views=Views
     } = State,
 
     Ids = [Id || {Id, _Revs} <- PurgedIdRevs],
-    {ok, Lookups, IdBtree2} = couch_btree:query_modify(IdBtree, Ids, [], Ids),
+    {ok, Lookups, LLookups, LogBtree2, IdBtree2} = case LogBtree of
+        nil ->
+            {ok, L, Bt} = couch_btree:query_modify(IdBtree, Ids, [], Ids),
+            {ok, L, [], nil, Bt};
+        _ ->
+            {ok, L, Bt} = couch_btree:query_modify(IdBtree, Ids, [], Ids),
+            {ok, LL, LBt} = couch_btree:query_modify(LogBtree, Ids, [], Ids),
+            {ok, L, LL, LBt, Bt}
+    end,
 
     MakeDictFun = fun
         ({ok, {DocId, ViewNumRowKeys}}, DictAcc) ->
-            FoldFun = fun({ViewNum, RowKey}, DictAcc2) ->
-                dict:append(ViewNum, {RowKey, DocId}, DictAcc2)
+            FoldFun = fun
+                ({ViewNum, {Key, Seq, _Op}}, DictAcc2) ->
+                    dict:append(ViewNum, {Key, Seq, DocId}, DictAcc2);
+                ({ViewNum, RowKey}, DictAcc2) ->
+                    dict:append(ViewNum, {RowKey, DocId}, DictAcc2)
             end,
             lists:foldl(FoldFun, DictAcc, ViewNumRowKeys);
         ({not_found, _}, DictAcc) ->
             DictAcc
     end,
     KeysToRemove = lists:foldl(MakeDictFun, dict:new(), Lookups),
+    SeqsToRemove = lists:foldl(MakeDictFun, dict:new(), LLookups),
+
+    RemKeysFun = fun(#mrview{id_num=ViewId}=View) ->
+        ToRem = couch_util:dict_find(ViewId, KeysToRemove, []),
+        {ok, VBtree2} = couch_btree:add_remove(View#mrview.btree, [], ToRem),
+        NewPurgeSeq = case VBtree2 =/= View#mrview.btree of
+            true -> PurgeSeq;
+            _ -> View#mrview.purge_seq
+        end,
+        {SeqBtree2, KeyBySeqBtree2} = case View#mrview.seq_indexed of
+            true ->
+                SToRem = couch_util:dict_find(ViewId, SeqsToRemove, []),
+                SKs = [{Seq, Key} || {Key, Seq, _} <- SToRem],
+                KSs = [{[Seq, Key], DocId} || {Key, Seq, DocId} <- SToRem],
+                {ok, SBt} = couch_btree:add_remove(View#mrview.seq_btree,
+                                                   [], SKs),
+                {ok, KSbt} = couch_btree:add_remove(View#mrview.key_byseq_btree,
+                                                    [], KSs),
+                {SBt, KSbt};
+            _ -> {nil, nil}
+        end,
+        View#mrview{btree=VBtree2,
+                    seq_btree=SeqBtree2,
+                    key_byseq_btree=KeyBySeqBtree2,
+                    purge_seq=NewPurgeSeq}
 
-    RemKeysFun = fun(#mrview{id_num=Num, btree=Btree}=View) ->
-        case dict:find(Num, KeysToRemove) of
-            {ok, RemKeys} ->
-                {ok, Btree2} = couch_btree:add_remove(Btree, [], RemKeys),
-                NewPurgeSeq = case Btree2 /= Btree of
-                    true -> PurgeSeq;
-                    _ -> View#mrview.purge_seq
-                end,
-                View#mrview{btree=Btree2, purge_seq=NewPurgeSeq};
-            error ->
-                View
-        end
     end,
 
     Views2 = lists:map(RemKeysFun, Views),
     {ok, State#mrst{
         id_btree=IdBtree2,
+        log_btree=LogBtree2,
         views=Views2,
         purge_seq=PurgeSeq
     }}.
@@ -345,7 +371,6 @@ update_log(Btree, Log, UpdatedSeq, _) ->
                             end, KeysAcc, DIKeys),
                 {[Id | IdsAcc], KeysAcc1} end, {[], []}, Log),
 
-    io:format("updated ~p~n", [Updated]),
     RemValue = {[{<<"_removed">>, true}]},
     {Log1, AddAcc, DelAcc} = walk_log(Btree, fun({DocId, VIdKeys},
                                                           {Log2, AddAcc2, DelAcc2}) ->


Mime
View raw message