You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2019/09/17 09:23:46 UTC
[incubator-iotdb] branch master updated: [IOTDB-191] Enrich Session
interfaces (#375)
This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 7d07bae [IOTDB-191] Enrich Session interfaces (#375)
7d07bae is described below
commit 7d07baef00fb7546ebb2809719c86c88ecc6bb9b
Author: Jack Tsai <ja...@outlook.com>
AuthorDate: Tue Sep 17 17:23:41 2019 +0800
[IOTDB-191] Enrich Session interfaces (#375)
---
.../UserGuide/7-Session API/1-Session API.md | 7 +
.../UserGuide/7-Session API/1-Session API.md | 7 +
.../main/java/org/apache/iotdb/SessionExample.java | 7 +
.../iotdb/db/qp/physical/crud/DeletePlan.java | 4 +-
.../org/apache/iotdb/db/service/TSServiceImpl.java | 19 ++
service-rpc/rpc-changelist.md | 6 +-
service-rpc/src/main/thrift/rpc.thrift | 9 +-
session/pom.xml | 12 ++
.../java/org/apache/iotdb/session/Session.java | 12 ++
.../org/apache/iotdb/session/IoTDBSessionIT.java | 98 +++++++++--
.../iotdb/session/utils/EnvironmentUtils.java | 192 +++++++++++++++++++++
11 files changed, 351 insertions(+), 22 deletions(-)
diff --git a/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md b/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md
index 4e9f0ee..01bb6f5 100644
--- a/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md
+++ b/docs/Documentation-CHN/UserGuide/7-Session API/1-Session API.md
@@ -75,6 +75,7 @@ public class SessionExample {
insert();
// insertRowBatch();
+ delete();
session.close();
}
@@ -94,6 +95,12 @@ public class SessionExample {
}
}
+ private static void delete() throws IoTDBSessionException {
+ String path = "root.sg1.d1.s1";
+ long deleteTime = 29999;
+ session.delete(path, deleteTime);
+ }
+
private static void insertRowBatch() throws IoTDBSessionException {
Schema schema = new Schema();
schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
diff --git a/docs/Documentation/UserGuide/7-Session API/1-Session API.md b/docs/Documentation/UserGuide/7-Session API/1-Session API.md
index 6312a5c..82e881c 100644
--- a/docs/Documentation/UserGuide/7-Session API/1-Session API.md
+++ b/docs/Documentation/UserGuide/7-Session API/1-Session API.md
@@ -84,6 +84,7 @@ public class SessionExample {
insert();
// insertRowBatch();
+ delete();
session.close();
}
@@ -103,6 +104,12 @@ public class SessionExample {
}
}
+ private static void delete() throws IoTDBSessionException {
+ String path = "root.sg1.d1.s1";
+ long deleteTime = 29999;
+ session.delete(path, deleteTime);
+ }
+
private static void insertRowBatch() throws IoTDBSessionException {
Schema schema = new Schema();
schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
diff --git a/example/session/src/main/java/org/apache/iotdb/SessionExample.java b/example/session/src/main/java/org/apache/iotdb/SessionExample.java
index 1b22ebb..dd1989d 100644
--- a/example/session/src/main/java/org/apache/iotdb/SessionExample.java
+++ b/example/session/src/main/java/org/apache/iotdb/SessionExample.java
@@ -44,6 +44,7 @@ public class SessionExample {
insert();
// insertRowBatch();
+ delete();
session.close();
}
@@ -63,6 +64,12 @@ public class SessionExample {
}
}
+ private static void delete() throws IoTDBSessionException {
+ String path = "root.sg1.d1.s1";
+ long deleteTime = 29999;
+ session.delete(path, deleteTime);
+ }
+
private static void insertRowBatch() throws IoTDBSessionException {
Schema schema = new Schema();
schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java
index 1af20fb..2bd139b 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/DeletePlan.java
@@ -38,7 +38,7 @@ public class DeletePlan extends PhysicalPlan {
/**
* constructor of DeletePlan with single path.
*
- * @param deleteTime delete time
+ * @param deleteTime delete time (data points to be deleted in the timeseries whose time is <= deleteTime)
* @param path time series path
*/
public DeletePlan(long deleteTime, Path path) {
@@ -50,7 +50,7 @@ public class DeletePlan extends PhysicalPlan {
/**
* constructor of DeletePlan with multiple paths.
*
- * @param deleteTime delete time
+ * @param deleteTime delete time (data points to be deleted in the timeseries whose time is <= deleteTime)
* @param paths time series paths in List structure
*/
public DeletePlan(long deleteTime, List<Path> paths) {
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 3ca62fb..2d913bd 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
@@ -52,6 +52,7 @@ import org.apache.iotdb.db.qp.executor.QueryProcessExecutor;
import org.apache.iotdb.db.qp.logical.sys.MetadataOperator;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan;
+import org.apache.iotdb.db.qp.physical.crud.DeletePlan;
import org.apache.iotdb.db.qp.physical.crud.InsertPlan;
import org.apache.iotdb.db.qp.physical.sys.AuthorPlan;
import org.apache.iotdb.db.qp.physical.sys.MetadataPlan;
@@ -1022,6 +1023,24 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
}
@Override
+ public TSRPCResp deleteRow(TSDeleteReq req) throws TException {
+ if (!checkLogin()) {
+ logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
+ return new TSRPCResp(getStatus(TSStatusType.NOT_LOGIN_ERROR));
+ }
+
+ DeletePlan plan = new DeletePlan();
+ plan.setDeleteTime(req.getTimestamp());
+ plan.addPath(new Path(req.getPath()));
+
+ TS_Status status = checkAuthority(plan);
+ if (status != null) {
+ return new TSRPCResp(status);
+ }
+ return new TSRPCResp(executePlan(plan));
+ }
+
+ @Override
public TSExecuteBatchStatementResp insertBatch(TSBatchInsertionReq req) {
long t1 = System.currentTimeMillis();
try {
diff --git a/service-rpc/rpc-changelist.md b/service-rpc/rpc-changelist.md
index eff3f8d..b110d28 100644
--- a/service-rpc/rpc-changelist.md
+++ b/service-rpc/rpc-changelist.md
@@ -25,10 +25,12 @@
* Use struct **TSRPCResp** to replace all structs with only one field `1: required TS_Status status`, including: ~~TSCloseSessionResp~~ closeSession, ~~TSCancelOperationResp~~ cancelOperation, ~~TSCloseOperationResp~~ closeOperation, ~~TSSetTimeZoneResp~~ setTimeZone.
-* Add **TSBatchInsertionReq**, **TSCreateTimeseriesReq** and **TSSetStorageGroupReq**.
+* Add **TSBatchInsertionReq**, **TSCreateTimeseriesReq**, **TSSetStorageGroupReq** and **TSDeleteReq**.
* Change method name ~~TSExecuteStatementResp executeInsertion(1:TSInsertionReq req)~~ to **TSExecuteStatementResp insert(1:TSInsertionReq req)**, and add method **TSExecuteBatchStatementResp insertBatch(1:TSBatchInsertionReq req)** for batch inserting interface.
-* Add method **TSRPCResp setStorageGroup(1:TSSetStorageGroupReq req)** and **TSRPCResp createTimeseries(1:TSCreateTimeseriesReq req)** for creating matadata interface.
+* Add method **TSRPCResp setStorageGroup(1:TSSetStorageGroupReq req)** and **TSRPCResp createTimeseries(1:TSCreateTimeseriesReq req)** for creating metadata interface.
+
+* Add method **TSRPCResp deleteTimeseries(1:TSDeleteReq req)** for deleting timeseries.
* Change item in enum **TSProtocolVersion** from ~~TSFILE_SERVICE_PROTOCOL_V1~~ to IOTDB_SERVICE_PROTOCOL_V1.
diff --git a/service-rpc/src/main/thrift/rpc.thrift b/service-rpc/src/main/thrift/rpc.thrift
index 5cedb0c..6eb33b7 100644
--- a/service-rpc/src/main/thrift/rpc.thrift
+++ b/service-rpc/src/main/thrift/rpc.thrift
@@ -246,6 +246,11 @@ struct TSInsertReq {
4: required i64 timestamp
}
+struct TSDeleteReq {
+ 1: required string path
+ 2: required i64 timestamp
+}
+
struct TSSetStorageGroupReq {
1: required string storageGroupId
}
@@ -304,5 +309,7 @@ service TSIService {
TSRPCResp insertRow(1:TSInsertReq req);
+ TSRPCResp deleteRow(1:TSDeleteReq req);
+
i64 requestStatementId();
- }
+}
diff --git a/session/pom.xml b/session/pom.xml
index 87cb14b..406167b 100644
--- a/session/pom.xml
+++ b/session/pom.xml
@@ -76,5 +76,17 @@
<artifactId>tsfile</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>iotdb-server</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>iotdb-jdbc</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java b/session/src/main/java/org/apache/iotdb/session/Session.java
index 50e00fa..2ee79e9 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -172,6 +172,18 @@ public class Session {
}
}
+ public synchronized TSRPCResp delete(String path, long time) throws IoTDBSessionException {
+ TSDeleteReq request = new TSDeleteReq();
+ request.setPath(path);
+ request.setTimestamp(time);
+
+ try {
+ return client.deleteRow(request);
+ } catch (TException e) {
+ throw new IoTDBSessionException(e);
+ }
+ }
+
public synchronized TSRPCResp setStorageGroup(String storageGroupId) throws IoTDBSessionException {
TSSetStorageGroupReq request = new TSSetStorageGroupReq();
request.setStorageGroupId(storageGroupId);
diff --git a/example/session/src/main/java/org/apache/iotdb/SessionExample.java b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
similarity index 53%
copy from example/session/src/main/java/org/apache/iotdb/SessionExample.java
copy to session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
index 1b22ebb..67fce4e 100644
--- a/example/session/src/main/java/org/apache/iotdb/SessionExample.java
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
@@ -7,7 +7,7 @@
* "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
+ * 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
@@ -16,45 +16,74 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb;
+package org.apache.iotdb.session;
+import java.sql.*;
import java.util.ArrayList;
import java.util.List;
-import org.apache.iotdb.session.IoTDBSessionException;
-import org.apache.iotdb.session.Session;
+import org.apache.iotdb.db.service.IoTDB;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.session.utils.EnvironmentUtils;
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.write.record.RowBatch;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.apache.iotdb.tsfile.write.schema.Schema;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class SessionExample {
+public class IoTDBSessionIT {
- private static Session session;
+ private IoTDB daemon;
+ private Session session;
- public static void main(String[] args) throws IoTDBSessionException {
+ @Before
+ public void setUp() throws Exception {
+ EnvironmentUtils.closeStatMonitor();
+ daemon = IoTDB.getInstance();
+ daemon.active();
+ EnvironmentUtils.envSetUp();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ daemon.stop();
+ EnvironmentUtils.cleanEnv();
+ }
+
+ @Test
+ public void test() throws ClassNotFoundException, SQLException, IoTDBSessionException {
session = new Session("127.0.0.1", 6667, "root", "root");
session.open();
session.setStorageGroup("root.sg1");
- session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
- session.createTimeseries("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
- session.createTimeseries("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
- insert();
-// insertRowBatch();
+ createTimeseriesTest();
+ insertTest();
+// insertRowBatchTest();
+ deleteTest();
+
+ queryTest();
session.close();
}
- private static void insert() throws IoTDBSessionException {
+ public void createTimeseriesTest() throws IoTDBSessionException {
+ session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
+ session.createTimeseries("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
+ session.createTimeseries("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
+ }
+
+ public void insertTest() throws IoTDBSessionException {
String deviceId = "root.sg1.d1";
List<String> measurements = new ArrayList<>();
measurements.add("s1");
measurements.add("s2");
measurements.add("s3");
- for (long time = 0; time < 30000; time++) {
+ for (long time = 0; time < 100; time++) {
List<String> values = new ArrayList<>();
values.add("1");
values.add("2");
@@ -63,7 +92,7 @@ public class SessionExample {
}
}
- private static void insertRowBatch() throws IoTDBSessionException {
+ private void insertRowBatchTest() throws IoTDBSessionException {
Schema schema = new Schema();
schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE));
schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE));
@@ -74,7 +103,7 @@ public class SessionExample {
long[] timestamps = rowBatch.timestamps;
Object[] values = rowBatch.values;
- for (long time = 0; time < 30000; time++) {
+ for (long time = 0; time < 100; time++) {
int row = rowBatch.batchSize++;
timestamps[row] = time;
for (int i = 0; i < 3; i++) {
@@ -92,4 +121,39 @@ public class SessionExample {
rowBatch.reset();
}
}
-}
\ No newline at end of file
+
+ public void deleteTest() throws IoTDBSessionException {
+ String path1 = "root.sg1.d1.s1";
+ String path2 = "root.sg1.d1.s2";
+ String path3 = "root.sg1.d1.s3";
+ long deleteTime = 99;
+
+ session.delete(path1, deleteTime);
+ session.delete(path2, deleteTime);
+ session.delete(path3, deleteTime);
+ }
+
+ public void queryTest() throws ClassNotFoundException, SQLException {
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ String standard =
+ "Time\n" + "root.sg1.d1.s1\n" + "root.sg1.d1.s2\n" + "root.sg1.d1.s3\n";
+ try (Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+ ResultSet resultSet = statement.executeQuery("select * from root");
+ final ResultSetMetaData metaData = resultSet.getMetaData();
+ final int colCount = metaData.getColumnCount();
+ StringBuilder resultStr = new StringBuilder();
+ for (int i = 0; i < colCount; i++) {
+ resultStr.append(metaData.getColumnLabel(i + 1) + "\n");
+ }
+ while (resultSet.next()) {
+ for (int i = 1; i <= colCount; i++) {
+ resultStr.append(resultSet.getString(i)).append(",");
+ }
+ resultStr.append("\n");
+ }
+ Assert.assertEquals(resultStr.toString(), standard);
+ }
+ }
+}
diff --git a/session/src/test/java/org/apache/iotdb/session/utils/EnvironmentUtils.java b/session/src/test/java/org/apache/iotdb/session/utils/EnvironmentUtils.java
new file mode 100644
index 0000000..dbdbc79
--- /dev/null
+++ b/session/src/test/java/org/apache/iotdb/session/utils/EnvironmentUtils.java
@@ -0,0 +1,192 @@
+/**
+ * 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.session.utils;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.auth.authorizer.IAuthorizer;
+import org.apache.iotdb.db.auth.authorizer.LocalFileAuthorizer;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.conf.adapter.IoTDBConfigDynamicAdapter;
+import org.apache.iotdb.db.conf.directories.DirectoryManager;
+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.exception.StartupException;
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.metadata.MManager;
+import org.apache.iotdb.db.monitor.StatMonitor;
+import org.apache.iotdb.db.query.context.QueryContext;
+import org.apache.iotdb.db.query.control.FileReaderManager;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
+import org.apache.iotdb.db.writelog.manager.MultiFileLogNodeManager;
+import org.junit.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <p>
+ * This class is used for cleaning test environment in unit test and integration test
+ * </p>
+ */
+public class EnvironmentUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(EnvironmentUtils.class);
+
+ private static IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
+ private static DirectoryManager directoryManager = DirectoryManager.getInstance();
+
+ public static long TEST_QUERY_JOB_ID = QueryResourceManager.getInstance().assignJobId();
+ public static QueryContext TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID);
+
+ private static long oldTsFileThreshold = config.getTsFileSizeThreshold();
+
+ private static int oldMaxMemTableNumber = config.getMaxMemtableNumber();
+
+ private static long oldGroupSizeInByte = config.getMemtableSizeThreshold();
+
+ public static void cleanEnv() throws IOException, StorageEngineException {
+
+ QueryResourceManager.getInstance().endQueryForGivenJob(TEST_QUERY_JOB_ID);
+
+ // clear opened file streams
+ FileReaderManager.getInstance().closeAndRemoveAllOpenedReaders();
+
+ // clean storage group manager
+ if (!StorageEngine.getInstance().deleteAll()) {
+ logger.error("Can't close the storage group manager in EnvironmentUtils");
+ Assert.fail();
+ }
+ StorageEngine.getInstance().reset();
+ IoTDBDescriptor.getInstance().getConfig().setReadOnly(false);
+
+ StatMonitor.getInstance().close();
+ // clean wal
+ MultiFileLogNodeManager.getInstance().stop();
+ // clean cache
+ if (config.isMetaDataCacheEnable()) {
+ TsFileMetaDataCache.getInstance().clear();
+ DeviceMetaDataCache.getInstance().clear();
+ }
+ // close metadata
+ MManager.getInstance().clear();
+ // delete all directory
+ cleanAllDir();
+
+ config.setMaxMemtableNumber(oldMaxMemTableNumber);
+ config.setTsFileSizeThreshold(oldTsFileThreshold);
+ config.setMemtableSizeThreshold(oldGroupSizeInByte);
+ IoTDBConfigDynamicAdapter.getInstance().reset();
+ }
+
+ public static void cleanAllDir() throws IOException {
+ // delete sequential files
+ for (String path : directoryManager.getAllSequenceFileFolders()) {
+ cleanDir(path);
+ }
+ // delete unsequence files
+ for (String path : directoryManager.getAllUnSequenceFileFolders()) {
+ cleanDir(path);
+ }
+ // delete system info
+ cleanDir(config.getSystemDir());
+ // delete wal
+ cleanDir(config.getWalFolder());
+ // delete index
+ cleanDir(config.getIndexFileDir());
+ cleanDir(config.getBaseDir());
+ // delete data files
+ for (String dataDir : config.getDataDirs()) {
+ cleanDir(dataDir);
+ }
+ }
+
+ public static void cleanDir(String dir) throws IOException {
+ FileUtils.deleteDirectory(new File(dir));
+ }
+
+ /**
+ * disable the system monitor</br>
+ * this function should be called before all code in the setup
+ */
+ public static void closeStatMonitor() {
+ config.setEnableStatMonitor(false);
+ }
+
+ /**
+ * disable memory control</br>
+ * this function should be called before all code in the setup
+ */
+ public static void envSetUp() throws StartupException, IOException {
+ IoTDBDescriptor.getInstance().getConfig().setEnableParameterAdapter(false);
+ MManager.getInstance().init();
+ IoTDBConfigDynamicAdapter.getInstance().setInitialized(true);
+
+ createAllDir();
+ // disable the system monitor
+ config.setEnableStatMonitor(false);
+ IAuthorizer authorizer;
+ try {
+ authorizer = LocalFileAuthorizer.getInstance();
+ } catch (AuthException e) {
+ throw new StartupException(e);
+ }
+ try {
+ authorizer.reset();
+ } catch (AuthException e) {
+ throw new StartupException(e);
+ }
+ StorageEngine.getInstance().reset();
+ MultiFileLogNodeManager.getInstance().start();
+ FlushManager.getInstance().start();
+ TEST_QUERY_JOB_ID = QueryResourceManager.getInstance().assignJobId();
+ TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID);
+ }
+
+ private static void createAllDir() {
+ // create sequential files
+ for (String path : directoryManager.getAllSequenceFileFolders()) {
+ createDir(path);
+ }
+ // create unsequential files
+ for (String path : directoryManager.getAllUnSequenceFileFolders()) {
+ createDir(path);
+ }
+ // create storage group
+ createDir(config.getSystemDir());
+ // create wal
+ createDir(config.getWalFolder());
+ // create index
+ createDir(config.getIndexFileDir());
+ // create data
+ for (String dataDir: config.getDataDirs()) {
+ createDir(dataDir);
+ }
+ }
+
+ private static void createDir(String dir) {
+ File file = new File(dir);
+ file.mkdirs();
+ }
+}