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 2020/11/03 20:54:28 UTC

[couchdb] branch cache_grv created (now 2fce0fe)

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

rnewson pushed a change to branch cache_grv
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 2fce0fe  reuse GRV within an http request

This branch includes the following new commits:

     new 2fce0fe  reuse GRV within an http request

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: reuse GRV within an http request

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

rnewson pushed a commit to branch cache_grv
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 2fce0feadba490b6e6e29671604bc2fe569d5762
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Nov 3 20:23:03 2020 +0000

    reuse GRV within an http request
---
 src/chttpd/src/chttpd.erl      |  1 +
 src/fabric/include/fabric2.hrl |  1 +
 src/fabric/src/fabric2_fdb.erl | 18 ++++++++++++++++++
 3 files changed, 20 insertions(+)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index dc9a30f..663abb3 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -153,6 +153,7 @@ stop() ->
     mochiweb_http:stop(?MODULE).
 
 handle_request(MochiReq0) ->
+    fabric2_fdb:clear_grv(),
     erlang:put(?REWRITE_COUNT, 0),
     MochiReq = couch_httpd_vhost:dispatch_host(MochiReq0),
     handle_request_int(MochiReq).
diff --git a/src/fabric/include/fabric2.hrl b/src/fabric/include/fabric2.hrl
index ebbb7c7..7c355b4 100644
--- a/src/fabric/include/fabric2.hrl
+++ b/src/fabric/include/fabric2.hrl
@@ -76,6 +76,7 @@
 -define(PDICT_TX_ID_KEY, '$fabric_tx_id').
 -define(PDICT_TX_RES_KEY, '$fabric_tx_result').
 -define(PDICT_FOLD_ACC_STATE, '$fabric_fold_acc_state').
+-define(PDICT_GRV, '$fabric_grv').
 
 % Let's keep these in ascending order
 -define(TRANSACTION_TOO_OLD, 1007).
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 36fa451..04c729e 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -18,6 +18,8 @@
     transactional/3,
     transactional/2,
 
+    clear_grv/0,
+
     create/2,
     open/2,
     ensure_current/1,
@@ -158,10 +160,15 @@ transactional(#{tx := {erlfdb_transaction, _}} = Db, Fun) ->
     end).
 
 
+clear_grv() ->
+    put(?PDICT_GRV, pending).
+
+
 do_transaction(Fun, LayerPrefix) when is_function(Fun, 1) ->
     Db = get_db_handle(),
     try
         erlfdb:transactional(Db, fun(Tx) ->
+            maybe_set_grv(Tx),
             case get(erlfdb_trace) of
                 Name when is_binary(Name) ->
                     UId = erlang:unique_integer([positive]),
@@ -183,6 +190,17 @@ do_transaction(Fun, LayerPrefix) when is_function(Fun, 1) ->
     end.
 
 
+maybe_set_grv(Tx) ->
+    case get(?PDICT_GRV) of
+        undefined ->
+            ok;
+        pending ->
+            put(?PDICT_GRV, erlfdb:get_read_version(Tx));
+        GRV ->
+            erlfdb:set_read_version(Tx, erlfdb:wait(GRV))
+    end.
+
+
 create(#{} = Db0, Options) ->
     #{
         name := DbName,