10
10
-include_lib (" rabbit_common/include/rabbit.hrl" ).
11
11
-include (" vhost.hrl" ).
12
12
13
- -export ([recover /0 , recover /1 ]).
13
+ -export ([recover /0 , recover /1 , read_config / 1 ]).
14
14
-export ([add /2 , add /4 , delete /2 , exists /1 , with /2 , with_user_and_vhost /3 , assert /1 , update /2 ,
15
15
set_limits /2 , vhost_cluster_state /1 , is_running_on_all_nodes /1 , await_running_on_all_nodes /2 ,
16
16
list /0 , count /0 , list_names /0 , all /0 ]).
17
17
-export ([parse_tags /1 , update_metadata /2 , tag_with /2 , untag_from /2 , update_tags /2 , update_tags /3 ]).
18
18
-export ([lookup /1 ]).
19
19
-export ([info /1 , info /2 , info_all /0 , info_all /1 , info_all /2 , info_all /3 ]).
20
- -export ([dir /1 , msg_store_dir_path /1 , msg_store_dir_wildcard /0 ]).
20
+ -export ([dir /1 , msg_store_dir_path /1 , msg_store_dir_wildcard /0 , config_file_path / 1 ]).
21
21
-export ([delete_storage /1 ]).
22
22
-export ([vhost_down /1 ]).
23
23
-export ([put_vhost /5 ]).
@@ -53,6 +53,7 @@ recover(VHost) ->
53
53
VHostStubFile = filename :join (VHostDir , " .vhost" ),
54
54
ok = rabbit_file :ensure_dir (VHostStubFile ),
55
55
ok = file :write_file (VHostStubFile , VHost ),
56
+ ok = ensure_config_file (VHost ),
56
57
{Recovered , Failed } = rabbit_amqqueue :recover (VHost ),
57
58
AllQs = Recovered ++ Failed ,
58
59
QNames = [amqqueue :get_name (Q ) || Q <- AllQs ],
@@ -62,6 +63,42 @@ recover(VHost) ->
62
63
ok = rabbit_mirror_queue_misc :on_vhost_up (VHost ),
63
64
ok .
64
65
66
+ ensure_config_file (VHost ) ->
67
+ Path = config_file_path (VHost ),
68
+ case filelib :is_regular (Path ) of
69
+ % % The config file exists. Do nothing.
70
+ true ->
71
+ ok ;
72
+ % % The config file does not exist.
73
+ % % Check if there are queues in this vhost.
74
+ false ->
75
+ QueueDirs = rabbit_queue_index :all_queue_directory_names (VHost ),
76
+ SegmentEntryCount = case QueueDirs of
77
+ % % There are no queues. Write the configured value for
78
+ % % the segment entry count, or the new RabbitMQ default
79
+ % % introduced in v3.8.17. The new default provides much
80
+ % % better memory footprint when many queues are used.
81
+ [] ->
82
+ application :get_env (rabbit , queue_index_segment_entry_count ,
83
+ 2048 );
84
+ % % There are queues already. Write the historic RabbitMQ
85
+ % % default of 16384 for forward compatibility. Historic
86
+ % % default calculated as trunc(math:pow(2,?REL_SEQ_BITS)).
87
+ _ ->
88
+ 16384
89
+ end ,
90
+ rabbit_log :info (" Setting segment_entry_count for vhost '~s ' with ~b queues to '~b '" ,
91
+ [VHost , length (QueueDirs ), SegmentEntryCount ]),
92
+ file :write_file (Path , io_lib :format (
93
+ " %% This file is auto-generated! Edit at your own risk!~n "
94
+ " {segment_entry_count, ~b }." ,
95
+ [SegmentEntryCount ]))
96
+ end .
97
+
98
+ read_config (VHost ) ->
99
+ {ok , Config } = file :consult (config_file_path (VHost )),
100
+ maps :from_list (Config ).
101
+
65
102
-define (INFO_KEYS , vhost :info_keys ()).
66
103
67
104
-spec parse_tags (binary () | string () | atom ()) -> [atom ()].
@@ -446,6 +483,10 @@ msg_store_dir_base() ->
446
483
Dir = rabbit_mnesia :dir (),
447
484
filename :join ([Dir , " msg_stores" , " vhosts" ]).
448
485
486
+ config_file_path (VHost ) ->
487
+ VHostDir = msg_store_dir_path (VHost ),
488
+ filename :join (VHostDir , " .config" ).
489
+
449
490
-spec trim_tag (list () | binary () | atom ()) -> atom ().
450
491
trim_tag (Val ) ->
451
492
rabbit_data_coercion :to_atom (string :trim (rabbit_data_coercion :to_list (Val ))).
0 commit comments