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 10:30:23 UTC

(couchdb) 02/02: consolidate peer id generation from sig into one place

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 a33e98c424eac3dd48aa728aaf90c67fe7c4a54d
Author: Robert Newson <rn...@apache.org>
AuthorDate: Thu Apr 24 11:27:45 2025 +0100

    consolidate peer id generation from sig into one place
---
 src/couch_mrview/src/couch_mrview_index.erl |  4 ++--
 src/couch_mrview/src/couch_mrview_util.erl  |  8 --------
 src/dreyfus/src/dreyfus_index.erl           | 12 ++----------
 src/dreyfus/src/dreyfus_index_updater.erl   |  2 +-
 src/fabric/src/fabric_drop_seq.erl          | 10 +++++++++-
 src/nouveau/src/nouveau_index_updater.erl   | 11 ++---------
 6 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl
index 2c755e6f7..b7d08bddb 100644
--- a/src/couch_mrview/src/couch_mrview_index.erl
+++ b/src/couch_mrview/src/couch_mrview_index.erl
@@ -222,7 +222,7 @@ commit(State) ->
         State#mrst.db_name,
         <<"mrview">>,
         State#mrst.idx_name,
-        couch_mrview_util:peer_checkpoint_id(State),
+        fabric_drop_seq:peer_id_from_sig(State#mrst.db_name, State#mrst.sig),
         State#mrst.update_seq
     ),
     ok.
@@ -315,7 +315,7 @@ ensure_peer_checkpoint_doc(#mrst{} = State) ->
         State#mrst.db_name,
         <<"mrview">>,
         State#mrst.idx_name,
-        couch_mrview_util:peer_checkpoint_id(State),
+        fabric_drop_seq:peer_id_from_sig(State#mrst.db_name, State#mrst.sig),
         State#mrst.update_seq
     ).
 
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index f0e708722..a478685da 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -36,7 +36,6 @@
 -export([get_collator_versions/1]).
 -export([compact_on_collator_upgrade/0]).
 -export([commit_on_header_upgrade/0]).
--export([peer_checkpoint_id/1]).
 
 -define(MOD, couch_mrview_index).
 -define(GET_VIEW_RETRY_COUNT, 1).
@@ -1356,10 +1355,3 @@ compact_on_collator_upgrade() ->
 
 commit_on_header_upgrade() ->
     config:get_boolean("view_upgrade", "commit_on_header_upgrade", true).
-
-peer_checkpoint_id(#mrst{} = State) ->
-    Sig = couch_util:encodeBase64Url(State#mrst.sig),
-    Hash = couch_util:encodeBase64Url(
-        crypto:hash(sha256, [atom_to_binary(node()), $0, State#mrst.db_name])
-    ),
-    <<Sig/binary, "-", Hash/binary>>.
diff --git a/src/dreyfus/src/dreyfus_index.erl b/src/dreyfus/src/dreyfus_index.erl
index 717dd85bf..c2b6fa6ea 100644
--- a/src/dreyfus/src/dreyfus_index.erl
+++ b/src/dreyfus/src/dreyfus_index.erl
@@ -28,8 +28,7 @@
     info/1,
     group1/2,
     group2/2,
-    design_doc_to_indexes/1,
-    peer_checkpoint_id/2
+    design_doc_to_indexes/1
 ]).
 
 % gen_server api.
@@ -129,7 +128,7 @@ init({DbName, Index}) ->
                         DbName,
                         <<"search">>,
                         <<(Index#index.ddoc_id)/binary, "/", (Index#index.name)/binary>>,
-                        peer_checkpoint_id(DbName, Index#index.sig),
+                        fabric_drop_seq:peer_id_from_sig(DbName, Index#index.sig),
                         Seq
                     ),
                     proc_lib:init_ack({ok, self()}),
@@ -429,10 +428,3 @@ group2_int(Pid, QueryArgs0) ->
 
 info_int(Pid) ->
     clouseau_rpc:info(Pid).
-
-peer_checkpoint_id(DbName, Sig0) ->
-    Sig1 = couch_util:encodeBase64Url(Sig0),
-    Hash = couch_util:encodeBase64Url(
-        crypto:hash(sha256, [atom_to_binary(node()), $0, DbName])
-    ),
-    <<Sig1/binary, "-", Hash/binary>>.
diff --git a/src/dreyfus/src/dreyfus_index_updater.erl b/src/dreyfus/src/dreyfus_index_updater.erl
index 178f34de4..f8404cc53 100644
--- a/src/dreyfus/src/dreyfus_index_updater.erl
+++ b/src/dreyfus/src/dreyfus_index_updater.erl
@@ -66,7 +66,7 @@ update(IndexPid, Index) ->
                 DbName,
                 <<"search">>,
                 <<(Index#index.ddoc_id)/binary, "/", (Index#index.name)/binary>>,
-                dreyfus_index:peer_checkpoint_id(
+                fabric_drop_seq:peer_id_from_sig(
                     DbName,
                     Index#index.sig
                 ),
diff --git a/src/fabric/src/fabric_drop_seq.erl b/src/fabric/src/fabric_drop_seq.erl
index 5ad5c395e..65795c9ab 100644
--- a/src/fabric/src/fabric_drop_seq.erl
+++ b/src/fabric/src/fabric_drop_seq.erl
@@ -10,7 +10,8 @@
 -export([
     create_peer_checkpoint_doc_if_missing/5,
     update_peer_checkpoint_doc/5,
-    peer_checkpoint_doc/4
+    peer_checkpoint_doc/4,
+    peer_id_from_sig/2
 ]).
 
 -type range() :: [non_neg_integer()].
@@ -369,6 +370,13 @@ peer_checkpoint_doc(PeerId, Subtype, Source, UpdateSeq) when
 peer_checkpoint_id(Subtype, PeerId) ->
     <<?LOCAL_DOC_PREFIX, "peer-checkpoint-", Subtype/binary, "-", PeerId/binary>>.
 
+peer_id_from_sig(DbName, Sig0) ->
+    Sig1 = couch_util:encodeBase64Url(Sig0),
+    Hash = couch_util:encodeBase64Url(
+        crypto:hash(sha256, [atom_to_binary(node()), $0, DbName])
+    ),
+    <<Sig1/binary, "-", Hash/binary>>.
+
 pack_seq(DbName, UpdateSeq) ->
     DbUuid = couch_util:with_db(DbName, fun(Db) -> couch_db:get_uuid(Db) end),
     Seq0 = [node(), mem3:range(DbName), {UpdateSeq, DbUuid, node()}],
diff --git a/src/nouveau/src/nouveau_index_updater.erl b/src/nouveau/src/nouveau_index_updater.erl
index 526725960..6ba3c3738 100644
--- a/src/nouveau/src/nouveau_index_updater.erl
+++ b/src/nouveau/src/nouveau_index_updater.erl
@@ -91,7 +91,7 @@ update(#index{} = Index) ->
                     Index#index.dbname,
                     <<"nouveau">>,
                     <<(Index#index.ddoc_id)/binary, "/", (Index#index.name)/binary>>,
-                    peer_checkpoint_id(Index#index.dbname, Index#index.sig),
+                    fabric_drop_seq:peer_id_from_sig(Index#index.dbname, Index#index.sig),
                     NewCurSeq
                 ),
                 Proc = get_os_process(Index#index.def_lang),
@@ -121,7 +121,7 @@ update(#index{} = Index) ->
                         Index#index.dbname,
                         <<"nouveau">>,
                         <<(Index#index.ddoc_id)/binary, "/", (Index#index.name)/binary>>,
-                        peer_checkpoint_id(Index#index.dbname, Index#index.sig),
+                        fabric_drop_seq:peer_id_from_sig(Index#index.dbname, Index#index.sig),
                         CommittedUpdateSeq
                     ),
                     exit(nouveau_api:set_update_seq(ConnPid, Index, Acc1#acc.update_seq, NewCurSeq))
@@ -306,10 +306,3 @@ update_local_doc(Db, #index{} = Index, PurgeSeq) ->
     DocId = nouveau_util:get_local_purge_doc_id(Index#index.sig),
     DocContent = nouveau_util:get_local_purge_doc_body(DocId, PurgeSeq, Index),
     couch_db:update_doc(Db, DocContent, []).
-
-peer_checkpoint_id(DbName, Sig0) ->
-    Sig1 = couch_util:encodeBase64Url(Sig0),
-    Hash = couch_util:encodeBase64Url(
-        crypto:hash(sha256, [atom_to_binary(node()), $0, DbName])
-    ),
-    <<Sig1/binary, "-", Hash/binary>>.