You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/01/21 01:04:11 UTC
[iotdb] 01/01: Fix NoSuchFileException while querying and ttl happened same time
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch FileTimeIndexTTL
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit b723a003110ffeeaf8463af51a6410838447796f
Author: JackieTien97 <ja...@gmail.com>
AuthorDate: Fri Jan 21 09:03:04 2022 +0800
Fix NoSuchFileException while querying and ttl happened same time
---
.../apache/iotdb/db/engine/storagegroup/TsFileResource.java | 2 +-
.../db/engine/storagegroup/timeindex/DeviceTimeIndex.java | 3 ++-
.../db/engine/storagegroup/timeindex/FileTimeIndex.java | 13 ++++++++++++-
.../iotdb/db/engine/storagegroup/timeindex/ITimeIndex.java | 3 ++-
4 files changed, 17 insertions(+), 4 deletions(-)
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 630df4f..410ce81 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
@@ -427,7 +427,7 @@ public class TsFileResource {
}
public Set<String> getDevices() {
- return timeIndex.getDevices(file.getPath());
+ return timeIndex.getDevices(file.getPath(), this);
}
public boolean endTimeEmpty() {
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
index d7a7122..ce65f62 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
@@ -20,6 +20,7 @@
package org.apache.iotdb.db.engine.storagegroup.timeindex;
import org.apache.iotdb.db.engine.StorageEngine;
+import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
import org.apache.iotdb.db.exception.PartitionViolationException;
import org.apache.iotdb.db.rescon.CachedStringPool;
import org.apache.iotdb.db.utils.SerializeUtils;
@@ -160,7 +161,7 @@ public class DeviceTimeIndex implements ITimeIndex {
}
@Override
- public Set<String> getDevices(String tsFilePath) {
+ public Set<String> getDevices(String tsFilePath, TsFileResource tsFileResource) {
return deviceToIndex.keySet();
}
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
index 5defc50..b0768be 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
@@ -20,6 +20,7 @@
package org.apache.iotdb.db.engine.storagegroup.timeindex;
import org.apache.iotdb.db.engine.StorageEngine;
+import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
import org.apache.iotdb.db.exception.PartitionViolationException;
import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
import org.apache.iotdb.tsfile.utils.FilePathUtils;
@@ -33,6 +34,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
+import java.nio.file.NoSuchFileException;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -79,9 +82,17 @@ public class FileTimeIndex implements ITimeIndex {
}
@Override
- public Set<String> getDevices(String tsFilePath) {
+ public Set<String> getDevices(String tsFilePath, TsFileResource tsFileResource) {
try (TsFileSequenceReader fileReader = new TsFileSequenceReader(tsFilePath)) {
return new HashSet<>(fileReader.getAllDevices());
+ } catch (NoSuchFileException e) {
+ // deleted by ttl
+ if (tsFileResource.isDeleted()) {
+ return Collections.emptySet();
+ } else {
+ logger.error("Can't read file {} from disk ", tsFilePath, e);
+ throw new RuntimeException("Can't read file " + tsFilePath + " from disk");
+ }
} catch (IOException e) {
logger.error("Can't read file {} from disk ", tsFilePath, e);
throw new RuntimeException("Can't read file " + tsFilePath + " from disk");
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/ITimeIndex.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/ITimeIndex.java
index 37fac06..9252aa4 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/ITimeIndex.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/ITimeIndex.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.engine.storagegroup.timeindex;
+import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
import org.apache.iotdb.db.exception.PartitionViolationException;
import java.io.IOException;
@@ -62,7 +63,7 @@ public interface ITimeIndex {
*
* @return device names
*/
- Set<String> getDevices(String tsFilePath);
+ Set<String> getDevices(String tsFilePath, TsFileResource tsFileResource);
/** @return whether end time is empty (Long.MIN_VALUE) */
boolean endTimeEmpty();