This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch dev_TTL
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/dev_TTL by this push:
new 75e4eb5 add tests
75e4eb5 is described below
commit 75e4eb52c4fd135978a2f3fdf041c6351f820783
Author: jt <[email protected]>
AuthorDate: Tue Sep 17 20:13:41 2019 +0800
add tests
---
.../main/java/org/apache/iotdb/jdbc/Constant.java | 2 +-
.../org/apache/iotdb/jdbc/IoTDBConnection.java | 6 +-
.../apache/iotdb/jdbc/IoTDBDatabaseMetadata.java | 16 +-
.../org/apache/iotdb/jdbc/IoTDBQueryResultSet.java | 2 +-
.../org/apache/iotdb/jdbc/IoTDBSQLException.java | 5 +
.../java/org/apache/iotdb/jdbc/IoTDBStatement.java | 6 +-
.../antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g | 2 +-
.../org/apache/iotdb/db/sql/parse/TSParser.g | 2 +-
.../org/apache/iotdb/db/conf/IoTDBConstant.java | 9 +
.../db/conf/directories/DirectoryManager.java | 12 +-
.../directories/strategy/DirectoryStrategy.java | 21 +-
.../iotdb/db/engine/cache/DeviceMetaDataCache.java | 3 -
.../iotdb/db/engine/cache/TsFileMetaDataCache.java | 3 -
.../engine/storagegroup/StorageGroupProcessor.java | 34 +--
.../db/exception/NotStorageGroupException.java | 12 +
.../iotdb/db/exception/OutOfTTLException.java | 15 ++
.../java/org/apache/iotdb/db/metadata/MGraph.java | 4 +-
.../org/apache/iotdb/db/metadata/MManager.java | 8 +-
.../java/org/apache/iotdb/db/metadata/MTree.java | 149 ++++---------
.../apache/iotdb/db/qp/constant/SQLConstant.java | 4 +
.../iotdb/db/qp/executor/QueryProcessExecutor.java | 4 +-
.../iotdb/db/qp/logical/sys/TTLOperator.java | 1 +
.../iotdb/db/qp/strategy/LogicalGenerator.java | 17 +-
.../iotdb/db/qp/strategy/PhysicalGenerator.java | 3 +-
.../iotdb/db/service/JDBCServiceEventHandler.java | 13 +-
.../org/apache/iotdb/db/service/TSServiceImpl.java | 49 ++---
.../db/engine/cache/DeviceMetaDataCacheTest.java | 6 +-
.../storagegroup/StorageGroupProcessorTest.java | 13 +-
.../iotdb/db/engine/storagegroup/TTLTest.java | 243 +++++++++++++++++++++
.../apache/iotdb/db/integration/IoTDBTTLTest.java | 132 +++++++++++
.../iotdb/db/integration/IoTDBTimeZoneIT.java | 10 +-
.../iotdb/db/integration/IoTDBVersionIT.java | 13 +-
.../iotdb/db/metadata/MManagerAdvancedTest.java | 4 +-
.../iotdb/db/metadata/MManagerImproveTest.java | 2 +-
.../org/apache/iotdb/db/metadata/MTreeTest.java | 83 ++++---
.../iotdb/db/query/reader/ReaderTestHelper.java | 5 +-
.../fileRelated/UnSealedTsFileReaderTest.java | 3 +-
.../resourceRelated/SeqResourceReaderTest.java | 3 +-
.../resourceRelated/UnseqResourceReaderTest.java | 4 +-
.../apache/iotdb/db/utils/EnvironmentUtils.java | 5 +
.../java/org/apache/iotdb/rpc/TSStatusType.java | 3 +-
41 files changed, 643 insertions(+), 288 deletions(-)
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/Constant.java
b/jdbc/src/main/java/org/apache/iotdb/jdbc/Constant.java
index 0ae18cb..6ce5d93 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/Constant.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/Constant.java
@@ -28,7 +28,7 @@ public class Constant {
public static final String GLOBAL_COLUMN_REQ = "COLUMN";
- public static final String GLOBAL_DELTA_OBJECT_REQ = "DELTA_OBEJECT";
+ public static final String GLOBAL_DELTA_OBJECT_REQ = "DELTA_OBJECT";
public static final String GLOBAL_SHOW_TIMESERIES_REQ = "SHOW_TIMESERIES";
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
index 85270e1..3f445bf 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
@@ -415,7 +415,7 @@ public class IoTDBConnection implements Connection {
} catch (IoTDBRPCException e) {
// failed to connect, disconnect from the server
transport.close();
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), openResp.getStatus());
}
if (protocolVersion.getValue() !=
openResp.getServerProtocolVersion().getValue()) {
throw new TException(String
@@ -476,7 +476,7 @@ public class IoTDBConnection implements Connection {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return resp.getTimeZone();
}
@@ -487,7 +487,7 @@ public class IoTDBConnection implements Connection {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
this.zoneId = ZoneId.of(zoneId);
}
diff --git
a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDatabaseMetadata.java
b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDatabaseMetadata.java
index 50f7cfd..30951f7 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDatabaseMetadata.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDatabaseMetadata.java
@@ -83,7 +83,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return new IoTDBMetadataResultSet(resp.getColumnsList(),
IoTDBMetadataResultSet.MetadataType.COLUMN);
} catch (TException e) {
@@ -97,7 +97,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return new IoTDBMetadataResultSet(resp.getColumnsList(),
IoTDBMetadataResultSet.MetadataType.COLUMN);
} catch (TException e) {
@@ -110,7 +110,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
List<String> showStorageGroup = resp.getShowStorageGroups();
return new IoTDBMetadataResultSet(showStorageGroup,
IoTDBMetadataResultSet.MetadataType.STORAGE_GROUP);
@@ -125,7 +125,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
List<List<String>> showTimeseriesList = resp.getShowTimeseriesList();
return new IoTDBMetadataResultSet(showTimeseriesList,
IoTDBMetadataResultSet.MetadataType.TIMESERIES);
@@ -140,7 +140,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return new IoTDBMetadataResultSet(resp.getColumnsList().size(),
IoTDBMetadataResultSet.MetadataType.COUNT_TIMESERIES);
} catch (TException e) {
@@ -189,7 +189,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return new IoTDBMetadataResultSet(resp.getNodesList().size(),
IoTDBMetadataResultSet.MetadataType.COUNT_NODES);
} catch (TException e) {
@@ -203,7 +203,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return new IoTDBMetadataResultSet(resp.getNodeTimeseriesNum(),
IoTDBMetadataResultSet.MetadataType.COUNT_NODE_TIMESERIES);
} catch (TException e) {
@@ -1341,7 +1341,7 @@ public class IoTDBDatabaseMetadata implements
DatabaseMetaData {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return resp.getMetadataInJson();
}
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java
b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java
index 012c766..683d85c 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBQueryResultSet.java
@@ -707,7 +707,7 @@ public class IoTDBQueryResultSet implements ResultSet {
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
if (!resp.hasResultSet) {
emptyResultSet = true;
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java
b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java
index 8a1a916..ac857ef 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java
@@ -20,6 +20,7 @@
package org.apache.iotdb.jdbc;
import java.sql.SQLException;
+import org.apache.iotdb.service.rpc.thrift.TS_Status;
public class IoTDBSQLException extends SQLException {
@@ -29,6 +30,10 @@ public class IoTDBSQLException extends SQLException {
super(reason);
}
+ public IoTDBSQLException(String reason, TS_Status status) {
+ super(reason, status.sqlState, status.statusType.code);
+ }
+
public IoTDBSQLException(Throwable cause) {
super(cause);
}
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
index 35b2361..8295a68 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
@@ -274,7 +274,7 @@ public class IoTDBStatement implements Statement {
try {
RpcUtils.verifySuccess(execResp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), execResp.getStatus());
}
if (execResp.getOperationHandle().hasResultSet) {
IoTDBQueryResultSet resSet = new IoTDBQueryResultSet(this,
@@ -378,7 +378,7 @@ public class IoTDBStatement implements Statement {
try {
RpcUtils.verifySuccess(execResp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), execResp.getStatus());
}
IoTDBQueryResultSet resSet = new IoTDBQueryResultSet(this,
execResp.getColumns(), client,
operationHandle, sql, execResp.getOperationType(),
execResp.getDataTypeList(),
@@ -435,7 +435,7 @@ public class IoTDBStatement implements Statement {
try {
RpcUtils.verifySuccess(execResp.getStatus());
} catch (IoTDBRPCException e) {
- throw new IoTDBSQLException(e.getMessage());
+ throw new IoTDBSQLException(e.getMessage(), execResp.getStatus());
}
return 0;
}
diff --git a/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g
b/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g
index cbfe520..7e32fd8 100644
--- a/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g
+++ b/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSLexer.g
@@ -77,7 +77,7 @@ KW_INDEX: 'INDEX';
KW_INTO: 'INTO';
KW_WITH: 'WITH';
KW_SET: 'SET';
-KW_UNSER: 'UNSET';
+KW_UNSET: 'UNSET';
KW_DELETE: 'DELETE';
KW_UPDATE: 'UPDATE';
KW_VALUES: 'VALUES';
diff --git a/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g
b/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g
index 9e7ce88..4afdd68 100644
--- a/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g
+++ b/server/src/main/antlr3/org/apache/iotdb/db/sql/parse/TSParser.g
@@ -917,7 +917,7 @@ ttlStatement
setTTLStatement
:
- KW_SET KW_TTL KW_TO path=prefixPath time=DATETIME
+ KW_SET KW_TTL KW_TO path=prefixPath time=dateFormatWithNumber
-> ^(TOK_TTL TOK_SET $path $time)
;
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
index 02fe51c..9f6bbe1 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
@@ -65,4 +65,13 @@ public class IoTDBConstant {
public static final String USER = "User";
public static final String PRIVILEGE = "Privilege";
+ // JDBC constants
+ public static final String GLOBAL_COLUMN_REQ = "COLUMN";
+ public static final String GLOBAL_DELTA_OBJECT_REQ = "DELTA_OBJECT";
+ public static final String GLOBAL_SHOW_TIMESERIES_REQ = "SHOW_TIMESERIES";
+ public static final String GLOBAL_COUNT_TIMESERIES_REQ = "COUNT_TIMESERIES";
+ public static final String GLOBAL_COUNT_NODE_TIMESERIES_REQ =
"COUNT_NODE_TIMESERIES";
+ public static final String GLOBAL_COUNT_NODES_REQ = "COUNT_NODES";
+ public static final String GLOBAL_SHOW_STORAGE_GROUP_REQ =
"SHOW_STORAGE_GROUP";
+ public static final String GLOBAL_COLUMNS_REQ = "ALL_COLUMNS";
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/conf/directories/DirectoryManager.java
b/server/src/main/java/org/apache/iotdb/db/conf/directories/DirectoryManager.java
index 9b4b58d..289db14 100644
---
a/server/src/main/java/org/apache/iotdb/db/conf/directories/DirectoryManager.java
+++
b/server/src/main/java/org/apache/iotdb/db/conf/directories/DirectoryManager.java
@@ -83,17 +83,7 @@ public class DirectoryManager {
}
}
}
-
- // only used by test
- public String getSequenceFolderForTest() {
- return sequenceFileFolders.get(0);
- }
-
- // only used by test
- public void setSequenceFolderForTest(String path) {
- sequenceFileFolders.set(0, path);
- }
-
+
public String getNextFolderForSequenceFile() throws
DiskSpaceInsufficientException {
return getSequenceFileFolder(getNextFolderIndexForSequenceFile());
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/DirectoryStrategy.java
b/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/DirectoryStrategy.java
index 993d42d..e955c9c 100644
---
a/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/DirectoryStrategy.java
+++
b/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/DirectoryStrategy.java
@@ -37,7 +37,7 @@ public abstract class DirectoryStrategy {
/**
* All the folders of data files, should be init once the subclass is
created.
*/
- protected List<String> folders;
+ List<String> folders;
/**
* To init folders. Do not recommend to overwrite.
@@ -68,23 +68,4 @@ public abstract class DirectoryStrategy {
*/
public abstract int nextFolderIndex() throws DiskSpaceInsufficientException;
- /**
- * Return the actual string value of a folder by its index.
- *
- * @param index the index of the folder
- * @return the string value of the folder
- */
- public String getTsFileFolder(int index) {
- return folders.get(index);
- }
-
- // only used by test
- public String getFolderForTest() {
- return getTsFileFolder(0);
- }
-
- // only used by test
- public void setFolderForTest(String path) {
- folders.set(0, path);
- }
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCache.java
b/server/src/main/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCache.java
index d77fb1a..772767d 100644
---
a/server/src/main/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCache.java
+++
b/server/src/main/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCache.java
@@ -65,9 +65,6 @@ public class DeviceMetaDataCache {
private long chunkMetaDataSize = 0;
private DeviceMetaDataCache(long memoryThreshold) {
- if (!cacheEnable) {
- return;
- }
lruCache = new LRULinkedHashMap<String,
List<ChunkMetaData>>(memoryThreshold, true) {
@Override
protected long calEntrySize(String key, List<ChunkMetaData> value) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/engine/cache/TsFileMetaDataCache.java
b/server/src/main/java/org/apache/iotdb/db/engine/cache/TsFileMetaDataCache.java
index d85a18d..7328a71 100644
---
a/server/src/main/java/org/apache/iotdb/db/engine/cache/TsFileMetaDataCache.java
+++
b/server/src/main/java/org/apache/iotdb/db/engine/cache/TsFileMetaDataCache.java
@@ -59,9 +59,6 @@ public class TsFileMetaDataCache {
private long versionAndCreatebySize = 10;
private TsFileMetaDataCache() {
- if (!cacheEnable) {
- return;
- }
cache = new LRULinkedHashMap<TsFileResource,
TsFileMetaData>(MEMORY_THRESHOLD_IN_B, true) {
@Override
protected long calEntrySize(TsFileResource key, TsFileMetaData value) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
index 6e7f19b..54ebf8c 100755
---
a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
+++
b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.ConcurrentModificationException;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -60,7 +61,9 @@ import org.apache.iotdb.db.engine.version.VersionController;
import org.apache.iotdb.db.exception.DiskSpaceInsufficientException;
import org.apache.iotdb.db.exception.MergeException;
import org.apache.iotdb.db.exception.MetadataErrorException;
+import org.apache.iotdb.db.exception.OutOfTTLException;
import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.exception.StorageGroupProcessorException;
import org.apache.iotdb.db.exception.TsFileProcessorException;
import org.apache.iotdb.db.metadata.MManager;
@@ -341,10 +344,10 @@ public class StorageGroupProcessor {
}
}
- public boolean insert(InsertPlan insertPlan) {
+ public boolean insert(InsertPlan insertPlan) throws StorageEngineException {
// reject insertions that are out of ttl
if (!checkTTL(insertPlan.getTime())) {
- return false;
+ throw new OutOfTTLException(insertPlan.getTime(),
System.currentTimeMillis() - dataTTL);
}
writeLock();
try {
@@ -512,6 +515,7 @@ public class StorageGroupProcessor {
} else {
baseDir =
DirectoryManager.getInstance().getNextFolderForUnSequenceFile();
}
+ logger.info("Got a base dir for new TsFileProcessor {}, sequence {}",
baseDir, sequence);
new File(baseDir, storageGroupName).mkdirs();
String filePath = Paths.get(baseDir, storageGroupName,
@@ -586,11 +590,15 @@ public class StorageGroupProcessor {
public synchronized void checkFilesTTL() {
long timeBound = System.currentTimeMillis() - dataTTL;
logger.info("TTL removing files before {}", new Date(timeBound));
- for (TsFileResource tsFileResource : unSequenceFileList) {
- checkFileTTL(tsFileResource, timeBound, true);
- }
- for (TsFileResource tsFileResource : sequenceFileList) {
- checkFileTTL(tsFileResource, timeBound, false);
+ try {
+ for (TsFileResource tsFileResource : unSequenceFileList) {
+ checkFileTTL(tsFileResource, timeBound, true);
+ }
+ for (TsFileResource tsFileResource : sequenceFileList) {
+ checkFileTTL(tsFileResource, timeBound, false);
+ }
+ } catch (ConcurrentModificationException e) {
+ // ignore
}
}
@@ -744,14 +752,14 @@ public class StorageGroupProcessor {
}
closeQueryLock.readLock().lock();
- if (dataTTL != Long.MAX_VALUE) {
- Long deviceEndTime = tsFileResource.getEndTimeMap().get(deviceId);
- if (deviceEndTime != null && !checkTTL(deviceEndTime)) {
- continue;
+ try {
+ if (dataTTL != Long.MAX_VALUE) {
+ Long deviceEndTime = tsFileResource.getEndTimeMap().get(deviceId);
+ if (deviceEndTime != null && !checkTTL(deviceEndTime)) {
+ continue;
+ }
}
- }
- try {
if (tsFileResource.isClosed()) {
tsfileResourcesForQuery.add(tsFileResource);
} else {
diff --git
a/server/src/main/java/org/apache/iotdb/db/exception/NotStorageGroupException.java
b/server/src/main/java/org/apache/iotdb/db/exception/NotStorageGroupException.java
new file mode 100644
index 0000000..cfba664
--- /dev/null
+++
b/server/src/main/java/org/apache/iotdb/db/exception/NotStorageGroupException.java
@@ -0,0 +1,12 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership. The ASF licenses
this file to you under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless
required by applicable law or ag [...]
+ */
+
+package org.apache.iotdb.db.exception;
+
+public class NotStorageGroupException extends PathErrorException {
+
+ public NotStorageGroupException(String path) {
+ super(String.format("%s is not a storage group", path));
+ }
+}
\ No newline at end of file
diff --git
a/server/src/main/java/org/apache/iotdb/db/exception/OutOfTTLException.java
b/server/src/main/java/org/apache/iotdb/db/exception/OutOfTTLException.java
new file mode 100644
index 0000000..529420c
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/exception/OutOfTTLException.java
@@ -0,0 +1,15 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership. The ASF licenses
this file to you under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless
required by applicable law or ag [...]
+ */
+
+package org.apache.iotdb.db.exception;
+
+import java.util.Date;
+
+public class OutOfTTLException extends StorageEngineException {
+
+ public OutOfTTLException(long insertionTime, long timeBound) {
+ super(String.format("Insertion time [%s] is less than ttl time bound [%s]",
+ new Date(insertionTime), new Date(timeBound)));
+ }
+}
\ No newline at end of file
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MGraph.java
b/server/src/main/java/org/apache/iotdb/db/metadata/MGraph.java
index 63e581f..436b00f 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MGraph.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MGraph.java
@@ -22,10 +22,8 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.apache.iotdb.db.exception.MetadataErrorException;
import org.apache.iotdb.db.exception.PathErrorException;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
@@ -335,7 +333,7 @@ public class MGraph implements Serializable {
}
MNode getNodeByPathWithCheck(String path) throws PathErrorException {
- return mtree.getNodeByPathWithFileLevelCheck(path);
+ return mtree.getNodeByPathWithStorageGroupCheck(path);
}
/**
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
index c70286e..412544c 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
@@ -26,6 +26,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.conf.adapter.IoTDBConfigDynamicAdapter;
import org.apache.iotdb.db.exception.ConfigAdjusterException;
import org.apache.iotdb.db.exception.MetadataErrorException;
+import org.apache.iotdb.db.exception.NotStorageGroupException;
import org.apache.iotdb.db.exception.PathErrorException;
import org.apache.iotdb.db.monitor.MonitorConstants;
import org.apache.iotdb.db.qp.logical.Operator.OperatorType;
@@ -1021,10 +1022,10 @@ public class MManager {
/**
* function for getting node by deviceId from cache.
*/
- public MNode getNodeByDeviceIdFromCache(String deviceId) throws
PathErrorException {
+ public MNode getNodeByPathFromCache(String path) throws PathErrorException {
lock.readLock().lock();
try {
- return mNodeCache.get(deviceId);
+ return mNodeCache.get(path);
} catch (CacheException e) {
throw new PathErrorException(e);
} finally {
@@ -1242,6 +1243,9 @@ public class MManager {
lock.writeLock().lock();
try {
MNode sgNode = getNodeByPath(storageGroup);
+ if (!sgNode.isStorageLevel()) {
+ throw new NotStorageGroupException(storageGroup);
+ }
sgNode.setDataTTL(dataTTL);
if (writeToLog) {
BufferedWriter writer = getLogWriter();
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index c133b04..0e405d4 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -18,14 +18,18 @@
*/
package org.apache.iotdb.db.metadata;
-import java.io.Serializable;
-import java.util.*;
-
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
import org.apache.iotdb.db.exception.PathErrorException;
-import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
@@ -37,7 +41,7 @@ import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
public class MTree implements Serializable {
private static final long serialVersionUID = -4200394435237291964L;
- private static final String DOUB_SEPARATOR = "\\.";
+ private static final String PATH_SEPARATOR = "\\.";
private static final String NO_CHILD_ERROR = "Timeseries is not correct.
Node[%s] "
+ "doesn't have child named:%s";
private static final String NOT_LEAF_NODE = "Timeseries %s is not the leaf
node";
@@ -49,28 +53,12 @@ public class MTree implements Serializable {
this.root = new MNode(rootName, null, false);
}
- public MTree(MNode root) {
- this.root = root;
- }
-
- /**
- * this is just for compatibility
- */
- void addTimeseriesPath(String timeseriesPath, String dataType, String
encoding)
- throws PathErrorException {
- TSDataType tsDataType = TSDataType.valueOf(dataType);
- TSEncoding tsEncoding = TSEncoding.valueOf(encoding);
- CompressionType compressionType =
CompressionType.valueOf(TSFileConfig.compressor);
- addTimeseriesPath(timeseriesPath, tsDataType, tsEncoding, compressionType,
- Collections.emptyMap());
- }
-
/**
* function for adding timeseries.It should check whether seriesPath exists.
*/
void addTimeseriesPath(String timeseriesPath, TSDataType dataType,
TSEncoding encoding,
CompressionType compressor, Map<String, String> props) throws
PathErrorException {
- String[] nodeNames = timeseriesPath.trim().split(DOUB_SEPARATOR);
+ String[] nodeNames = timeseriesPath.trim().split(PATH_SEPARATOR);
if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
throw new PathErrorException(String.format("Timeseries %s is not
right.", timeseriesPath));
}
@@ -125,7 +113,7 @@ public class MTree implements Serializable {
* @param path -seriesPath not necessarily the whole seriesPath (possibly a
prefix of a sequence)
*/
boolean isPathExist(String path) {
- String[] nodeNames = path.trim().split(DOUB_SEPARATOR);
+ String[] nodeNames = path.trim().split(PATH_SEPARATOR);
MNode cur = root;
int i = 0;
while (i < nodeNames.length - 1) {
@@ -146,10 +134,10 @@ public class MTree implements Serializable {
}
/**
- * function for checking whether the given path exists under the given mnode.
+ * function for checking whether the given path exists under the given mNode.
*/
boolean isPathExist(MNode node, String path) {
- String[] nodeNames = path.trim().split(DOUB_SEPARATOR);
+ String[] nodeNames = path.trim().split(PATH_SEPARATOR);
if (nodeNames.length < 1) {
return true;
}
@@ -180,7 +168,7 @@ public class MTree implements Serializable {
* make sure check seriesPath before setting storage group.
*/
public void setStorageGroup(String path) throws PathErrorException {
- String[] nodeNames = path.split(DOUB_SEPARATOR);
+ String[] nodeNames = path.split(PATH_SEPARATOR);
MNode cur = root;
if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
throw new PathErrorException(
@@ -221,7 +209,7 @@ public class MTree implements Serializable {
* @apiNote :for cluster
*/
boolean checkStorageGroup(String path) {
- String[] nodeNames = path.split(DOUB_SEPARATOR);
+ String[] nodeNames = path.split(PATH_SEPARATOR);
MNode cur = root;
if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
return false;
@@ -239,22 +227,6 @@ public class MTree implements Serializable {
return temp != null && temp.isStorageLevel();
}
- /**
- * Check whether set file seriesPath for this node or not. If not, throw an
exception
- */
- private void checkStorageGroup(MNode node) throws PathErrorException {
- if (node.getDataFileName() != null) {
- throw new PathErrorException(
- String.format("The storage group %s has been set",
node.getDataFileName()));
- }
- if (node.getChildren() == null) {
- return;
- }
- for (MNode child : node.getChildren().values()) {
- checkStorageGroup(child);
- }
- }
-
private void setDataFileName(String path, MNode node) {
node.setDataFileName(path);
if (node.getChildren() == null) {
@@ -272,7 +244,7 @@ public class MTree implements Serializable {
* node.
*/
String deletePath(String path) throws PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length == 0 || !nodes[0].equals(getRoot().getName())) {
throw new PathErrorException("Timeseries %s is not correct." + path);
}
@@ -307,35 +279,6 @@ public class MTree implements Serializable {
}
/**
- * Check whether the seriesPath given exists.
- */
- public boolean hasPath(String path) {
- String[] nodes = path.split(DOUB_SEPARATOR);
- if (nodes.length == 0 || !nodes[0].equals(getRoot().getName())) {
- return false;
- }
- return hasPath(getRoot(), nodes, 1);
- }
-
- private boolean hasPath(MNode node, String[] nodes, int idx) {
- if (idx >= nodes.length) {
- return true;
- }
- if (("*").equals(nodes[idx])) {
- boolean res = false;
- for (MNode child : node.getChildren().values()) {
- res |= hasPath(child, nodes, idx + 1);
- }
- return res;
- } else {
- if (node.hasChild(nodes[idx])) {
- return hasPath(node.getChild(nodes[idx]), nodes, idx + 1);
- }
- return false;
- }
- }
-
- /**
* Get ColumnSchema for given seriesPath. Notice: Path must be a complete
Path from root to leaf
* node.
*/
@@ -362,7 +305,7 @@ public class MTree implements Serializable {
private MNode getLeafByPath(String path) throws PathErrorException {
getNode(path);
- String[] node = path.split(DOUB_SEPARATOR);
+ String[] node = path.split(PATH_SEPARATOR);
MNode cur = getRoot();
for (int i = 1; i < node.length; i++) {
cur = cur.getChild(node[i]);
@@ -375,7 +318,7 @@ public class MTree implements Serializable {
private MNode getLeafByPath(MNode node, String path) throws
PathErrorException {
checkPath(node, path);
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
MNode cur = node.getChild(nodes[0]);
for (int i = 1; i < nodes.length; i++) {
cur = cur.getChild(nodes[i]);
@@ -387,7 +330,7 @@ public class MTree implements Serializable {
}
private MNode getLeafByPathWithCheck(MNode node, String path) throws
PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length < 1 || !node.hasChild(nodes[0])) {
throw new PathErrorException(String.format(SERIES_NOT_CORRECT, path));
}
@@ -407,7 +350,7 @@ public class MTree implements Serializable {
}
private MNode getLeafByPathWithCheck(String path) throws PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length < 2 || !nodes[0].equals(getRoot().getName())) {
throw new PathErrorException(String.format(SERIES_NOT_CORRECT, path));
}
@@ -427,11 +370,11 @@ public class MTree implements Serializable {
}
/**
- * function for getting node by path with file level check.
+ * function for getting node by path with storage group check.
*/
- MNode getNodeByPathWithFileLevelCheck(String path) throws PathErrorException
{
- boolean fileLevelChecked = false;
- String[] nodes = path.split(DOUB_SEPARATOR);
+ MNode getNodeByPathWithStorageGroupCheck(String path) throws
PathErrorException {
+ boolean storageGroupChecked = false;
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length < 2 || !nodes[0].equals(getRoot().getName())) {
throw new PathErrorException(String.format(SERIES_NOT_CORRECT, path));
}
@@ -444,10 +387,10 @@ public class MTree implements Serializable {
}
cur = cur.getChild(nodes[i]);
if (cur.isStorageLevel()) {
- fileLevelChecked = true;
+ storageGroupChecked = true;
}
}
- if (!fileLevelChecked) {
+ if (!storageGroupChecked) {
throw new PathErrorException("FileLevel is not set for current
seriesPath:" + path);
}
return cur;
@@ -460,7 +403,7 @@ public class MTree implements Serializable {
*/
String getDeviceTypeByPath(String path) throws PathErrorException {
getNode(path);
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length < 2) {
throw new PathErrorException(
String.format("Timeseries %s must have two or more nodes", path));
@@ -474,7 +417,7 @@ public class MTree implements Serializable {
* @return last node in given seriesPath
*/
MNode getNode(String path) throws PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length < 2 || !nodes[0].equals(getRoot().getName())) {
throw new PathErrorException(String.format(SERIES_NOT_CORRECT, path));
}
@@ -490,7 +433,7 @@ public class MTree implements Serializable {
}
private void checkPath(MNode node, String path) throws PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length < 1) {
return;
}
@@ -511,7 +454,7 @@ public class MTree implements Serializable {
*/
String getStorageGroupNameByPath(String path) throws PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
MNode cur = getRoot();
for (int i = 1; i < nodes.length; i++) {
if (cur == null) {
@@ -539,7 +482,7 @@ public class MTree implements Serializable {
*/
List<String> getAllFileNamesByPath(String pathReg) throws PathErrorException
{
ArrayList<String> fileNames = new ArrayList<>();
- String[] nodes = pathReg.split(DOUB_SEPARATOR);
+ String[] nodes = pathReg.split(PATH_SEPARATOR);
if (nodes.length == 0 || !nodes[0].equals(getRoot().getName())) {
throw new PathErrorException(String.format(SERIES_NOT_CORRECT, pathReg));
}
@@ -580,7 +523,7 @@ public class MTree implements Serializable {
*/
String getStorageGroupNameByPath(MNode node, String path) throws
PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
MNode cur = node.getChild(nodes[0]);
for (int i = 1; i < nodes.length; i++) {
if (cur == null) {
@@ -608,7 +551,7 @@ public class MTree implements Serializable {
*/
boolean checkFileNameByPath(String path) {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
MNode cur = getRoot();
for (int i = 1; i <= nodes.length; i++) {
if (cur == null) {
@@ -630,7 +573,7 @@ public class MTree implements Serializable {
*/
HashMap<String, ArrayList<String>> getAllPath(String pathReg) throws
PathErrorException {
HashMap<String, ArrayList<String>> paths = new HashMap<>();
- String[] nodes = pathReg.split(DOUB_SEPARATOR);
+ String[] nodes = pathReg.split(PATH_SEPARATOR);
if (nodes.length == 0 || !nodes[0].equals(getRoot().getName())) {
throw new PathErrorException(String.format(SERIES_NOT_CORRECT, pathReg));
}
@@ -663,7 +606,7 @@ public class MTree implements Serializable {
*/
List<List<String>> getShowTimeseriesPath(String pathReg) throws
PathErrorException {
List<List<String>> res = new ArrayList<>();
- String[] nodes = pathReg.split(DOUB_SEPARATOR);
+ String[] nodes = pathReg.split(PATH_SEPARATOR);
if (nodes.length == 0 || !nodes[0].equals(getRoot().getName())) {
throw new PathErrorException(String.format(SERIES_NOT_CORRECT, pathReg));
}
@@ -705,7 +648,7 @@ public class MTree implements Serializable {
* @return The total count of storage-level nodes.
*/
int getFileCountForOneType(String path) throws PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length != 2 || !nodes[0].equals(getRoot().getName()) ||
!getRoot()
.hasChild(nodes[1])) {
throw new PathErrorException(
@@ -829,7 +772,7 @@ public class MTree implements Serializable {
* @return a list contains all column schema
*/
ArrayList<MeasurementSchema> getSchemaForOneType(String path) throws
PathErrorException {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
if (nodes.length != 2 || !nodes[0].equals(getRoot().getName()) ||
!getRoot()
.hasChild(nodes[1])) {
throw new PathErrorException(
@@ -848,7 +791,7 @@ public class MTree implements Serializable {
*/
ArrayList<MeasurementSchema> getSchemaForOneStorageGroup(String path) {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
HashMap<String, MeasurementSchema> leafMap = new HashMap<>();
MNode cur = getRoot();
for (int i = 1; i < nodes.length; i++) {
@@ -863,7 +806,7 @@ public class MTree implements Serializable {
* function for getting schema map for one storage group.
*/
Map<String, MeasurementSchema> getSchemaMapForOneStorageGroup(String path) {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
MNode cur = getRoot();
for (int i = 1; i < nodes.length; i++) {
cur = cur.getChild(nodes[i]);
@@ -875,7 +818,7 @@ public class MTree implements Serializable {
* function for getting num schema map for one file node.
*/
Map<String, Integer> getNumSchemaMapForOneFileNode(String path) {
- String[] nodes = path.split(DOUB_SEPARATOR);
+ String[] nodes = path.split(PATH_SEPARATOR);
MNode cur = getRoot();
for (int i = 1; i < nodes.length; i++) {
cur = cur.getChild(nodes[i]);
@@ -981,15 +924,15 @@ public class MTree implements Serializable {
private JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
- jsonObject.put(getRoot().getName(), mnodeToJSON(getRoot()));
+ jsonObject.put(getRoot().getName(), mNodeToJSON(getRoot()));
return jsonObject;
}
- private JSONObject mnodeToJSON(MNode node) {
+ private JSONObject mNodeToJSON(MNode node) {
JSONObject jsonObject = new JSONObject();
if (!node.isLeaf() && node.getChildren().size() > 0) {
for (MNode child : node.getChildren().values()) {
- jsonObject.put(child.getName(), mnodeToJSON(child));
+ jsonObject.put(child.getName(), mNodeToJSON(child));
}
} else if (node.isLeaf()) {
jsonObject.put("DataType", node.getSchema().getType());
@@ -1008,10 +951,10 @@ public class MTree implements Serializable {
/**
* combine multiple metadata in string format
*/
- static String combineMetadataInStrings(String[] metadatas) {
- JSONObject[] jsonObjects = new JSONObject[metadatas.length];
+ static String combineMetadataInStrings(String[] metadataStrs) {
+ JSONObject[] jsonObjects = new JSONObject[metadataStrs.length];
for (int i = 0; i < jsonObjects.length; i++) {
- jsonObjects[i] = JSONObject.parseObject(metadatas[i]);
+ jsonObjects[i] = JSONObject.parseObject(metadataStrs[i]);
}
JSONObject root = jsonObjects[0];
diff --git
a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
index 9d22c59..e03251c 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
@@ -92,6 +92,8 @@ public class SQLConstant {
public static final int TOK_PROPERTY_LINK = 57;
public static final int TOK_PROPERTY_UNLINK = 58;
public static final int TOK_LIST = 59;
+ public static final int TOK_SET = 60;
+ public static final int TOK_UNSET = 61;
public static final Map<Integer, String> tokenSymbol = new HashMap<>();
public static final Map<Integer, String> tokenNames = new HashMap<>();
@@ -147,6 +149,8 @@ public class SQLConstant {
tokenNames.put(TOK_PROPERTY_UNLINK, "TOK_PROPERTY_UNLINK");
tokenNames.put(TOK_LIST, "TOK_LIST");
+ tokenNames.put(TOK_SET, "TOK_SET");
+ tokenNames.put(TOK_UNSET, "TOK_UNSET");
}
static {
diff --git
a/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java
b/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java
index 52ed70a..b2abcb5 100644
---
a/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java
+++
b/server/src/main/java/org/apache/iotdb/db/qp/executor/QueryProcessExecutor.java
@@ -223,7 +223,7 @@ public class QueryProcessExecutor extends
AbstractQueryProcessExecutor {
try {
String[] measurementList = insertPlan.getMeasurements();
String deviceId = insertPlan.getDeviceId();
- MNode node = mManager.getNodeByDeviceIdFromCache(deviceId);
+ MNode node = mManager.getNodeByPathFromCache(deviceId);
String[] values = insertPlan.getValues();
TSDataType[] dataTypes = new TSDataType[measurementList.length];
@@ -256,7 +256,7 @@ public class QueryProcessExecutor extends
AbstractQueryProcessExecutor {
try {
String[] measurementList = batchInsertPlan.getMeasurements();
String deviceId = batchInsertPlan.getDeviceId();
- MNode node = mManager.getNodeByDeviceIdFromCache(deviceId);
+ MNode node = mManager.getNodeByPathFromCache(deviceId);
for (String s : measurementList) {
if (!node.hasChild(s)) {
diff --git
a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/TTLOperator.java
b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/TTLOperator.java
index 0fbcac4..d336252 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/TTLOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/sys/TTLOperator.java
@@ -29,6 +29,7 @@ public class TTLOperator extends RootOperator {
public TTLOperator(int tokenIntType) {
super(tokenIntType);
+ this.operatorType = OperatorType.TTL;
}
public String getStorageGroup() {
diff --git
a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
index 65be2b5..0192473 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalGenerator.java
@@ -236,18 +236,23 @@ public class LogicalGenerator {
}
}
- private void analyzeSetTTL(AstNode astNode) {
- String path = astNode.getChild(1).getText();
- long dataTTL = Long.parseLong(astNode.getChild(2).getText());
- TTLOperator operator = new TTLOperator(TSParser.TOK_SET);
+ private void analyzeSetTTL(AstNode astNode) throws LogicalOperatorException {
+ String path = parsePath(astNode.getChild(1)).getFullPath();
+ long dataTTL;
+ try {
+ dataTTL = Long.parseLong(astNode.getChild(2).getText());
+ } catch (NumberFormatException e) {
+ dataTTL = parseTimeFormat(astNode.getChild(2).getText());
+ }
+ TTLOperator operator = new TTLOperator(SQLConstant.TOK_SET);
initializedOperator = operator;
operator.setStorageGroup(path);
operator.setDataTTL(dataTTL);
}
private void analyzeUnsetTTL(AstNode astNode) {
- String path = astNode.getChild(1).getText();
- TTLOperator operator = new TTLOperator(TSParser.TOK_UNSET);
+ String path = parsePath(astNode.getChild(1)).getFullPath();
+ TTLOperator operator = new TTLOperator(SQLConstant.TOK_UNSET);
initializedOperator = operator;
operator.setStorageGroup(path);
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
index 26ece61..ad65b44 100644
---
a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
+++
b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.iotdb.db.auth.AuthException;
import org.apache.iotdb.db.exception.qp.LogicalOperatorException;
import org.apache.iotdb.db.exception.qp.QueryProcessorException;
+import org.apache.iotdb.db.qp.constant.SQLConstant;
import org.apache.iotdb.db.qp.executor.IQueryProcessExecutor;
import org.apache.iotdb.db.qp.logical.Operator;
import org.apache.iotdb.db.qp.logical.crud.BasicFunctionOperator;
@@ -126,7 +127,7 @@ public class PhysicalGenerator {
return transformQuery(query);
case TTL:
TTLOperator ttlOperator = (TTLOperator) operator;
- if (ttlOperator.getTokenIntType() == TSParser.TOK_SET) {
+ if (ttlOperator.getTokenIntType() == SQLConstant.TOK_SET) {
return new TTLPlan(ttlOperator.getStorageGroup(),
ttlOperator.getDataTTL());
} else {
return new TTLPlan(ttlOperator.getStorageGroup());
diff --git
a/server/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java
b/server/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java
index be28868..e2d5cac 100644
---
a/server/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java
+++
b/server/src/main/java/org/apache/iotdb/db/service/JDBCServiceEventHandler.java
@@ -19,22 +19,17 @@
package org.apache.iotdb.db.service;
import java.util.concurrent.CountDownLatch;
-
-import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.server.ServerContext;
import org.apache.thrift.server.TServerEventHandler;
import org.apache.thrift.transport.TTransport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class JDBCServiceEventHandler implements TServerEventHandler {
- private static final Logger logger =
LoggerFactory.getLogger(JDBCServiceEventHandler.class);
private TSServiceImpl serviceImpl;
private CountDownLatch startLatch;
- public JDBCServiceEventHandler(TSServiceImpl serviceImpl, CountDownLatch
startLatch) {
+ JDBCServiceEventHandler(TSServiceImpl serviceImpl, CountDownLatch
startLatch) {
this.serviceImpl = serviceImpl;
this.startLatch = startLatch;
}
@@ -47,11 +42,7 @@ public class JDBCServiceEventHandler implements
TServerEventHandler {
@Override
public void deleteContext(ServerContext arg0, TProtocol arg1, TProtocol
arg2) {
- try {
- serviceImpl.handleClientExit();
- } catch (TException e) {
- logger.error("failed to clear client status", e);
- }
+ serviceImpl.handleClientExit();
}
@Override
diff --git
a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 4368cd2..70fea4b 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -99,7 +99,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
// TODO: remove unclosed statements
private Map<Long, PhysicalPlan> idStmtMap = new ConcurrentHashMap<>();
- public TSServiceImpl() throws IOException {
+ public TSServiceImpl() {
processor = new QueryProcessor(new QueryProcessExecutor());
}
@@ -189,7 +189,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
return new TSRPCResp(getStatus(TSStatusType.SUCCESS_STATUS));
}
- private void releaseQueryResource(TSCloseOperationReq req) throws
StorageEngineException {
+ private void releaseQueryResource(TSCloseOperationReq req) {
Map<Long, QueryContext> contextMap = contextMapLocal.get();
if (contextMap == null) {
return;
@@ -223,8 +223,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
*/
private TS_Status getStatus(TSStatusType statusType) {
TS_StatusType statusCodeAndMessage = new
TS_StatusType(statusType.getStatusCode(), statusType.getStatusMessage());
- TS_Status status = new TS_Status(statusCodeAndMessage);
- return status;
+ return new TS_Status(statusCodeAndMessage);
}
/**
@@ -237,8 +236,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
private TS_Status getStatus(TSStatusType statusType, String appendMessage) {
TS_StatusType statusCodeAndMessage = new
TS_StatusType(statusType.getStatusCode(),
statusType.getStatusMessage() + ": " + appendMessage);
- TS_Status status = new TS_Status(statusCodeAndMessage);
- return status;
+ return new TS_Status(statusCodeAndMessage);
}
@Override
@@ -268,7 +266,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
resp.setMetadataInJson(metadataInJson);
status = new TS_Status(getStatus(TSStatusType.SUCCESS_STATUS));
break;
- case "DELTA_OBEJECT":
+ case "DELTA_OBJECT":
Metadata metadata = getMetadata();
String column = req.getColumnPath();
Map<String, List<String>> deviceMap = metadata.getDeviceMap();
@@ -321,11 +319,11 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
return nodeColumnsNum;
}
- private List<String> getNodesList(String level) throws PathErrorException {
+ private List<String> getNodesList(String level) {
return MManager.getInstance().getNodesList(level);
}
- private List<String> getAllStorageGroups() throws PathErrorException {
+ private List<String> getAllStorageGroups() {
return MManager.getInstance().getAllStorageGroupNames();
}
@@ -472,9 +470,8 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
}
} catch (Exception e) {
String errMessage = String.format(
- "Fail to generate physcial plan and execute for statement "
- + "%s beacuse %s",
- statement, e.getMessage());
+ "Fail to generate physical plan and execute for statement "
+ + "%s because %s", statement, e.getMessage());
logger.warn("Error occurred when executing {}", statement, e);
result.add(Statement.EXECUTE_FAILED);
batchErrorMessage.append(errMessage).append("\n");
@@ -550,11 +547,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
return false;
}
statement = statement.toLowerCase().trim();
- if (Pattern.matches(IoTDBConstant.SHOW_FLUSH_TASK_INFO, statement)) {
- return true;
- } else {
- return false;
- }
+ return Pattern.matches(IoTDBConstant.SHOW_FLUSH_TASK_INFO, statement);
}
/**
@@ -565,11 +558,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
return false;
}
statement = statement.toLowerCase().trim();
- if (Pattern.matches(IoTDBConstant.SHOW_DYNAMIC_PARAMETERS, statement)) {
- return true;
- } else {
- return false;
- }
+ return Pattern.matches(IoTDBConstant.SHOW_DYNAMIC_PARAMETERS, statement);
}
/**
@@ -922,7 +911,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
return resp;
}
- void handleClientExit() throws TException {
+ void handleClientExit() {
closeOperation(null);
closeSession(null);
}
@@ -1002,7 +991,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
}
@Override
- public TSRPCResp insertRow(TSInsertReq req) throws TException {
+ public TSRPCResp insertRow(TSInsertReq req) {
if (!checkLogin()) {
logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
return new TSRPCResp(getStatus(TSStatusType.NOT_LOGIN_ERROR));
@@ -1069,7 +1058,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
}
@Override
- public TSRPCResp setStorageGroup(TSSetStorageGroupReq req) throws TException
{
+ public TSRPCResp setStorageGroup(TSSetStorageGroupReq req) {
if (!checkLogin()) {
logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
return new TSRPCResp(getStatus(TSStatusType.NOT_LOGIN_ERROR));
@@ -1084,7 +1073,7 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
}
@Override
- public TSRPCResp createTimeseries(TSCreateTimeseriesReq req) throws
TException {
+ public TSRPCResp createTimeseries(TSCreateTimeseriesReq req) {
if (!checkLogin()) {
logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
return new TSRPCResp(getStatus(TSStatusType.NOT_LOGIN_ERROR));
@@ -1127,7 +1116,13 @@ public class TSServiceImpl implements TSIService.Iface,
ServerContext {
execRet = executeNonQuery(plan);
} catch (ProcessorException e) {
logger.debug("meet error while processing non-query. ", e);
- return getStatus(TSStatusType.EXECUTE_STATEMENT_ERROR, e.getMessage());
+ if (e.getCause() instanceof OutOfTTLException) {
+ return getStatus(TSStatusType.OUT_OF_TTL_ERROR, e.getMessage());
+ } else if (e.getCause() instanceof PathErrorException) {
+ return getStatus(TSStatusType.NOT_A_STORAGE_GROUP_ERROR,
e.getMessage());
+ } else {
+ return getStatus(TSStatusType.EXECUTE_STATEMENT_ERROR, e.getMessage());
+ }
}
return execRet ? getStatus(TSStatusType.SUCCESS_STATUS, "Execute
successfully")
diff --git
a/server/src/test/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCacheTest.java
b/server/src/test/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCacheTest.java
index 153799d..83fae84 100644
---
a/server/src/test/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCacheTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/engine/cache/DeviceMetaDataCacheTest.java
@@ -25,6 +25,7 @@ import org.apache.iotdb.db.engine.MetadataManagerHelper;
import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
import org.apache.iotdb.db.engine.storagegroup.StorageGroupProcessor;
import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.metadata.MManager;
import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
import org.apache.iotdb.db.query.context.QueryContext;
@@ -51,7 +52,6 @@ public class DeviceMetaDataCacheTest {
private String measurementId3 = "s3";
private String measurementId4 = "s4";
private String measurementId5 = "s5";
- private String measurementId100 = "s100";
private StorageGroupProcessor storageGroupProcessor;
private String systemDir = "data/info";
@@ -74,7 +74,7 @@ public class DeviceMetaDataCacheTest {
EnvironmentUtils.cleanDir(systemDir);
}
- private void insertOneRecord(long time, int num) {
+ private void insertOneRecord(long time, int num) throws
StorageEngineException {
TSRecord record = new TSRecord(time, deviceId0);
record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId0,
String.valueOf(num)));
record.addTuple(DataPoint.getDataPoint(TSDataType.INT64, measurementId1,
String.valueOf(num)));
@@ -85,7 +85,7 @@ public class DeviceMetaDataCacheTest {
storageGroupProcessor.insert(new InsertPlan(record));
}
- protected void insertData() throws IOException {
+ protected void insertData() throws IOException, StorageEngineException {
for (int j = 1; j <= 100; j++) {
insertOneRecord(j, j);
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java
b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java
index 6539a3e..673eb24 100644
---
a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java
@@ -21,20 +21,17 @@ package org.apache.iotdb.db.engine.storagegroup;
import static org.junit.Assert.assertFalse;
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.ArrayList;
-
import org.apache.iotdb.db.engine.MetadataManagerHelper;
import org.apache.iotdb.db.engine.merge.manage.MergeManager;
import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
-
import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan;
-
import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
import org.apache.iotdb.db.query.context.QueryContext;
-import org.apache.iotdb.db.query.control.JobFileManager;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.write.record.TSRecord;
@@ -72,7 +69,7 @@ public class StorageGroupProcessorTest {
@Test
- public void testSequenceSyncClose() {
+ public void testSequenceSyncClose() throws StorageEngineException {
for (int j = 1; j <= 10; j++) {
TSRecord record = new TSRecord(j, deviceId);
record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId,
String.valueOf(j)));
@@ -146,7 +143,7 @@ public class StorageGroupProcessorTest {
@Test
- public void testSeqAndUnSeqSyncClose() {
+ public void testSeqAndUnSeqSyncClose() throws StorageEngineException {
for (int j = 21; j <= 30; j++) {
TSRecord record = new TSRecord(j, deviceId);
@@ -178,7 +175,7 @@ public class StorageGroupProcessorTest {
}
@Test
- public void testMerge() {
+ public void testMerge() throws StorageEngineException {
mergeLock = new AtomicLong(0);
for (int j = 21; j <= 30; j++) {
diff --git
a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TTLTest.java
b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TTLTest.java
new file mode 100644
index 0000000..a4fbb42
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TTLTest.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this work
for additional information regarding copyright ownership. The ASF licenses
this file to you under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless
required by applicable law or ag [...]
+ */
+
+package org.apache.iotdb.db.engine.storagegroup;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.conf.directories.DirectoryManager;
+import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
+import org.apache.iotdb.db.exception.ArgsErrorException;
+import org.apache.iotdb.db.exception.MetadataErrorException;
+import org.apache.iotdb.db.exception.OutOfTTLException;
+import org.apache.iotdb.db.exception.PathErrorException;
+import org.apache.iotdb.db.exception.ProcessorException;
+import org.apache.iotdb.db.exception.StartupException;
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.qp.QueryProcessorException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.metadata.MNode;
+import org.apache.iotdb.db.qp.QueryProcessor;
+import org.apache.iotdb.db.qp.executor.QueryProcessExecutor;
+import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
+import org.apache.iotdb.db.qp.physical.sys.TTLPlan;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
+import
org.apache.iotdb.db.query.reader.resourceRelated.SeqResourceIterateReader;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.read.common.BatchData;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TTLTest {
+
+ private String sg1 = "root.TTL_SG1";
+ private String sg2 = "root.TTL_SG2";
+ private long ttl = 12345;
+ private StorageGroupProcessor storageGroupProcessor;
+ private String s1 = "s1";
+ private String g1s1 = sg1 + IoTDBConstant.PATH_SEPARATOR + s1;
+
+ @Before
+ public void setUp()
+ throws MetadataErrorException, ProcessorException, IOException,
StartupException {
+ EnvironmentUtils.envSetUp();
+ createSchemas();
+ }
+
+ @After
+ public void tearDown() throws IOException, StorageEngineException {
+ storageGroupProcessor.waitForAllCurrentTsFileProcessorsClosed();
+ EnvironmentUtils.cleanEnv();
+ }
+
+ private void createSchemas() throws MetadataErrorException,
ProcessorException {
+ MManager.getInstance().setStorageLevelToMTree(sg1);
+ MManager.getInstance().setStorageLevelToMTree(sg2);
+ storageGroupProcessor = new
StorageGroupProcessor(IoTDBDescriptor.getInstance().getConfig()
+ .getSystemDir(), sg1);
+ MManager.getInstance().addPathToMTree(g1s1, TSDataType.INT64,
TSEncoding.PLAIN,
+ CompressionType.UNCOMPRESSED, Collections.emptyMap());
+ storageGroupProcessor.addMeasurement("s1", TSDataType.INT64,
TSEncoding.PLAIN,
+ CompressionType.UNCOMPRESSED, Collections.emptyMap());
+ }
+
+ @Test
+ public void testSetMetaTTL() throws IOException, PathErrorException {
+ // exception is expected when setting ttl to a non-exist storage group
+ boolean caught = false;
+ try {
+ MManager.getInstance().setTTL(sg1 + ".notExist", ttl);
+ } catch (PathErrorException e) {
+ caught = true;
+ }
+ assertTrue(caught);
+
+ // normally set ttl
+ MManager.getInstance().setTTL(sg1, ttl);
+ MNode mNode = MManager.getInstance().getNodeByPathFromCache(sg1);
+ assertEquals(ttl, mNode.getDataTTL());
+
+ // default ttl
+ mNode = MManager.getInstance().getNodeByPathFromCache(sg2);
+ assertEquals(Long.MAX_VALUE, mNode.getDataTTL());
+ }
+
+ @Test
+ public void testTTLWrite() throws StorageEngineException {
+ InsertPlan insertPlan = new InsertPlan();
+ insertPlan.setDeviceId(sg1);
+ insertPlan.setTime(System.currentTimeMillis());
+ insertPlan.setMeasurements(new String[]{"s1"});
+ insertPlan.setValues(new String[]{"1"});
+ insertPlan.setDataTypes(new TSDataType[]{TSDataType.INT64});
+
+ // ok without ttl
+ assertTrue(storageGroupProcessor.insert(insertPlan));
+
+ storageGroupProcessor.setDataTTL(1000);
+ // with ttl
+ insertPlan.setTime(System.currentTimeMillis() - 1001);
+ boolean caught = false;
+ try {
+ storageGroupProcessor.insert(insertPlan);
+ } catch (OutOfTTLException e) {
+ caught = true;
+ }
+ assertTrue(caught);
+ insertPlan.setTime(System.currentTimeMillis() - 900);
+ assertTrue(storageGroupProcessor.insert(insertPlan));
+ }
+
+ private void prepareData() throws StorageEngineException {
+ InsertPlan insertPlan = new InsertPlan();
+ insertPlan.setDeviceId(sg1);
+ insertPlan.setTime(System.currentTimeMillis());
+ insertPlan.setMeasurements(new String[]{"s1"});
+ insertPlan.setValues(new String[]{"1"});
+ insertPlan.setDataTypes(new TSDataType[]{TSDataType.INT64});
+
+ long initTime = System.currentTimeMillis();
+ // sequence data
+ for (int i = 1000; i < 2000; i++) {
+ insertPlan.setTime(initTime - 2000 + i);
+ assertTrue(storageGroupProcessor.insert(insertPlan));
+ if ((i + 1) % 300 == 0) {
+ storageGroupProcessor.putAllWorkingTsFileProcessorIntoClosingList();
+ }
+ }
+ // unsequence data
+ for (int i = 0; i < 1000; i++) {
+ insertPlan.setTime(initTime - 2000 + i);
+ storageGroupProcessor.insert(insertPlan);
+ if ((i + 1) % 300 == 0) {
+ storageGroupProcessor.putAllWorkingTsFileProcessorIntoClosingList();
+ }
+ }
+ }
+
+ @Test
+ public void testTTLRead() throws IOException, StorageEngineException {
+ prepareData();
+
+ storageGroupProcessor.merge(true);
+
+ // files before ttl
+ QueryDataSource dataSource = storageGroupProcessor.query(sg1, s1,
EnvironmentUtils.TEST_QUERY_CONTEXT
+ , null);
+ List<TsFileResource> seqResource = dataSource.getSeqResources();
+ List<TsFileResource> unseqResource = dataSource.getUnseqResources();
+ assertEquals(4, seqResource.size());
+ assertEquals(4, unseqResource.size());
+
+ storageGroupProcessor.setDataTTL(500);
+
+ // files after ttl
+ dataSource = storageGroupProcessor.query(sg1, s1,
EnvironmentUtils.TEST_QUERY_CONTEXT
+ , null);
+ seqResource = dataSource.getSeqResources();
+ unseqResource = dataSource.getUnseqResources();
+ assertTrue(seqResource.size() < 4);
+ assertEquals(0, unseqResource.size());
+ Path path = new Path(sg1, s1);
+ SeqResourceIterateReader reader = new SeqResourceIterateReader(path,
+ seqResource, null, EnvironmentUtils.TEST_QUERY_CONTEXT);
+
+ int cnt = 0;
+ while (reader.hasNext()) {
+ BatchData batchData = reader.nextBatch();
+ while (batchData.hasNext()) {
+ batchData.next();
+ cnt ++;
+ }
+ }
+ reader.close();
+ // we cannot offer the exact number since when exactly ttl will be checked
is unknown
+ assertTrue(cnt <= 1000);
+
+ storageGroupProcessor.setDataTTL(0);
+ dataSource = storageGroupProcessor.query(sg1, s1,
EnvironmentUtils.TEST_QUERY_CONTEXT
+ , null);
+ seqResource = dataSource.getSeqResources();
+ unseqResource = dataSource.getUnseqResources();
+ assertEquals(0, seqResource.size());
+ assertEquals(0, unseqResource.size());
+
+
+
QueryResourceManager.getInstance().endQueryForGivenJob(EnvironmentUtils.TEST_QUERY_JOB_ID);
+ }
+
+ @Test
+ public void testTTLRemoval() throws StorageEngineException {
+ prepareData();
+
+ storageGroupProcessor.waitForAllCurrentTsFileProcessorsClosed();
+
+ // files before ttl
+ File seqDir = new
File(DirectoryManager.getInstance().getNextFolderForSequenceFile(), sg1);
+ File unseqDir = new
File(DirectoryManager.getInstance().getNextFolderForUnSequenceFile(), sg1);
+ File[] seqFiles = seqDir.listFiles(f ->
f.getName().endsWith(TsFileConstant.TSFILE_SUFFIX));
+ File[] unseqFiles = unseqDir.listFiles(f ->
f.getName().endsWith(TsFileConstant.TSFILE_SUFFIX));
+ for (File file : seqFiles) {
+ System.out.println(file.getPath());
+ }
+ assertEquals(4, seqFiles.length);
+ assertEquals(4, unseqFiles.length);
+
+ storageGroupProcessor.setDataTTL(500);
+ storageGroupProcessor.checkFilesTTL();
+
+ // files after ttl
+ seqFiles = seqDir.listFiles(f ->
f.getName().endsWith(TsFileConstant.TSFILE_SUFFIX));
+ unseqFiles = unseqDir.listFiles(f ->
f.getName().endsWith(TsFileConstant.TSFILE_SUFFIX));
+ assertTrue(seqFiles.length <= 2);
+ assertEquals(0, unseqFiles.length);
+ }
+
+ @Test
+ public void testParseTTL()
+ throws ArgsErrorException, MetadataErrorException,
QueryProcessorException {
+ QueryProcessor queryProcessor = new QueryProcessor(new
QueryProcessExecutor());
+ TTLPlan plan = (TTLPlan) queryProcessor.parseSQLToPhysicalPlan("SET TTL TO
" + sg1 + " 10000");
+ assertEquals(sg1, plan.getStorageGroup());
+ assertEquals(10000, plan.getDataTTL());
+
+ plan = (TTLPlan) queryProcessor.parseSQLToPhysicalPlan("UNSET TTL TO " +
sg2);
+ assertEquals(sg2, plan.getStorageGroup());
+ assertEquals(Long.MAX_VALUE, plan.getDataTTL());
+ }
+
+}
\ No newline at end of file
diff --git
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTTLTest.java
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTTLTest.java
new file mode 100644
index 0000000..25ab87c
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTTLTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.iotdb.db.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.jdbc.IoTDBConnection;
+import org.apache.iotdb.rpc.TSStatusType;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class IoTDBTTLTest {
+ private IoTDB daemon;
+
+ @Before
+ public void setUp() throws Exception {
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ EnvironmentUtils.closeStatMonitor();
+ daemon = IoTDB.getInstance();
+ daemon.active();
+ EnvironmentUtils.envSetUp();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ daemon.stop();
+ EnvironmentUtils.cleanEnv();
+ }
+
+ @Test
+ public void testTTL() throws SQLException {
+ try (IoTDBConnection connection = (IoTDBConnection) DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",
"root");
+ Statement statement = connection.createStatement()) {
+ try {
+ statement.execute("SET TTL TO root.TTL_SG1 1000");
+ } catch (SQLException e) {
+ assertEquals(TSStatusType.NOT_A_STORAGE_GROUP_ERROR.getStatusCode(),
e.getErrorCode());
+ }
+ try {
+ statement.execute("UNSET TTL TO root.TTL_SG1");
+ } catch (SQLException e) {
+ assertEquals(TSStatusType.NOT_A_STORAGE_GROUP_ERROR.getStatusCode(),
e.getErrorCode());
+ }
+
+ statement.execute("SET STORAGE GROUP TO root.TTL_SG1");
+ statement.execute("CREATE TIMESERIES root.TTL_SG1.s1 WITH
DATATYPE=INT64,ENCODING=PLAIN");
+
+ long now = System.currentTimeMillis();
+ for (int i = 0; i < 100; i ++) {
+ statement.execute(String.format("INSERT INTO root.TTL_SG1(timestamp,
s1) VALUES (%d, %d)",
+ now - 100 + i, i));
+ }
+ for (int i = 0; i < 100; i ++) {
+ statement.execute(String.format("INSERT INTO root.TTL_SG1(timestamp,
s1) VALUES (%d, %d)",
+ now - 100000 + i, i));
+ }
+
+ try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM
root.TTL_SG1")) {
+ int cnt = 0;
+ while (resultSet.next()) {
+ cnt++;
+ }
+ assertEquals(200, cnt);
+ }
+
+ statement.execute("SET TTL TO root.TTL_SG1 10000");
+ try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM
root.TTL_SG1")) {
+ int cnt = 0;
+ while (resultSet.next()) {
+ cnt++;
+ }
+ assertEquals(100, cnt);
+ }
+ for (int i = 0; i < 100; i ++) {
+ try {
+ statement.execute(String.format("INSERT INTO root.TTL_SG1(timestamp,
s1) VALUES (%d, %d)",
+ now - 50000 + i, i));
+ } catch (SQLException e) {
+ assertEquals(TSStatusType.OUT_OF_TTL_ERROR.getStatusCode(),
e.getErrorCode());
+ }
+ }
+ try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM
root.TTL_SG1")) {
+ int cnt = 0;
+ while (resultSet.next()) {
+ cnt++;
+ }
+ assertEquals(100, cnt);
+ }
+
+ statement.execute("UNSET TTL TO root.TTL_SG1");
+ for (int i = 0; i < 100; i ++) {
+ statement.execute(String.format("INSERT INTO root.TTL_SG1(timestamp,
s1) VALUES (%d, %d)",
+ now - 30000 + i, i));
+ }
+ try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM
root.TTL_SG1")) {
+ int cnt = 0;
+ while (resultSet.next()) {
+ cnt++;
+ }
+ assertTrue(cnt >= 200);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTimeZoneIT.java
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTimeZoneIT.java
index 1c60ba0..a0a0841 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTimeZoneIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBTimeZoneIT.java
@@ -43,25 +43,25 @@ public class IoTDBTimeZoneIT {
private final String tz1 = "root.timezone.tz1";
// private boolean testFlag = TestUtils.testFlag;
- String[] retArray = new String[]{"1514775603000,4", "1514779200000,1",
"1514779201000,2",
+ private String[] retArray = new String[]{"1514775603000,4",
"1514779200000,1", "1514779201000,2",
"1514779202000,3",
"1514779203000,8", "1514782804000,5", "1514782805000,7",
"1514782806000,9",
"1514782807000,10",
"1514782808000,11", "1514782809000,12", "1514782810000,13",
"1514789200000,6",};
- private IoTDB deamon;
+ private IoTDB daemon;
@Before
public void setUp() throws Exception {
EnvironmentUtils.closeStatMonitor();
- deamon = IoTDB.getInstance();
- deamon.active();
+ daemon = IoTDB.getInstance();
+ daemon.active();
EnvironmentUtils.envSetUp();
createTimeseries();
}
@After
public void tearDown() throws Exception {
- deamon.stop();
+ daemon.stop();
EnvironmentUtils.cleanEnv();
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBVersionIT.java
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBVersionIT.java
index 4b53d9f..fe8351a 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBVersionIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBVersionIT.java
@@ -62,16 +62,9 @@ public class IoTDBVersionIT {
+ " WITH DATATYPE=INT32,ENCODING=PLAIN");
// insert and flush enough times to make the version file persist
- for (int i = 0; i < 2 * SimpleFileVersionController.getSaveInterval(); i
++) {
- for (int j = 1; j <= 10; j ++) {
- statement.execute(String
- .format("INSERT INTO root.versionTest1(timestamp, s0) VALUES
(%d, %d)", i*100+j, j));
- }
- statement.execute("FLUSH");
- for (int j = 1; j <= 10; j ++) {
- statement.execute(String
- .format("INSERT INTO root.versionTest2(timestamp, s0) VALUES
(%d, %d)", i*100+j, j));
- }
+ for (int i = 0; i < SimpleFileVersionController.getSaveInterval() + 1; i
++) {
+ statement.execute(String
+ .format("INSERT INTO root.versionTest1(timestamp, s0) VALUES (%d,
%d)", i*100, i));
statement.execute("FLUSH");
statement.execute("MERGE");
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java
b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java
index 1ac44e9..1719b9f 100644
---
a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java
@@ -114,11 +114,11 @@ public class MManagerAdvancedTest {
Assert.assertEquals(null,
mmanager.checkPathStorageLevelAndGetDataType("root.vehicle.d0.s100").getDataType());
- MNode node = mmanager.getNodeByDeviceIdFromCache("root.vehicle.d0");
+ MNode node = mmanager.getNodeByPathFromCache("root.vehicle.d0");
Assert.assertEquals(TSDataType.INT32,
node.getChild("s0").getSchema().getType());
try {
- MNode node1 = mmanager.getNodeByDeviceIdFromCache("root.vehicle.d100");
+ MNode node1 = mmanager.getNodeByPathFromCache("root.vehicle.d100");
fail();
} catch (PathErrorException e) {
diff --git
a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java
b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java
index ade6040..1f864af 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java
@@ -213,7 +213,7 @@ public class MManagerImproveTest {
public void doCacheTest(String deviceId, List<String> measurementList)
throws PathErrorException, ProcessorException {
- MNode node = mManager.getNodeByDeviceIdFromCache(deviceId);
+ MNode node = mManager.getNodeByPathFromCache(deviceId);
for (int i = 0; i < measurementList.size(); i++) {
assertEquals(true, node.hasChild(measurementList.get(i)));
MNode measurementNode = node.getChild(measurementList.get(i));
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
b/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
index 8cde744..1cc8e67 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
@@ -24,10 +24,12 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.apache.iotdb.db.exception.PathErrorException;
import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
@@ -52,13 +54,15 @@ public class MTreeTest {
public void testAddLeftNodePath() {
MTree root = new MTree("root");
try {
- root.addTimeseriesPath("root.laptop.d1.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.laptop.d1.s1", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
} catch (PathErrorException e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
- root.addTimeseriesPath("root.laptop.d1.s1.b", "INT32", "RLE");
+ root.addTimeseriesPath("root.laptop.d1.s1.b", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
} catch (PathErrorException e) {
Assert.assertEquals(
String.format("The Node [%s] is left node, the timeseries %s can't
be created", "s1",
@@ -73,7 +77,8 @@ public class MTreeTest {
assertEquals(true, root.isPathExist(path1));
assertEquals(false, root.isPathExist("root.laptop.d1"));
try {
- root.addTimeseriesPath("root.laptop.d1.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.laptop.d1.s1", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
} catch (PathErrorException e1) {
fail(e1.getMessage());
}
@@ -81,7 +86,8 @@ public class MTreeTest {
assertEquals(true, root.isPathExist("root.laptop"));
assertEquals(false, root.isPathExist("root.laptop.d1.s2"));
try {
- root.addTimeseriesPath("aa.bb.cc", "INT32", "RLE");
+ root.addTimeseriesPath("aa.bb.cc", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
} catch (PathErrorException e) {
Assert.assertEquals(String.format("Timeseries %s is not right.",
"aa.bb.cc"), e.getMessage());
}
@@ -94,17 +100,22 @@ public class MTreeTest {
assertEquals(false, root.isPathExist("root.a.d0"));
assertEquals(false, root.checkFileNameByPath("root.a.d0"));
root.setStorageGroup("root.a.d0");
- root.addTimeseriesPath("root.a.d0.s0", "INT32", "RLE");
- root.addTimeseriesPath("root.a.d0.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.a.d0.s0", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
+ root.addTimeseriesPath("root.a.d0.s1", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
assertEquals(false, root.isPathExist("root.a.d1"));
assertEquals(false, root.checkFileNameByPath("root.a.d1"));
root.setStorageGroup("root.a.d1");
- root.addTimeseriesPath("root.a.d1.s0", "INT32", "RLE");
- root.addTimeseriesPath("root.a.d1.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.a.d1.s0", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
+ root.addTimeseriesPath("root.a.d1.s1", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
root.setStorageGroup("root.a.b.d0");
- root.addTimeseriesPath("root.a.b.d0.s0", "INT32", "RLE");
+ root.addTimeseriesPath("root.a.b.d0.s0", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
} catch (PathErrorException e1) {
e1.printStackTrace();
@@ -136,32 +147,42 @@ public class MTreeTest {
MTree root3 = new MTree("root");
try {
root.setStorageGroup("root.a.d0");
- root.addTimeseriesPath("root.a.d0.s0", "INT32", "RLE");
- root.addTimeseriesPath("root.a.d0.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.a.d0.s0", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
+ root.addTimeseriesPath("root.a.d0.s1", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
root.setStorageGroup("root.a.d1");
- root.addTimeseriesPath("root.a.d1.s0", "INT32", "RLE");
- root.addTimeseriesPath("root.a.d1.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.a.d1.s0", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
+ root.addTimeseriesPath("root.a.d1.s1", TSDataType.INT32, TSEncoding.RLE,
CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
root.setStorageGroup("root.a.b.d0");
- root.addTimeseriesPath("root.a.b.d0.s0", "INT32", "RLE");
+ root.addTimeseriesPath("root.a.b.d0.s0", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
root1.setStorageGroup("root.a.d0");
- root1.addTimeseriesPath("root.a.d0.s0", "INT32", "RLE");
- root1.addTimeseriesPath("root.a.d0.s1", "INT32", "RLE");
+ root1.addTimeseriesPath("root.a.d0.s0", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
+ root1.addTimeseriesPath("root.a.d0.s1", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
root2.setStorageGroup("root.a.d1");
- root2.addTimeseriesPath("root.a.d1.s0", "INT32", "RLE");
- root2.addTimeseriesPath("root.a.d1.s1", "INT32", "RLE");
+ root2.addTimeseriesPath("root.a.d1.s0", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
+ root2.addTimeseriesPath("root.a.d1.s1", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
root3.setStorageGroup("root.a.b.d0");
- root3.addTimeseriesPath("root.a.b.d0.s0", "INT32", "RLE");
-
- String[] metadatas = new String[3];
- metadatas[0] = root1.toString();
- metadatas[1] = root2.toString();
- metadatas[2] = root3.toString();
- assertEquals(MTree.combineMetadataInStrings(metadatas), root.toString());
+ root3.addTimeseriesPath("root.a.b.d0.s0", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
+
+ String[] metadataStrs = new String[3];
+ metadataStrs[0] = root1.toString();
+ metadataStrs[1] = root2.toString();
+ metadataStrs[2] = root3.toString();
+ assertEquals(MTree.combineMetadataInStrings(metadataStrs),
root.toString());
} catch (PathErrorException e) {
e.printStackTrace();
fail(e.getMessage());
@@ -204,13 +225,17 @@ public class MTreeTest {
try {
assertEquals("root.laptop.d1",
root.getStorageGroupNameByPath("root.laptop.d1.s0"));
- root.addTimeseriesPath("root.laptop.d1.s0", "INT32", "RLE");
+ root.addTimeseriesPath("root.laptop.d1.s0", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
assertEquals("root.laptop.d1",
root.getStorageGroupNameByPath("root.laptop.d1.s1"));
- root.addTimeseriesPath("root.laptop.d1.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.laptop.d1.s1", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
assertEquals("root.laptop.d2",
root.getStorageGroupNameByPath("root.laptop.d2.s0"));
- root.addTimeseriesPath("root.laptop.d2.s0", "INT32", "RLE");
+ root.addTimeseriesPath("root.laptop.d2.s0", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
assertEquals("root.laptop.d2",
root.getStorageGroupNameByPath("root.laptop.d2.s1"));
- root.addTimeseriesPath("root.laptop.d2.s1", "INT32", "RLE");
+ root.addTimeseriesPath("root.laptop.d2.s1", TSDataType.INT32,
TSEncoding.RLE, CompressionType.valueOf
+ (TSFileConfig.compressor), Collections.EMPTY_MAP);
} catch (PathErrorException e) {
e.printStackTrace();
fail(e.getMessage());
diff --git
a/server/src/test/java/org/apache/iotdb/db/query/reader/ReaderTestHelper.java
b/server/src/test/java/org/apache/iotdb/db/query/reader/ReaderTestHelper.java
index 12fd774..d9cf752 100644
---
a/server/src/test/java/org/apache/iotdb/db/query/reader/ReaderTestHelper.java
+++
b/server/src/test/java/org/apache/iotdb/db/query/reader/ReaderTestHelper.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.db.query.reader;
import java.io.IOException;
import org.apache.iotdb.db.engine.MetadataManagerHelper;
import org.apache.iotdb.db.engine.storagegroup.StorageGroupProcessor;
+import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.metadata.MManager;
import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
import org.apache.iotdb.db.utils.EnvironmentUtils;
@@ -58,9 +59,9 @@ public abstract class ReaderTestHelper {
EnvironmentUtils.cleanDir(systemDir);
}
- abstract protected void insertData() throws IOException;
+ abstract protected void insertData() throws IOException,
StorageEngineException;
- protected void insertOneRecord(long time, int num) {
+ protected void insertOneRecord(long time, int num) throws
StorageEngineException {
TSRecord record = new TSRecord(time, deviceId);
record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId,
String.valueOf(num)));
storageGroupProcessor.insert(new InsertPlan(record));
diff --git
a/server/src/test/java/org/apache/iotdb/db/query/reader/fileRelated/UnSealedTsFileReaderTest.java
b/server/src/test/java/org/apache/iotdb/db/query/reader/fileRelated/UnSealedTsFileReaderTest.java
index 148ae50..9b588e3 100644
---
a/server/src/test/java/org/apache/iotdb/db/query/reader/fileRelated/UnSealedTsFileReaderTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/query/reader/fileRelated/UnSealedTsFileReaderTest.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.db.query.reader.fileRelated;
import java.io.IOException;
import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.reader.ReaderTestHelper;
import org.apache.iotdb.db.utils.EnvironmentUtils;
@@ -84,7 +85,7 @@ public class UnSealedTsFileReaderTest extends
ReaderTestHelper {
@Override
- protected void insertData() throws IOException {
+ protected void insertData() throws IOException, StorageEngineException {
for (int j = 1000; j <= 1009; j++) {
insertOneRecord(j, j);
}
diff --git
a/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/SeqResourceReaderTest.java
b/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/SeqResourceReaderTest.java
index 2d33d14..e4c0b65 100644
---
a/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/SeqResourceReaderTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/SeqResourceReaderTest.java
@@ -20,6 +20,7 @@ package org.apache.iotdb.db.query.reader.resourceRelated;
import java.io.IOException;
import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
+import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.reader.ReaderTestHelper;
import org.apache.iotdb.db.utils.EnvironmentUtils;
@@ -77,7 +78,7 @@ public class SeqResourceReaderTest extends ReaderTestHelper {
}
@Override
- protected void insertData() throws IOException {
+ protected void insertData() throws IOException, StorageEngineException {
for (int j = 1000; j <= 1009; j++) {
insertOneRecord(j, j);
storageGroupProcessor.putAllWorkingTsFileProcessorIntoClosingList();
diff --git
a/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/UnseqResourceReaderTest.java
b/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/UnseqResourceReaderTest.java
index adbdb27..e0f920e 100644
---
a/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/UnseqResourceReaderTest.java
+++
b/server/src/test/java/org/apache/iotdb/db/query/reader/resourceRelated/UnseqResourceReaderTest.java
@@ -38,7 +38,7 @@ public class UnseqResourceReaderTest extends ReaderTestHelper
{
private QueryContext context = EnvironmentUtils.TEST_QUERY_CONTEXT;
@Override
- protected void insertData() throws IOException {
+ protected void insertData() throws IOException, StorageEngineException {
for (int j = 1; j <= 100; j++) {
insertOneRecord(j, j);
}
@@ -111,7 +111,7 @@ public class UnseqResourceReaderTest extends
ReaderTestHelper {
}
@Test
- public void testUnseqResourceReaderByTimestamp() throws IOException,
StorageEngineException {
+ public void testUnseqResourceReaderByTimestamp() throws IOException {
Path path = new Path(deviceId, measurementId);
QueryDataSource queryDataSource = storageGroupProcessor.query(deviceId,
measurementId, context,
null);
diff --git
a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
index 6591cad..e903d5b 100644
--- a/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
+++ b/server/src/test/java/org/apache/iotdb/db/utils/EnvironmentUtils.java
@@ -32,6 +32,7 @@ import org.apache.iotdb.db.engine.StorageEngine;
import org.apache.iotdb.db.engine.cache.DeviceMetaDataCache;
import org.apache.iotdb.db.engine.cache.TsFileMetaDataCache;
import org.apache.iotdb.db.engine.flush.FlushManager;
+import org.apache.iotdb.db.engine.merge.manage.MergeManager;
import org.apache.iotdb.db.exception.StartupException;
import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.metadata.MManager;
@@ -93,6 +94,9 @@ public class EnvironmentUtils {
}
// close metadata
MManager.getInstance().clear();
+
+ MergeManager.getINSTANCE().stop();
+
// delete all directory
cleanAllDir();
@@ -162,6 +166,7 @@ public class EnvironmentUtils {
StorageEngine.getInstance().reset();
MultiFileLogNodeManager.getInstance().start();
FlushManager.getInstance().start();
+ MergeManager.getINSTANCE().start();
TEST_QUERY_JOB_ID = QueryResourceManager.getInstance().assignJobId();
TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID);
}
diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusType.java
b/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusType.java
index 58c8b4e..991db2b 100644
--- a/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusType.java
+++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusType.java
@@ -32,6 +32,7 @@ public enum TSStatusType {
SQL_PARSE_ERROR(401, "Meet error while parsing SQL"),
GENERATE_TIME_ZONE_ERROR(402, "Meet error while generating time zone"),
SET_TIME_ZONE_ERROR(403, "Meet error while setting time zone"),
+ NOT_A_STORAGE_GROUP_ERROR(404, "Given path is not a storage group"),
INTERNAL_SERVER_ERROR(500, "Internal server error"),
WRONG_LOGIN_PASSWORD_ERROR(600, "Username or password is wrong"),
NOT_LOGIN_ERROR(601, "Has not logged in"),
@@ -41,7 +42,7 @@ public enum TSStatusType {
private int statusCode;
private String statusMessage;
- private TSStatusType(int statusCode, String statusMessage) {
+ TSStatusType(int statusCode, String statusMessage) {
this.statusCode = statusCode;
this.statusMessage = statusMessage;
}