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 2021/07/18 05:13:48 UTC
[iotdb] branch master updated: add checkDeviceIdExist method to
ITimeIndex (#3562)
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/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new df46873 add checkDeviceIdExist method to ITimeIndex (#3562)
df46873 is described below
commit df468736fb1fb2b63afa39801348d40d599ba44a
Author: Yuting Yan <56...@users.noreply.github.com>
AuthorDate: Sun Jul 18 00:13:20 2021 -0500
add checkDeviceIdExist method to ITimeIndex (#3562)
---
.../db/engine/storagegroup/StorageGroupProcessor.java | 9 +++------
.../iotdb/db/engine/storagegroup/TsFileProcessor.java | 5 ++---
.../iotdb/db/engine/storagegroup/TsFileResource.java | 10 +++++++---
.../db/engine/storagegroup/timeindex/DeviceTimeIndex.java | 13 +++++--------
.../db/engine/storagegroup/timeindex/FileTimeIndex.java | 5 +++++
.../iotdb/db/engine/storagegroup/timeindex/ITimeIndex.java | 8 ++++++++
.../db/engine/storagegroup/timeindex/TimeIndexLevel.java | 10 ----------
.../iotdb/db/engine/storagegroup/TsFileProcessorTest.java | 14 ++++----------
8 files changed, 34 insertions(+), 40 deletions(-)
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 66110a1..be469be 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
@@ -1263,8 +1263,7 @@ public class StorageGroupProcessor {
storageGroupInfo,
this::closeUnsealedTsFileProcessorCallBack,
this::updateLatestFlushTimeCallback,
- true,
- deviceNumInLastClosedTsFile);
+ true);
} else {
tsFileProcessor =
new TsFileProcessor(
@@ -1273,8 +1272,7 @@ public class StorageGroupProcessor {
storageGroupInfo,
this::closeUnsealedTsFileProcessorCallBack,
this::unsequenceFlushCallback,
- false,
- deviceNumInLastClosedTsFile);
+ false);
}
if (enableMemControl) {
@@ -1853,7 +1851,7 @@ public class StorageGroupProcessor {
return false;
}
- if (tsFileResource.getDevices().contains(deviceId)
+ if (tsFileResource.isDeviceIdExist(deviceId)
&& (deleteEnd >= tsFileResource.getStartTime(deviceId) && deleteStart <= endTime)) {
return false;
}
@@ -2024,7 +2022,6 @@ public class StorageGroupProcessor {
closeQueryLock.writeLock().lock();
try {
tsFileProcessor.close();
- deviceNumInLastClosedTsFile = tsFileProcessor.getTsFileResource().getDevices().size();
} finally {
closeQueryLock.writeLock().unlock();
}
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java
index 28f0f6e..ff19c89 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java
@@ -160,11 +160,10 @@ public class TsFileProcessor {
StorageGroupInfo storageGroupInfo,
CloseFileListener closeTsFileCallback,
UpdateEndTimeCallBack updateLatestFlushTimeCallback,
- boolean sequence,
- int deviceNumInLastClosedTsFile)
+ boolean sequence)
throws IOException {
this.storageGroupName = storageGroupName;
- this.tsFileResource = new TsFileResource(tsfile, this, deviceNumInLastClosedTsFile);
+ this.tsFileResource = new TsFileResource(tsfile, this);
this.storageGroupInfo = storageGroupInfo;
this.writer = new RestorableTsFileIOWriter(tsfile);
this.updateLatestFlushTimeCallback = updateLatestFlushTimeCallback;
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 8f7dc81..f0c7d18 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
@@ -184,10 +184,10 @@ public class TsFileResource {
}
/** unsealed TsFile */
- public TsFileResource(File file, TsFileProcessor processor, int deviceNumInLastClosedTsFile) {
+ public TsFileResource(File file, TsFileProcessor processor) {
this.file = file;
this.version = FilePathUtils.splitAndGetTsFileVersion(this.file.getName());
- this.timeIndex = config.getTimeIndexLevel().getTimeIndex(deviceNumInLastClosedTsFile);
+ this.timeIndex = config.getTimeIndexLevel().getTimeIndex();
this.timeIndexType = (byte) config.getTimeIndexLevel().ordinal();
this.processor = processor;
}
@@ -627,10 +627,14 @@ public class TsFileResource {
return timeIndex.stillLives(timeLowerBound);
}
+ public boolean isDeviceIdExist(String deviceId) {
+ return timeIndex.checkDeviceIdExist(deviceId);
+ }
+
/** @return true if the device is contained in the TsFile and it lives beyond TTL */
public boolean isSatisfied(
String deviceId, Filter timeFilter, boolean isSeq, long ttl, boolean debug) {
- if (!getDevices().contains(deviceId)) {
+ if (!timeIndex.checkDeviceIdExist(deviceId)) {
if (debug) {
DEBUG_LOGGER.info(
"Path: {} file {} is not satisfied because of no device!", deviceId, file);
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 36d42e9..b93cf87 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
@@ -64,14 +64,6 @@ public class DeviceTimeIndex implements ITimeIndex {
initTimes(endTimes, Long.MIN_VALUE);
}
- public DeviceTimeIndex(int deviceNumInLastClosedTsFile) {
- this.deviceToIndex = new ConcurrentHashMap<>();
- this.startTimes = new long[deviceNumInLastClosedTsFile];
- this.endTimes = new long[deviceNumInLastClosedTsFile];
- initTimes(startTimes, Long.MAX_VALUE);
- initTimes(endTimes, Long.MIN_VALUE);
- }
-
public DeviceTimeIndex(Map<String, Integer> deviceToIndex, long[] startTimes, long[] endTimes) {
this.startTimes = startTimes;
this.endTimes = endTimes;
@@ -309,4 +301,9 @@ public class DeviceTimeIndex implements ITimeIndex {
}
return endTimes[deviceToIndex.get(deviceId)];
}
+
+ @Override
+ public boolean checkDeviceIdExist(String deviceId) {
+ return deviceToIndex.containsKey(deviceId);
+ }
}
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 1cd35d6..9cc46eb 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
@@ -213,4 +213,9 @@ public class FileTimeIndex implements ITimeIndex {
public long getEndTime(String deviceId) {
return endTime;
}
+
+ @Override
+ public boolean checkDeviceIdExist(String deviceId) {
+ return true;
+ }
}
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 ba98c34..3710362 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
@@ -147,4 +147,12 @@ public interface ITimeIndex {
* @return end time
*/
long getEndTime(String deviceId);
+
+ /**
+ * check whether deviceId exists in TsFile
+ *
+ * @param deviceId device name
+ * @return true if the deviceId may exist in TsFile, otherwise false.
+ */
+ boolean checkDeviceIdExist(String deviceId);
}
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/TimeIndexLevel.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/TimeIndexLevel.java
index 93650fb..95e9b9e 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/TimeIndexLevel.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/TimeIndexLevel.java
@@ -36,16 +36,6 @@ public enum TimeIndexLevel {
}
}
- public ITimeIndex getTimeIndex(int deviceNumInLastClosedTsFile) {
- switch (this) {
- case FILE_TIME_INDEX:
- return new FileTimeIndex();
- case DEVICE_TIME_INDEX:
- default:
- return new DeviceTimeIndex(deviceNumInLastClosedTsFile);
- }
- }
-
public static TimeIndexLevel valueOf(int ordinal) {
if (ordinal < 0 || ordinal >= values().length) {
throw new IndexOutOfBoundsException("Invalid ordinal");
diff --git a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessorTest.java b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessorTest.java
index ad96383..e72ee80 100644
--- a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessorTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessorTest.java
@@ -71,8 +71,6 @@ public class TsFileProcessorTest {
private QueryContext context;
private static Logger logger = LoggerFactory.getLogger(TsFileProcessorTest.class);
- protected static final int INIT_ARRAY_SIZE = 64;
-
@Before
public void setUp() {
EnvironmentUtils.envSetUp();
@@ -96,8 +94,7 @@ public class TsFileProcessorTest {
sgInfo,
this::closeTsFileProcessor,
(tsFileProcessor) -> true,
- true,
- INIT_ARRAY_SIZE);
+ true);
TsFileProcessorInfo tsFileProcessorInfo = new TsFileProcessorInfo(sgInfo);
processor.setTsFileProcessorInfo(tsFileProcessorInfo);
@@ -172,8 +169,7 @@ public class TsFileProcessorTest {
sgInfo,
this::closeTsFileProcessor,
(tsFileProcessor) -> true,
- true,
- INIT_ARRAY_SIZE);
+ true);
TsFileProcessorInfo tsFileProcessorInfo = new TsFileProcessorInfo(sgInfo);
processor.setTsFileProcessorInfo(tsFileProcessorInfo);
@@ -274,8 +270,7 @@ public class TsFileProcessorTest {
sgInfo,
this::closeTsFileProcessor,
(tsFileProcessor) -> true,
- true,
- INIT_ARRAY_SIZE);
+ true);
TsFileProcessorInfo tsFileProcessorInfo = new TsFileProcessorInfo(sgInfo);
processor.setTsFileProcessorInfo(tsFileProcessorInfo);
@@ -330,8 +325,7 @@ public class TsFileProcessorTest {
sgInfo,
this::closeTsFileProcessor,
(tsFileProcessor) -> true,
- true,
- INIT_ARRAY_SIZE);
+ true);
TsFileProcessorInfo tsFileProcessorInfo = new TsFileProcessorInfo(sgInfo);
processor.setTsFileProcessorInfo(tsFileProcessorInfo);