summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2018-10-11 12:12:39 +0200
committerJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2019-02-01 11:23:15 +0100
commit93168ae5cc707efd524116d85bd9a62d867f6699 (patch)
tree9d3eda89eed1e63344ff6899404a15f222f87dd9 /include
parentb0d54da7e5ca68456fa9e2d60831f13e454911c1 (diff)
downloadrabbitmq-server-git-93168ae5cc707efd524116d85bd9a62d867f6699.tar.gz
Make #amqqueue{} a private record + add a feature flag
The #amqqueue{} record is now isolated in the `amqqueue` module: all accesses and modifications to the record are made through this helper. The type `rabbit_types:amqqueue()` is now `amqqueue:amqqueue()`. `amqqueue` knows about the new #amqqueue{} record introduced with quorum queues. If the actual record is the old one (as defined in RabbitMQ 3.7.x), it calls `amqqueue_v1` which knows about the old definition. When it needs to produce an #amqqueue{} record, it verifies if it is allowed to, using the new Feature flags subsystem and the `quorum_queue` feature flag specifically, and proceeds. If an old format #amqqueue{} is required, the creation is deferred to `amqqueue_v1`. The new modules come with a couple headers: they provide macros to replace pattern matching with `when` conditions. The `amqqueue_v*.hrl` headers are generated using the `macros()` functions in `amqqueue` and `amqqueue_v1` modules. Some operations now depend on the state of the `quorum_queue` feature flag. In particular, creating a quorum queue is denied if the feature flag is disabled. In the process, the following modules were moved from rabbitmq-common to rabbitmq-server: * rabbit_backing_queue * rabbit_queue_master_locator Likewise, the few functions were copied from `rabbit_misc` to `rabbit_amqqueue` because they depend on `amqqueue`. They don't really need to live in rabbitmq-common and they prevent further progress with the feature flags: feature flags need informations about the cluster. The `quorum_queue` feature flag comes with a migration function which is responsible of converting the #amqqueue{} records in Mnesia tables `rabbit_queue` and `rabbit_durable_queue`. Therefore, the upgrade function which did this is removed in this commit. [#159298729]
Diffstat (limited to 'include')
-rw-r--r--include/amqqueue.hrl113
-rw-r--r--include/amqqueue_v1.hrl20
-rw-r--r--include/amqqueue_v2.hrl22
3 files changed, 155 insertions, 0 deletions
diff --git a/include/amqqueue.hrl b/include/amqqueue.hrl
new file mode 100644
index 0000000000..d08a740d95
--- /dev/null
+++ b/include/amqqueue.hrl
@@ -0,0 +1,113 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2018-2019 Pivotal Software, Inc. All rights reserved.
+%%
+
+-include("amqqueue_v1.hrl").
+-include("amqqueue_v2.hrl").
+
+-define(is_amqqueue(Q),
+ (?is_amqqueue_v2(Q) orelse
+ ?is_amqqueue_v1(Q))).
+
+-define(amqqueue_is_auto_delete(Q),
+ ((?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_field_auto_delete(Q) =:= true) orelse
+ (?is_amqqueue_v1(Q) andalso
+ ?amqqueue_v1_field_auto_delete(Q) =:= true))).
+
+-define(amqqueue_is_durable(Q),
+ ((?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_field_durable(Q) =:= true) orelse
+ (?is_amqqueue_v1(Q) andalso
+ ?amqqueue_v1_field_durable(Q) =:= true))).
+
+-define(amqqueue_exclusive_owner_is(Q, Owner),
+ ((?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_field_exclusive_owner(Q) =:= Owner) orelse
+ (?is_amqqueue_v1(Q) andalso
+ ?amqqueue_v1_field_exclusive_owner(Q) =:= Owner))).
+
+-define(amqqueue_exclusive_owner_is_pid(Q),
+ ((?is_amqqueue_v2(Q) andalso
+ is_pid(?amqqueue_v2_field_exclusive_owner(Q))) orelse
+ (?is_amqqueue_v1(Q) andalso
+ is_pid(?amqqueue_v1_field_exclusive_owner(Q))))).
+
+-define(amqqueue_state_is(Q, State),
+ ((?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_field_state(Q) =:= State) orelse
+ (?is_amqqueue_v1(Q) andalso
+ ?amqqueue_v1_field_state(Q) =:= State))).
+
+-define(amqqueue_v1_type, classic).
+
+-define(amqqueue_is_classic(Q),
+ ((?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_field_type(Q) =:= classic) orelse
+ ?is_amqqueue_v1(Q))).
+
+-define(amqqueue_is_quorum(Q),
+ (?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_field_type(Q) =:= quorum) orelse
+ false).
+
+-define(amqqueue_has_valid_pid(Q),
+ ((?is_amqqueue_v2(Q) andalso
+ is_pid(?amqqueue_v2_field_pid(Q))) orelse
+ (?is_amqqueue_v1(Q) andalso
+ is_pid(?amqqueue_v1_field_pid(Q))))).
+
+-define(amqqueue_pid_runs_on_local_node(Q),
+ ((?is_amqqueue_v2(Q) andalso
+ node(?amqqueue_v2_field_pid(Q)) =:= node()) orelse
+ (?is_amqqueue_v1(Q) andalso
+ node(?amqqueue_v1_field_pid(Q)) =:= node()))).
+
+-define(amqqueue_pid_equals(Q, Pid),
+ ((?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_field_pid(Q) =:= Pid) orelse
+ (?is_amqqueue_v1(Q) andalso
+ ?amqqueue_v1_field_pid(Q) =:= Pid))).
+
+-define(amqqueue_pids_are_equal(Q0, Q1),
+ ((?is_amqqueue_v2(Q0) andalso ?is_amqqueue_v2(Q1) andalso
+ ?amqqueue_v2_field_pid(Q0) =:= ?amqqueue_v2_field_pid(Q1)) orelse
+ (?is_amqqueue_v1(Q0) andalso ?is_amqqueue_v1(Q1) andalso
+ ?amqqueue_v1_field_pid(Q0) =:= ?amqqueue_v1_field_pid(Q1)))).
+
+-define(amqqueue_field_name(Q),
+ case ?is_amqqueue_v2(Q) of
+ true -> ?amqqueue_v2_field_name(Q);
+ false -> case ?is_amqqueue_v1(Q) of
+ true -> ?amqqueue_v1_field_name(Q)
+ end
+ end).
+
+-define(amqqueue_field_pid(Q),
+ case ?is_amqqueue_v2(Q) of
+ true -> ?amqqueue_v2_field_pid(Q);
+ false -> case ?is_amqqueue_v1(Q) of
+ true -> ?amqqueue_v1_field_pid(Q)
+ end
+ end).
+
+-define(amqqueue_v1_vhost(Q), element(2, ?amqqueue_v1_field_name(Q))).
+-define(amqqueue_v2_vhost(Q), element(2, ?amqqueue_v2_field_name(Q))).
+
+-define(amqqueue_vhost_equals(Q, VHost),
+ ((?is_amqqueue_v2(Q) andalso
+ ?amqqueue_v2_vhost(Q) =:= VHost) orelse
+ (?is_amqqueue_v1(Q) andalso
+ ?amqqueue_v1_vhost(Q) =:= VHost))).
diff --git a/include/amqqueue_v1.hrl b/include/amqqueue_v1.hrl
new file mode 100644
index 0000000000..04b2d72850
--- /dev/null
+++ b/include/amqqueue_v1.hrl
@@ -0,0 +1,20 @@
+-define(is_amqqueue_v1(Q), is_record(Q, amqqueue, 19)).
+
+-define(amqqueue_v1_field_name(Q), element(2, Q)).
+-define(amqqueue_v1_field_durable(Q), element(3, Q)).
+-define(amqqueue_v1_field_auto_delete(Q), element(4, Q)).
+-define(amqqueue_v1_field_exclusive_owner(Q), element(5, Q)).
+-define(amqqueue_v1_field_arguments(Q), element(6, Q)).
+-define(amqqueue_v1_field_pid(Q), element(7, Q)).
+-define(amqqueue_v1_field_slave_pids(Q), element(8, Q)).
+-define(amqqueue_v1_field_sync_slave_pids(Q), element(9, Q)).
+-define(amqqueue_v1_field_recoverable_slaves(Q), element(10, Q)).
+-define(amqqueue_v1_field_policy(Q), element(11, Q)).
+-define(amqqueue_v1_field_operator_policy(Q), element(12, Q)).
+-define(amqqueue_v1_field_gm_pids(Q), element(13, Q)).
+-define(amqqueue_v1_field_decorators(Q), element(14, Q)).
+-define(amqqueue_v1_field_state(Q), element(15, Q)).
+-define(amqqueue_v1_field_policy_version(Q), element(16, Q)).
+-define(amqqueue_v1_field_slave_pids_pending_shutdown(Q), element(17, Q)).
+-define(amqqueue_v1_field_vhost(Q), element(18, Q)).
+-define(amqqueue_v1_field_options(Q), element(19, Q)).
diff --git a/include/amqqueue_v2.hrl b/include/amqqueue_v2.hrl
new file mode 100644
index 0000000000..37cd7ba2a8
--- /dev/null
+++ b/include/amqqueue_v2.hrl
@@ -0,0 +1,22 @@
+-define(is_amqqueue_v2(Q), is_record(Q, amqqueue, 21)).
+
+-define(amqqueue_v2_field_name(Q), element(2, Q)).
+-define(amqqueue_v2_field_durable(Q), element(3, Q)).
+-define(amqqueue_v2_field_auto_delete(Q), element(4, Q)).
+-define(amqqueue_v2_field_exclusive_owner(Q), element(5, Q)).
+-define(amqqueue_v2_field_arguments(Q), element(6, Q)).
+-define(amqqueue_v2_field_pid(Q), element(7, Q)).
+-define(amqqueue_v2_field_slave_pids(Q), element(8, Q)).
+-define(amqqueue_v2_field_sync_slave_pids(Q), element(9, Q)).
+-define(amqqueue_v2_field_recoverable_slaves(Q), element(10, Q)).
+-define(amqqueue_v2_field_policy(Q), element(11, Q)).
+-define(amqqueue_v2_field_operator_policy(Q), element(12, Q)).
+-define(amqqueue_v2_field_gm_pids(Q), element(13, Q)).
+-define(amqqueue_v2_field_decorators(Q), element(14, Q)).
+-define(amqqueue_v2_field_state(Q), element(15, Q)).
+-define(amqqueue_v2_field_policy_version(Q), element(16, Q)).
+-define(amqqueue_v2_field_slave_pids_pending_shutdown(Q), element(17, Q)).
+-define(amqqueue_v2_field_vhost(Q), element(18, Q)).
+-define(amqqueue_v2_field_options(Q), element(19, Q)).
+-define(amqqueue_v2_field_type(Q), element(20, Q)).
+-define(amqqueue_v2_field_quorum_nodes(Q), element(21, Q)).