You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2022/09/22 04:06:09 UTC

[couchdb] branch add-multi-open-docs-revs-worker-callback created (now d8877202f)

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

vatamane pushed a change to branch add-multi-open-docs-revs-worker-callback
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at d8877202f Add couch_db:open_doc_revs/3

This branch includes the following new commits:

     new d8877202f Add couch_db:open_doc_revs/3

The 1 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.



[couchdb] 01/01: Add couch_db:open_doc_revs/3

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch add-multi-open-docs-revs-worker-callback
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit d8877202f0fdc7b1eb7815134e4c7ff2edb3a030
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Wed Sep 21 23:57:14 2022 -0400

    Add couch_db:open_doc_revs/3
    
    This is the companion to open_doc_revs/4 which operates on a batch of docs at a
    time. As a lucky coincidence, the internal open_doc_revs_int/3 function already
    operates on batches, so we just expose the batched variant.
    
    This function will be the used to optimize the _bulk_get implementation as
    described in issue https://github.com/apache/couchdb/issues/4183. To allow
    incremental node updates, let's have the backend implementation in a separate
    commit so it could be included in separate rolling updates releases.
    
    Issue: https://github.com/apache/couchdb/issues/4183
---
 src/couch/src/couch_db.erl    | 22 ++++++++++++++++++++--
 src/fabric/src/fabric_rpc.erl |  5 ++++-
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index dd7e07517..969b93636 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -72,6 +72,7 @@
 
     open_doc/2,
     open_doc/3,
+    open_doc_revs/3,
     open_doc_revs/4,
     open_doc_int/3,
     get_doc_info/2,
@@ -347,6 +348,18 @@ find_ancestor_rev_pos({RevPos, [RevId | Rest]}, AttsSinceRevs) ->
             find_ancestor_rev_pos({RevPos - 1, Rest}, AttsSinceRevs)
     end.
 
+open_doc_revs(Db, IdRevsOpts, Options) when is_list(IdRevsOpts) ->
+    increment_stat(Db, [couchdb, database_reads], length(IdRevsOpts)),
+    % IdRevsOpts looks like [{{Id, Revs}, DocOpts}, ...]
+    {IdRevs, DocOptsOnly} = lists:unzip(IdRevsOpts),
+    % Function open_doc_revs_int takes [{Id, Revs},...] as its argument
+    AllResults = open_doc_revs_int(Db, IdRevs, Options),
+    % Apply document open options like {atts_since, ...} etc
+    ResultsZipFun = fun(DocOpts, {ok, Results}) ->
+        [apply_open_options(R, DocOpts) || R <- Results]
+    end,
+    lists:zipwith(ResultsZipFun, DocOptsOnly, AllResults).
+
 open_doc_revs(Db, Id, Revs, Options) ->
     increment_stat(Db, [couchdb, database_reads]),
     [{ok, Results}] = open_doc_revs_int(Db, [{Id, Revs}], Options),
@@ -1985,12 +1998,17 @@ after_doc_read(#db{} = Db, Doc) ->
     DocWithBody = couch_doc:with_ejson_body(Doc),
     couch_db_plugin:after_doc_read(Db, DocWithBody).
 
-increment_stat(#db{options = Options}, Stat) ->
+increment_stat(#db{} = Db, Stat) ->
+    increment_stat(Db, Stat, 1).
+
+increment_stat(#db{options = Options}, Stat, Count) when
+    is_integer(Count), Count >= 0
+->
     case lists:member(sys_db, Options) of
         true ->
             ok;
         false ->
-            couch_stats:increment_counter(Stat)
+            couch_stats:increment_counter(Stat, Count)
     end.
 
 -spec normalize_dbname(list() | binary()) -> binary().
diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index eb909519b..8b9c94c87 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -20,7 +20,7 @@
 ]).
 -export([
     open_doc/3,
-    open_revs/4,
+    open_revs/3, open_revs/4,
     get_doc_info/3,
     get_full_doc_info/3,
     get_missing_revs/2, get_missing_revs/3,
@@ -270,6 +270,9 @@ set_purge_infos_limit(DbName, Limit, Options) ->
 open_doc(DbName, DocId, Options) ->
     with_db(DbName, Options, {couch_db, open_doc, [DocId, Options]}).
 
+open_revs(DbName, IdRevsOpts, Options) ->
+    with_db(DbName, Options, {couch_db, open_doc_revs, [IdRevsOpts, Options]}).
+
 open_revs(DbName, Id, Revs, Options) ->
     with_db(DbName, Options, {couch_db, open_doc_revs, [Id, Revs, Options]}).