From 8073a0daa561917a1c76584755e2acbadf30ed3a Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Wed, 19 Oct 2022 13:19:48 +0200 Subject: [PATCH] Tx push at retry before mutex instead of after --- src/mrdb.erl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/mrdb.erl b/src/mrdb.erl index cbd80e9..4c79532 100644 --- a/src/mrdb.erl +++ b/src/mrdb.erl @@ -290,16 +290,13 @@ do_activity(F, Alias, Ctxt, WithLock) -> abort_and_pop(Cat, Err) end. +-spec run_f(_, #{'activity':=#{'handle':=_, 'type':='batch' | 'tx', 'attempt'=>1, 'no_snapshot'=>boolean(), 'retries'=>non_neg_integer(), _=>_}, 'alias':=_, 'db_ref':=_, 'no_snapshot'=>boolean(), 'retries'=>non_neg_integer(), _=>_}, boolean(), _) -> any(). run_f(F, Ctxt, false, _) -> push_ctxt(Ctxt), F(); run_f(F, Ctxt, true, Alias) -> - mrdb_mutex:do( - Alias, - fun() -> - push_ctxt(incr_attempt(Ctxt)), - F() - end). + push_ctxt(incr_attempt(Ctxt)), + mrdb_mutex:do(Alias, F). incr_attempt(#{ activity := #{type := tx, attempt := A} = Act, db_ref := DbRef } = C) -> {ok, TxH} = rdb_transaction(DbRef, []),