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 c4e0c8b6b53 Scope the TsFile scan of
IoTDBLoadStorageTsFileWithCompactionIT to its own database (#19169)
c4e0c8b6b53 is described below
commit c4e0c8b6b538f573589ff1e79592c9c54967a0c5
Author: Zhenyu Luo <[email protected]>
AuthorDate: Fri Dec 4 15:22:34 2026 +0800
Scope the TsFile scan of IoTDBLoadStorageTsFileWithCompactionIT to its own
database (#19169)
* Scope the TsFile scan of the load-storage IT to its own database
IoTDBLoadStorageTsFileWithCompactionIT walked the whole DataNode data
directory and required every TsFile below it to carry the table schema of
table t1, and the TsFile counting helpers were built on the same scan.
That directory is shared by every database of the node. Internal
databases that store system records are tree-model databases, whose
TsFiles legitimately have an empty table schema map, so the assertion
fails with
TsFile has no schema entry for table t1: {}
as soon as the node holds such a database (observed on a downstream
distribution that records the password history of "root" in root.__audit).
The same files also polluted the counting helpers: "two TsFiles before
compaction" could be satisfied by a single data file, and "exactly one
TsFile after compaction" could never hold.
Restrict every scan to <dataPath>/{sequence,unsequence}/load_storage_db,
keep the assertions unchanged, and name the offending file in the failure
messages.
* Skip TsFiles deleted by concurrent compaction in the load-storage IT scan
The TsFile scan of IoTDBLoadStorageTsFileWithCompactionIT also runs while
compaction deletes the source TsFiles and their .resource sidecars.
Files.walk stats every entry it lists, so an entry that disappears between
listing and stat aborts the poll with NoSuchFileException, which Awaitility
reports as a test error long before the 60s budget is used.
List the database directory with Files.walkFileTree and ignore entries that
were deleted by the time the walker reached them, while still propagating
any other IO error. The assertions are unchanged.
* Exercise the database-scoped TsFile scan in the load-storage IT
Create a second, tree-model database (root.other) on the producer and flush
a
TsFile for it before compaction. That file carries no table schema, so
assertAllTsFilesHaveTableSchema only stays green because listDatabaseTsFiles
scopes the scan to the test database; reverting the helpers to a whole-data-
directory scan now fails on this file instead of passing silently, and
countTsFiles can no longer be satisfied by unrelated TsFiles.
Wait for the extra TsFile to reach the data directory, so the guard does not
depend on flush timing.
---
.../it/IoTDBLoadStorageTsFileWithCompactionIT.java | 137 +++++++++++++++------
1 file changed, 102 insertions(+), 35 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadStorageTsFileWithCompactionIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadStorageTsFileWithCompactionIT.java
index bb8c79b921b..e1c73425e16 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadStorageTsFileWithCompactionIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadStorageTsFileWithCompactionIT.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.relational.it.db.it;
+import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.it.env.MultiEnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.MultiClusterIT2DualTableManualBasic;
@@ -37,17 +38,21 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import java.io.IOException;
+import java.nio.file.FileVisitResult;
import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
@RunWith(IoTDBTestRunner.class)
@@ -55,8 +60,10 @@ import java.util.stream.Stream;
public class IoTDBLoadStorageTsFileWithCompactionIT {
private static final String DATABASE = "load_storage_db";
+ private static final String TREE_DATABASE = "root.other";
private static final String TABLE = "t1";
private static final long COMPACTION_WAIT_SECONDS = 60L;
+ private static final long FLUSH_WAIT_SECONDS = 60L;
private static final String TABLE_MODEL_PROPERTY = "isTableModel";
private static BaseEnv producerEnv;
@@ -153,6 +160,8 @@ public class IoTDBLoadStorageTsFileWithCompactionIT {
}
}
+ createTreeModelFileOnProducer();
+
Awaitility.await()
.pollInterval(200, TimeUnit.MILLISECONDS)
.atMost(COMPACTION_WAIT_SECONDS, TimeUnit.SECONDS)
@@ -160,6 +169,30 @@ public class IoTDBLoadStorageTsFileWithCompactionIT {
return countTsFiles(producerEnv);
}
+ /**
+ * Creates a second database of the other data model on the producer and
flushes a TsFile for it.
+ *
+ * <p>This file carries no table schema, so it is harmless only because
{@link
+ * #listDatabaseTsFiles} scopes the scan to {@link #DATABASE}. Regressing
the helpers back to a
+ * scan of the whole DataNode data directory would include this file, make
{@link
+ * #assertAllTsFilesHaveTableSchema} fail on it and keep {@link
#countTsFiles} from ever reaching
+ * the expected count.
+ */
+ private static void createTreeModelFileOnProducer() throws Exception {
+ try (final Connection connection = producerEnv.getConnection();
+ final Statement statement = connection.createStatement()) {
+ statement.execute("CREATE DATABASE " + TREE_DATABASE);
+ statement.execute("INSERT INTO " + TREE_DATABASE + ".d1(time, s1) VALUES
(1, 1)");
+ statement.execute("FLUSH");
+ }
+ // The file has to be on disk before the table-model assertions run,
otherwise a regression to
+ // a whole-data-directory scan would not be caught.
+ Awaitility.await()
+ .pollInterval(200, TimeUnit.MILLISECONDS)
+ .atMost(FLUSH_WAIT_SECONDS, TimeUnit.SECONDS)
+ .until(() -> countTsFiles(producerEnv, TREE_DATABASE) >= 1);
+ }
+
private static void enableSeqSpaceCompaction(final BaseEnv env) throws
Exception {
try (final Connection connection =
env.getConnection(BaseEnv.TABLE_SQL_DIALECT);
final Statement statement = connection.createStatement()) {
@@ -194,59 +227,93 @@ public class IoTDBLoadStorageTsFileWithCompactionIT {
try (final TsFileSequenceReader reader =
new TsFileSequenceReader(tsFile.toAbsolutePath().toString())) {
final Map<String, TableSchema> tableSchemaMap =
reader.getTableSchemaMap();
- Assert.assertNotNull("TsFile has no table schema map", tableSchemaMap);
+ Assert.assertNotNull("TsFile " + tsFile + " has no table schema map",
tableSchemaMap);
Assert.assertTrue(
- "TsFile has no schema entry for table " + TABLE + ": " +
tableSchemaMap,
+ "TsFile " + tsFile + " has no schema entry for table " + TABLE + ":
" + tableSchemaMap,
tableSchemaMap.containsKey(TABLE));
Assert.assertFalse(
- "The storage path must not synthesize a TIME column: " +
tableSchemaMap.get(TABLE),
+ "The storage path must not synthesize a TIME column: " + tsFile,
tableSchemaMap.get(TABLE).getColumnTypes().contains(ColumnCategory.TIME));
Assert.assertTrue(
- "A table-model TsFile must carry the " + TABLE_MODEL_PROPERTY + "
property",
+ "A table-model TsFile must carry the "
+ + TABLE_MODEL_PROPERTY
+ + " property, but "
+ + tsFile
+ + " does not",
reader.readFileMetadata().getTsFileProperties().containsKey(TABLE_MODEL_PROPERTY));
}
}
private static void assertAllTsFilesHaveTableSchema(final BaseEnv env)
throws IOException {
- final Path dataPath = Paths.get(env.getDataNodeWrapper(0).getDataPath());
- try (final Stream<Path> paths = Files.walk(dataPath)) {
- final List<Path> tsFiles =
- paths
- .filter(Files::isRegularFile)
- .filter(path ->
path.getFileName().toString().endsWith(TsFileConstant.TSFILE_SUFFIX))
- .collect(Collectors.toList());
- Assert.assertFalse("No TsFile was produced", tsFiles.isEmpty());
- for (final Path tsFile : tsFiles) {
- assertTableSchemaRegistered(tsFile);
- }
+ final List<Path> tsFiles = listDatabaseTsFiles(env, DATABASE);
+ Assert.assertFalse("No TsFile was produced for database " + DATABASE,
tsFiles.isEmpty());
+ for (final Path tsFile : tsFiles) {
+ assertTableSchemaRegistered(tsFile);
}
}
private static long countTsFiles(final BaseEnv env) throws IOException {
- final Path dataPath = Paths.get(env.getDataNodeWrapper(0).getDataPath());
- if (!Files.exists(dataPath)) {
- return 0;
- }
- try (final Stream<Path> paths = Files.walk(dataPath)) {
- return paths
- .filter(Files::isRegularFile)
- .filter(path ->
path.getFileName().toString().endsWith(TsFileConstant.TSFILE_SUFFIX))
- .count();
- }
+ return countTsFiles(env, DATABASE);
+ }
+
+ private static long countTsFiles(final BaseEnv env, final String database)
throws IOException {
+ return listDatabaseTsFiles(env, database).size();
}
private static Path findSingleTsFile(final BaseEnv env) throws IOException {
+ final List<Path> tsFiles = listDatabaseTsFiles(env, DATABASE);
+ Assert.assertEquals(
+ "Expected exactly one compacted TsFile, but got " + tsFiles, 1,
tsFiles.size());
+ return tsFiles.get(0);
+ }
+
+ /**
+ * Lists the TsFiles of the given database.
+ *
+ * <p>The DataNode data directory is shared by every database of the node,
including the internal
+ * ones that store system records. Those databases are tree-model databases
whose TsFiles
+ * legitimately carry no table schema at all, so scanning the whole data
directory would mix
+ * unrelated TsFiles into the table-schema assertions of this test.
+ *
+ * <p>The listing must also tolerate files that disappear while it runs: the
compaction assertions
+ * poll this directory exactly while compaction is deleting the source
TsFiles and their {@code
+ * .resource} sidecars, and a lazily walked entry that is gone by the time
it is stat'ed would
+ * abort the poll with a {@link NoSuchFileException}.
+ */
+ private static List<Path> listDatabaseTsFiles(final BaseEnv env, final
String database)
+ throws IOException {
final Path dataPath = Paths.get(env.getDataNodeWrapper(0).getDataPath());
- try (final Stream<Path> paths = Files.walk(dataPath)) {
- final List<Path> tsFiles =
- paths
- .filter(Files::isRegularFile)
- .filter(path ->
path.getFileName().toString().endsWith(TsFileConstant.TSFILE_SUFFIX))
- .collect(Collectors.toList());
- Assert.assertEquals(
- "Expected exactly one compacted TsFile, but got " + tsFiles, 1,
tsFiles.size());
- return tsFiles.get(0);
+ final List<Path> tsFiles = new ArrayList<>();
+ for (final String folder :
+ new String[] {IoTDBConstant.SEQUENCE_FOLDER_NAME,
IoTDBConstant.UNSEQUENCE_FOLDER_NAME}) {
+ final Path databaseDir = dataPath.resolve(folder).resolve(database);
+ if (!Files.isDirectory(databaseDir)) {
+ continue;
+ }
+ Files.walkFileTree(
+ databaseDir,
+ new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(final Path file, final
BasicFileAttributes attrs) {
+ if
(file.getFileName().toString().endsWith(TsFileConstant.TSFILE_SUFFIX)) {
+ tsFiles.add(file);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(final Path file, final
IOException exception)
+ throws IOException {
+ // The entry was listed but deleted by the concurrent compaction
before it was
+ // stat'ed.
+ if (exception instanceof NoSuchFileException) {
+ return FileVisitResult.CONTINUE;
+ }
+ throw exception;
+ }
+ });
}
+ return tsFiles;
}
private static void deleteRecursively(final Path path) throws IOException {