diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-07-01 17:01:32 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-07-01 17:01:32 +0100 |
commit | 79db9f89664fc9a1cb357b1696fbc1802526e47f (patch) | |
tree | 1976cd42e0f0b099add57a2766aaae7db794e949 | |
parent | 5e7e810d856ae05c069afb69bcd0a8ee2ff353e1 (diff) | |
parent | 7d098036e5d07899fb0a4e9590107d5fd27c57a7 (diff) | |
download | rabbitmq-server-79db9f89664fc9a1cb357b1696fbc1802526e47f.tar.gz |
merge bug23825 into default
-rw-r--r-- | include/rabbit.hrl | 3 | ||||
-rw-r--r-- | src/rabbit_exchange.erl | 20 | ||||
-rw-r--r-- | src/rabbit_upgrade_functions.erl | 14 |
3 files changed, 35 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..a3300a59 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_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,6 +58,7 @@ (name()) -> rabbit_types:exchange() | rabbit_types:channel_exit()). -spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:exchange()]). +-spec(update_scratch/2 :: (name(), fun((any()) -> any())) -> 'ok'). -spec(info_keys/0 :: () -> rabbit_types:info_keys()). -spec(info/1 :: (rabbit_types:exchange()) -> rabbit_types:infos()). -spec(info/2 :: @@ -199,6 +200,23 @@ list(VHostPath) -> rabbit_exchange, #exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}). +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. 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) -> |