Check for return values in transaction/2. Closes 818.
This commit is contained in:
parent
6c03f7fd40
commit
fe3606b881
|
@ -109,28 +109,35 @@ transaction(_Fun, 0) ->
|
|||
txn_abort(),
|
||||
{error, {transaction_failed, retry_limit_reached}};
|
||||
transaction(Fun, Retries) ->
|
||||
txn_begin(),
|
||||
try Fun() of
|
||||
abort ->
|
||||
txn_abort(),
|
||||
{error, transaction_aborted};
|
||||
case txn_begin() of
|
||||
ok ->
|
||||
try Fun() of
|
||||
abort ->
|
||||
txn_abort(),
|
||||
{error, transaction_aborted};
|
||||
|
||||
Value ->
|
||||
txn_commit(),
|
||||
{ok, Value}
|
||||
catch
|
||||
throw : {error, {_Op, Error}} when ?is_lock_error(Error) ->
|
||||
txn_abort(),
|
||||
erlang:yield(),
|
||||
R = case Retries of
|
||||
infinity -> infinity;
|
||||
Retries -> Retries - 1
|
||||
end,
|
||||
transaction(Fun, R);
|
||||
Value ->
|
||||
case txn_commit() of
|
||||
ok -> {ok, Value};
|
||||
Error -> Error
|
||||
end
|
||||
catch
|
||||
throw : {error, {_Op, Error}} when ?is_lock_error(Error) ->
|
||||
txn_abort(),
|
||||
erlang:yield(),
|
||||
R = case Retries of
|
||||
infinity -> infinity;
|
||||
Retries -> Retries - 1
|
||||
end,
|
||||
transaction(Fun, R);
|
||||
|
||||
_ : Reason ->
|
||||
txn_abort(),
|
||||
{error, {transaction_failed, Reason}}
|
||||
_ : Reason ->
|
||||
txn_abort(),
|
||||
{error, {transaction_failed, Reason}}
|
||||
end;
|
||||
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
put(Db, Key, Value) ->
|
||||
|
@ -205,7 +212,7 @@ update(Db, Key, Fun, Args) ->
|
|||
undefined -> Fun(Key, Value);
|
||||
Args -> Fun(Key, Value, Args)
|
||||
end,
|
||||
put_commit_r(Db, Key, NewValue),
|
||||
put_r(Db, Key, NewValue),
|
||||
NewValue
|
||||
end,
|
||||
transaction(F).
|
||||
|
|
|
@ -121,18 +121,17 @@ transaction_should_abort_on_user_abort(Config) ->
|
|||
not_found = bdberl:get(Db, mykey).
|
||||
|
||||
transaction_error_should_return_error(_Config) ->
|
||||
{skip, waiting_on_bug_818}.
|
||||
%% Db = ?config(db, _Config),
|
||||
%% F = fun() ->
|
||||
%% bdberl:put(Db, mykey, should_not_see_this),
|
||||
%% %% Explicitly kill the transaction so that when transaction/2
|
||||
%% %% tries to commit it will fail
|
||||
%% bdberl:txn_abort(),
|
||||
%% %% Value to return
|
||||
%% avalue
|
||||
%% end,
|
||||
%% %% This should fail as there is no transaction to commit
|
||||
%% {error,{txn_commit,no_txn}} = bdberl:transaction(F).
|
||||
Db = ?config(db, _Config),
|
||||
F = fun() ->
|
||||
bdberl:put(Db, mykey, should_not_see_this),
|
||||
%% Explicitly kill the transaction so that when transaction/2
|
||||
%% tries to commit it will fail
|
||||
bdberl:txn_abort(),
|
||||
%% Value to return
|
||||
avalue
|
||||
end,
|
||||
%% This should fail as there is no transaction to commit
|
||||
{error,{txn_commit,no_txn}} = bdberl:transaction(F).
|
||||
|
||||
update_should_save_value_if_successful(Config) ->
|
||||
Db = ?config(db, Config),
|
||||
|
|
Loading…
Reference in a new issue