Added ability to pass flags to transaction/3
This commit is contained in:
parent
c3d7638c0b
commit
e492c51026
|
@ -14,7 +14,7 @@
|
||||||
get_cache_size/0,
|
get_cache_size/0,
|
||||||
get_data_dirs/0,
|
get_data_dirs/0,
|
||||||
get_txn_timeout/0,
|
get_txn_timeout/0,
|
||||||
transaction/1, transaction/2,
|
transaction/1, transaction/2, transaction/3,
|
||||||
put/3, put/4,
|
put/3, put/4,
|
||||||
put_r/3, put_r/4,
|
put_r/3, put_r/4,
|
||||||
put_commit/3, put_commit/4,
|
put_commit/3, put_commit/4,
|
||||||
|
@ -448,8 +448,8 @@ txn_abort() ->
|
||||||
%% where
|
%% where
|
||||||
%% Fun = function()
|
%% Fun = function()
|
||||||
%%
|
%%
|
||||||
%% @equiv transaction(Fun, infinity)
|
%% @equiv transaction(Fun, infinity, [])
|
||||||
%% @see transaction/2
|
%% @see transaction/3
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec transaction(Fun :: txn_fun()) -> {ok, db_value()} | db_error().
|
-spec transaction(Fun :: txn_fun()) -> {ok, db_value()} | db_error().
|
||||||
|
@ -458,6 +458,26 @@ transaction(Fun) ->
|
||||||
transaction(Fun, infinity).
|
transaction(Fun, infinity).
|
||||||
|
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Execute a fun inside of a transaction.
|
||||||
|
%%
|
||||||
|
%% @spec transaction(Fun, Retries) -> {ok, Value} | {error, Error}
|
||||||
|
%% where
|
||||||
|
%% Fun = function()
|
||||||
|
%% Retries = infinity | integer()
|
||||||
|
%%
|
||||||
|
%% @equiv transaction(Fun, Retries, [])
|
||||||
|
%% @see transaction/3
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
-spec transaction(Fun :: txn_fun(), Retries :: txn_retries()) ->
|
||||||
|
{ok, db_value()} | {error, db_error_reason() | {transaction_failed, term()}}.
|
||||||
|
|
||||||
|
transaction(Fun, Retries) ->
|
||||||
|
transaction(Fun, Retries, []).
|
||||||
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Execute a fun inside of a transaction.
|
%% Execute a fun inside of a transaction.
|
||||||
|
@ -472,21 +492,24 @@ transaction(Fun) ->
|
||||||
%% again until the commit succeeds or the number of retries exceeds the
|
%% again until the commit succeeds or the number of retries exceeds the
|
||||||
%% value of the `Retries' parameter.
|
%% value of the `Retries' parameter.
|
||||||
%%
|
%%
|
||||||
%% @spec transaction(Fun, Retries) -> {ok, Value} | {error, Error}
|
%% The 'Opts' parameter is used to set flags for the call to txn_begin/1.
|
||||||
|
%%
|
||||||
|
%% @spec transaction(Fun, Retries, Opts) -> {ok, Value} | {error, Error}
|
||||||
%% where
|
%% where
|
||||||
%% Fun = function()
|
%% Fun = function()
|
||||||
%% Retries = infinity | integer()
|
%% Retries = infinity | integer()
|
||||||
|
%% Opts = [atom()]
|
||||||
%%
|
%%
|
||||||
%% @end
|
%% @end
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec transaction(Fun :: txn_fun(), Retries :: txn_retries()) ->
|
-spec transaction(Fun :: txn_fun(), Retries :: txn_retries(), Opts :: db_flags()) ->
|
||||||
{ok, db_value()} | {error, db_error_reason() | {transaction_failed, term()}}.
|
{ok, db_value()} | {error, db_error_reason() | {transaction_failed, term()}}.
|
||||||
|
|
||||||
transaction(_Fun, 0) ->
|
transaction(_Fun, 0, _Opts) ->
|
||||||
ok = txn_abort(),
|
ok = txn_abort(),
|
||||||
{error, {transaction_failed, retry_limit_reached}};
|
{error, {transaction_failed, retry_limit_reached}};
|
||||||
transaction(Fun, Retries) ->
|
transaction(Fun, Retries, Opts) ->
|
||||||
case txn_begin() of
|
case txn_begin(Opts) of
|
||||||
ok ->
|
ok ->
|
||||||
try Fun() of
|
try Fun() of
|
||||||
abort ->
|
abort ->
|
||||||
|
|
Loading…
Reference in a new issue