This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new ad94d2b68cd Fix WAL roll file test flush wait (#17904)
ad94d2b68cd is described below
commit ad94d2b68cd3cc2ef4d23df18aebe600a1caad24
Author: Caideyipi <[email protected]>
AuthorDate: Thu Nov 5 16:47:59 2026 +0800
Fix WAL roll file test flush wait (#17904)
---
.../wal/node/WALNodeWaitForRollFileTest.java | 101 +++++++++++----------
1 file changed, 52 insertions(+), 49 deletions(-)
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALNodeWaitForRollFileTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALNodeWaitForRollFileTest.java
index 1720a76cfbf..503660da267 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALNodeWaitForRollFileTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/wal/node/WALNodeWaitForRollFileTest.java
@@ -31,6 +31,8 @@ import org.apache.iotdb.db.storageengine.StorageEngine;
import org.apache.iotdb.db.storageengine.dataregion.memtable.IMemTable;
import org.apache.iotdb.db.storageengine.dataregion.memtable.PrimitiveMemTable;
import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALMode;
+import
org.apache.iotdb.db.storageengine.dataregion.wal.utils.listener.AbstractResultListener.Status;
+import
org.apache.iotdb.db.storageengine.dataregion.wal.utils.listener.WALFlushListener;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.db.utils.constant.TestConstant;
@@ -40,7 +42,6 @@ import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.BitMap;
import org.apache.tsfile.write.schema.MeasurementSchema;
-import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -54,6 +55,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -123,12 +125,11 @@ public class WALNodeWaitForRollFileTest {
// write a small amount of data (not enough to trigger roll)
InsertTabletNode insertTabletNode = getInsertTabletNode(devicePath, new
long[] {1});
insertTabletNode.setSearchIndex(1);
- walNode.log(
- memTable.getMemTableId(),
- insertTabletNode,
- Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()}));
-
- Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() ->
walNode.isAllWALEntriesConsumed());
+ waitForFlush(
+ walNode.log(
+ memTable.getMemTableId(),
+ insertTabletNode,
+ Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()})));
// data is flushed to buffer but no WAL file roll happened yet, iterator
at search index 1
// should not find data (because the current-writing WAL file is not
readable by the iterator)
@@ -159,17 +160,15 @@ public class WALNodeWaitForRollFileTest {
for (int i = 1; i <= 5; i++) {
InsertTabletNode insertTabletNode = getInsertTabletNode(devicePath, new
long[] {i});
insertTabletNode.setSearchIndex(i);
- walNode.log(
- memTable.getMemTableId(),
- insertTabletNode,
- Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()}));
+ waitForFlush(
+ walNode.log(
+ memTable.getMemTableId(),
+ insertTabletNode,
+ Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()})));
}
- Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() ->
walNode.isAllWALEntriesConsumed());
-
// roll the WAL file so the data is in a closed file readable by the
iterator
walNode.rollWALFile();
- Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() ->
walNode.isAllWALEntriesConsumed());
// iterator at search index 1 should find the data after roll
ConsensusReqReader.ReqIterator iterator = walNode.getReqIterator(1);
@@ -184,16 +183,15 @@ public class WALNodeWaitForRollFileTest {
InsertTabletNode insertTabletNode = getInsertTabletNode(devicePath, new
long[] {1});
insertTabletNode.setSearchIndex(1);
- walNode.log(
- memTable.getMemTableId(),
- insertTabletNode,
- Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()}));
- walNode.log(memTable.getMemTableId(), new
ContinuousSameSearchIndexSeparatorNode());
-
- Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() ->
walNode.isAllWALEntriesConsumed());
+ waitForFlush(
+ walNode.log(
+ memTable.getMemTableId(),
+ insertTabletNode,
+ Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()})));
+ waitForFlush(
+ walNode.log(memTable.getMemTableId(), new
ContinuousSameSearchIndexSeparatorNode()));
walNode.rollWALFile();
- Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() ->
walNode.isAllWALEntriesConsumed());
ConsensusReqReader.ReqIterator iterator = walNode.getReqIterator(1);
assertTrue(iterator.hasNext());
@@ -213,12 +211,11 @@ public class WALNodeWaitForRollFileTest {
InsertTabletNode insertTabletNode = getInsertTabletNode(devicePath, new
long[] {1});
insertTabletNode.setSearchIndex(1);
insertTabletNode.setLastFragment(true);
- walNode.log(
- memTable.getMemTableId(),
- insertTabletNode,
- Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()}));
-
- Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() ->
walNode.isAllWALEntriesConsumed());
+ waitForFlush(
+ walNode.log(
+ memTable.getMemTableId(),
+ insertTabletNode,
+ Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()})));
ConsensusReqReader.ReqIterator iterator = walNode.getReqIterator(1);
@@ -238,9 +235,6 @@ public class WALNodeWaitForRollFileTest {
// trigger WAL file roll — this should signal rollLogWriterCondition and
wake up the iterator
walNode.rollWALFile();
- Awaitility.await()
- .atMost(10, TimeUnit.SECONDS)
- .until(() -> walNode.isAllWALEntriesConsumed());
assertTrue(
"Iterator should have found data after WAL file roll",
@@ -269,14 +263,11 @@ public class WALNodeWaitForRollFileTest {
// write initial data with search index
InsertTabletNode first = getInsertTabletNode(devicePath, new long[] {1});
first.setSearchIndex(1);
- walNode.log(
- memTable.getMemTableId(),
- first,
- Collections.singletonList(new int[] {0, first.getRowCount()}));
-
- Awaitility.await()
- .atMost(10, TimeUnit.SECONDS)
- .until(() -> walNode.isAllWALEntriesConsumed());
+ waitForFlush(
+ walNode.log(
+ memTable.getMemTableId(),
+ first,
+ Collections.singletonList(new int[] {0, first.getRowCount()})));
ConsensusReqReader.ReqIterator iterator = walNode.getReqIterator(1);
@@ -291,14 +282,17 @@ public class WALNodeWaitForRollFileTest {
assertTrue(waiterStarted.await(10, TimeUnit.SECONDS));
// write more data to exceed the small threshold and trigger auto-roll
+ WALFlushListener lastFlushListener = null;
for (int i = 2; i <= 50; i++) {
InsertTabletNode node = getInsertTabletNode(devicePath, new long[]
{i});
node.setSearchIndex(i);
- walNode.log(
- memTable.getMemTableId(),
- node,
- Collections.singletonList(new int[] {0, node.getRowCount()}));
+ lastFlushListener =
+ walNode.log(
+ memTable.getMemTableId(),
+ node,
+ Collections.singletonList(new int[] {0, node.getRowCount()}));
}
+ waitForFlush(lastFlushListener);
assertTrue(
"Iterator should have found data after auto WAL file roll",
@@ -327,12 +321,11 @@ public class WALNodeWaitForRollFileTest {
InsertTabletNode insertTabletNode = getInsertTabletNode(devicePath, new
long[] {1});
insertTabletNode.setSearchIndex(1);
insertTabletNode.setLastFragment(true);
- walNode.log(
- memTable.getMemTableId(),
- insertTabletNode,
- Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()}));
-
- Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() ->
walNode.isAllWALEntriesConsumed());
+ waitForFlush(
+ walNode.log(
+ memTable.getMemTableId(),
+ insertTabletNode,
+ Collections.singletonList(new int[] {0,
insertTabletNode.getRowCount()})));
// iterator cannot read the active WAL file, so hasNext() should be false
ConsensusReqReader.ReqIterator iterator = walNode.getReqIterator(1);
@@ -426,4 +419,14 @@ public class WALNodeWaitForRollFileTest {
columns,
times.length);
}
+
+ private void waitForFlush(WALFlushListener flushListener) throws Exception {
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ try {
+ Future<Status> waitFuture =
executor.submit(flushListener::waitForResult);
+ assertEquals(Status.SUCCESS, waitFuture.get(10, TimeUnit.SECONDS));
+ } finally {
+ executor.shutdownNow();
+ }
+ }
}