Skip to content

Commit 5b71eb3

Browse files
Merge pull request #292 from rabbitmq/rabbitmq-server-291
fetches IndexMaxSize at BQ init time
2 parents 7b2daba + 725b3c7 commit 5b71eb3

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/rabbit_variable_queue.erl

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@
273273
msg_store_clients,
274274
durable,
275275
transient_threshold,
276+
qi_embed_msgs_below,
276277

277278
len, %% w/o unacked
278279
bytes, %% w/o unacked
@@ -371,6 +372,7 @@
371372
{any(), binary()}},
372373
durable :: boolean(),
373374
transient_threshold :: non_neg_integer(),
375+
qi_embed_msgs_below :: non_neg_integer(),
374376

375377
len :: non_neg_integer(),
376378
bytes :: non_neg_integer(),
@@ -570,12 +572,13 @@ publish(Msg = #basic_message { is_persistent = IsPersistent, id = MsgId },
570572
MsgProps = #message_properties { needs_confirming = NeedsConfirming },
571573
IsDelivered, _ChPid, _Flow,
572574
State = #vqstate { q1 = Q1, q3 = Q3, q4 = Q4,
573-
next_seq_id = SeqId,
574-
in_counter = InCount,
575-
durable = IsDurable,
576-
unconfirmed = UC }) ->
575+
qi_embed_msgs_below = IndexMaxSize,
576+
next_seq_id = SeqId,
577+
in_counter = InCount,
578+
durable = IsDurable,
579+
unconfirmed = UC }) ->
577580
IsPersistent1 = IsDurable andalso IsPersistent,
578-
MsgStatus = msg_status(IsPersistent1, IsDelivered, SeqId, Msg, MsgProps),
581+
MsgStatus = msg_status(IsPersistent1, IsDelivered, SeqId, Msg, MsgProps, IndexMaxSize),
579582
{MsgStatus1, State1} = maybe_write_to_disk(false, false, MsgStatus, State),
580583
State2 = case ?QUEUE:is_empty(Q3) of
581584
false -> State1 #vqstate { q1 = ?QUEUE:in(m(MsgStatus1), Q1) };
@@ -594,13 +597,14 @@ publish_delivered(Msg = #basic_message { is_persistent = IsPersistent,
594597
MsgProps = #message_properties {
595598
needs_confirming = NeedsConfirming },
596599
_ChPid, _Flow,
597-
State = #vqstate { next_seq_id = SeqId,
598-
out_counter = OutCount,
599-
in_counter = InCount,
600-
durable = IsDurable,
601-
unconfirmed = UC }) ->
600+
State = #vqstate { qi_embed_msgs_below = IndexMaxSize,
601+
next_seq_id = SeqId,
602+
out_counter = OutCount,
603+
in_counter = InCount,
604+
durable = IsDurable,
605+
unconfirmed = UC }) ->
602606
IsPersistent1 = IsDurable andalso IsPersistent,
603-
MsgStatus = msg_status(IsPersistent1, true, SeqId, Msg, MsgProps),
607+
MsgStatus = msg_status(IsPersistent1, true, SeqId, Msg, MsgProps, IndexMaxSize),
604608
{MsgStatus1, State1} = maybe_write_to_disk(false, false, MsgStatus, State),
605609
State2 = record_pending_ack(m(MsgStatus1), State1),
606610
UC1 = gb_sets_maybe_insert(NeedsConfirming, MsgId, UC),
@@ -968,15 +972,15 @@ gb_sets_maybe_insert(false, _Val, Set) -> Set;
968972
gb_sets_maybe_insert(true, Val, Set) -> gb_sets:add(Val, Set).
969973

970974
msg_status(IsPersistent, IsDelivered, SeqId,
971-
Msg = #basic_message {id = MsgId}, MsgProps) ->
975+
Msg = #basic_message {id = MsgId}, MsgProps, IndexMaxSize) ->
972976
#msg_status{seq_id = SeqId,
973977
msg_id = MsgId,
974978
msg = Msg,
975979
is_persistent = IsPersistent,
976980
is_delivered = IsDelivered,
977981
msg_in_store = false,
978982
index_on_disk = false,
979-
persist_to = determine_persist_to(Msg, MsgProps),
983+
persist_to = determine_persist_to(Msg, MsgProps, IndexMaxSize),
980984
msg_props = MsgProps}.
981985

982986
beta_msg_status({Msg = #basic_message{id = MsgId},
@@ -1137,6 +1141,9 @@ init(IsDurable, IndexState, DeltaCount, DeltaBytes, Terms,
11371141
Now = now(),
11381142
IoBatchSize = rabbit_misc:get_env(rabbit, msg_store_io_batch_size,
11391143
?IO_BATCH_SIZE),
1144+
1145+
{ok, IndexMaxSize} = application:get_env(
1146+
rabbit, queue_index_embed_msgs_below),
11401147
State = #vqstate {
11411148
q1 = ?QUEUE:new(),
11421149
q2 = ?QUEUE:new(),
@@ -1151,6 +1158,7 @@ init(IsDurable, IndexState, DeltaCount, DeltaBytes, Terms,
11511158
msg_store_clients = {PersistentClient, TransientClient},
11521159
durable = IsDurable,
11531160
transient_threshold = NextSeqId,
1161+
qi_embed_msgs_below = IndexMaxSize,
11541162

11551163
len = DeltaCount1,
11561164
persistent_count = DeltaCount1,
@@ -1408,9 +1416,8 @@ maybe_write_to_disk(ForceMsg, ForceIndex, MsgStatus, State) ->
14081416
determine_persist_to(#basic_message{
14091417
content = #content{properties = Props,
14101418
properties_bin = PropsBin}},
1411-
#message_properties{size = BodySize}) ->
1412-
{ok, IndexMaxSize} = application:get_env(
1413-
rabbit, queue_index_embed_msgs_below),
1419+
#message_properties{size = BodySize},
1420+
IndexMaxSize) ->
14141421
%% The >= is so that you can set the env to 0 and never persist
14151422
%% to the index.
14161423
%%

0 commit comments

Comments
 (0)