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/25 12:43:22 UTC

(couchdb) branch auto-delete-3 updated: a more useful response for _update_drop_seq

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 0eb86219d a more useful response for _update_drop_seq
0eb86219d is described below

commit 0eb86219d051e43273d49edb8abb8fa7aaa51024
Author: Robert Newson <rn...@apache.org>
AuthorDate: Fri Apr 25 13:43:13 2025 +0100

    a more useful response for _update_drop_seq
---
 src/chttpd/src/chttpd_db.erl       |  8 ++++++--
 src/fabric/src/fabric_drop_seq.erl | 31 +++++++++++++++++++++++--------
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index dfcfc0d7f..3e22dc423 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -395,8 +395,12 @@ handle_update_drop_seq_req(
     #httpd{method = 'POST', path_parts = [_DbName, <<"_update_drop_seq">>]} = Req, Db
 ) ->
     chttpd:validate_ctype(Req, "application/json"),
-    ok = fabric:update_drop_seq(Db),
-    send_json(Req, 201, {[{ok, true}]});
+    case fabric:update_drop_seq(Db) of
+        {ok, Results} ->
+            send_json(Req, 201, {[{ok, true}, {results, Results}]});
+        {error, Reason} ->
+            chttpd:send_error(Req, Reason)
+    end;
 handle_update_drop_seq_req(Req, _Db) ->
     send_method_not_allowed(Req, "POST").
 
diff --git a/src/fabric/src/fabric_drop_seq.erl b/src/fabric/src/fabric_drop_seq.erl
index 1b4ddad04..360ca1422 100644
--- a/src/fabric/src/fabric_drop_seq.erl
+++ b/src/fabric/src/fabric_drop_seq.erl
@@ -44,7 +44,7 @@ go(DbName) ->
                         Node,
                         {fabric_rpc, set_drop_seq, [ShardName, UuidPrefix, DropSeq, [?ADMIN_CTX]]}
                     ),
-                    {true, Shard#shard{ref = Ref}};
+                    {true, Shard#shard{ref = Ref, opts = [{drop_seq, DropSeq}]}};
                 error ->
                     false
             end
@@ -57,11 +57,11 @@ go(DbName) ->
             ok;
         true ->
             RexiMon = fabric_util:create_monitors(Shards),
-            Acc0 = {Workers, length(Workers) - 1},
+            Acc0 = {#{}, length(Workers) - 1},
             try
                 case fabric_util:recv(Workers, #shard.ref, fun handle_set_drop_seq_reply/3, Acc0) of
-                    {ok, ok} ->
-                        ok;
+                    {ok, Results} ->
+                        {ok, Results};
                     {timeout, {WorkersDict, _}} ->
                         DefunctWorkers = fabric_util:remove_done_workers(
                             WorkersDict,
@@ -86,10 +86,25 @@ calculate_drop_seqs(PeerCheckpoints0, ShardSyncHistory) ->
     PeerCheckpoints1 = maps:merge_with(fun merge_peers/3, PeerCheckpoints0, ShardSyncCheckpoints),
     crossref(PeerCheckpoints1, ShardSyncHistory).
 
-handle_set_drop_seq_reply(ok, _Worker, {_Workers, 0}) ->
-    {stop, ok};
-handle_set_drop_seq_reply(ok, Worker, {Workers, Waiting}) ->
-    {ok, {lists:delete(Worker, Workers), Waiting - 1}};
+handle_set_drop_seq_reply(ok, Worker, {Results0, Waiting}) ->
+    DropSeq = proplists:get_value(drop_seq, Worker#shard.opts),
+    [B, E] = Worker#shard.range,
+    BHex = couch_util:to_hex(<<B:32/integer>>),
+    EHex = couch_util:to_hex(<<E:32/integer>>),
+    Range = list_to_binary([BHex, "-", EHex]),
+    Results1 = maps:merge_with(
+        fun(_Key, Val1, Val2) ->
+            maps:merge(Val1, Val2)
+        end,
+        Results0,
+        #{Range => #{Worker#shard.node => DropSeq}}
+    ),
+    if
+        Waiting == 0 ->
+            {stop, Results1};
+        true ->
+            {ok, {Results1, Waiting - 1}}
+    end;
 handle_set_drop_seq_reply(Error, _, _Acc) ->
     {error, Error}.