Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ private boolean checkQueueOk(PopCheckPointWrapper pointWrapper) {
*/
public boolean addCkJustOffset(PopCheckPoint point, int reviveQueueId, long reviveQueueOffset,
long nextBeginOffset) {
if (this.counter.get() > brokerController.getBrokerConfig().getPopCkMaxBufferSize()) {
POP_LOGGER.warn("[PopBuffer]add ck just offset, max size, {}, {}", point, this.counter.get());
return false;
}
Comment thread
wang-jiahua marked this conversation as resolved.

Comment thread
wang-jiahua marked this conversation as resolved.
PopCheckPointWrapper pointWrapper = new PopCheckPointWrapper(reviveQueueId, reviveQueueOffset, point, nextBeginOffset, true);

if (this.buffer.containsKey(pointWrapper.getMergeKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,32 @@ public void testPutAckToStore() throws Exception {
method.invoke(popBufferMergeService, pointWrapper, msgIndex, count);
verify(escapeBridge, times(1)).putMessageToSpecificQueue(any(MessageExtBrokerInner.class));
}

@Test
public void testAddCkJustOffsetMaxSize() {
// Set popCkMaxBufferSize to 0 so any addCkJustOffset should be rejected
when(brokerConfig.getPopCkMaxBufferSize()).thenReturn(0);

PopCheckPoint point1 = mock(PopCheckPoint.class);
when(point1.getTopic()).thenReturn("topic1");
when(point1.getCId()).thenReturn("cid1");
when(point1.getQueueId()).thenReturn(0);
when(point1.getStartOffset()).thenReturn(0L);
when(point1.getPopTime()).thenReturn(0L);
when(point1.getBrokerName()).thenReturn("");

// counter starts at 0, 0 > 0 is false, so first add succeeds and counter becomes 1
assertThat(popBufferMergeService.addCkJustOffset(point1, 0, 0, 0)).isTrue();

PopCheckPoint point2 = mock(PopCheckPoint.class);
when(point2.getTopic()).thenReturn("topic2");
when(point2.getCId()).thenReturn("cid2");
when(point2.getQueueId()).thenReturn(0);
when(point2.getStartOffset()).thenReturn(1L);
when(point2.getPopTime()).thenReturn(1L);
when(point2.getBrokerName()).thenReturn("");

// counter is now 1, 1 > 0 is true, so second add is rejected
assertThat(popBufferMergeService.addCkJustOffset(point2, 0, 0, 1)).isFalse();
}
}
Loading