Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ databaseAttributeClause

databaseAttributeKey
: TTL
| SCHEMA_REPLICATION_FACTOR
| DATA_REPLICATION_FACTOR
| TIME_PARTITION_INTERVAL
| SCHEMA_REGION_GROUP_NUM
| DATA_REGION_GROUP_NUM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,68 +62,68 @@ public PartialPath getDatabasePath() {
return databasePath;
}

public void setDatabasePath(PartialPath databasePath) {
public void setDatabasePath(final PartialPath databasePath) {
this.databasePath = databasePath;
}

public Long getTtl() {
return ttl;
}

public void setTtl(Long ttl) {
public void setTtl(final Long ttl) {
this.ttl = ttl;
}

public Integer getSchemaReplicationFactor() {
return schemaReplicationFactor;
}

public void setSchemaReplicationFactor(Integer schemaReplicationFactor) {
public void setSchemaReplicationFactor(final Integer schemaReplicationFactor) {
this.schemaReplicationFactor = schemaReplicationFactor;
}

public Integer getDataReplicationFactor() {
return dataReplicationFactor;
}

public void setDataReplicationFactor(Integer dataReplicationFactor) {
public void setDataReplicationFactor(final Integer dataReplicationFactor) {
this.dataReplicationFactor = dataReplicationFactor;
}

public Long getTimePartitionInterval() {
return timePartitionInterval;
}

public void setTimePartitionInterval(Long timePartitionInterval) {
public void setTimePartitionInterval(final Long timePartitionInterval) {
this.timePartitionInterval = timePartitionInterval;
}

public Integer getSchemaRegionGroupNum() {
return schemaRegionGroupNum;
}

public void setSchemaRegionGroupNum(Integer schemaRegionGroupNum) {
public void setSchemaRegionGroupNum(final Integer schemaRegionGroupNum) {
this.schemaRegionGroupNum = schemaRegionGroupNum;
}

public Integer getDataRegionGroupNum() {
return dataRegionGroupNum;
}

public void setDataRegionGroupNum(Integer dataRegionGroupNum) {
public void setDataRegionGroupNum(final Integer dataRegionGroupNum) {
this.dataRegionGroupNum = dataRegionGroupNum;
}

public boolean getEnablePrintExceptionLog() {
return enablePrintExceptionLog;
}

public void setEnablePrintExceptionLog(boolean enablePrintExceptionLog) {
public void setEnablePrintExceptionLog(final boolean enablePrintExceptionLog) {
this.enablePrintExceptionLog = enablePrintExceptionLog;
}

@Override
public <R, C> R accept(StatementVisitor<R, C> visitor, C context) {
public <R, C> R accept(final StatementVisitor<R, C> visitor, final C context) {
switch (subType) {
case CREATE:
return visitor.visitSetDatabase(this, context);
Expand All @@ -142,7 +144,7 @@ public List<PartialPath> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

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

private Map<String, String> props = null;

// Cache, avoid string parsing
private transient long ttlValue = Long.MIN_VALUE;
private transient int idNums = 0;
private transient int measurementNum = 0;

Expand Down Expand Up @@ -179,16 +183,26 @@ public List<TsTableColumnSchema> 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() {
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() {
return Long.parseLong(getPropValue(TTL_PROPERTY).orElse(Long.MAX_VALUE + ""));
final Optional<String> ttl = getPropValue(TTL_PROPERTY);
return ttl.isPresent() && !ttl.get().equalsIgnoreCase(TTL_INFINITE)
? Long.parseLong(ttl.get())
: Long.MAX_VALUE;
}

public Optional<String> getPropValue(final String propKey) {
Expand Down