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 ca8074d15c8 Stabilize IT observation periods and restart cache checks
(#19095)
ca8074d15c8 is described below
commit ca8074d15c824f2533d357778e40f773d02b5565
Author: Caideyipi <[email protected]>
AuthorDate: Tue Nov 3 16:15:18 2026 +0800
Stabilize IT observation periods and restart cache checks (#19095)
* Stabilize IT observation periods and restart cache checks
* Persist restart-cache IT input before stopping nodes
---
.../apache/iotdb/db/it/utils/IoTDBTestUtilsIT.java | 47 +++++
.../org/apache/iotdb/db/it/utils/TestUtils.java | 203 ++++++++++-----------
.../iotdb/session/it/IoTDBSessionSimpleIT.java | 23 ++-
3 files changed, 160 insertions(+), 113 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/IoTDBTestUtilsIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/IoTDBTestUtilsIT.java
index 814de53ba68..234f59cbe0b 100644
---
a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/IoTDBTestUtilsIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/IoTDBTestUtilsIT.java
@@ -31,6 +31,10 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
+import java.sql.Connection;
+import java.sql.Statement;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -126,6 +130,49 @@ public class IoTDBTestUtilsIT {
handleFailure));
}
+ @Test
+ public void testAssertDataAlwaysIncludesQueryTime() {
+ final AtomicInteger queries = new AtomicInteger();
+ final BaseEnv slowEnv = delayQueries(BaseEnv.class, EnvFactory.getEnv(),
queries);
+ assertObservationPeriod(
+ () ->
+ TestUtils.assertDataAlwaysOnEnv(
+ slowEnv,
+ "count databases",
+ "count,",
+ Collections.singleton("0,"),
+ 1,
+ (String) null));
+ // A successful query taking longer than the observation period must not
cause a timeout.
+ assertEquals(1, queries.get());
+ }
+
+ private <T> T delayQueries(final Class<T> type, final T delegate, final
AtomicInteger queries) {
+ return type.cast(
+ Proxy.newProxyInstance(
+ type.getClassLoader(),
+ new Class<?>[] {type},
+ (proxy, method, args) -> {
+ if ("executeQuery".equals(method.getName())) {
+ queries.incrementAndGet();
+ TimeUnit.SECONDS.sleep(7);
+ }
+ final Object result;
+ try {
+ result = method.invoke(delegate, args);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ if (result instanceof Connection) {
+ return delayQueries(Connection.class, (Connection) result,
queries);
+ }
+ if (result instanceof Statement) {
+ return delayQueries(Statement.class, (Statement) result,
queries);
+ }
+ return result;
+ }));
+ }
+
private void assertObservationPeriod(final Runnable assertion) {
final long start = System.nanoTime();
assertion.run();
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
index 5b9482c362b..2a013e5a014 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
@@ -2029,15 +2029,9 @@ public class TestUtils {
final BaseEnv env, final String sql, final long consistentSeconds) {
try (final Connection connection =
env.getConnection(BaseEnv.TABLE_SQL_DIALECT);
final Statement statement = connection.createStatement()) {
- await()
- .pollInSameThread()
- .pollDelay(0L, TimeUnit.SECONDS)
- .pollInterval(1L, TimeUnit.SECONDS)
- .during(consistentSeconds, TimeUnit.SECONDS)
- .atMost(consistentSeconds + 5, TimeUnit.SECONDS)
- .failFast(
- () -> Assert.assertThrows(SQLException.class, () ->
statement.executeQuery(sql)))
- .until(() -> true);
+ assertAlways(
+ consistentSeconds,
+ () -> Assert.assertThrows(SQLException.class, () ->
statement.executeQuery(sql)));
} catch (final Exception e) {
fail(e.getMessage());
}
@@ -2172,34 +2166,28 @@ public class TestUtils {
env.getConnection(
Objects.isNull(database) ? TREE_SQL_DIALECT :
BaseEnv.TABLE_SQL_DIALECT);
Statement statement = connection.createStatement()) {
- await()
- .pollInSameThread()
- .pollDelay(0L, TimeUnit.SECONDS)
- .pollInterval(1L, TimeUnit.SECONDS)
- .during(consistentSeconds, TimeUnit.SECONDS)
- .atMost(consistentSeconds + 5, TimeUnit.SECONDS)
- .failFast(
- () -> {
- try {
- if (Objects.nonNull(database)) {
- statement.execute("use " + database);
- }
- // For IoTV2 batch mode, the pipe receiver may need to flush
because the replica
- // sync requires tsFile to process. We flush in the middle
of assertion because we
- // don't know when the data reaches the receiver in general
cases
- if (!flushed[0]
- && isHalfTimeoutElapsed(
- System.currentTimeMillis() - startTime,
consistentSeconds)) {
- flushed[0] = true;
- statement.execute("flush");
- }
- TestUtils.assertResultSetEqual(
- executeQueryWithRetry(statement, sql), expectedHeader,
expectedResSet);
- } catch (Exception e) {
- Assert.fail();
- }
- })
- .until(() -> true);
+ assertAlways(
+ consistentSeconds,
+ () -> {
+ try {
+ if (Objects.nonNull(database)) {
+ statement.execute("use " + database);
+ }
+ // For IoTV2 batch mode, the pipe receiver may need to flush
because the replica
+ // sync requires tsFile to process. We flush in the middle of
assertion because we
+ // don't know when the data reaches the receiver in general cases
+ if (!flushed[0]
+ && isHalfTimeoutElapsed(
+ System.currentTimeMillis() - startTime,
consistentSeconds)) {
+ flushed[0] = true;
+ statement.execute("flush");
+ }
+ TestUtils.assertResultSetEqual(
+ executeQueryWithRetry(statement, sql), expectedHeader,
expectedResSet);
+ } catch (Exception e) {
+ Assert.fail();
+ }
+ });
} catch (Exception e) {
e.printStackTrace();
fail();
@@ -2217,39 +2205,33 @@ public class TestUtils {
final boolean[] flushed = {false};
try (Connection connection = env.getConnection();
Statement statement = connection.createStatement()) {
- await()
- .pollInSameThread()
- .pollDelay(0L, TimeUnit.SECONDS)
- .pollInterval(1L, TimeUnit.SECONDS)
- .during(consistentSeconds, TimeUnit.SECONDS)
- .atMost(consistentSeconds + 5, TimeUnit.SECONDS)
- .failFast(
- () -> {
- try {
- // For IoTV2 batch mode, the pipe receiver may need to flush
because the replica
- // sync requires tsFile to process. We flush in the middle
of assertion because we
- // don't know when the data reaches the receiver in general
cases
- if (!flushed[0]
- && isHalfTimeoutElapsed(
- System.currentTimeMillis() - startTime,
consistentSeconds)) {
- flushed[0] = true;
- statement.execute("flush");
- }
- TestUtils.assertResultSetEqual(
- executeQueryWithRetry(statement, sql), expectedHeader,
expectedResSet);
- } catch (Exception e) {
- if (handleFailure != null) {
- handleFailure.accept(e.getMessage());
- }
- Assert.fail();
- } catch (Error e) {
- if (handleFailure != null) {
- handleFailure.accept(e.getMessage());
- }
- throw e;
- }
- })
- .until(() -> true);
+ assertAlways(
+ consistentSeconds,
+ () -> {
+ try {
+ // For IoTV2 batch mode, the pipe receiver may need to flush
because the replica
+ // sync requires tsFile to process. We flush in the middle of
assertion because we
+ // don't know when the data reaches the receiver in general cases
+ if (!flushed[0]
+ && isHalfTimeoutElapsed(
+ System.currentTimeMillis() - startTime,
consistentSeconds)) {
+ flushed[0] = true;
+ statement.execute("flush");
+ }
+ TestUtils.assertResultSetEqual(
+ executeQueryWithRetry(statement, sql), expectedHeader,
expectedResSet);
+ } catch (Exception e) {
+ if (handleFailure != null) {
+ handleFailure.accept(e.getMessage());
+ }
+ Assert.fail();
+ } catch (Error e) {
+ if (handleFailure != null) {
+ handleFailure.accept(e.getMessage());
+ }
+ throw e;
+ }
+ });
} catch (Exception e) {
e.printStackTrace();
fail();
@@ -2269,48 +2251,57 @@ public class TestUtils {
try (Connection connection =
env.getConnection(database == null ? TREE_SQL_DIALECT :
BaseEnv.TABLE_SQL_DIALECT);
Statement statement = connection.createStatement()) {
- await()
- .pollInSameThread()
- .pollDelay(0L, TimeUnit.SECONDS)
- .pollInterval(1L, TimeUnit.SECONDS)
- .during(consistentSeconds, TimeUnit.SECONDS)
- .atMost(consistentSeconds + 5, TimeUnit.SECONDS)
- .failFast(
- () -> {
- try {
- if (database != null) {
- statement.execute("use " + database);
- }
- // For IoTV2 batch mode, the pipe receiver may need to flush
because the replica
- // sync requires tsFile to process. We flush in the middle
of assertion because we
- // don't know when the data reaches the receiver in general
cases
- if (!flushed[0]
- && isHalfTimeoutElapsed(
- System.currentTimeMillis() - startTime,
consistentSeconds)) {
- flushed[0] = true;
- statement.execute("flush");
- }
- TestUtils.assertResultSetEqual(
- executeQueryWithRetry(statement, sql), expectedHeader,
expectedResSet);
- } catch (Exception e) {
- if (handleFailure != null) {
- handleFailure.accept(e.getMessage());
- }
- Assert.fail();
- } catch (Error e) {
- if (handleFailure != null) {
- handleFailure.accept(e.getMessage());
- }
- throw e;
- }
- })
- .until(() -> true);
+ assertAlways(
+ consistentSeconds,
+ () -> {
+ try {
+ if (database != null) {
+ statement.execute("use " + database);
+ }
+ // For IoTV2 batch mode, the pipe receiver may need to flush
because the replica
+ // sync requires tsFile to process. We flush in the middle of
assertion because we
+ // don't know when the data reaches the receiver in general cases
+ if (!flushed[0]
+ && isHalfTimeoutElapsed(
+ System.currentTimeMillis() - startTime,
consistentSeconds)) {
+ flushed[0] = true;
+ statement.execute("flush");
+ }
+ TestUtils.assertResultSetEqual(
+ executeQueryWithRetry(statement, sql), expectedHeader,
expectedResSet);
+ } catch (Exception e) {
+ if (handleFailure != null) {
+ handleFailure.accept(e.getMessage());
+ }
+ Assert.fail();
+ } catch (Error e) {
+ if (handleFailure != null) {
+ handleFailure.accept(e.getMessage());
+ }
+ throw e;
+ }
+ });
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
+ /** Observe for a bounded period, including time spent executing and
checking each query. */
+ private static void assertAlways(final long consistentSeconds, final
Runnable assertion)
+ throws InterruptedException {
+ final long start = System.nanoTime();
+ final long duration = TimeUnit.SECONDS.toNanos(consistentSeconds);
+ while (true) {
+ assertion.run();
+ final long remaining = duration - (System.nanoTime() - start);
+ if (remaining <= 0) {
+ return;
+ }
+ TimeUnit.NANOSECONDS.sleep(Math.min(remaining,
TimeUnit.SECONDS.toNanos(1)));
+ }
+ }
+
public static void restartDataNodes() {
EnvFactory.getEnv().shutdownAllDataNodes();
EnvFactory.getEnv().startAllDataNodes();
diff --git
a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
index 1ec46f9d519..101f1be9b73 100644
---
a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionSimpleIT.java
@@ -2117,21 +2117,30 @@ public class IoTDBSessionSimpleIT {
throws IoTDBConnectionException, StatementExecutionException {
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
session.insertRecord("root.sg1.d1", 1, Arrays.asList("s3"),
Arrays.asList("1"));
+ session.executeNonQueryStatement("FLUSH");
+ }
- TestUtils.stopForciblyAndRestartDataNodes();
+ TestUtils.stopForciblyAndRestartDataNodes();
- SessionDataSet dataSet = session.executeQueryStatement("select s3 from
root.sg1.d1");
- dataSet.next();
- dataSet.close();
+ // This case verifies recovered database caches, so do not retain
transports across the restart.
+ try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+ try (SessionDataSet dataSet = session.executeQueryStatement("select s3
from root.sg1.d1")) {
+ assertTrue(dataSet.hasNext());
+ dataSet.next();
+ assertFalse(dataSet.hasNext());
+ }
session.executeNonQueryStatement("DELETE DATABASE root.sg1");
session.insertRecord(
"root.sg1.d1", 1, Arrays.asList("s1", "s2", "s3"),
Arrays.asList("1", "1", "1"));
- dataSet = session.executeQueryStatement("SELECT * FROM root.sg1.d1");
- RowRecord record = dataSet.next();
- assertEquals(3, record.getFields().size());
+ try (SessionDataSet dataSet = session.executeQueryStatement("SELECT *
FROM root.sg1.d1")) {
+ assertTrue(dataSet.hasNext());
+ RowRecord record = dataSet.next();
+ assertEquals(3, record.getFields().size());
+ assertFalse(dataSet.hasNext());
+ }
}
}