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

rnewson pushed a commit to branch nouveau-purge-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit de9168a3e92d2ae4d63ced697be9884c582d4f1a
Author: Nick Vatamaniuc <[email protected]>
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.
    
    Fix: https://github.com/apache/couchdb/issues/6128
---
 src/couch_mrview/src/couch_mrview_compactor.erl | 9 ++++++++-
 1 file changed, 8 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..fa8ce71fe 100644
--- a/src/couch_mrview/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview/src/couch_mrview_compactor.erl
@@ -40,6 +40,7 @@ compact(State) ->
         idx_name = IdxName,
         sig = Sig,
         update_seq = Seq,
+        purge_seq = PurgeSeq,
         id_btree = IdBtree,
         views = Views
     } = State,
@@ -126,10 +127,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) ->

Reply via email to