Skip to content

Commit 08b286c

Browse files
committed
Merge pull request #2939 from rabbitmq/configurable-segment-entry-count
Add queue_index_segment_entry_count configuration (cherry picked from commit 98f33fc) Signed-off-by: Gerhard Lazu <gerhard@lazu.co.uk>
1 parent cb4c1f8 commit 08b286c

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

deps/rabbit/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ define PROJECT_ENV
118118
{writer_gc_threshold, 1000000000},
119119
%% interval at which connection/channel tracking executes post operations
120120
{tracking_execution_timeout, 15000},
121-
{track_auth_attempt_source, false}
121+
{track_auth_attempt_source, false}
122+
%% Number of entries per index segment.
123+
%% This value can only be changed safely
124+
%% on an empty node. Default calculated
125+
%% as trunc(math:pow(2,?REL_SEQ_BITS))).
126+
{queue_index_segment_entry_count, 16384}
122127
]
123128
endef
124129

deps/rabbit/src/rabbit_queue_index.erl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
-module(rabbit_queue_index).
99

10+
-compile({inline, [segment_entry_count/0]}).
11+
1012
-export([erase/1, init/3, reset_state/1, recover/6,
1113
terminate/3, delete_and_terminate/1,
1214
pre_publish/7, flush_pre_publish_cache/2,
@@ -43,13 +45,13 @@
4345
%% then delivered, then ack'd.
4446
%%
4547
%% In order to be able to clean up ack'd messages, we write to segment
46-
%% files. These files have a fixed number of entries: ?SEGMENT_ENTRY_COUNT
48+
%% files. These files have a fixed number of entries: segment_entry_count()
4749
%% publishes, delivers and acknowledgements. They are numbered, and so
4850
%% it is known that the 0th segment contains messages 0 ->
49-
%% ?SEGMENT_ENTRY_COUNT - 1, the 1st segment contains messages
50-
%% ?SEGMENT_ENTRY_COUNT -> 2*?SEGMENT_ENTRY_COUNT - 1 and so on. As
51+
%% segment_entry_count() - 1, the 1st segment contains messages
52+
%% segment_entry_count() -> 2*segment_entry_count() - 1 and so on. As
5153
%% such, in the segment files, we only refer to message sequence ids
52-
%% by the LSBs as SeqId rem ?SEGMENT_ENTRY_COUNT. This gives them a
54+
%% by the LSBs as SeqId rem segment_entry_count(). This gives them a
5355
%% fixed size.
5456
%%
5557
%% However, transient messages which are not sent to disk at any point
@@ -127,8 +129,6 @@
127129
%% binary generation/matching with constant vs variable lengths.
128130

129131
-define(REL_SEQ_BITS, 14).
130-
%% calculated as trunc(math:pow(2,?REL_SEQ_BITS))).
131-
-define(SEGMENT_ENTRY_COUNT, 16384).
132132

133133
%% seq only is binary 01 followed by 14 bits of rel seq id
134134
%% (range: 0 - 16383)
@@ -349,11 +349,11 @@ pre_publish(MsgOrId, SeqId, MsgProps, IsPersistent, IsDelivered, JournalSizeHint
349349
%% pre_publish_cache is the entry with most elements when compared to
350350
%% delivered_cache so we only check the former in the guard.
351351
maybe_flush_pre_publish_cache(JournalSizeHint,
352-
#qistate{pre_publish_cache = PPC} = State)
353-
when length(PPC) >= ?SEGMENT_ENTRY_COUNT ->
354-
flush_pre_publish_cache(JournalSizeHint, State);
355-
maybe_flush_pre_publish_cache(_JournalSizeHint, State) ->
356-
State.
352+
#qistate{pre_publish_cache = PPC} = State) ->
353+
case length(PPC) >= segment_entry_count() of
354+
true -> flush_pre_publish_cache(JournalSizeHint, State);
355+
false -> State
356+
end.
357357

358358
flush_pre_publish_cache(JournalSizeHint, State) ->
359359
State1 = flush_pre_publish_cache(State),
@@ -985,10 +985,11 @@ notify_sync(State = #qistate{unconfirmed = UC,
985985
%%----------------------------------------------------------------------------
986986

987987
seq_id_to_seg_and_rel_seq_id(SeqId) ->
988-
{ SeqId div ?SEGMENT_ENTRY_COUNT, SeqId rem ?SEGMENT_ENTRY_COUNT }.
988+
SegmentEntryCount = segment_entry_count(),
989+
{ SeqId div SegmentEntryCount, SeqId rem SegmentEntryCount }.
989990

990991
reconstruct_seq_id(Seg, RelSeq) ->
991-
(Seg * ?SEGMENT_ENTRY_COUNT) + RelSeq.
992+
(Seg * segment_entry_count()) + RelSeq.
992993

993994
all_segment_nums(#qistate { dir = Dir, segments = Segments }) ->
994995
lists:sort(
@@ -1157,7 +1158,12 @@ array_new() ->
11571158
array_new(undefined).
11581159

11591160
array_new(Default) ->
1160-
array:new([{default, Default}, fixed, {size, ?SEGMENT_ENTRY_COUNT}]).
1161+
array:new([{default, Default}, fixed, {size, segment_entry_count()}]).
1162+
1163+
segment_entry_count() ->
1164+
{ok, SegmentEntryCount} =
1165+
application:get_env(rabbit, queue_index_segment_entry_count),
1166+
SegmentEntryCount.
11611167

11621168
bool_to_int(true ) -> 1;
11631169
bool_to_int(false) -> 0.

deps/rabbit/src/rabbit_variable_queue.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ a(State = #vqstate { q1 = Q1, q2 = Q2, delta = Delta, q3 = Q3, q4 = Q4,
11101110
%% disk). See push_alphas_to_betas/2.
11111111
true = E2 or not ED,
11121112
%% if delta has messages then q3 cannot be empty. This is enforced
1113-
%% by paging, where min([?SEGMENT_ENTRY_COUNT, len(q3)]) messages
1113+
%% by paging, where min([segment_entry_count(), len(q3)]) messages
11141114
%% are always kept on RAM.
11151115
true = ED or not E3,
11161116
%% if the queue length is 0, then q3 and q4 must be empty.

0 commit comments

Comments
 (0)