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

vatamane pushed a commit to branch fix-dreyfus-purgeseq-tracking
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ac9238d9c1b663787524b24c17d7e34a5c96c6d0
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Mon Mar 9 16:58:08 2026 -0400

    Do not reset dreyfus purge_seq back to 0 in dreyfus
    
    Issue: https://github.com/apache/couchdb/issues/5916
    
    Previously, `dreyfus_index_updater:purge_index/3`, updated the final 
purge_seq
    from the last value seen in the accumulator. When there is nothing to purge
    that will be the initial accumulator purge_seq value = 0, which is wrong.
    
    For example, if the minimimum purge sequence is 12 and current purge 
sequence
    is 42, resetting the value back to 0 would mean the users would get an
    exception like `{invalid_start_purge_seq, 0, 12}` every time they update the
    index. To the purge system this looks like the "client" (the search index) 
has
    missed processing some purges and is now out of sync with the main database.
    
    To fix the issue we do what nouveau does, and set the index purge sequence
    based on the current database purge sequence, instead of getting it from the
    accumulator. As a side-effect, we simplify the fold function a bit, since we
    don't have to track the purge sequence inside.
---
 src/dreyfus/src/dreyfus_index_updater.erl | 43 ++++++++++++++-----------------
 1 file changed, 20 insertions(+), 23 deletions(-)

diff --git a/src/dreyfus/src/dreyfus_index_updater.erl 
b/src/dreyfus/src/dreyfus_index_updater.erl
index 6edc5a257..278d42b54 100644
--- a/src/dreyfus/src/dreyfus_index_updater.erl
+++ b/src/dreyfus/src/dreyfus_index_updater.erl
@@ -92,30 +92,27 @@ purge_index(Db, IndexPid, Index) ->
     Proc = get_os_process(Index#index.def_lang),
     try
         true = proc_prompt(Proc, [<<"add_fun">>, Index#index.def]),
-        FoldFun = fun({PurgeSeq, _UUID, Id, _Revs}, {Acc, _}) ->
-            Acc0 =
-                case couch_db:get_full_doc_info(Db, Id) of
-                    not_found ->
-                        ok = clouseau_rpc:delete(IndexPid, Id),
-                        Acc;
-                    FDI ->
-                        DI = couch_doc:to_doc_info(FDI),
-                        #doc_info{id = Id, revs = [#rev_info{rev = Rev} | _]} 
= DI,
-                        case lists:member({Id, Rev}, Acc) of
-                            true ->
-                                Acc;
-                            false ->
-                                update_or_delete_index(IndexPid, Db, DI, Proc),
-                                [{Id, Rev} | Acc]
-                        end
-                end,
-            update_task(1),
-            {ok, {Acc0, PurgeSeq}}
+        FoldFun = fun({_PurgeSeq, _UUID, Id, _Revs}, Acc) ->
+            case couch_db:get_full_doc_info(Db, Id) of
+                not_found ->
+                    ok = clouseau_rpc:delete(IndexPid, Id),
+                    update_task(1),
+                    {ok, Acc};
+                FDI ->
+                    DI = couch_doc:to_doc_info(FDI),
+                    #doc_info{id = Id, revs = [#rev_info{rev = Rev} | _]} = DI,
+                    case lists:member({Id, Rev}, Acc) of
+                        true ->
+                            {ok, Acc};
+                        false ->
+                            update_or_delete_index(IndexPid, Db, DI, Proc),
+                            update_task(1),
+                            {ok, [{Id, Rev} | Acc]}
+                    end
+            end
         end,
-
-        {ok, {ExcludeList, NewPurgeSeq}} = couch_db:fold_purge_infos(
-            Db, IdxPurgeSeq, FoldFun, {[], 0}, []
-        ),
+        {ok, ExcludeList} = couch_db:fold_purge_infos(Db, IdxPurgeSeq, 
FoldFun, []),
+        NewPurgeSeq = couch_db:get_purge_seq(Db),
         clouseau_rpc:set_purge_seq(IndexPid, NewPurgeSeq),
         update_local_doc(Db, Index, NewPurgeSeq),
         {ok, ExcludeList}

Reply via email to