diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2014-02-11 10:31:42 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2014-02-11 10:31:42 +0000 |
commit | 73eddad1a4751afe39477340fda6c6c7aa31fd0f (patch) | |
tree | 19908eeff8bf7124061e95a87bbe935c9abe2ee0 | |
parent | 0a7addc288aecb035525410d65279d65501c0431 (diff) | |
parent | 07228f915a2023171e3df2db45153f683f866088 (diff) | |
download | rabbitmq-server-73eddad1a4751afe39477340fda6c6c7aa31fd0f.tar.gz |
Merge bug26000 into stable again
-rw-r--r-- | src/mirrored_supervisor.erl | 15 | ||||
-rw-r--r-- | src/mirrored_supervisor_tests.erl | 19 |
2 files changed, 27 insertions, 7 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl index 6c5c09df..f44b1f1d 100644 --- a/src/mirrored_supervisor.erl +++ b/src/mirrored_supervisor.erl @@ -70,6 +70,19 @@ %% application should invoke create_tables() (or table_definitions() %% if it wants to manage table creation itself). %% +%% The TxFun parameter to start_link/{4,5} is a function which the +%% mirrored supervisor can use to execute Mnesia transactions. In the +%% RabbitMQ server this goes via a worker pool; in other cases a +%% function like: +%% +%% tx_fun(Fun) -> +%% case mnesia:sync_transaction(Fun) of +%% {atomic, Result} -> Result; +%% {aborted, Reason} -> throw({error, Reason}) +%% end. +%% +%% could be used. +%% %% Internals %% --------- %% @@ -161,7 +174,7 @@ -type group_name() :: any(). --type(tx_fun() :: fun((fun(() -> any())) -> any())). +-type(tx_fun() :: fun((fun(() -> A)) -> A)). -spec start_link(GroupName, TxFun, Module, Args) -> startlink_ret() when GroupName :: group_name(), diff --git a/src/mirrored_supervisor_tests.erl b/src/mirrored_supervisor_tests.erl index 780ef11d..6d7c55dd 100644 --- a/src/mirrored_supervisor_tests.erl +++ b/src/mirrored_supervisor_tests.erl @@ -175,14 +175,14 @@ test_start_idempotence() -> test_unsupported() -> try - ?MS:start_link({global, foo}, get_group(group), ?MODULE, + ?MS:start_link({global, foo}, get_group(group), fun tx_fun/1, ?MODULE, {sup, one_for_one, []}), exit(no_global) catch error:badarg -> ok end, try - ?MS:start_link({local, foo}, get_group(group), ?MODULE, + ?MS:start_link({local, foo}, get_group(group), fun tx_fun/1, ?MODULE, {sup, simple_one_for_one, []}), exit(no_sofo) catch error:badarg -> @@ -192,7 +192,7 @@ test_unsupported() -> %% Just test we don't blow up test_ignore() -> - ?MS:start_link({local, foo}, get_group(group), ?MODULE, + ?MS:start_link({local, foo}, get_group(group), fun tx_fun/1, ?MODULE, {sup, fake_strategy_for_ignore, []}), passed. @@ -202,7 +202,7 @@ test_startup_failure() -> test_startup_failure(Fail) -> process_flag(trap_exit, true), - ?MS:start_link(get_group(group), ?MODULE, + ?MS:start_link(get_group(group), fun tx_fun/1, ?MODULE, {sup, one_for_one, [childspec(Fail)]}), receive {'EXIT', _, shutdown} -> @@ -236,10 +236,11 @@ start_sup(Name, Group) -> start_sup({Name, []}, Group). start_sup0(anon, Group, ChildSpecs) -> - ?MS:start_link(Group, ?MODULE, {sup, one_for_one, ChildSpecs}); + ?MS:start_link(Group, fun tx_fun/1, ?MODULE, + {sup, one_for_one, ChildSpecs}); start_sup0(Name, Group, ChildSpecs) -> - ?MS:start_link({local, Name}, Group, ?MODULE, + ?MS:start_link({local, Name}, Group, fun tx_fun/1, ?MODULE, {sup, one_for_one, ChildSpecs}). childspec(Id) -> @@ -258,6 +259,12 @@ pid_of(Id) -> {received, Pid, ping} = call(Id, ping), Pid. +tx_fun(Fun) -> + case mnesia:sync_transaction(Fun) of + {atomic, Result} -> Result; + {aborted, Reason} -> throw({error, Reason}) + end. + inc_group() -> Count = case get(counter) of undefined -> 0; |