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/18 19:21:03 UTC
[couchdb-erlfdb] 01/01: Do not create a new transaction object
during retries
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch dont-create-new-tx-object-on-retries
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git
commit 15b597460d922a0e9df463bd3f2990cf6abdacb0
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Sat Apr 18 15:16:23 2020 -0400
Do not create a new transaction object during retries
`on_error` function automatically resets the transaction object but
preserves retry and backoff-related information in the object. Avoid
creating a new transaction object which would lose that context in
case transactions retry more than 2 times.
Reference:
https://apple.github.io/foundationdb/api-c.html#c.fdb_transaction_on_error
---
src/erlfdb.erl | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/erlfdb.erl b/src/erlfdb.erl
index d4e7d8a..2f6460e 100644
--- a/src/erlfdb.erl
+++ b/src/erlfdb.erl
@@ -156,7 +156,8 @@ create_transaction(?IS_DB = Db) ->
transactional(?IS_DB = Db, UserFun) when is_function(UserFun, 1) ->
clear_erlfdb_error(),
- do_transaction(Db, UserFun);
+ Tx = create_transaction(Db),
+ do_transaction(Tx, UserFun);
transactional(?IS_TX = Tx, UserFun) when is_function(UserFun, 1) ->
UserFun(Tx);
@@ -641,8 +642,7 @@ clear_erlfdb_error() ->
put(?ERLFDB_ERROR, undefined).
-do_transaction(Db, UserFun) ->
- Tx = create_transaction(Db),
+do_transaction(?IS_TX = Tx, UserFun) ->
try
Ret = UserFun(Tx),
wait(commit(Tx)),
@@ -650,7 +650,7 @@ do_transaction(Db, UserFun) ->
catch error:{erlfdb_error, Code} ->
put(?ERLFDB_ERROR, Code),
wait(on_error(Tx, Code)),
- do_transaction(Db, UserFun)
+ do_transaction(Tx, UserFun)
end.