Skip to content

Commit d597732

Browse files
Merge pull request #12723 from rabbitmq/md/khepri-path-preproc-macros
2 parents e5bcf7f + c3c7675 commit d597732

12 files changed

+106
-42
lines changed

deps/rabbit/app.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def all_srcs(name = "all_srcs"):
531531
"include/amqqueue.hrl",
532532
"include/amqqueue_v2.hrl",
533533
"include/internal_user.hrl",
534-
"include/khepri.hrl",
534+
"include/rabbit_khepri.hrl",
535535
"include/mc.hrl",
536536
"include/rabbit_amqp.hrl",
537537
"include/rabbit_global_counters.hrl",

deps/rabbit/include/khepri.hrl

-9
This file was deleted.

deps/rabbit/include/rabbit_khepri.hrl

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
%% This Source Code Form is subject to the terms of the Mozilla Public
2+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
3+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
%%
5+
%% Copyright (c) 2024 Broadcom. All Rights Reserved. The term “Broadcom”
6+
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
7+
%%
8+
9+
%% This header has macros that define the `khepri_path:native_pattern()'
10+
%% path patterns used for each piece of metadata in the store. We use macros
11+
%% for these so that we can pattern match on these path patterns as well as
12+
%% create them as new terms.
13+
%%
14+
%% If you are creating a path pattern to use in a call to the Khepri API (for
15+
%% example `rabbit_khepri:get/1') you should prefer using the
16+
%% `khepri_<entity>_path' function from the `rabbit_db_<entity>' modules
17+
%% instead, for example `rabbit_db_queue:khepri_queue_path/2', since those
18+
%% functions have guards to assert that the variables passed are valid pattern
19+
%% components.
20+
21+
-define(RABBITMQ_KHEPRI_ROOT_PATH, ?RABBITMQ_KHEPRI_ROOT_PATH([])).
22+
-define(RABBITMQ_KHEPRI_ROOT_PATH(Rest), [rabbitmq | Rest]).
23+
24+
-define(RABBITMQ_KHEPRI_MAINTENANCE_PATH(Node),
25+
?RABBITMQ_KHEPRI_ROOT_PATH([node_maintenance, Node])).
26+
27+
-define(RABBITMQ_KHEPRI_GLOBAL_RUNTIME_PARAM_PATH(Key),
28+
?RABBITMQ_KHEPRI_ROOT_PATH([runtime_params, Key])).
29+
30+
-define(RABBITMQ_KHEPRI_USER_PATH(Username),
31+
?RABBITMQ_KHEPRI_ROOT_PATH([users, Username])).
32+
33+
-define(RABBITMQ_KHEPRI_MIRRORED_SUPERVISOR_PATH(Group, Id),
34+
?RABBITMQ_KHEPRI_ROOT_PATH([mirrored_supervisors, Group, Id])).
35+
36+
-define(RABBITMQ_KHEPRI_VHOST_PATH(Name),
37+
?RABBITMQ_KHEPRI_VHOST_PATH(Name, [])).
38+
-define(RABBITMQ_KHEPRI_VHOST_PATH(Name, Rest),
39+
?RABBITMQ_KHEPRI_ROOT_PATH([vhosts, Name | Rest])).
40+
41+
-define(RABBITMQ_KHEPRI_VHOST_RUNTIME_PARAM_PATH(VHost, Component, Name),
42+
?RABBITMQ_KHEPRI_VHOST_PATH(VHost, [runtime_params, Component, Name])).
43+
44+
-define(RABBITMQ_KHEPRI_USER_PERMISSION_PATH(VHost, Username),
45+
?RABBITMQ_KHEPRI_VHOST_PATH(VHost, [user_permissions, Username])).
46+
47+
-define(RABBITMQ_KHEPRI_EXCHANGE_PATH(VHost, Name),
48+
?RABBITMQ_KHEPRI_EXCHANGE_PATH(VHost, Name, [])).
49+
-define(RABBITMQ_KHEPRI_EXCHANGE_PATH(VHost, Name, Rest),
50+
?RABBITMQ_KHEPRI_VHOST_PATH(VHost, [exchanges, Name | Rest])).
51+
52+
-define(RABBITMQ_KHEPRI_EXCHANGE_SERIAL_PATH(VHost, Name),
53+
?RABBITMQ_KHEPRI_EXCHANGE_PATH(VHost, Name, [serial])).
54+
55+
-define(RABBITMQ_KHEPRI_TOPIC_PERMISSION_PATH(VHost, Exchange, Username),
56+
?RABBITMQ_KHEPRI_EXCHANGE_PATH(
57+
VHost, Exchange, [user_permissions, Username])).
58+
59+
-define(RABBITMQ_KHEPRI_ROUTE_PATH(VHost, SrcName, Kind, DstName, RoutingKey),
60+
?RABBITMQ_KHEPRI_EXCHANGE_PATH(
61+
VHost, SrcName, [bindings, Kind, DstName, RoutingKey])).
62+
63+
-define(RABBITMQ_KHEPRI_QUEUE_PATH(VHost, Name),
64+
?RABBITMQ_KHEPRI_VHOST_PATH(VHost, [queues, Name])).

deps/rabbit/src/rabbit_db_binding.erl

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
-include_lib("khepri/include/khepri.hrl").
1111
-include_lib("rabbit_common/include/rabbit.hrl").
1212

13+
-include("include/rabbit_khepri.hrl").
14+
1315
-export([exists/1,
1416
create/2,
1517
delete/2,
@@ -1021,8 +1023,7 @@ khepri_route_path(VHost, SrcName, Kind, DstName, RoutingKey)
10211023
when ?IS_KHEPRI_PATH_CONDITION(Kind) andalso
10221024
?IS_KHEPRI_PATH_CONDITION(DstName) andalso
10231025
?IS_KHEPRI_PATH_CONDITION(RoutingKey) ->
1024-
ExchangePath = rabbit_db_exchange:khepri_exchange_path(VHost, SrcName),
1025-
ExchangePath ++ [bindings, Kind, DstName, RoutingKey].
1026+
?RABBITMQ_KHEPRI_ROUTE_PATH(VHost, SrcName, Kind, DstName, RoutingKey).
10261027

10271028
khepri_route_path_to_args(Path) ->
10281029
Pattern = khepri_route_path(

deps/rabbit/src/rabbit_db_exchange.erl

+11-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-include_lib("khepri/include/khepri.hrl").
1111
-include_lib("rabbit_common/include/rabbit.hrl").
1212

13-
-include("include/khepri.hrl").
13+
-include("include/rabbit_khepri.hrl").
1414

1515
-export([
1616
get_all/0,
@@ -960,11 +960,15 @@ maybe_auto_delete_in_khepri(XName, OnlyDurable) ->
960960
khepri_exchange_path(#resource{virtual_host = VHost, name = Name}) ->
961961
khepri_exchange_path(VHost, Name).
962962

963-
khepri_exchange_path(VHost, Name) when ?IS_KHEPRI_PATH_CONDITION(Name) ->
964-
rabbit_db_vhost:khepri_vhost_path(VHost) ++ [exchanges, Name].
963+
khepri_exchange_path(VHost, Name)
964+
when ?IS_KHEPRI_PATH_CONDITION(VHost) andalso
965+
?IS_KHEPRI_PATH_CONDITION(Name) ->
966+
?RABBITMQ_KHEPRI_EXCHANGE_PATH(VHost, Name).
965967

966-
khepri_exchange_serial_path(#resource{} = Resource) ->
967-
khepri_exchange_path(Resource) ++ [serial].
968+
khepri_exchange_serial_path(#resource{virtual_host = VHost, name = Name}) ->
969+
khepri_exchange_serial_path(VHost, Name).
968970

969-
khepri_exchange_serial_path(VHost, Name) ->
970-
khepri_exchange_path(VHost, Name) ++ [serial].
971+
khepri_exchange_serial_path(VHost, Name)
972+
when ?IS_KHEPRI_PATH_CONDITION(VHost) andalso
973+
?IS_KHEPRI_PATH_CONDITION(Name) ->
974+
?RABBITMQ_KHEPRI_EXCHANGE_SERIAL_PATH(VHost, Name).

deps/rabbit/src/rabbit_db_maintenance.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-include_lib("khepri/include/khepri.hrl").
1111
-include_lib("rabbit_common/include/rabbit.hrl").
1212

13-
-include("include/khepri.hrl").
13+
-include("include/rabbit_khepri.hrl").
1414

1515
-export([
1616
table_definitions/0,
@@ -170,4 +170,4 @@ get_consistent_in_khepri(Node) ->
170170
%% -------------------------------------------------------------------
171171

172172
khepri_maintenance_path(Node) when ?IS_KHEPRI_PATH_CONDITION(Node) ->
173-
?KHEPRI_ROOT_PATH ++ [node_maintenance, Node].
173+
?RABBITMQ_KHEPRI_MAINTENANCE_PATH(Node).

deps/rabbit/src/rabbit_db_msup.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-include_lib("khepri/include/khepri.hrl").
1111
-include("mirrored_supervisor.hrl").
1212

13-
-include("include/khepri.hrl").
13+
-include("include/rabbit_khepri.hrl").
1414

1515
-export([
1616
create_tables/0,
@@ -328,8 +328,8 @@ clear_in_khepri() ->
328328
khepri_mirrored_supervisor_path(Group, Id)
329329
when ?IS_KHEPRI_PATH_CONDITION(Group) andalso
330330
?IS_KHEPRI_PATH_CONDITION(Id) ->
331-
?KHEPRI_ROOT_PATH ++ [mirrored_supervisors, Group, Id];
331+
?RABBITMQ_KHEPRI_MIRRORED_SUPERVISOR_PATH(Group, Id);
332332
khepri_mirrored_supervisor_path(Group, Id)
333333
when is_atom(Group) ->
334334
IdPath = Group:id_to_khepri_path(Id),
335-
?KHEPRI_ROOT_PATH ++ [mirrored_supervisors, Group] ++ IdPath.
335+
?RABBITMQ_KHEPRI_ROOT_PATH ++ [mirrored_supervisors, Group] ++ IdPath.

deps/rabbit/src/rabbit_db_queue.erl

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
-include_lib("rabbit_common/include/rabbit.hrl").
1414
-include("amqqueue.hrl").
1515

16+
-include("include/rabbit_khepri.hrl").
17+
1618
-export([
1719
get/1,
1820
get_many/1,
@@ -1394,5 +1396,7 @@ list_with_possible_retry_in_khepri(Fun) ->
13941396
khepri_queue_path(#resource{virtual_host = VHost, name = Name}) ->
13951397
khepri_queue_path(VHost, Name).
13961398

1397-
khepri_queue_path(VHost, Name) when ?IS_KHEPRI_PATH_CONDITION(Name) ->
1398-
rabbit_db_vhost:khepri_vhost_path(VHost) ++ [queues, Name].
1399+
khepri_queue_path(VHost, Name)
1400+
when ?IS_KHEPRI_PATH_CONDITION(VHost) andalso
1401+
?IS_KHEPRI_PATH_CONDITION(Name) ->
1402+
?RABBITMQ_KHEPRI_QUEUE_PATH(VHost, Name).

deps/rabbit/src/rabbit_db_rtparams.erl

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-include_lib("khepri/include/khepri.hrl").
1111
-include_lib("rabbit_common/include/rabbit.hrl").
1212

13-
-include("include/khepri.hrl").
13+
-include("include/rabbit_khepri.hrl").
1414

1515
-export([set/2, set/4,
1616
get/1,
@@ -364,10 +364,9 @@ khepri_rp_path(Key) ->
364364
khepri_global_rp_path(Key).
365365

366366
khepri_global_rp_path(Key) when ?IS_KHEPRI_PATH_CONDITION(Key) ->
367-
?KHEPRI_ROOT_PATH ++ [runtime_params, Key].
367+
?RABBITMQ_KHEPRI_GLOBAL_RUNTIME_PARAM_PATH(Key).
368368

369369
khepri_vhost_rp_path(VHost, Component, Name)
370370
when ?IS_KHEPRI_PATH_CONDITION(Component) andalso
371371
?IS_KHEPRI_PATH_CONDITION(Name) ->
372-
VHostPath = rabbit_db_vhost:khepri_vhost_path(VHost),
373-
VHostPath ++ [runtime_params, Component, Name].
372+
?RABBITMQ_KHEPRI_VHOST_RUNTIME_PARAM_PATH(VHost, Component, Name).

deps/rabbit/src/rabbit_db_user.erl

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-include_lib("khepri/include/khepri.hrl").
1313
-include_lib("rabbit_common/include/rabbit.hrl").
1414

15-
-include("include/khepri.hrl").
15+
-include("include/rabbit_khepri.hrl").
1616

1717
-export([create/1,
1818
update/2,
@@ -1094,14 +1094,15 @@ clear_in_khepri() ->
10941094

10951095
khepri_user_path(Username)
10961096
when ?IS_KHEPRI_PATH_CONDITION(Username) ->
1097-
?KHEPRI_ROOT_PATH ++ [users, Username].
1097+
?RABBITMQ_KHEPRI_USER_PATH(Username).
10981098

10991099
khepri_user_permission_path(Username, VHostName)
1100-
when ?IS_KHEPRI_PATH_CONDITION(Username) ->
1101-
(rabbit_db_vhost:khepri_vhost_path(VHostName) ++
1102-
[user_permissions, Username]).
1100+
when ?IS_KHEPRI_PATH_CONDITION(Username) andalso
1101+
?IS_KHEPRI_PATH_CONDITION(VHostName) ->
1102+
?RABBITMQ_KHEPRI_USER_PERMISSION_PATH(VHostName, Username).
11031103

11041104
khepri_topic_permission_path(Username, VHostName, Exchange)
1105-
when ?IS_KHEPRI_PATH_CONDITION(Username) ->
1106-
(rabbit_db_exchange:khepri_exchange_path(VHostName, Exchange) ++
1107-
[user_permissions, Username]).
1105+
when ?IS_KHEPRI_PATH_CONDITION(Username) andalso
1106+
?IS_KHEPRI_PATH_CONDITION(VHostName) andalso
1107+
?IS_KHEPRI_PATH_CONDITION(Exchange) ->
1108+
?RABBITMQ_KHEPRI_TOPIC_PERMISSION_PATH(VHostName, Exchange, Username).

deps/rabbit/src/rabbit_db_vhost.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
-include_lib("rabbit_common/include/logging.hrl").
1212
-include_lib("khepri/include/khepri.hrl").
1313

14-
-include("include/khepri.hrl").
14+
-include("include/rabbit_khepri.hrl").
1515
-include("vhost.hrl").
1616

1717
-export([create_or_get/3,
@@ -533,4 +533,4 @@ clear_in_khepri() ->
533533
%% --------------------------------------------------------------
534534

535535
khepri_vhost_path(VHost) when ?IS_KHEPRI_PATH_CONDITION(VHost) ->
536-
?KHEPRI_ROOT_PATH ++ [vhosts, VHost].
536+
?RABBITMQ_KHEPRI_VHOST_PATH(VHost).

deps/rabbit/src/rabbit_khepri.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
-include_lib("rabbit_common/include/logging.hrl").
9797
-include_lib("rabbit_common/include/rabbit.hrl").
9898

99-
-include("include/khepri.hrl").
99+
-include("include/rabbit_khepri.hrl").
100100

101101
-export([setup/0,
102102
setup/1,
@@ -943,7 +943,7 @@ cluster_status_from_khepri() ->
943943
%% This path must be prepended to all paths used by RabbitMQ subsystems.
944944

945945
root_path() ->
946-
?KHEPRI_ROOT_PATH.
946+
?RABBITMQ_KHEPRI_ROOT_PATH.
947947

948948
%% -------------------------------------------------------------------
949949
%% "Proxy" functions to Khepri API.

0 commit comments

Comments
 (0)