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/03/10 17:14:16 UTC

(couchdb) branch auto-delete-3 updated (580d33997 -> f1d1e8baf)

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

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


 discard 580d33997 don't go lower than latest sync
     new f32920b36 don't go lower than latest sync
     new f1d1e8baf tidier?

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (580d33997)
            \
             N -- N -- N   refs/heads/auto-delete-3 (f1d1e8baf)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/fabric/src/fabric_drop_seq.erl | 122 ++++++++++++++++++-------------------
 1 file changed, 60 insertions(+), 62 deletions(-)


(couchdb) 02/02: tidier?

Posted by rn...@apache.org.
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

commit f1d1e8bafa66ef47c89573cba5b8da5521587269
Author: Robert Newson <rn...@apache.org>
AuthorDate: Mon Mar 10 17:14:00 2025 +0000

    tidier?
---
 src/fabric/src/fabric_drop_seq.erl | 122 ++++++++++++++++++-------------------
 1 file changed, 60 insertions(+), 62 deletions(-)

diff --git a/src/fabric/src/fabric_drop_seq.erl b/src/fabric/src/fabric_drop_seq.erl
index 1c3b2abb8..1416dea23 100644
--- a/src/fabric/src/fabric_drop_seq.erl
+++ b/src/fabric/src/fabric_drop_seq.erl
@@ -6,74 +6,70 @@
 
 -export([go/1]).
 
-go(DbName) ->
-    Shards = mem3:shards(DbName),
-    RangeToNodes = range_to_nodes(Shards),
+-type range() :: [non_neg_integer()].
 
-    {ok, {PeerCheckpoints, ShardSyncHistory}} = parse_local_docs(DbName),
+-type uuid() :: binary().
 
-    SyncFloor = maps:fold(
-        fun({Range, _SrcNode, TgtNode}, History, Acc) ->
-            {_SourceUuid, _SourceSeq, TargetUuid, TargetSeq} = hd(History),
-            maps:update_with(
-                {Range, TgtNode}, fun({Uuid, Seq}) -> {Uuid, Seq} end, {TargetUuid, TargetSeq}, Acc
-            )
-        end,
-        #{},
-        ShardSyncHistory
-    ),
+-type seq() :: non_neg_integer().
+
+-type peer_checkpoints() :: #{{range(), Node :: node()} => {Uuid :: uuid(), Seq :: seq()}}.
 
-    Expanded = maps:fold(
-        fun({Range, SrcNode}, {Uuid, Seq}, Acc1) ->
-            OtherNodes = maps:get(Range, RangeToNodes, []) -- [SrcNode],
-            lists:foldl(
-                fun(TgtNode, Acc2) ->
-                    History = maps:get({Range, SrcNode, TgtNode}, ShardSyncHistory, []),
+-type history_item() :: {
+    SourceUuid :: uuid(), SourceSeq :: seq(), TargetUuid :: uuid(), TargetSeq :: seq()
+}.
+
+-type shard_sync_history() :: #{
+    {Range :: range(), SourceNode :: node(), TargetNode :: node()} => [history_item()]
+}.
+
+go(DbName) ->
+    {PeerCheckpoints0, ShardSyncHistory} = parse_local_docs(DbName),
+    ShardSyncCheckpoints = latest_shard_sync_checkpoints(ShardSyncHistory),
+    PeerCheckpoints1 = maps:merge_with(fun merge_peers/3, PeerCheckpoints0, ShardSyncCheckpoints),
+    #{peercheckpoints => PeerCheckpoints0, shardsync => ShardSyncHistory, result => crossref(PeerCheckpoints1, ShardSyncHistory)}.
+
+crossref(PeerCheckpoints0, ShardSyncHistory) ->
+    PeerCheckpoints1 = maps:fold(
+        fun({Range, Node}, {Uuid, Seq}, Acc1) ->
+            Others = maps:filter(fun({R, _S, T}, _V) -> R == Range andalso T /= Node end, ShardSyncHistory),
+            maps:fold(
+                fun({R, S, T}, H, Acc2) ->
                     case
                         lists:search(
-                            fun({SourceUuid, SourceSeq, _TargetUuid, _TargetSeq}) ->
-                                Uuid == SourceUuid andalso SourceSeq =< Seq
-                            end,
-                            History
+                            fun({SU, SS, _TU, _TS}) -> Uuid == SU andalso SS =< Seq end,
+                            H
                         )
                     of
-                        {value, {_SourceUuid, _SourceSeq, TargetUuid, TargetSeq}} ->
-                            maps:update_with(
-                                {Range, TgtNode},
-                                fun({U, S}) when U == TargetUuid ->
-                                    case maps:find({Range, TgtNode}, SyncFloor) of
-                                        error ->
-                                            {U, min(TargetSeq, S)};
-                                        {ok, Floor} ->
-                                            {U, max(Floor, min(TargetSeq, S))}
-                                    end
-                                end,
-                                {TargetUuid, TargetSeq},
-                                Acc2
-                            );
+                        {value, {_SU, _SS, TU, TS}} ->
+                            maps:merge_with(fun merge_peers/3, #{{R, T} => {TU, TS}}, Acc2);
                         false ->
                             Acc2
                     end
                 end,
-                Acc1,
-                OtherNodes
+              Acc1,
+                Others
             )
         end,
-        PeerCheckpoints,
-        PeerCheckpoints
-    ),
-
-    Workers = lists:map(
-        fun(#shard{} = Shard) ->
-            {Shard, maps:get({Shard#shard.range, Shard#shard.node}, Expanded, undefined)}
-        end,
-        Shards
+        PeerCheckpoints0,
+        PeerCheckpoints0
     ),
 
-    Workers.
-
+    %% mem3 sync is not hub-spoke, each iteration of crossref will add
+    %% some crossreferences. we call it again if the map changes as new
+    %% crossreferences may be possible.
+    if
+        PeerCheckpoints0 == PeerCheckpoints1 ->
+            PeerCheckpoints1;
+        true ->
+            crossref(PeerCheckpoints1, ShardSyncHistory)
+    end.
+
+-spec parse_local_docs(DbName :: binary()) -> {peer_checkpoints(), shard_sync_history()}.
 parse_local_docs(DbName) ->
-    fabric:all_docs(DbName, fun parse_local_docs_cb/2, {#{}, #{}}, all_docs_mrargs()).
+    {ok, Result} = fabric:all_docs(
+        DbName, fun parse_local_docs_cb/2, {#{}, #{}}, all_docs_mrargs()
+    ),
+    Result.
 
 parse_local_docs_cb({row, Row}, Acc) ->
     case lists:keyfind(doc, 1, Row) of
@@ -94,6 +90,7 @@ parse_local_doc(#doc{id = <<"_local/shard-sync-", _/binary>>} = Doc, Acc) ->
         DbName ->
             Range = mem3:range(DbName),
             {[{_SrcNode, History}]} = couch_util:get_value(<<"history">>, Props),
+            {PeerCheckpoints, ShardSyncHistory0} = Acc,
             KeyFun = fun({Item}) ->
                 {Range, binary_to_existing_atom(couch_util:get_value(<<"source_node">>, Item)),
                     binary_to_existing_atom(couch_util:get_value(<<"target_node">>, Item))}
@@ -106,7 +103,7 @@ parse_local_doc(#doc{id = <<"_local/shard-sync-", _/binary>>} = Doc, Acc) ->
                     couch_util:get_value(<<"target_seq">>, Item)
                 }
             end,
-            {PeerCheckpoints, ShardSyncHistory0} = Acc,
+
             ShardSyncHistory1 = maps:merge(
                 maps:groups_from_list(KeyFun, ValueFun, History), ShardSyncHistory0
             ),
@@ -127,15 +124,6 @@ parse_local_doc(#doc{id = <<"_local/peer-checkpoint-", _/binary>>} = Doc, Acc) -
 parse_local_doc(_Doc, Acc) ->
     {ok, Acc}.
 
-range_to_nodes(Shards) ->
-    maps:groups_from_list(fun range/1, fun node/1, Shards).
-
-range(Shard) ->
-    Shard#shard.range.
-
-node(Shard) ->
-    Shard#shard.node.
-
 merge_peers(_Key, {Uuid, Val1}, {Uuid, Val2}) when is_integer(Val1), is_integer(Val2) ->
     {Uuid, min(Val1, Val2)}.
 
@@ -170,3 +158,13 @@ all_docs_mrargs() ->
             {namespace, <<"_local">>}
         ]
     }.
+
+latest_shard_sync_checkpoints(ShardSyncHistory) ->
+    maps:fold(
+        fun({R, _SN, TN}, History, Acc) ->
+            {_, _, TU, TS} = hd(History),
+            maps:merge_with(fun merge_peers/3, #{{R, TN} => {TU, TS}}, Acc)
+        end,
+        #{},
+        ShardSyncHistory
+    ).


(couchdb) 01/02: don't go lower than latest sync

Posted by rn...@apache.org.
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

commit f32920b362b71e4b26239aae21d30ed77e63e911
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Mar 5 15:57:36 2025 +0000

    don't go lower than latest sync
---
 src/fabric/src/fabric_drop_seq.erl | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/fabric/src/fabric_drop_seq.erl b/src/fabric/src/fabric_drop_seq.erl
index 5d790b383..1c3b2abb8 100644
--- a/src/fabric/src/fabric_drop_seq.erl
+++ b/src/fabric/src/fabric_drop_seq.erl
@@ -12,6 +12,17 @@ go(DbName) ->
 
     {ok, {PeerCheckpoints, ShardSyncHistory}} = parse_local_docs(DbName),
 
+    SyncFloor = maps:fold(
+        fun({Range, _SrcNode, TgtNode}, History, Acc) ->
+            {_SourceUuid, _SourceSeq, TargetUuid, TargetSeq} = hd(History),
+            maps:update_with(
+                {Range, TgtNode}, fun({Uuid, Seq}) -> {Uuid, Seq} end, {TargetUuid, TargetSeq}, Acc
+            )
+        end,
+        #{},
+        ShardSyncHistory
+    ),
+
     Expanded = maps:fold(
         fun({Range, SrcNode}, {Uuid, Seq}, Acc1) ->
             OtherNodes = maps:get(Range, RangeToNodes, []) -- [SrcNode],
@@ -27,7 +38,19 @@ go(DbName) ->
                         )
                     of
                         {value, {_SourceUuid, _SourceSeq, TargetUuid, TargetSeq}} ->
-                            Acc2#{{Range, TgtNode} => {TargetUuid, TargetSeq}};
+                            maps:update_with(
+                                {Range, TgtNode},
+                                fun({U, S}) when U == TargetUuid ->
+                                    case maps:find({Range, TgtNode}, SyncFloor) of
+                                        error ->
+                                            {U, min(TargetSeq, S)};
+                                        {ok, Floor} ->
+                                            {U, max(Floor, min(TargetSeq, S))}
+                                    end
+                                end,
+                                {TargetUuid, TargetSeq},
+                                Acc2
+                            );
                         false ->
                             Acc2
                     end