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 2020/04/22 17:17:07 UTC
[couchdb-erlfdb] 02/02: Do not commit read-only transactions
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git
commit 01f79dbb3938ceac4638752953b84a396d78c0ce
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Wed Apr 22 12:25:31 2020 -0400
Do not commit read-only transactions
This might save a round-trip to the network thread [1]. It also follows the
recommendation in the C api docs [2].
[1] https://forums.foundationdb.org/t/performance-of-read-only-transactions/1998
[2] https://apple.github.io/foundationdb/api-c.html#c.fdb_transaction_commit
However, it turns out in order for the watches to fire the read-only
transaction still has to commit, so avoid this optimization if has_watches(Tx)
is true.
---
src/erlfdb.erl | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/erlfdb.erl b/src/erlfdb.erl
index 2b62b91..b50f843 100644
--- a/src/erlfdb.erl
+++ b/src/erlfdb.erl
@@ -653,7 +653,10 @@ clear_erlfdb_error() ->
do_transaction(?IS_TX = Tx, UserFun) ->
try
Ret = UserFun(Tx),
- wait(commit(Tx)),
+ case is_read_only(Tx) andalso not has_watches(Tx) of
+ true -> ok;
+ false -> wait(commit(Tx))
+ end,
Ret
catch error:{erlfdb_error, Code} ->
put(?ERLFDB_ERROR, Code),