summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2011-06-29 12:08:49 +0100
committerSimon MacMullen <simon@rabbitmq.com>2011-06-29 12:08:49 +0100
commit2238eacec12a34849fafc68946391b5fa74c37bf (patch)
tree02baf8171fd280203aeb37e8b9929127ef4d23a1
parent5a019a63958f75164beffefc626094a6c41bea2c (diff)
downloadrabbitmq-server-2238eacec12a34849fafc68946391b5fa74c37bf.tar.gz
- use rabbit_misc:execute_mnesia_transaction
- call the function update_scratch and only update the scratch space - call Fun(X) once - make 'read' into a 'wread'
-rw-r--r--src/rabbit_exchange.erl42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl
index be88fba3..0afd2c5a 100644
--- a/src/rabbit_exchange.erl
+++ b/src/rabbit_exchange.erl
@@ -20,7 +20,7 @@
-export([recover/0, callback/3, declare/6,
assert_equivalence/6, assert_args_equivalence/2, check_type/1,
- lookup/1, lookup_or_die/1, list/1, update/2,
+ lookup/1, lookup_or_die/1, list/1, update_scratch/2,
info_keys/0, info/1, info/2, info_all/1, info_all/2,
publish/2, delete/2]).
%% these must be run inside a mnesia tx
@@ -58,9 +58,7 @@
(name()) -> rabbit_types:exchange() |
rabbit_types:channel_exit()).
-spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:exchange()]).
--spec(update/2 ::
- (name(), fun((rabbit_types:exchange()) -> rabbit_types:exchange()))
- -> rabbit_types:ok_or_error(term())).
+-spec(update_scratch/2 :: (name(), fun((term()) -> term())) -> 'ok').
-spec(info_keys/0 :: () -> rabbit_types:info_keys()).
-spec(info/1 :: (rabbit_types:exchange()) -> rabbit_types:infos()).
-spec(info/2 ::
@@ -202,26 +200,22 @@ list(VHostPath) ->
rabbit_exchange,
#exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}).
-update(Name, Fun) ->
- case mnesia:transaction(
- fun() ->
- case mnesia:read(rabbit_exchange, Name, write) of
- [X = #exchange{durable = Durable}] ->
- ok = mnesia:write(rabbit_exchange, Fun(X), write),
- case Durable of
- true ->
- ok = mnesia:write(rabbit_durable_exchange,
- Fun(X), write);
- _ ->
- ok
- end;
- [] ->
- ok
- end
- end) of
- {atomic, ok} -> ok;
- {aborted, Reason} -> {error, Reason}
- end.
+update_scratch(Name, Fun) ->
+ rabbit_misc:execute_mnesia_transaction(
+ fun() ->
+ case mnesia:wread({rabbit_exchange, Name}) of
+ [X = #exchange{durable = Durable, scratch = Scratch}] ->
+ X1 = X#exchange{scratch = Fun(Scratch)},
+ ok = mnesia:write(rabbit_exchange, X1, write),
+ case Durable of
+ true -> ok = mnesia:write(rabbit_durable_exchange,
+ X1, write);
+ _ -> ok
+ end;
+ [] ->
+ ok
+ end
+ end).
info_keys() -> ?INFO_KEYS.