summaryrefslogtreecommitdiff
path: root/include/amqqueue.hrl
blob: bb5fdd258e1c089c8e873d0640988ab26cb9cdbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
%% 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 https://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-2020 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, rabbit_classic_queue).

-define(amqqueue_is_classic(Q),
        ((?is_amqqueue_v2(Q) andalso
          ?amqqueue_v2_field_type(Q) =:= rabbit_classic_queue) orelse
         ?is_amqqueue_v1(Q))).

-define(amqqueue_is_quorum(Q),
        (?is_amqqueue_v2(Q) andalso
         ?amqqueue_v2_field_type(Q) =:= rabbit_quorum_queue) 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))).

-ifdef(DEBUG_QUORUM_QUEUE_FF).
-define(enable_quorum_queue_if_debug,
        begin
            rabbit_log:info(
              "---- ENABLING quorum_queue as part of "
              "?try_mnesia_tx_or_upgrade_amqqueue_and_retry() ----"),
            ok = rabbit_feature_flags:enable(quorum_queue)
        end).
-else.
-define(enable_quorum_queue_if_debug, noop).
-endif.

-define(try_mnesia_tx_or_upgrade_amqqueue_and_retry(Expr1, Expr2),
        try
            ?enable_quorum_queue_if_debug,
            Expr1
        catch
            throw:{error, {bad_type, T}} when ?is_amqqueue(T) ->
                Expr2;
            throw:{aborted, {bad_type, T}} when ?is_amqqueue(T) ->
                Expr2
        end).