Skip to content
Merged
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 @@ -1507,6 +1507,10 @@
}
if (batchResult != MaterializationResult.SUCCESS) {
if (batchResult == MaterializationResult.WAL_GAP) {
if (!lingerBatch.isEmpty() && !flushBatch(lingerBatch, observedSeekGeneration)) {
resetRoundStateForSeek(seekGeneration.get());
return PrefetchRoundResult.rescheduleNow();
}
return PrefetchRoundResult.rescheduleAfter(WAL_GAP_RETRY_SLEEP_MS);
}
if (batchResult == MaterializationResult.MEMORY_BLOCKED) {
Expand Down Expand Up @@ -2100,7 +2104,7 @@
walReplayFailureMessage =
String.format(
DataNodePipeMessages
.MESSAGE_CONSENSUSPREFETCHINGQUEUE_WAL_REPLAY_CANNOT_RECOVER_SEARCH_INDEXES_70781B22,

Check warning on line 2107 in iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Line is longer than 100 characters (found 103).

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AaDyjP5mBxenDX0ixV_x&open=AaDyjP5mBxenDX0ixV_x&pullRequest=18785
this,
expectedSearchIndex,
actualSearchIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,94 @@ public void testWalReplayCountsOnlyUnavailableSearchIndexes() throws Exception {
}
}

@Test
public void testPendingWalGapFlushesLingerBatchBeforeRetry() throws Exception {
final String originalSystemDir = IoTDBDescriptor.getInstance().getConfig().getSystemDir();
final int originalBatchMaxWalEntries =
CommonDescriptor.getInstance().getConfig().getSubscriptionConsensusBatchMaxWalEntries();
final int originalBatchMaxDelay =
CommonDescriptor.getInstance().getConfig().getSubscriptionConsensusBatchMaxDelayInMs();
final File systemDir = temporaryFolder.newFolder("pending-gap-flush-linger-batch");
ConsensusPrefetchingQueue queue = null;
try {
CommonDescriptor.getInstance().getConfig().setSubscriptionConsensusBatchMaxWalEntries(2);
CommonDescriptor.getInstance().getConfig().setSubscriptionConsensusBatchMaxDelayInMs(60_000);

final DataRegionId regionId = new DataRegionId(13);
final WALNode walNode = mock(WALNode.class);
when(walNode.getCurrentSearchIndex()).thenReturn(5L);
when(walNode.getLogDirectory()).thenReturn(systemDir);
final IoTConsensusServerImpl serverImpl = mock(IoTConsensusServerImpl.class);
when(serverImpl.getConsensusReqReader()).thenReturn(walNode);
when(serverImpl.getWriterSafeFrontierTracker()).thenReturn(new WriterSafeFrontierTracker());

final ConsensusLogToTabletConverter converter = mock(ConsensusLogToTabletConverter.class);
when(converter.convert(any())).thenReturn(Collections.singletonList(createTablet()));
when(converter.getDatabaseName()).thenReturn("db");

queue =
new ConsensusPrefetchingQueue(
"consumerGroup",
"topic",
TopicConstant.ORDER_MODE_LEADER_ONLY_VALUE,
regionId,
serverImpl,
new SubscriptionWalRetentionPolicy(
"topic",
SubscriptionWalRetentionPolicy.UNBOUNDED,
SubscriptionWalRetentionPolicy.UNBOUNDED),
converter,
newCommitManager(systemDir),
new RegionProgress(Collections.emptyMap()),
1L,
1L,
true) {
@Override
protected ProgressWALIterator createSubscriptionWALIterator(
final long startSearchIndex) {
final Iterator<IndexedConsensusRequest> walEntries =
Arrays.asList(
createRequest(1L),
createRequest(2L),
createRequest(3L),
createRequest(4L),
createRequest(5L))
.iterator();
final ProgressWALIterator iterator = mock(ProgressWALIterator.class);
when(iterator.hasNext()).thenAnswer(ignored -> walEntries.hasNext());
when(iterator.next()).thenAnswer(ignored -> walEntries.next());
return iterator;
}
};
queue.setSubscriptionMemoryManager(new SubscriptionMemoryManager(16L * 1024 * 1024));

assertNull(queue.poll("consumer"));
assertTrue(pendingEntries(queue).offer(createRequest(5L)));

queue.drivePrefetchOnce();

assertEquals(3L, queue.getCurrentReadSearchIndex());
assertEquals(1, queue.getPrefetchedEventCount());
final SubscriptionEvent event = queue.poll("consumer");
assertNotNull(event);
assertEquals(
SubscriptionPollResponseType.TABLETS.getType(),
event.getCurrentResponse().getResponseType());
assertTrue(queue.ack("consumer", event.getCommitContext()));
} finally {
if (queue != null) {
queue.close();
}
CommonDescriptor.getInstance()
.getConfig()
.setSubscriptionConsensusBatchMaxWalEntries(originalBatchMaxWalEntries);
CommonDescriptor.getInstance()
.getConfig()
.setSubscriptionConsensusBatchMaxDelayInMs(originalBatchMaxDelay);
IoTDBDescriptor.getInstance().getConfig().setSystemDir(originalSystemDir);
}
}

@Test
public void testWalReplayFailsCriticallyWhenGapRemainsUnavailable() throws Exception {
final String originalSystemDir = IoTDBDescriptor.getInstance().getConfig().getSystemDir();
Expand Down
Loading