You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/07/20 08:10:40 UTC
[iotdb] branch rel/0.11 updated: [IoTDB-1513] fix recover
TsFileResource time bug in restart (#3601)
This is an automated email from the ASF dual-hosted git repository.
haonan 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 6f6d0d3 [IoTDB-1513] fix recover TsFileResource time bug in restart (#3601)
6f6d0d3 is described below
commit 6f6d0d3ddc7bd08b56b8b6b3120f8d60002b3182
Author: Jialin Qiao <qj...@mails.tsinghua.edu.cn>
AuthorDate: Tue Jul 20 03:10:16 2021 -0500
[IoTDB-1513] fix recover TsFileResource time bug in restart (#3601)
---
.../writelog/recover/TsFileRecoverPerformer.java | 25 ++++++++---
.../iotdb/db/integration/IoTDBRestartIT.java | 49 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java b/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java
index cd5e7b3..7f39525 100644
--- a/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java
+++ b/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java
@@ -23,7 +23,9 @@ import static org.apache.iotdb.db.engine.storagegroup.TsFileResource.RESOURCE_SU
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -191,13 +193,24 @@ public class TsFileRecoverPerformer {
for (Map.Entry<String, List<ChunkMetadata>> entry : deviceChunkMetaDataMap.entrySet()) {
String deviceId = entry.getKey();
List<ChunkMetadata> chunkMetadataList = entry.getValue();
- TSDataType dataType = entry.getValue().get(entry.getValue().size() - 1).getDataType();
- for (ChunkMetadata chunkMetaData : chunkMetadataList) {
- if (!chunkMetaData.getDataType().equals(dataType)) {
- continue;
+
+ // measurement -> List<ChunkMetadata>
+ Map<String, List<ChunkMetadata>> measurementToChunkMetadatas = new HashMap<>();
+ for (ChunkMetadata chunkMetadata : chunkMetadataList) {
+ List<ChunkMetadata> list = measurementToChunkMetadatas
+ .computeIfAbsent(chunkMetadata.getMeasurementUid(), n -> new ArrayList<>());
+ list.add(chunkMetadata);
+ }
+
+ for (List<ChunkMetadata> metadataList : measurementToChunkMetadatas.values()) {
+ TSDataType dataType = metadataList.get(metadataList.size() - 1).getDataType();
+ for (ChunkMetadata chunkMetaData : chunkMetadataList) {
+ if (!chunkMetaData.getDataType().equals(dataType)) {
+ continue;
+ }
+ tsFileResource.updateStartTime(deviceId, chunkMetaData.getStartTime());
+ tsFileResource.updateEndTime(deviceId, chunkMetaData.getEndTime());
}
- tsFileResource.updateStartTime(deviceId, chunkMetaData.getStartTime());
- tsFileResource.updateEndTime(deviceId, chunkMetaData.getEndTime());
}
}
long fileVersion = Long.parseLong(
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBRestartIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBRestartIT.java
index c40f9b2..b45ac83 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBRestartIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBRestartIT.java
@@ -28,6 +28,8 @@ import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.jdbc.Config;
@@ -350,6 +352,53 @@ public class IoTDBRestartIT {
EnvironmentUtils.cleanEnv();
}
+
+ @Test
+ public void testRecoverWALDeleteSchemaCheckResourceTime() throws Exception {
+ EnvironmentUtils.envSetUp();
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
+ int avgSeriesPointNumberThreshold = config.getAvgSeriesPointNumberThreshold();
+ config.setAvgSeriesPointNumberThreshold(2);
+ long tsfileSize = config.getTsFileSizeThreshold();
+ config.setTsFileSizeThreshold(10000000);
+
+ try(Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",
+ "root");
+ Statement statement = connection.createStatement()){
+ statement.execute("create timeseries root.turbine1.d1.s1 with datatype=INT64");
+ statement.execute("insert into root.turbine1.d1(timestamp,s1) values(1,1)");
+ statement.execute("insert into root.turbine1.d1(timestamp,s1) values(2,1)");
+ statement.execute("create timeseries root.turbine1.d1.s2 with datatype=BOOLEAN");
+ statement.execute("insert into root.turbine1.d1(timestamp,s2) values(3,true)");
+ statement.execute("insert into root.turbine1.d1(timestamp,s2) values(4,true)");
+ }
+
+ Thread.sleep(1000);
+ EnvironmentUtils.restartDaemon();
+
+ try(Connection connection = DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",
+ "root");
+ Statement statement = connection.createStatement()){
+
+ long[] result = new long[]{1L,2L};
+ statement.execute("select s1 from root.turbine1.d1 where time < 3");
+ ResultSet resultSet = statement.getResultSet();
+ int cnt = 0;
+ while (resultSet.next()) {
+ assertEquals(resultSet.getLong(1), result[cnt]);
+ cnt++;
+ }
+ assertEquals(2, cnt);
+ }
+
+ config.setAvgSeriesPointNumberThreshold(avgSeriesPointNumberThreshold);
+ config.setTsFileSizeThreshold(tsfileSize);
+ EnvironmentUtils.cleanEnv();
+ }
+
@Test
public void testRestartCompaction()
throws SQLException, ClassNotFoundException, IOException, StorageEngineException {