diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-06-27 17:32:57 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-06-27 17:32:57 +0100 |
commit | a0d8596c230e8ebf3e177eb0bd71b6113076d170 (patch) | |
tree | 9a19ea5cea88bf0de41796253a37bbac3434ee57 | |
parent | 63a164675ed039f00f3861e8074e64b02d4423de (diff) | |
download | rabbitmq-server-a0d8596c230e8ebf3e177eb0bd71b6113076d170.tar.gz |
Scratch space for exchanges, and rabbit_exchange:update/2.
-rw-r--r-- | include/rabbit.hrl | 3 | ||||
-rw-r--r-- | src/rabbit_exchange.erl | 23 | ||||
-rw-r--r-- | src/rabbit_upgrade_functions.erl | 14 |
3 files changed, 38 insertions, 2 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl index 00b7e6e9..9c594b05 100644 --- a/include/rabbit.hrl +++ b/include/rabbit.hrl @@ -42,7 +42,8 @@ -record(resource, {virtual_host, kind, name}). --record(exchange, {name, type, durable, auto_delete, internal, arguments}). +-record(exchange, {name, type, durable, auto_delete, internal, arguments, + scratch}). -record(exchange_serial, {name, next}). -record(amqqueue, {name, durable, auto_delete, exclusive_owner = none, diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index cab1b99f..0c335463 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, + lookup/1, lookup_or_die/1, list/1, update/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 @@ -199,6 +199,27 @@ 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. + info_keys() -> ?INFO_KEYS. map(VHostPath, F) -> diff --git a/src/rabbit_upgrade_functions.erl b/src/rabbit_upgrade_functions.erl index 0f7a7810..acf45bf3 100644 --- a/src/rabbit_upgrade_functions.erl +++ b/src/rabbit_upgrade_functions.erl @@ -32,6 +32,7 @@ -rabbit_upgrade({user_admin_to_tags, mnesia, [user_to_internal_user]}). -rabbit_upgrade({ha_mirrors, mnesia, []}). -rabbit_upgrade({gm, mnesia, []}). +-rabbit_upgrade({exchange_scratch, mnesia, [trace_exchanges]}). %% ------------------------------------------------------------------- @@ -49,6 +50,7 @@ -spec(user_admin_to_tags/0 :: () -> 'ok'). -spec(ha_mirrors/0 :: () -> 'ok'). -spec(gm/0 :: () -> 'ok'). +-spec(exchange_scratch/0 :: () -> 'ok'). -endif. @@ -155,6 +157,18 @@ gm() -> create(gm_group, [{record_name, gm_group}, {attributes, [name, version, members]}]). +exchange_scratch() -> + ok = exchange_scratch(rabbit_exchange), + ok = exchange_scratch(rabbit_durable_exchange). + +exchange_scratch(Table) -> + transform( + Table, + fun ({exchange, Name, Type, Dur, AutoDel, Int, Args}) -> + {exchange, Name, Type, Dur, AutoDel, Int, Args, undefined} + end, + [name, type, durable, auto_delete, internal, arguments, scratch]). + %%-------------------------------------------------------------------- transform(TableName, Fun, FieldList) -> |