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/09 13:15:15 UTC

(couchdb) branch auto-delete-3 updated: metadata for peer checkpoints

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 054fdb506 metadata for peer checkpoints
054fdb506 is described below

commit 054fdb506356bdcf6693cbcd6cff981ccf81f171
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Apr 9 14:15:00 2025 +0100

    metadata for peer checkpoints
---
 src/couch_mrview/src/couch_mrview_index.erl        |  4 ++
 .../src/couch_replicator_scheduler_job.erl         | 15 ++++--
 src/fabric/src/fabric_drop_seq.erl                 | 57 ++++++++++++++++------
 3 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl
index dbcbf8d1d..5b1b92ba0 100644
--- a/src/couch_mrview/src/couch_mrview_index.erl
+++ b/src/couch_mrview/src/couch_mrview_index.erl
@@ -220,6 +220,8 @@ commit(State) ->
     ok = couch_file:sync(State#mrst.fd),
     fabric_drop_seq:update_peer_checkpoint_doc(
         State#mrst.db_name,
+        <<"mrview">>,
+        State#mrst.idx_name,
         couch_mrview_util:peer_checkpoint_id(State),
         State#mrst.update_seq
     ).
@@ -310,6 +312,8 @@ ensure_local_purge_doc(Db, #mrst{} = State) ->
 ensure_peer_checkpoint_doc(#mrst{} = State) ->
     fabric_drop_seq:create_peer_checkpoint_doc_if_missing(
         State#mrst.db_name,
+        <<"mrview">>,
+        State#mrst.idx_name,
         couch_mrview_util:peer_checkpoint_id(State),
         State#mrst.update_seq
     ).
diff --git a/src/couch_replicator/src/couch_replicator_scheduler_job.erl b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
index f92019cda..add67ac28 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler_job.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
@@ -887,7 +887,7 @@ do_checkpoint(State) ->
                 {TgtRevPos, TgtRevId} = update_checkpoint(
                     Target, TargetLog#doc{body = NewRepHistory}, target
                 ),
-                update_checkpoint(Source, peer_checkpoint_doc(BaseId, NewSeq), source),
+                update_checkpoint(Source, peer_checkpoint_doc(Source, BaseId, NewSeq), source),
                 NewState = State#rep_state{
                     checkpoint_history = NewRepHistory,
                     committed_seq = NewTsSeq,
@@ -921,7 +921,7 @@ create_peer_checkpoint_doc_if_missing(#httpdb{} = Db, BaseId, SourceSeq) when
         {ok, _} ->
             ok;
         {error, <<"not_found">>} ->
-            Doc = peer_checkpoint_doc(BaseId, SourceSeq),
+            Doc = peer_checkpoint_doc(Db, BaseId, SourceSeq),
             case couch_replicator_api_wrap:update_doc(Db, Doc, []) of
                 {ok, _} ->
                     ok;
@@ -932,11 +932,16 @@ create_peer_checkpoint_doc_if_missing(#httpdb{} = Db, BaseId, SourceSeq) when
             throw({checkpoint_commit_failure, Reason})
     end.
 
-peer_checkpoint_doc(BaseId, Seq) ->
-    #doc{id = peer_checkpoint_id(BaseId), body = {[{<<"update_seq">>, Seq}]}}.
+peer_checkpoint_doc(#httpdb{} = Db, BaseId, UpdateSeq) ->
+    fabric_drop_seq:peer_checkpoint_doc(
+        peer_checkpoint_id(BaseId),
+        <<"replication">>,
+        ?l2b(couch_replicator_api_wrap:db_uri(Db)),
+        UpdateSeq
+    ).
 
 peer_checkpoint_id(BaseId) when is_list(BaseId) ->
-    ?l2b(?LOCAL_DOC_PREFIX ++ "peer-checkpoint-repl-" ++ BaseId).
+    ?l2b("repl-" ++ BaseId).
 
 update_checkpoint(Db, Doc, DbType) ->
     try
diff --git a/src/fabric/src/fabric_drop_seq.erl b/src/fabric/src/fabric_drop_seq.erl
index cc5907605..a02f4264e 100644
--- a/src/fabric/src/fabric_drop_seq.erl
+++ b/src/fabric/src/fabric_drop_seq.erl
@@ -7,8 +7,9 @@
 -export([go/1]).
 
 -export([
-    create_peer_checkpoint_doc_if_missing/3,
-    update_peer_checkpoint_doc/3
+    create_peer_checkpoint_doc_if_missing/5,
+    update_peer_checkpoint_doc/5,
+    peer_checkpoint_doc/4
 ]).
 
 -type range() :: [non_neg_integer()].
@@ -228,19 +229,25 @@ latest_shard_sync_checkpoints(ShardSyncHistory) ->
         ShardSyncHistory
     ).
 
-create_peer_checkpoint_doc_if_missing(DbName, PeerId, UpdateSeq) when
+create_peer_checkpoint_doc_if_missing(DbName, Subtype, Source, PeerId, UpdateSeq) when
     is_binary(DbName), is_binary(PeerId), is_integer(UpdateSeq)
 ->
-    create_peer_checkpoint_doc_if_missing(DbName, PeerId, pack_seq(DbName, UpdateSeq));
-create_peer_checkpoint_doc_if_missing(DbName, PeerId, UpdateSeq) when
-    is_binary(DbName), is_binary(PeerId), is_binary(UpdateSeq)
+    create_peer_checkpoint_doc_if_missing(
+        DbName, Subtype, Source, PeerId, pack_seq(DbName, UpdateSeq)
+    );
+create_peer_checkpoint_doc_if_missing(DbName, Subtype, Source, PeerId, UpdateSeq) when
+    is_binary(DbName),
+    is_binary(Subtype),
+    is_binary(Source),
+    is_binary(PeerId),
+    is_binary(UpdateSeq)
 ->
     {_, Ref} = spawn_monitor(fun() ->
         case fabric:open_doc(mem3:dbname(DbName), peer_checkpoint_id(PeerId), [?ADMIN_CTX]) of
             {ok, _} ->
                 ok;
             {not_found, _} ->
-                update_peer_checkpoint_doc(DbName, PeerId, UpdateSeq);
+                update_peer_checkpoint_doc(DbName, Subtype, Source, PeerId, UpdateSeq);
             {error, Reason} ->
                 throw({checkpoint_commit_failure, Reason})
         end
@@ -252,14 +259,22 @@ create_peer_checkpoint_doc_if_missing(DbName, PeerId, UpdateSeq) when
             Else
     end.
 
-update_peer_checkpoint_doc(DbName, PeerId, UpdateSeq) when
-    is_binary(DbName), is_binary(PeerId), is_integer(UpdateSeq)
+update_peer_checkpoint_doc(DbName, Subtype, Source, PeerId, UpdateSeq) when
+    is_binary(DbName),
+    is_binary(Subtype),
+    is_binary(Source),
+    is_binary(PeerId),
+    is_integer(UpdateSeq)
 ->
-    update_peer_checkpoint_doc(DbName, PeerId, pack_seq(DbName, UpdateSeq));
-update_peer_checkpoint_doc(DbName, PeerId, UpdateSeq) when
-    is_binary(DbName), is_binary(PeerId), is_binary(UpdateSeq)
+    update_peer_checkpoint_doc(DbName, Subtype, Source, PeerId, pack_seq(DbName, UpdateSeq));
+update_peer_checkpoint_doc(DbName, Subtype, Source, PeerId, UpdateSeq) when
+    is_binary(DbName),
+    is_binary(Subtype),
+    is_binary(Source),
+    is_binary(PeerId),
+    is_binary(UpdateSeq)
 ->
-    Doc = peer_checkpoint_doc(PeerId, 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, _} ->
@@ -275,8 +290,20 @@ update_peer_checkpoint_doc(DbName, PeerId, UpdateSeq) when
             Else
     end.
 
-peer_checkpoint_doc(PeerId, UpdateSeq) when is_binary(PeerId), is_binary(UpdateSeq) ->
-    #doc{id = peer_checkpoint_id(PeerId), body = {[{<<"update_seq">>, UpdateSeq}]}}.
+peer_checkpoint_doc(PeerId, Subtype, Source, UpdateSeq) when
+    is_binary(PeerId), is_binary(Subtype), is_binary(Source), is_binary(UpdateSeq)
+->
+    #doc{
+        id = peer_checkpoint_id(PeerId),
+        body =
+            {[
+                {<<"type">>, <<"peer-checkpoint">>},
+                {<<"subtype">>, Subtype},
+                {<<"source">>, Source},
+                {<<"update_seq">>, UpdateSeq},
+                {<<"last_updated">>, ?l2b(couch_log_util:iso8601_timestamp())}
+            ]}
+    }.
 
 peer_checkpoint_id(PeerId) ->
     <<?LOCAL_DOC_PREFIX, "peer-checkpoint-", PeerId/binary>>.