|
18 | 18 |
|
19 | 19 | -export([erase/1, init/3, recover/6,
|
20 | 20 | terminate/2, delete_and_terminate/1,
|
21 |
| - pre_publish/6, flush_pre_publish_cache/2, |
| 21 | + pre_publish/7, flush_pre_publish_cache/2, |
22 | 22 | publish/6, deliver/2, ack/2, sync/1, needs_sync/1, flush/1,
|
23 | 23 | read/3, next_segment_boundary/1, bounds/1, start/1, stop/0]).
|
24 | 24 |
|
@@ -295,11 +295,11 @@ delete_and_terminate(State) ->
|
295 | 295 | ok = rabbit_file:recursive_delete([Dir]),
|
296 | 296 | State1.
|
297 | 297 |
|
298 |
| -pre_publish(MsgOrId, SeqId, MsgProps, IsPersistent, IsDelivered, |
299 |
| - State = #qistate{unconfirmed = UC, |
300 |
| - unconfirmed_msg = UCM, |
301 |
| - pre_publish_cache = PPC, |
302 |
| - delivered_cache = DC}) -> |
| 298 | +pre_publish(MsgOrId, SeqId, MsgProps, IsPersistent, IsDelivered, JournalSizeHint, |
| 299 | + State = #qistate{unconfirmed = UC, |
| 300 | + unconfirmed_msg = UCM, |
| 301 | + pre_publish_cache = PPC, |
| 302 | + delivered_cache = DC}) -> |
303 | 303 | MsgId = case MsgOrId of
|
304 | 304 | #basic_message{id = Id} -> Id;
|
305 | 305 | Id when is_binary(Id) -> Id
|
@@ -334,7 +334,19 @@ pre_publish(MsgOrId, SeqId, MsgProps, IsPersistent, IsDelivered,
|
334 | 334 | end,
|
335 | 335 |
|
336 | 336 | add_to_journal(SeqId, {IsPersistent, Bin, MsgBin},
|
337 |
| - State1#qistate{pre_publish_cache = PPC1, delivered_cache = DC1}). |
| 337 | + maybe_flush_pre_publish_cache( |
| 338 | + JournalSizeHint, |
| 339 | + State1#qistate{pre_publish_cache = PPC1, |
| 340 | + delivered_cache = DC1})). |
| 341 | + |
| 342 | +%% pre_publish_cache is the entry with most elements when comapred to |
| 343 | +%% delivered_cache so we only check the former in the guard. |
| 344 | +maybe_flush_pre_publish_cache(JournalSizeHint, |
| 345 | + #qistate{pre_publish_cache = PPC} = State) |
| 346 | + when length(PPC) >= ?SEGMENT_ENTRY_COUNT -> |
| 347 | + flush_pre_publish_cache(JournalSizeHint, State); |
| 348 | +maybe_flush_pre_publish_cache(_JournalSizeHint, State) -> |
| 349 | + State. |
338 | 350 |
|
339 | 351 | flush_pre_publish_cache(JournalSizeHint, State) ->
|
340 | 352 | State1 = flush_pre_publish_cache(State),
|
|
0 commit comments