From 3b78e99072d9d8900a2e014c240c1c59217ed6c2 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:03:59 +0800 Subject: [PATCH 1/4] disable tree --- .../apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 | 2 -- .../queryengine/plan/parser/ASTVisitor.java | 24 +++++++--------- .../metadata/DatabaseSchemaStatement.java | 28 ++++++++++--------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 b/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 index 57d686de88e65..70b7f0c4bed8e 100644 --- a/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 +++ b/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 @@ -112,8 +112,6 @@ databaseAttributeClause databaseAttributeKey : TTL - | SCHEMA_REPLICATION_FACTOR - | DATA_REPLICATION_FACTOR | TIME_PARTITION_INTERVAL | SCHEMA_REGION_GROUP_NUM | DATA_REGION_GROUP_NUM diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java index 6c0ee3db25421..1a39b2377e6a2 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java @@ -2611,27 +2611,23 @@ public Statement visitAlterDatabase(IoTDBSqlParser.AlterDatabaseContext ctx) { } private void parseDatabaseAttributesClause( - DatabaseSchemaStatement databaseSchemaStatement, - IoTDBSqlParser.DatabaseAttributesClauseContext ctx) { - for (IoTDBSqlParser.DatabaseAttributeClauseContext attribute : ctx.databaseAttributeClause()) { - IoTDBSqlParser.DatabaseAttributeKeyContext attributeKey = attribute.databaseAttributeKey(); + final DatabaseSchemaStatement databaseSchemaStatement, + final IoTDBSqlParser.DatabaseAttributesClauseContext ctx) { + for (final IoTDBSqlParser.DatabaseAttributeClauseContext attribute : + ctx.databaseAttributeClause()) { + final IoTDBSqlParser.DatabaseAttributeKeyContext attributeKey = + attribute.databaseAttributeKey(); if (attributeKey.TTL() != null) { - long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText()); + final long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText()); databaseSchemaStatement.setTtl(ttl); - } else if (attributeKey.SCHEMA_REPLICATION_FACTOR() != null) { - int schemaReplicationFactor = Integer.parseInt(attribute.INTEGER_LITERAL().getText()); - databaseSchemaStatement.setSchemaReplicationFactor(schemaReplicationFactor); - } else if (attributeKey.DATA_REPLICATION_FACTOR() != null) { - int dataReplicationFactor = Integer.parseInt(attribute.INTEGER_LITERAL().getText()); - databaseSchemaStatement.setDataReplicationFactor(dataReplicationFactor); } else if (attributeKey.TIME_PARTITION_INTERVAL() != null) { - long timePartitionInterval = Long.parseLong(attribute.INTEGER_LITERAL().getText()); + final long timePartitionInterval = Long.parseLong(attribute.INTEGER_LITERAL().getText()); databaseSchemaStatement.setTimePartitionInterval(timePartitionInterval); } else if (attributeKey.SCHEMA_REGION_GROUP_NUM() != null) { - int schemaRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText()); + final int schemaRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText()); databaseSchemaStatement.setSchemaRegionGroupNum(schemaRegionGroupNum); } else if (attributeKey.DATA_REGION_GROUP_NUM() != null) { - int dataRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText()); + final int dataRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText()); databaseSchemaStatement.setDataRegionGroupNum(dataRegionGroupNum); } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/metadata/DatabaseSchemaStatement.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/metadata/DatabaseSchemaStatement.java index 24fd17bd80a80..9ba1c5fad995a 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/metadata/DatabaseSchemaStatement.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/metadata/DatabaseSchemaStatement.java @@ -39,14 +39,16 @@ public class DatabaseSchemaStatement extends Statement implements IConfigStateme private PartialPath databasePath; private Long ttl = null; - private Integer schemaReplicationFactor = null; - private Integer dataReplicationFactor = null; private Long timePartitionInterval = null; private Integer schemaRegionGroupNum = null; private Integer dataRegionGroupNum = null; private boolean enablePrintExceptionLog = true; - public DatabaseSchemaStatement(DatabaseSchemaStatementType subType) { + // Deprecated + private Integer schemaReplicationFactor = null; + private Integer dataReplicationFactor = null; + + public DatabaseSchemaStatement(final DatabaseSchemaStatementType subType) { super(); this.subType = subType; statementType = StatementType.STORAGE_GROUP_SCHEMA; @@ -60,7 +62,7 @@ public PartialPath getDatabasePath() { return databasePath; } - public void setDatabasePath(PartialPath databasePath) { + public void setDatabasePath(final PartialPath databasePath) { this.databasePath = databasePath; } @@ -68,7 +70,7 @@ public Long getTtl() { return ttl; } - public void setTtl(Long ttl) { + public void setTtl(final Long ttl) { this.ttl = ttl; } @@ -76,7 +78,7 @@ public Integer getSchemaReplicationFactor() { return schemaReplicationFactor; } - public void setSchemaReplicationFactor(Integer schemaReplicationFactor) { + public void setSchemaReplicationFactor(final Integer schemaReplicationFactor) { this.schemaReplicationFactor = schemaReplicationFactor; } @@ -84,7 +86,7 @@ public Integer getDataReplicationFactor() { return dataReplicationFactor; } - public void setDataReplicationFactor(Integer dataReplicationFactor) { + public void setDataReplicationFactor(final Integer dataReplicationFactor) { this.dataReplicationFactor = dataReplicationFactor; } @@ -92,7 +94,7 @@ public Long getTimePartitionInterval() { return timePartitionInterval; } - public void setTimePartitionInterval(Long timePartitionInterval) { + public void setTimePartitionInterval(final Long timePartitionInterval) { this.timePartitionInterval = timePartitionInterval; } @@ -100,7 +102,7 @@ public Integer getSchemaRegionGroupNum() { return schemaRegionGroupNum; } - public void setSchemaRegionGroupNum(Integer schemaRegionGroupNum) { + public void setSchemaRegionGroupNum(final Integer schemaRegionGroupNum) { this.schemaRegionGroupNum = schemaRegionGroupNum; } @@ -108,7 +110,7 @@ public Integer getDataRegionGroupNum() { return dataRegionGroupNum; } - public void setDataRegionGroupNum(Integer dataRegionGroupNum) { + public void setDataRegionGroupNum(final Integer dataRegionGroupNum) { this.dataRegionGroupNum = dataRegionGroupNum; } @@ -116,12 +118,12 @@ public boolean getEnablePrintExceptionLog() { return enablePrintExceptionLog; } - public void setEnablePrintExceptionLog(boolean enablePrintExceptionLog) { + public void setEnablePrintExceptionLog(final boolean enablePrintExceptionLog) { this.enablePrintExceptionLog = enablePrintExceptionLog; } @Override - public R accept(StatementVisitor visitor, C context) { + public R accept(final StatementVisitor visitor, final C context) { switch (subType) { case CREATE: return visitor.visitSetDatabase(this, context); @@ -142,7 +144,7 @@ public List getPaths() { } @Override - public TSStatus checkPermissionBeforeProcess(String userName) { + public TSStatus checkPermissionBeforeProcess(final String userName) { if (AuthorityChecker.SUPER_USER.equals(userName)) { return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()); } From 329823787182ed9ac5703178a951755188a65c93 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:40:09 +0800 Subject: [PATCH 2/4] Update TsTable.java --- .../iotdb/commons/schema/table/TsTable.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java index dc8f372daf53b..f16230b675007 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java @@ -67,6 +67,8 @@ public class TsTable { private Map props = null; + // Cache, avoid string parsing + private transient long ttlValue = Long.MIN_VALUE; private transient int idNums = 0; private transient int measurementNum = 0; @@ -180,11 +182,16 @@ public List getColumnList() { } public long getTableTTL() { - long ttl = getTableTTLInMS(); - return ttl == Long.MAX_VALUE - ? ttl - : CommonDateTimeUtils.convertMilliTimeWithPrecision( - ttl, CommonDescriptor.getInstance().getConfig().getTimestampPrecision()); + // Cache for performance + if (ttlValue < 0) { + final long ttl = getTableTTLInMS(); + ttlValue = + ttl == Long.MAX_VALUE + ? ttl + : CommonDateTimeUtils.convertMilliTimeWithPrecision( + ttl, CommonDescriptor.getInstance().getConfig().getTimestampPrecision()); + } + return ttlValue; } public long getTableTTLInMS() { From 17aaee71865cdb6ccc74e8a6c24f4e40a9e10399 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:42:27 +0800 Subject: [PATCH 3/4] change --- .../plan/analyze/cache/schema/DataNodeTTLCache.java | 4 ++-- .../java/org/apache/iotdb/commons/schema/table/TsTable.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DataNodeTTLCache.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DataNodeTTLCache.java index 3a8cb0f542620..eb85874f191a9 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DataNodeTTLCache.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DataNodeTTLCache.java @@ -84,8 +84,8 @@ public long getTTLForTree(IDeviceID deviceID) { } } - public long getTTLForTable(String database, String table) { - TsTable tsTable = DataNodeTableCache.getInstance().getTable(database, table); + public long getTTLForTable(final String database, final String table) { + final TsTable tsTable = DataNodeTableCache.getInstance().getTable(database, table); return tsTable == null ? Long.MAX_VALUE : tsTable.getTableTTL(); } diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java index f16230b675007..78375159bde62 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java @@ -181,6 +181,8 @@ public List getColumnList() { } } + // This shall only be called on DataNode, where the tsTable is replaced completely thus an old + // cache won't pollute the newest value public long getTableTTL() { // Cache for performance if (ttlValue < 0) { From 680eab9fb269e8cf09fa2cb8280afae2b56e4eb7 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:49:05 +0800 Subject: [PATCH 4/4] Update TsTable.java --- .../org/apache/iotdb/commons/schema/table/TsTable.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java index 78375159bde62..4070fc2158051 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java @@ -49,6 +49,8 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import static org.apache.iotdb.commons.conf.IoTDBConstant.TTL_INFINITE; + @ThreadSafe public class TsTable { @@ -197,7 +199,10 @@ public long getTableTTL() { } public long getTableTTLInMS() { - return Long.parseLong(getPropValue(TTL_PROPERTY).orElse(Long.MAX_VALUE + "")); + final Optional ttl = getPropValue(TTL_PROPERTY); + return ttl.isPresent() && !ttl.get().equalsIgnoreCase(TTL_INFINITE) + ? Long.parseLong(ttl.get()) + : Long.MAX_VALUE; } public Optional getPropValue(final String propKey) {