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 759d26bc251264f471c575a44ae7513e1d9402d1
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 | 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) ->

Reply via email to