You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by su...@apache.org on 2021/03/30 02:01:30 UTC
[iotdb] branch rel/0.11 updated: [IOTDB-1194] [To rel/0.11] Fix a
bug of checking time partition in DeviceTimeIndex in rel/0.11 (#2895)
This is an automated email from the ASF dual-hosted git repository.
sunzesong pushed a commit to branch rel/0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.11 by this push:
new 76970d0 [IOTDB-1194] [To rel/0.11] Fix a bug of checking time partition in DeviceTimeIndex in rel/0.11 (#2895)
76970d0 is described below
commit 76970d0b47e4afb07f344d5e0898f93462f2aae6
Author: Ring-k <36...@users.noreply.github.com>
AuthorDate: Tue Mar 30 10:01:11 2021 +0800
[IOTDB-1194] [To rel/0.11] Fix a bug of checking time partition in DeviceTimeIndex in rel/0.11 (#2895)
* add it
* format
* rename IT
* remove attr of config in storage engine
* recover Storage Engine
* recover storage engine
* start up
---
.../org/apache/iotdb/db/engine/StorageEngine.java | 9 +-
.../db/engine/storagegroup/TsFileResource.java | 16 +-
.../iotdb/db/integration/IoTDBLargeDataIT.java | 696 ++++++++++-----------
...IoTDBLoadExternalTsfileWithTimePartitionIT.java | 204 ++++++
4 files changed, 562 insertions(+), 363 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
index 8bd7155..5f08ea4 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
@@ -122,7 +122,6 @@ public class StorageEngine implements IService {
private ExecutorService recoverAllSgThreadPool;
-
static class InstanceHolder {
private InstanceHolder() {
@@ -386,7 +385,8 @@ public class StorageEngine implements IService {
public void insert(InsertRowsOfOneDevicePlan insertRowsOfOneDevicePlan)
throws StorageEngineException {
- StorageGroupProcessor storageGroupProcessor = getProcessor(insertRowsOfOneDevicePlan.getDeviceId());
+ StorageGroupProcessor storageGroupProcessor = getProcessor(
+ insertRowsOfOneDevicePlan.getDeviceId());
// TODO monitor: update statistics
try {
@@ -855,8 +855,9 @@ public class StorageEngine implements IService {
try {
TimeUnit.MILLISECONDS.sleep(config.getCheckPeriodWhenInsertBlocked());
if (System.currentTimeMillis() - startTime > config.getMaxWaitingTimeWhenInsertBlocked()) {
- throw new WriteProcessRejectException("System rejected over " + config.getMaxWaitingTimeWhenInsertBlocked() +
- "ms");
+ throw new WriteProcessRejectException(
+ "System rejected over " + config.getMaxWaitingTimeWhenInsertBlocked() +
+ "ms");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileResource.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileResource.java
index 2cca8d7..2433259 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileResource.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileResource.java
@@ -717,8 +717,8 @@ public class TsFileResource {
*/
public long getTimePartitionWithCheck() throws PartitionViolationException {
long partitionId = -1;
- for (Long startTime : startTimes) {
- long p = StorageEngine.getTimePartition(startTime);
+ for (int index : deviceToIndex.values()) {
+ long p = StorageEngine.getTimePartition(startTimes[index]);
if (partitionId == -1) {
partitionId = p;
} else {
@@ -726,15 +726,9 @@ public class TsFileResource {
throw new PartitionViolationException(this);
}
}
- }
- for (Long endTime : endTimes) {
- long p = StorageEngine.getTimePartition(endTime);
- if (partitionId == -1) {
- partitionId = p;
- } else {
- if (partitionId != p) {
- throw new PartitionViolationException(this);
- }
+ p = StorageEngine.getTimePartition(endTimes[index]);
+ if (partitionId != p) {
+ throw new PartitionViolationException(this);
}
}
if (partitionId == -1) {
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLargeDataIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLargeDataIT.java
index d949d05..7506602 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLargeDataIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLargeDataIT.java
@@ -1,348 +1,348 @@
-/*
- * 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 static org.junit.Assert.fail;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import org.apache.iotdb.db.conf.IoTDBConstant;
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.constant.TestConstant;
-import org.apache.iotdb.db.engine.compaction.CompactionStrategy;
-import org.apache.iotdb.db.utils.EnvironmentUtils;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
-import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Notice that, all test begins with "IoTDB" is integration test. All test which will start the IoTDB server should be
- * defined as integration test.
- */
-public class IoTDBLargeDataIT {
-
- private static TSFileConfig tsFileConfig = TSFileDescriptor.getInstance().getConfig();
- private static int maxNumberOfPointsInPage;
- private static int pageSizeInByte;
- private static int groupSizeInByte;
-
- @BeforeClass
- public static void setUp() throws Exception {
-
- EnvironmentUtils.closeStatMonitor();
- IoTDBDescriptor.getInstance().getConfig()
- .setCompactionStrategy(CompactionStrategy.NO_COMPACTION);
-
- // use small page setting
- // origin value
- maxNumberOfPointsInPage = tsFileConfig.getMaxNumberOfPointsInPage();
- pageSizeInByte = tsFileConfig.getPageSizeInByte();
- groupSizeInByte = tsFileConfig.getGroupSizeInByte();
-
- // new value
- tsFileConfig.setMaxNumberOfPointsInPage(1000);
- tsFileConfig.setPageSizeInByte(1024 * 150);
- tsFileConfig.setGroupSizeInByte(1024 * 1000);
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(1024 * 1000);
-
- EnvironmentUtils.envSetUp();
-
- insertData();
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
-
- // recovery value
- tsFileConfig.setMaxNumberOfPointsInPage(maxNumberOfPointsInPage);
- tsFileConfig.setPageSizeInByte(pageSizeInByte);
- tsFileConfig.setGroupSizeInByte(groupSizeInByte);
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(groupSizeInByte);
- IoTDBDescriptor.getInstance().getConfig()
- .setCompactionStrategy(CompactionStrategy.LEVEL_COMPACTION);
-
- EnvironmentUtils.cleanEnv();
- }
-
- private static void insertData()
- throws ClassNotFoundException, SQLException, InterruptedException {
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
-
- for (String sql : TestConstant.create_sql) {
- statement.execute(sql);
- }
-
- // insert large amount of data time range : 13700 ~ 24000
- for (int time = 13700; time < 24000; time++) {
-
- String sql = String
- .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time % 40);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time % 123);
- statement.execute(sql);
- }
-
- // insert large amount of data time range : 3000 ~ 13600
- for (int time = 3000; time < 13600; time++) {
- // System.out.println("===" + time);
- String sql = String
- .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time % 100);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time % 17);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time % 22);
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s3) values(%s,'%s')", time,
- TestConstant.stringValue[time % 5]);
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s4) values(%s, %s)", time,
- TestConstant.booleanValue[time % 2]);
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s5) values(%s, %s)", time, time);
- statement.execute(sql);
- }
-
- statement.execute("flush");
- statement.execute("merge");
-
- // buffwrite data, unsealed file
- for (int time = 100000; time < 101000; time++) {
-
- String sql = String
- .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time % 20);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time % 30);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time % 77);
- statement.execute(sql);
- }
-
- statement.execute("flush");
-
- // sequential data, memory data
- for (int time = 200000; time < 201000; time++) {
-
- String sql = String
- .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, -time % 20);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, -time % 30);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, -time % 77);
- statement.execute(sql);
- }
-
- // unseq insert, time < 3000
- for (int time = 2000; time < 2500; time++) {
-
- String sql = String
- .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time + 1);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time + 2);
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s3) values(%s,'%s')", time,
- TestConstant.stringValue[time % 5]);
- statement.execute(sql);
- }
-
- // seq insert, time > 200000
- for (int time = 200900; time < 201000; time++) {
-
- String sql = String
- .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, 6666);
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, 7777);
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, 8888);
- statement.execute(sql);
- sql = String
- .format("insert into root.vehicle.d0(timestamp,s3) values(%s,'%s')", time, "goodman");
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s4) values(%s, %s)", time,
- TestConstant.booleanValue[time % 2]);
- statement.execute(sql);
- sql = String.format("insert into root.vehicle.d0(timestamp,s5) values(%s, %s)", time, 9999);
- statement.execute(sql);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- // "select * from root.vehicle" : test select wild data
- @Test
- public void selectAllTest() throws ClassNotFoundException, SQLException {
- String selectSql = "select * from root.vehicle";
-
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
-
- boolean hasResultSet = statement.execute(selectSql);
- Assert.assertTrue(hasResultSet);
-
- try (ResultSet resultSet = statement.getResultSet()) {
- int cnt = 0;
- while (resultSet.next()) {
- String ans =
- resultSet.getString(TestConstant.TIMESTAMP_STR) + "," + resultSet.getString(
- TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s0)
- + "," + resultSet.getString(
- TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s1) + "," + resultSet
- .getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s2) + ","
- + resultSet.getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s3) + "," + resultSet.getString(
- TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s4)
- + ","
- + resultSet.getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s5);
- cnt++;
- }
-
- assertEquals(23400, cnt);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- // "select s0 from root.vehicle.d0 where s0 >= 20" : test select same series with same series filter
- @Test
- public void selectOneSeriesWithValueFilterTest() throws ClassNotFoundException, SQLException {
-
- String selectSql = "select s0 from root.vehicle.d0 where s0 >= 20";
-
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
-Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(selectSql);
- Assert.assertTrue(hasResultSet);
-
- try (ResultSet resultSet = statement.getResultSet()) {
- int cnt = 0;
- while (resultSet.next()) {
- String ans =
- resultSet.getString(TestConstant.TIMESTAMP_STR) + "," + resultSet.getString(
- TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s0);
- // System.out.println("===" + ans);
- cnt++;
- }
- assertEquals(16440, cnt);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- // "select s0 from root.vehicle.d0 where time > 22987 " : test select clause with only global time filter
- @Test
- public void seriesGlobalTimeFilterTest() throws ClassNotFoundException, SQLException {
-
- Class.forName(Config.JDBC_DRIVER_NAME);
-
- boolean hasResultSet;
-
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement();) {
- hasResultSet = statement.execute("select s0 from root.vehicle.d0 where time > 22987");
- assertTrue(hasResultSet);
-
- int cnt = 0;
- try (ResultSet resultSet = statement.getResultSet();) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString(TestConstant.TIMESTAMP_STR) + "," + resultSet.getString(
- TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s0);
-// System.out.println(ans);
- cnt++;
- }
-
- assertEquals(3012, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- // "select s1 from root.vehicle.d0 where s0 < 111" : test select clause with different series filter
- @Test
- public void crossSeriesReadUpdateTest() throws ClassNotFoundException, SQLException {
- Class.forName(Config.JDBC_DRIVER_NAME);
-
- boolean hasResultSet;
- try (Connection connection = DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
- hasResultSet = statement.execute("select s1 from root.vehicle.d0 where s0 < 111");
- assertTrue(hasResultSet);
-
- try (ResultSet resultSet = statement.getResultSet()) {
- int cnt = 0;
- while (resultSet.next()) {
- long time = Long.parseLong(resultSet.getString(
- TestConstant.TIMESTAMP_STR));
- String value = resultSet.getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s1);
- if (time > 200900) {
- assertEquals("7777", value);
- }
- // String ans = resultSet.getString(d0s1);
- cnt++;
- }
- assertEquals(22800, cnt);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-}
+/*
+ * 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 static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.constant.TestConstant;
+import org.apache.iotdb.db.engine.compaction.CompactionStrategy;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
+import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Notice that, all test begins with "IoTDB" is integration test. All test which will start the IoTDB server should be
+ * defined as integration test.
+ */
+public class IoTDBLargeDataIT {
+
+ private static TSFileConfig tsFileConfig = TSFileDescriptor.getInstance().getConfig();
+ private static int maxNumberOfPointsInPage;
+ private static int pageSizeInByte;
+ private static int groupSizeInByte;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+
+ EnvironmentUtils.closeStatMonitor();
+ IoTDBDescriptor.getInstance().getConfig()
+ .setCompactionStrategy(CompactionStrategy.NO_COMPACTION);
+
+ // use small page setting
+ // origin value
+ maxNumberOfPointsInPage = tsFileConfig.getMaxNumberOfPointsInPage();
+ pageSizeInByte = tsFileConfig.getPageSizeInByte();
+ groupSizeInByte = tsFileConfig.getGroupSizeInByte();
+
+ // new value
+ tsFileConfig.setMaxNumberOfPointsInPage(1000);
+ tsFileConfig.setPageSizeInByte(1024 * 150);
+ tsFileConfig.setGroupSizeInByte(1024 * 1000);
+ IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(1024 * 1000);
+
+ EnvironmentUtils.envSetUp();
+
+ insertData();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+
+ // recovery value
+ tsFileConfig.setMaxNumberOfPointsInPage(maxNumberOfPointsInPage);
+ tsFileConfig.setPageSizeInByte(pageSizeInByte);
+ tsFileConfig.setGroupSizeInByte(groupSizeInByte);
+ IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(groupSizeInByte);
+ IoTDBDescriptor.getInstance().getConfig()
+ .setCompactionStrategy(CompactionStrategy.LEVEL_COMPACTION);
+
+ EnvironmentUtils.cleanEnv();
+ }
+
+ private static void insertData()
+ throws ClassNotFoundException, SQLException, InterruptedException {
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+
+ for (String sql : TestConstant.create_sql) {
+ statement.execute(sql);
+ }
+
+ // insert large amount of data time range : 13700 ~ 24000
+ for (int time = 13700; time < 24000; time++) {
+
+ String sql = String
+ .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time % 70);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time % 40);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time % 123);
+ statement.execute(sql);
+ }
+
+ // insert large amount of data time range : 3000 ~ 13600
+ for (int time = 3000; time < 13600; time++) {
+ // System.out.println("===" + time);
+ String sql = String
+ .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time % 100);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time % 17);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time % 22);
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s3) values(%s,'%s')", time,
+ TestConstant.stringValue[time % 5]);
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s4) values(%s, %s)", time,
+ TestConstant.booleanValue[time % 2]);
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s5) values(%s, %s)", time, time);
+ statement.execute(sql);
+ }
+
+ statement.execute("flush");
+ statement.execute("merge");
+
+ // buffwrite data, unsealed file
+ for (int time = 100000; time < 101000; time++) {
+
+ String sql = String
+ .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time % 20);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time % 30);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time % 77);
+ statement.execute(sql);
+ }
+
+ statement.execute("flush");
+
+ // sequential data, memory data
+ for (int time = 200000; time < 201000; time++) {
+
+ String sql = String
+ .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, -time % 20);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, -time % 30);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, -time % 77);
+ statement.execute(sql);
+ }
+
+ // unseq insert, time < 3000
+ for (int time = 2000; time < 2500; time++) {
+
+ String sql = String
+ .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, time);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, time + 1);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, time + 2);
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s3) values(%s,'%s')", time,
+ TestConstant.stringValue[time % 5]);
+ statement.execute(sql);
+ }
+
+ // seq insert, time > 200000
+ for (int time = 200900; time < 201000; time++) {
+
+ String sql = String
+ .format("insert into root.vehicle.d0(timestamp,s0) values(%s,%s)", time, 6666);
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s1) values(%s,%s)", time, 7777);
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s2) values(%s,%s)", time, 8888);
+ statement.execute(sql);
+ sql = String
+ .format("insert into root.vehicle.d0(timestamp,s3) values(%s,'%s')", time, "goodman");
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s4) values(%s, %s)", time,
+ TestConstant.booleanValue[time % 2]);
+ statement.execute(sql);
+ sql = String.format("insert into root.vehicle.d0(timestamp,s5) values(%s, %s)", time, 9999);
+ statement.execute(sql);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ // "select * from root.vehicle" : test select wild data
+ @Test
+ public void selectAllTest() throws ClassNotFoundException, SQLException {
+ String selectSql = "select * from root.vehicle";
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+
+ boolean hasResultSet = statement.execute(selectSql);
+ Assert.assertTrue(hasResultSet);
+
+ try (ResultSet resultSet = statement.getResultSet()) {
+ int cnt = 0;
+ while (resultSet.next()) {
+ String ans =
+ resultSet.getString(TestConstant.TIMESTAMP_STR) + "," + resultSet.getString(
+ TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s0)
+ + "," + resultSet.getString(
+ TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s1) + "," + resultSet
+ .getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s2) + ","
+ + resultSet.getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s3) + "," + resultSet.getString(
+ TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s4)
+ + ","
+ + resultSet.getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s5);
+ cnt++;
+ }
+
+ assertEquals(23400, cnt);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ // "select s0 from root.vehicle.d0 where s0 >= 20" : test select same series with same series filter
+ @Test
+ public void selectOneSeriesWithValueFilterTest() throws ClassNotFoundException, SQLException {
+
+ String selectSql = "select s0 from root.vehicle.d0 where s0 >= 20";
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+Statement statement = connection.createStatement()) {
+ boolean hasResultSet = statement.execute(selectSql);
+ Assert.assertTrue(hasResultSet);
+
+ try (ResultSet resultSet = statement.getResultSet()) {
+ int cnt = 0;
+ while (resultSet.next()) {
+ String ans =
+ resultSet.getString(TestConstant.TIMESTAMP_STR) + "," + resultSet.getString(
+ TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s0);
+ // System.out.println("===" + ans);
+ cnt++;
+ }
+ assertEquals(16440, cnt);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ // "select s0 from root.vehicle.d0 where time > 22987 " : test select clause with only global time filter
+ @Test
+ public void seriesGlobalTimeFilterTest() throws ClassNotFoundException, SQLException {
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+
+ boolean hasResultSet;
+
+ try (Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement();) {
+ hasResultSet = statement.execute("select s0 from root.vehicle.d0 where time > 22987");
+ assertTrue(hasResultSet);
+
+ int cnt = 0;
+ try (ResultSet resultSet = statement.getResultSet();) {
+ while (resultSet.next()) {
+ String ans =
+ resultSet.getString(TestConstant.TIMESTAMP_STR) + "," + resultSet.getString(
+ TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s0);
+// System.out.println(ans);
+ cnt++;
+ }
+
+ assertEquals(3012, cnt);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ // "select s1 from root.vehicle.d0 where s0 < 111" : test select clause with different series filter
+ @Test
+ public void crossSeriesReadUpdateTest() throws ClassNotFoundException, SQLException {
+ Class.forName(Config.JDBC_DRIVER_NAME);
+
+ boolean hasResultSet;
+ try (Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+ hasResultSet = statement.execute("select s1 from root.vehicle.d0 where s0 < 111");
+ assertTrue(hasResultSet);
+
+ try (ResultSet resultSet = statement.getResultSet()) {
+ int cnt = 0;
+ while (resultSet.next()) {
+ long time = Long.parseLong(resultSet.getString(
+ TestConstant.TIMESTAMP_STR));
+ String value = resultSet.getString(TestConstant.d0 + IoTDBConstant.PATH_SEPARATOR + TestConstant.s1);
+ if (time > 200900) {
+ assertEquals("7777", value);
+ }
+ // String ans = resultSet.getString(d0s1);
+ cnt++;
+ }
+ assertEquals(22800, cnt);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLoadExternalTsfileWithTimePartitionIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLoadExternalTsfileWithTimePartitionIT.java
new file mode 100644
index 0000000..25b8741
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLoadExternalTsfileWithTimePartitionIT.java
@@ -0,0 +1,204 @@
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Arrays;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.engine.StorageEngine;
+import org.apache.iotdb.db.engine.compaction.CompactionStrategy;
+import org.apache.iotdb.db.exception.metadata.IllegalPathException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.db.utils.FileUtils;
+import org.apache.iotdb.jdbc.Config;
+import org.apache.iotdb.tsfile.exception.write.WriteProcessException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.fileSystem.FSFactoryProducer;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.write.TsFileWriter;
+import org.apache.iotdb.tsfile.write.record.TSRecord;
+import org.apache.iotdb.tsfile.write.record.datapoint.DataPoint;
+import org.apache.iotdb.tsfile.write.record.datapoint.LongDataPoint;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+import org.apache.iotdb.tsfile.write.writer.TsFileIOWriter;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class IoTDBLoadExternalTsfileWithTimePartitionIT {
+
+ String DOT = ".";
+ String tempDir = "temp";
+
+ String STORAGE_GROUP = "root.ln";
+ String[] devices = new String[]{"d1", "d2"};
+ String[] measurements = new String[]{"s1", "s2"};
+
+ // generate several tsfiles, with timestamp from startTime(inclusive) to endTime(exclusive)
+ long startTime = 0;
+ long endTime = 1000_000;
+
+ long timePartition = 100;// unit s
+
+ boolean originalIsEnablePartition;
+ long originalPartitionInterval;
+
+ IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
+
+ @Before
+ public void setUp() throws Exception {
+ originalIsEnablePartition = config.isEnablePartition();
+ originalPartitionInterval = config.getPartitionInterval();
+ EnvironmentUtils.closeStatMonitor();
+ EnvironmentUtils.envSetUp();
+ Class.forName(Config.JDBC_DRIVER_NAME);
+
+ StorageEngine.setEnablePartition(true);
+ StorageEngine.setTimePartitionInterval(timePartition);
+
+ prepareData();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ EnvironmentUtils.cleanEnv();
+ IoTDBDescriptor.getInstance()
+ .getConfig()
+ .setCompactionStrategy(CompactionStrategy.LEVEL_COMPACTION);
+ StorageEngine.setEnablePartition(originalIsEnablePartition);
+ StorageEngine.setTimePartitionInterval(originalPartitionInterval);
+ File f = new File(tempDir);
+ if (f.exists()) {
+ FileUtils.deleteDirectory(f);
+ }
+ }
+
+ /**
+ * get the name of tsfile given counter
+ */
+ String getName(int counter) {
+ return tempDir + File.separator + System.currentTimeMillis() + "-" + counter
+ + "-0.tsfile";
+ }
+
+ /**
+ * write a record, given timestamp
+ */
+ void writeData(TsFileWriter tsFileWriter, long timestamp)
+ throws IOException, WriteProcessException {
+ for (String deviceId : devices) {
+ TSRecord tsRecord = new TSRecord(timestamp,
+ STORAGE_GROUP + DOT + deviceId);
+ for (String measurement : measurements) {
+ DataPoint dPoint = new LongDataPoint(measurement, 10000);
+ tsRecord.addTuple(dPoint);
+ }
+ tsFileWriter.write(tsRecord);
+ }
+ }
+
+ /**
+ * register all timeseries in tsfiles
+ */
+ void register(TsFileWriter tsFileWriter) {
+ try {
+ for (String deviceId : devices) {
+ for (String measurement : measurements) {
+ tsFileWriter.registerTimeseries(
+ new Path(STORAGE_GROUP + DOT + deviceId, measurement),
+ new MeasurementSchema(measurement, TSDataType.INT64, TSEncoding.RLE));
+ }
+ }
+ } catch (WriteProcessException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * create multiple tsfiles, each correspond to a time partition.
+ */
+ private void prepareData() throws IOException {
+ File dir = new File(tempDir);
+ if (dir.exists()) {
+ FileUtils.deleteDirectory(dir);
+ }
+ dir.mkdir();
+ try {
+ File f;
+ TsFileWriter tsFileWriter = null;
+ int counter = 0;
+ for (long timestamp = startTime; timestamp < endTime; timestamp += 1000) {
+ if (timestamp % (timePartition * 1000) == 0) {
+ if (tsFileWriter != null) {
+ tsFileWriter.flushAllChunkGroups();
+ tsFileWriter.close();
+ counter++;
+ }
+ String path = getName(counter);
+ f = FSFactoryProducer.getFSFactory().getFile(path);
+ tsFileWriter = new TsFileWriter(new TsFileIOWriter(f));
+ register(tsFileWriter);
+ }
+ writeData(tsFileWriter, timestamp);
+ }
+ tsFileWriter.flushAllChunkGroups();
+ tsFileWriter.close();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+
+ }
+
+
+ @Test
+ public void loadTsfileWithTimePartition() {
+ try (Connection connection =
+ DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+
+ statement.execute(String.format("load \"%s\"", new File(tempDir).getAbsolutePath()));
+
+ String dataDir = config.getDataDirs()[0];
+ File f = new File(dataDir,
+ new PartialPath("sequence") + File.separator + "root.ln");
+ System.out.println(Arrays.toString(f.list()));
+ Assert.assertEquals((endTime - startTime) / (timePartition * 1000), f.list().length);
+
+ for (int i = 0; i < (endTime - startTime) / (timePartition * 1000); i++) {
+ Assert.assertEquals("" + i, f.list()[i]);
+ }
+ // each time partition folder should contain 2 files, the tsfile and the resource file
+ for (int i = 0; i < (endTime - startTime) / (timePartition * 1000); i++) {
+ Assert.assertEquals(2, new File(f.getAbsolutePath(), "" + i).list().length);
+ }
+ } catch (SQLException | IllegalPathException throwables) {
+ throwables.printStackTrace();
+ }
+ }
+
+}
\ No newline at end of file