You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2026/09/24 06:50:53 UTC

(couchdb) branch fix-view-compaction-purge-seq created (now d400c3ede)

This is an automated email from the ASF dual-hosted git repository.

nickva pushed a change to branch fix-view-compaction-purge-seq
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at d400c3ede Preserve view purge sequences when compacting

This branch includes the following new commits:

     new d400c3ede Preserve view purge sequences when compacting

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(couchdb) 01/01: Preserve view purge sequences when compacting

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nickva pushed a commit to branch fix-view-compaction-purge-seq
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit d400c3ede18e567fb2546d438b9728cce0cf9a9e
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Thu Sep 24 02:45:58 2026 -0400

    Preserve view purge sequences when compacting
    
    Previously, the view's new state was initialized with the purge sequence of the
    db. But the view might not have yet processed all the purges up until that db
    purge sequence. That lead to us possibly skipping over purges in the view (the
    ones that occurred right before the compaction started). To avoid that,
    preserve the view's old purge sequence and carry that over to the new state.
    After compaction swaps it can continue processing those purges where it left
    off.
---
 src/couch_mrview/src/couch_mrview_compactor.erl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/couch_mrview/src/couch_mrview_compactor.erl b/src/couch_mrview/src/couch_mrview_compactor.erl
index 4686d77eb..7d937c2e8 100644
--- a/src/couch_mrview/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview/src/couch_mrview_compactor.erl
@@ -40,9 +40,12 @@ compact(State) ->
         idx_name = IdxName,
         sig = Sig,
         update_seq = Seq,
+        purge_seq = PurgeSeq,
         id_btree = IdBtree,
         views = Views
     } = State,
+    % Get the old PurgeSeq and apply it to the new state when we swap down
+    % below. Do not rely on reset_index to give us the db's purge seq.
     erlang:put(io_priority, {view_compact, DbName, IdxName}),
 
     {EmptyState, NumDocIds} = couch_util:with_db(DbName, fun(Db) ->
@@ -126,10 +129,16 @@ compact(State) ->
     ),
 
     unlink(EmptyState#mrst.fd),
+    % EmptyState from reset_index/3 has the purge_seq set to db's purge
+    % sequence. However the B-trees we just copied are from the old state, and
+    % we should also carry over the old purge_seq of this view, so it can
+    % continue processsing where it left off right before the compaction
+    % started.
     {ok, EmptyState#mrst{
         id_btree = NewIdBtree,
         views = NewViews,
-        update_seq = Seq
+        update_seq = Seq,
+        purge_seq = PurgeSeq
     }}.
 
 recompact(State) ->