jt2594838 commented on code in PR #18453:
URL: https://github.com/apache/iotdb/pull/18453#discussion_r3764914940
##########
iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatusTest.java:
##########
@@ -242,4 +251,59 @@ public void waitTest() throws InterruptedException,
ExecutionException {
Assert.assertEquals(
config.getReplication().getMaxPendingBatchesNum() + 1,
status.getNextSendingIndex());
}
+
+ @Test
+ public void testFirstBatchRetriesMemoryReservation()
+ throws InterruptedException, ExecutionException, TimeoutException {
+ IndexController controller =
+ new IndexController(storageDir.getAbsolutePath(), peer, 0,
CHECK_POINT_GAP);
+ IoTConsensusConfig retryConfig =
+ IoTConsensusConfig.newBuilder()
+ .setReplication(
+
IoTConsensusConfig.Replication.newBuilder().setBasicRetryWaitTimeMs(10).build())
+ .build();
+ SyncStatus status = new SyncStatus(controller, retryConfig);
+ TLogEntry logEntry = new TLogEntry().setSearchIndex(1).setMemorySize(1);
+ Batch batch = new Batch(retryConfig);
+ batch.addTLogEntry(logEntry);
+ batch.buildIndex();
+
+ IoTConsensusMemoryManager memoryManager =
IoTConsensusMemoryManager.getInstance();
+ IMemoryBlock previousMemoryBlock = memoryManager.getMemoryBlock();
+ CountDownLatch firstAllocationFailed = new CountDownLatch(1);
+ AtomicBoolean rejectAllocation = new AtomicBoolean(true);
+ IMemoryBlock memoryBlock =
+ new AtomicLongMemoryBlock("SyncStatusTest", null,
batch.getMemorySize()) {
+ @Override
+ public boolean allocate(long sizeInByte) {
+ if (rejectAllocation.compareAndSet(true, false)) {
+ firstAllocationFailed.countDown();
+ return false;
+ }
+ return super.allocate(sizeInByte);
+ }
+ };
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ memoryManager.setMemoryBlock(memoryBlock);
+ try {
+ Future<?> future =
+ executor.submit(
+ () -> {
+ status.addNextBatch(batch);
+ return null;
+ });
+
+ Assert.assertTrue(firstAllocationFailed.await(5, TimeUnit.SECONDS));
Review Comment:
This regression test deterministically rejects the first allocation, then
waits for `addNextBatch` to retry without any external notification. The
bounded latches/future make a permanent wait fail quickly, and the `finally`
block restores the singleton memory block so the test cannot leak global state
into other consensus tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]