Skip to content

Commit 32d0f4b

Browse files
committed
Merge branch 'master' of github.com:apache/iotdb into refector_py_table_session
2 parents b94e73a + c3bd12d commit 32d0f4b

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ databaseAttributeClause
112112

113113
databaseAttributeKey
114114
: TTL
115-
| SCHEMA_REPLICATION_FACTOR
116-
| DATA_REPLICATION_FACTOR
117115
| TIME_PARTITION_INTERVAL
118116
| SCHEMA_REGION_GROUP_NUM
119117
| DATA_REGION_GROUP_NUM

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DataNodeTTLCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public long getTTLForTree(IDeviceID deviceID) {
8484
}
8585
}
8686

87-
public long getTTLForTable(String database, String table) {
88-
TsTable tsTable = DataNodeTableCache.getInstance().getTable(database, table);
87+
public long getTTLForTable(final String database, final String table) {
88+
final TsTable tsTable = DataNodeTableCache.getInstance().getTable(database, table);
8989
return tsTable == null ? Long.MAX_VALUE : tsTable.getTableTTL();
9090
}
9191

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,27 +2611,23 @@ public Statement visitAlterDatabase(IoTDBSqlParser.AlterDatabaseContext ctx) {
26112611
}
26122612

26132613
private void parseDatabaseAttributesClause(
2614-
DatabaseSchemaStatement databaseSchemaStatement,
2615-
IoTDBSqlParser.DatabaseAttributesClauseContext ctx) {
2616-
for (IoTDBSqlParser.DatabaseAttributeClauseContext attribute : ctx.databaseAttributeClause()) {
2617-
IoTDBSqlParser.DatabaseAttributeKeyContext attributeKey = attribute.databaseAttributeKey();
2614+
final DatabaseSchemaStatement databaseSchemaStatement,
2615+
final IoTDBSqlParser.DatabaseAttributesClauseContext ctx) {
2616+
for (final IoTDBSqlParser.DatabaseAttributeClauseContext attribute :
2617+
ctx.databaseAttributeClause()) {
2618+
final IoTDBSqlParser.DatabaseAttributeKeyContext attributeKey =
2619+
attribute.databaseAttributeKey();
26182620
if (attributeKey.TTL() != null) {
2619-
long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText());
2621+
final long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText());
26202622
databaseSchemaStatement.setTtl(ttl);
2621-
} else if (attributeKey.SCHEMA_REPLICATION_FACTOR() != null) {
2622-
int schemaReplicationFactor = Integer.parseInt(attribute.INTEGER_LITERAL().getText());
2623-
databaseSchemaStatement.setSchemaReplicationFactor(schemaReplicationFactor);
2624-
} else if (attributeKey.DATA_REPLICATION_FACTOR() != null) {
2625-
int dataReplicationFactor = Integer.parseInt(attribute.INTEGER_LITERAL().getText());
2626-
databaseSchemaStatement.setDataReplicationFactor(dataReplicationFactor);
26272623
} else if (attributeKey.TIME_PARTITION_INTERVAL() != null) {
2628-
long timePartitionInterval = Long.parseLong(attribute.INTEGER_LITERAL().getText());
2624+
final long timePartitionInterval = Long.parseLong(attribute.INTEGER_LITERAL().getText());
26292625
databaseSchemaStatement.setTimePartitionInterval(timePartitionInterval);
26302626
} else if (attributeKey.SCHEMA_REGION_GROUP_NUM() != null) {
2631-
int schemaRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText());
2627+
final int schemaRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText());
26322628
databaseSchemaStatement.setSchemaRegionGroupNum(schemaRegionGroupNum);
26332629
} else if (attributeKey.DATA_REGION_GROUP_NUM() != null) {
2634-
int dataRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText());
2630+
final int dataRegionGroupNum = Integer.parseInt(attribute.INTEGER_LITERAL().getText());
26352631
databaseSchemaStatement.setDataRegionGroupNum(dataRegionGroupNum);
26362632
}
26372633
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/metadata/DatabaseSchemaStatement.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ public class DatabaseSchemaStatement extends Statement implements IConfigStateme
3939

4040
private PartialPath databasePath;
4141
private Long ttl = null;
42-
private Integer schemaReplicationFactor = null;
43-
private Integer dataReplicationFactor = null;
4442
private Long timePartitionInterval = null;
4543
private Integer schemaRegionGroupNum = null;
4644
private Integer dataRegionGroupNum = null;
4745
private boolean enablePrintExceptionLog = true;
4846

49-
public DatabaseSchemaStatement(DatabaseSchemaStatementType subType) {
47+
// Deprecated
48+
private Integer schemaReplicationFactor = null;
49+
private Integer dataReplicationFactor = null;
50+
51+
public DatabaseSchemaStatement(final DatabaseSchemaStatementType subType) {
5052
super();
5153
this.subType = subType;
5254
statementType = StatementType.STORAGE_GROUP_SCHEMA;
@@ -60,68 +62,68 @@ public PartialPath getDatabasePath() {
6062
return databasePath;
6163
}
6264

63-
public void setDatabasePath(PartialPath databasePath) {
65+
public void setDatabasePath(final PartialPath databasePath) {
6466
this.databasePath = databasePath;
6567
}
6668

6769
public Long getTtl() {
6870
return ttl;
6971
}
7072

71-
public void setTtl(Long ttl) {
73+
public void setTtl(final Long ttl) {
7274
this.ttl = ttl;
7375
}
7476

7577
public Integer getSchemaReplicationFactor() {
7678
return schemaReplicationFactor;
7779
}
7880

79-
public void setSchemaReplicationFactor(Integer schemaReplicationFactor) {
81+
public void setSchemaReplicationFactor(final Integer schemaReplicationFactor) {
8082
this.schemaReplicationFactor = schemaReplicationFactor;
8183
}
8284

8385
public Integer getDataReplicationFactor() {
8486
return dataReplicationFactor;
8587
}
8688

87-
public void setDataReplicationFactor(Integer dataReplicationFactor) {
89+
public void setDataReplicationFactor(final Integer dataReplicationFactor) {
8890
this.dataReplicationFactor = dataReplicationFactor;
8991
}
9092

9193
public Long getTimePartitionInterval() {
9294
return timePartitionInterval;
9395
}
9496

95-
public void setTimePartitionInterval(Long timePartitionInterval) {
97+
public void setTimePartitionInterval(final Long timePartitionInterval) {
9698
this.timePartitionInterval = timePartitionInterval;
9799
}
98100

99101
public Integer getSchemaRegionGroupNum() {
100102
return schemaRegionGroupNum;
101103
}
102104

103-
public void setSchemaRegionGroupNum(Integer schemaRegionGroupNum) {
105+
public void setSchemaRegionGroupNum(final Integer schemaRegionGroupNum) {
104106
this.schemaRegionGroupNum = schemaRegionGroupNum;
105107
}
106108

107109
public Integer getDataRegionGroupNum() {
108110
return dataRegionGroupNum;
109111
}
110112

111-
public void setDataRegionGroupNum(Integer dataRegionGroupNum) {
113+
public void setDataRegionGroupNum(final Integer dataRegionGroupNum) {
112114
this.dataRegionGroupNum = dataRegionGroupNum;
113115
}
114116

115117
public boolean getEnablePrintExceptionLog() {
116118
return enablePrintExceptionLog;
117119
}
118120

119-
public void setEnablePrintExceptionLog(boolean enablePrintExceptionLog) {
121+
public void setEnablePrintExceptionLog(final boolean enablePrintExceptionLog) {
120122
this.enablePrintExceptionLog = enablePrintExceptionLog;
121123
}
122124

123125
@Override
124-
public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
126+
public <R, C> R accept(final StatementVisitor<R, C> visitor, final C context) {
125127
switch (subType) {
126128
case CREATE:
127129
return visitor.visitSetDatabase(this, context);
@@ -142,7 +144,7 @@ public List<PartialPath> getPaths() {
142144
}
143145

144146
@Override
145-
public TSStatus checkPermissionBeforeProcess(String userName) {
147+
public TSStatus checkPermissionBeforeProcess(final String userName) {
146148
if (AuthorityChecker.SUPER_USER.equals(userName)) {
147149
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
148150
}

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import java.util.concurrent.locks.ReadWriteLock;
5050
import java.util.concurrent.locks.ReentrantReadWriteLock;
5151

52+
import static org.apache.iotdb.commons.conf.IoTDBConstant.TTL_INFINITE;
53+
5254
@ThreadSafe
5355
public class TsTable {
5456

@@ -67,6 +69,8 @@ public class TsTable {
6769

6870
private Map<String, String> props = null;
6971

72+
// Cache, avoid string parsing
73+
private transient long ttlValue = Long.MIN_VALUE;
7074
private transient int idNums = 0;
7175
private transient int measurementNum = 0;
7276

@@ -179,16 +183,26 @@ public List<TsTableColumnSchema> getColumnList() {
179183
}
180184
}
181185

186+
// This shall only be called on DataNode, where the tsTable is replaced completely thus an old
187+
// cache won't pollute the newest value
182188
public long getTableTTL() {
183-
long ttl = getTableTTLInMS();
184-
return ttl == Long.MAX_VALUE
185-
? ttl
186-
: CommonDateTimeUtils.convertMilliTimeWithPrecision(
187-
ttl, CommonDescriptor.getInstance().getConfig().getTimestampPrecision());
189+
// Cache for performance
190+
if (ttlValue < 0) {
191+
final long ttl = getTableTTLInMS();
192+
ttlValue =
193+
ttl == Long.MAX_VALUE
194+
? ttl
195+
: CommonDateTimeUtils.convertMilliTimeWithPrecision(
196+
ttl, CommonDescriptor.getInstance().getConfig().getTimestampPrecision());
197+
}
198+
return ttlValue;
188199
}
189200

190201
public long getTableTTLInMS() {
191-
return Long.parseLong(getPropValue(TTL_PROPERTY).orElse(Long.MAX_VALUE + ""));
202+
final Optional<String> ttl = getPropValue(TTL_PROPERTY);
203+
return ttl.isPresent() && !ttl.get().equalsIgnoreCase(TTL_INFINITE)
204+
? Long.parseLong(ttl.get())
205+
: Long.MAX_VALUE;
192206
}
193207

194208
public Optional<String> getPropValue(final String propKey) {

0 commit comments

Comments
 (0)