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 @@ -1339,7 +1339,8 @@ public void checkAndReviseMetrics() {
LinkedList<SelectMappedBufferResult> sbrs = new LinkedList<>();
boolean hasError = false;
try {
while (true) {
// Long.MAX_VALUE means no eligible slot in the timer wheel, skip the scan but still revise the metrics
while (currOffsetPy != Long.MAX_VALUE) {
SelectMappedBufferResult timeSbr = timerLog.getWholeBuffer(currOffsetPy);
if (timeSbr == null) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,51 @@ public void testRollMessage() throws Exception {
storeConfig.setTimerRollWindowSlot(Integer.MAX_VALUE);
}

@Test
public void testCheckAndReviseMetricsWithEmptyTimerWheel() throws Exception {
String topic = "TimerTest_testCheckAndReviseMetricsWithEmptyTimerWheel";
TimerMessageStore timerMessageStore = createTimerMessageStore(null, true);
timerMessageStore.load();

// the timer log has a mapped file, but no slot in the timer wheel is eligible
TimerLog timerLog = Mockito.spy(timerMessageStore.getTimerLog());
Field timerLogField = TimerMessageStore.class.getDeclaredField("timerLog");
timerLogField.setAccessible(true);
timerLogField.set(timerMessageStore, timerLog);
assertNotNull(timerLog.getMappedFileQueue().getLastMappedFile(0));
timerMessageStore.currReadTimeMs = System.currentTimeMillis() / precisionMs * precisionMs;
assertEquals(Long.MAX_VALUE, timerMessageStore.getTimerWheel().checkPhyPos(timerMessageStore.currReadTimeMs, 0));

timerMessageStore.getTimerMetrics().getTopicPair(topic).getCount().set(5);
timerMessageStore.checkAndReviseMetrics();

verify(timerLog, Mockito.never()).getWholeBuffer(Long.MAX_VALUE);
assertEquals(0, timerMessageStore.getTimerMetrics().getTimingCount(topic));
}

@Test
public void testCheckAndReviseMetricsWithValidSlot() throws Exception {
String topic = "TimerTest_testCheckAndReviseMetricsWithValidSlot";
TimerMessageStore timerMessageStore = createTimerMessageStore(null, true);
timerMessageStore.load();

long curr = System.currentTimeMillis() / precisionMs * precisionMs;
timerMessageStore.currReadTimeMs = curr;
timerMessageStore.currWriteTimeMs = curr;
long delayedTime = curr + 2 * precisionMs;
for (int i = 0; i < 2; i++) {
MessageExtBrokerInner inner = buildMessage(delayedTime, topic, false);
MessageAccessor.putProperty(inner, MessageConst.PROPERTY_REAL_TOPIC, topic);
assertTrue(timerMessageStore.doEnqueue(i * 100L, 100, delayedTime, inner, false));
}
assertEquals(0, timerMessageStore.getTimerWheel().checkPhyPos(curr, 0));

timerMessageStore.getTimerMetrics().getTopicPair(topic).getCount().set(5);
timerMessageStore.checkAndReviseMetrics();

assertEquals(2, timerMessageStore.getTimerMetrics().getTimingCount(topic));
}

public ByteBuffer getOneMessage(String topic, int queue, long offset, int timeout) throws Exception {
int retry = timeout / 100;
while (retry-- > 0) {
Expand Down