summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-04-26 11:44:12 +0100
committerSimon MacMullen <simon@rabbitmq.com>2012-04-26 11:44:12 +0100
commit48ed9f2a5bbc39ef752c7d698416b1d368c7322e (patch)
treeb6a7727f0ecec3796ecc4f4a0f64f85be14f77bf
parente36c827ed6e4e49763196df94ef547e93384591f (diff)
downloadrabbitmq-server-git-48ed9f2a5bbc39ef752c7d698416b1d368c7322e.tar.gz
Share the exchange scratch space
-rw-r--r--include/rabbit.hrl2
-rw-r--r--src/rabbit_exchange.erl35
-rw-r--r--src/rabbit_upgrade_functions.erl18
3 files changed, 44 insertions, 11 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl
index 5c73c8b88b..8de31490c8 100644
--- a/include/rabbit.hrl
+++ b/include/rabbit.hrl
@@ -43,7 +43,7 @@
-record(resource, {virtual_host, kind, name}).
-record(exchange, {name, type, durable, auto_delete, internal, arguments,
- scratch}).
+ scratches}).
-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 ac2f26108f..7455c797e3 100644
--- a/src/rabbit_exchange.erl
+++ b/src/rabbit_exchange.erl
@@ -20,7 +20,7 @@
-export([recover/0, callback/4, declare/6,
assert_equivalence/6, assert_args_equivalence/2, check_type/1,
- lookup/1, lookup_or_die/1, list/1, lookup_scratch/1, update_scratch/2,
+ lookup/1, lookup_or_die/1, list/1, lookup_scratch/2, update_scratch/3,
info_keys/0, info/1, info/2, info_all/1, info_all/2,
route/2, delete/2]).
%% these must be run inside a mnesia tx
@@ -60,10 +60,10 @@
(name()) -> rabbit_types:exchange() |
rabbit_types:channel_exit()).
-spec(list/1 :: (rabbit_types:vhost()) -> [rabbit_types:exchange()]).
--spec(lookup_scratch/1 :: (name()) ->
+-spec(lookup_scratch/2 :: (name(), atom()) ->
rabbit_types:ok(term()) |
rabbit_types:error('not_found')).
--spec(update_scratch/2 :: (name(), fun((any()) -> any())) -> 'ok').
+-spec(update_scratch/3 :: (name(), atom(), fun((any()) -> any())) -> 'ok').
-spec(info_keys/0 :: () -> rabbit_types:info_keys()).
-spec(info/1 :: (rabbit_types:exchange()) -> rabbit_types:infos()).
-spec(info/2 ::
@@ -108,7 +108,6 @@ recover() ->
callback(X = #exchange{type = XType}, Fun, Serial0, Args) ->
%% TODO cache this?
- %% TODO what about sharing the scratch space?
Serial = fun (Bool) ->
case Serial0 of
_ when is_atom(Serial0) -> Serial0;
@@ -237,18 +236,34 @@ list(VHostPath) ->
rabbit_exchange,
#exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}).
-lookup_scratch(Name) ->
+lookup_scratch(Name, App) ->
case lookup(Name) of
- {ok, #exchange{scratch = Scratch}} -> {ok, Scratch};
- {error, not_found} -> {error, not_found}
+ {ok, #exchange{scratches = undefined}} ->
+ {error, not_found};
+ {ok, #exchange{scratches = Scratches}} ->
+ case orddict:find(App, Scratches) of
+ {ok, Value} -> {ok, Value};
+ error -> {error, not_found}
+ end;
+ {error, not_found} ->
+ {error, not_found}
end.
-update_scratch(Name, Fun) ->
+update_scratch(Name, App, 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)},
+ [X = #exchange{durable = Durable, scratches = Scratches0}] ->
+ Scratches1 = case Scratches0 of
+ undefined -> orddict:new();
+ _ -> Scratches0
+ end,
+ Scratch = case orddict:find(App, Scratches1) of
+ {ok, S} -> S;
+ error -> undefined
+ end,
+ Scratches2 = orddict:store(App, Fun(Scratch), Scratches1),
+ X1 = X#exchange{scratches = Scratches2},
ok = mnesia:write(rabbit_exchange, X1, write),
case Durable of
true -> ok = mnesia:write(rabbit_durable_exchange,
diff --git a/src/rabbit_upgrade_functions.erl b/src/rabbit_upgrade_functions.erl
index 485ccc5f02..87e560e869 100644
--- a/src/rabbit_upgrade_functions.erl
+++ b/src/rabbit_upgrade_functions.erl
@@ -37,6 +37,7 @@
-rabbit_upgrade({mirrored_supervisor, mnesia, []}).
-rabbit_upgrade({topic_trie_node, mnesia, []}).
-rabbit_upgrade({runtime_parameters, mnesia, []}).
+-rabbit_upgrade({exchange_scratches, mnesia, [exchange_scratch]}).
%% -------------------------------------------------------------------
@@ -193,6 +194,23 @@ runtime_parameters() ->
{attributes, [key, value]},
{disc_copies, [node()]}]).
+exchange_scratches() ->
+ ok = exchange_scratches(rabbit_exchange),
+ ok = exchange_scratches(rabbit_durable_exchange).
+
+exchange_scratches(Table) ->
+ transform(
+ Table,
+ fun ({exchange, Name, Type = <<"x-federation">>, Dur, AutoDel, Int, Args,
+ Scratch}) ->
+ Scratches = orddict:store(federation, Scratch, orddict:new()),
+ {exchange, Name, Type, Dur, AutoDel, Int, Args, Scratches};
+ %% We assert here that nothing else uses the scratch mechanism ATM
+ ({exchange, Name, Type, Dur, AutoDel, Int, Args, undefined}) ->
+ {exchange, Name, Type, Dur, AutoDel, Int, Args, undefined}
+ end,
+ [name, type, durable, auto_delete, internal, arguments, scratches]).
+
%%--------------------------------------------------------------------
transform(TableName, Fun, FieldList) ->