You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2025/04/24 13:33:37 UTC

(couchdb) branch auto-delete-3 updated: update peer checkpoints with correct rev

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

rnewson pushed a commit to branch auto-delete-3
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/auto-delete-3 by this push:
     new d0e3eb356 update peer checkpoints with correct rev
d0e3eb356 is described below

commit d0e3eb356e112a95914424f8116b83ab4b36b4b3
Author: Robert Newson <rn...@apache.org>
AuthorDate: Thu Apr 24 14:33:20 2025 +0100

    update peer checkpoints with correct rev
---
 src/fabric/src/fabric_drop_seq.erl | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/fabric/src/fabric_drop_seq.erl b/src/fabric/src/fabric_drop_seq.erl
index 65795c9ab..1b4ddad04 100644
--- a/src/fabric/src/fabric_drop_seq.erl
+++ b/src/fabric/src/fabric_drop_seq.erl
@@ -336,19 +336,37 @@ update_peer_checkpoint_doc(DbName, Subtype, Source, PeerId, UpdateSeq) when
     is_binary(PeerId),
     is_binary(UpdateSeq)
 ->
-    Doc = peer_checkpoint_doc(PeerId, Subtype, Source, UpdateSeq),
-    {_, Ref} = spawn_monitor(fun() ->
-        case fabric:update_doc(mem3:dbname(DbName), Doc, [?ADMIN_CTX]) of
-            {ok, _} ->
-                ok;
+    {_, OpenRef} = spawn_monitor(fun() ->
+        case
+            fabric:open_doc(mem3:dbname(DbName), peer_checkpoint_id(Subtype, PeerId), [?ADMIN_CTX])
+        of
+            {ok, Doc} ->
+                exit({ok, Doc});
+            {not_found, Reason} ->
+                throw({peer_checkpoint_missing, Reason});
             {error, Reason} ->
-                throw({checkpoint_commit_failure, Reason})
+                throw({checkpoint_fetch_failure, Reason})
         end
     end),
     receive
-        {'DOWN', Ref, _, _, ok} ->
-            ok;
-        {'DOWN', Ref, _, _, Else} ->
+        {'DOWN', OpenRef, _, _, {ok, ExistingDoc}} ->
+            NewDoc0 = peer_checkpoint_doc(PeerId, Subtype, Source, UpdateSeq),
+            NewDoc1 = NewDoc0#doc{revs = ExistingDoc#doc.revs},
+            {_, UpdateRef} = spawn_monitor(fun() ->
+                case fabric:update_doc(mem3:dbname(DbName), NewDoc1, [?ADMIN_CTX]) of
+                    {ok, _} ->
+                        ok;
+                    {error, Reason} ->
+                        throw({checkpoint_commit_failure, Reason})
+                end
+            end),
+            receive
+                {'DOWN', UpdateRef, _, _, ok} ->
+                    ok;
+                {'DOWN', UpdateRef, _, _, Else} ->
+                    Else
+            end;
+        {'DOWN', OpenRef, _, _, Else} ->
             Else
     end.