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 , parse_tags /1 ]).
17
17
-export ([info /1 , info /2 , info_all /0 , info_all /1 , info_all /2 , info_all /3 ]).
18
- -export ([dir /1 , msg_store_dir_path /1 , msg_store_dir_wildcard /0 ]).
18
+ -export ([dir /1 , msg_store_dir_path /1 , msg_store_dir_wildcard /0 , config_file_path / 1 ]).
19
19
-export ([delete_storage /1 ]).
20
20
-export ([vhost_down /1 ]).
21
21
-export ([put_vhost /5 ]).
@@ -48,6 +48,7 @@ recover(VHost) ->
48
48
VHostStubFile = filename :join (VHostDir , " .vhost" ),
49
49
ok = rabbit_file :ensure_dir (VHostStubFile ),
50
50
ok = file :write_file (VHostStubFile , VHost ),
51
+ ok = ensure_config_file (VHost ),
51
52
{Recovered , Failed } = rabbit_amqqueue :recover (VHost ),
52
53
AllQs = Recovered ++ Failed ,
53
54
QNames = [amqqueue :get_name (Q ) || Q <- AllQs ],
@@ -57,6 +58,38 @@ recover(VHost) ->
57
58
ok = rabbit_mirror_queue_misc :on_vhost_up (VHost ),
58
59
ok .
59
60
61
+ ensure_config_file (VHost ) ->
62
+ Path = config_file_path (VHost ),
63
+ case filelib :is_regular (Path ) of
64
+ % % The config file exists. Do nothing.
65
+ true ->
66
+ ok ;
67
+ % % The config file does not exist.
68
+ % % Check if there are queues in this vhost.
69
+ false ->
70
+ QueueDirs = rabbit_queue_index :all_queue_directory_names (VHost ),
71
+ SegmentEntryCount = case QueueDirs of
72
+ % % There are no queues. Write the configured value for
73
+ % % the segment entry count, or the new RabbitMQ default
74
+ % % introduced in v3.8.16.
75
+ [] ->
76
+ application :get_env (rabbit , queue_index_segment_entry_count ,
77
+ 1024 ); % % @todo Figure out what the new default should be.
78
+ % % There are queues already. Write the historic RabbitMQ
79
+ % % default of 16384 for forward compatibility. Historic
80
+ % % default calculated as trunc(math:pow(2,?REL_SEQ_BITS)).
81
+ _ ->
82
+ 16384
83
+ end ,
84
+ rabbit_log :info (" Setting segment_entry_count for vhost '~s ' with ~b queues to '~b '" ,
85
+ [VHost , length (QueueDirs ), SegmentEntryCount ]),
86
+ file :write_file (Path , io_lib :format (" {segment_entry_count, ~b }." , [SegmentEntryCount ]))
87
+ end .
88
+
89
+ read_config (VHost ) ->
90
+ {ok , Config } = file :consult (config_file_path (VHost )),
91
+ maps :from_list (Config ).
92
+
60
93
-define (INFO_KEYS , vhost :info_keys ()).
61
94
62
95
-spec parse_tags (binary () | string () | atom ()) -> [atom ()].
@@ -377,6 +410,10 @@ msg_store_dir_base() ->
377
410
Dir = rabbit_mnesia :dir (),
378
411
filename :join ([Dir , " msg_stores" , " vhosts" ]).
379
412
413
+ config_file_path (VHost ) ->
414
+ VHostDir = msg_store_dir_path (VHost ),
415
+ filename :join (VHostDir , " .config" ).
416
+
380
417
-spec trim_tag (list () | binary () | atom ()) -> atom ().
381
418
trim_tag (Val ) ->
382
419
rabbit_data_coercion :to_atom (string :trim (rabbit_data_coercion :to_list (Val ))).
0 commit comments