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