diff options
author | Michal Kuratczyk <mkuratczyk@vmware.com> | 2023-03-21 13:12:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 13:12:00 +0100 |
commit | 4da170fbf975ee185e032b9f05d5c5b88d540ecc (patch) | |
tree | c8984dcd123a78129c4201b9b1c07f82dee412d0 | |
parent | b4871e2b83101c3f99f19fa9dca862320e56caaa (diff) | |
download | rabbitmq-server-git-4da170fbf975ee185e032b9f05d5c5b88d540ecc.tar.gz |
Faster node start with many classic queues v2 (#7676)
* Faster all_queue_directory_names/1
* Optimise writing stub files
Combined, this reduces node startup time by half with many empty classic queues v2
-rw-r--r-- | deps/rabbit/src/rabbit_classic_queue_index_v2.erl | 14 | ||||
-rw-r--r-- | deps/rabbit/src/rabbit_queue_index.erl | 19 |
2 files changed, 25 insertions, 8 deletions
diff --git a/deps/rabbit/src/rabbit_classic_queue_index_v2.erl b/deps/rabbit/src/rabbit_classic_queue_index_v2.erl index d2e70324f3..51937558d7 100644 --- a/deps/rabbit/src/rabbit_classic_queue_index_v2.erl +++ b/deps/rabbit/src/rabbit_classic_queue_index_v2.erl @@ -205,8 +205,7 @@ init1(Name, Dir, OnSyncFun, OnSyncMsgFun) -> ensure_queue_name_stub_file(#resource{virtual_host = VHost, name = QName}, Dir) -> QueueNameFile = filename:join(Dir, ?QUEUE_NAME_STUB_FILE), - ok = filelib:ensure_dir(QueueNameFile), - ok = file:write_file(QueueNameFile, <<"VHOST: ", VHost/binary, "\n", + ok = write_file_and_ensure_dir(QueueNameFile, <<"VHOST: ", VHost/binary, "\n", "QUEUE: ", QName/binary, "\n", "INDEX: v2\n">>). @@ -1292,3 +1291,14 @@ highest_continuous_seq_id([SeqId1, SeqId2|Tail], EndSeqId) highest_continuous_seq_id([SeqId2|Tail], EndSeqId); highest_continuous_seq_id([SeqId|Tail], _) -> {SeqId, Tail}. + +write_file_and_ensure_dir(Name, IOData) -> + case file:write_file(Name, IOData, [raw]) of + ok -> ok; + {error, enoent} -> + case filelib:ensure_dir(Name) of + ok -> file:write_file(Name, IOData, [raw]); + Err -> Err + end; + Err -> Err + end. diff --git a/deps/rabbit/src/rabbit_queue_index.erl b/deps/rabbit/src/rabbit_queue_index.erl index 34f956d674..37a05263fd 100644 --- a/deps/rabbit/src/rabbit_queue_index.erl +++ b/deps/rabbit/src/rabbit_queue_index.erl @@ -549,10 +549,12 @@ start(VHost, DurableQueueNames) -> sets:add_element(DirName, ValidDirectories)} end, {[], sets:new()}, DurableQueueNames), %% Any queue directory we've not been asked to recover is considered garbage - _ = rabbit_file:recursive_delete( - [DirName || - DirName <- all_queue_directory_names(VHost), - not sets:is_element(filename:basename(DirName), DurableDirectories)]), + ToDelete = [filename:join([rabbit_vhost:msg_store_dir_path(VHost), "queues", Dir]) + || Dir <- lists:subtract(all_queue_directory_names(VHost), + sets:to_list(DurableDirectories))], + rabbit_log:debug("Deleting unknown files/folders: ~p", [ToDelete]), + _ = rabbit_file:recursive_delete(ToDelete), + rabbit_recovery_terms:clear(VHost), %% The backing queue interface requires that the queue recovery terms @@ -564,8 +566,13 @@ start(VHost, DurableQueueNames) -> stop(VHost) -> rabbit_recovery_terms:stop(VHost). all_queue_directory_names(VHost) -> - filelib:wildcard(filename:join([rabbit_vhost:msg_store_dir_path(VHost), - "queues", "*"])). + VHostQueuesPath = filename:join([rabbit_vhost:msg_store_dir_path(VHost), "queues"]), + case filelib:is_dir(VHostQueuesPath) of + true -> + {ok, Dirs} = file:list_dir(VHostQueuesPath), + Dirs; + false -> [] + end. %%---------------------------------------------------------------------------- %% startup and shutdown |