This is an automated email from the ASF dual-hosted git repository.
xingtanzjr 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 ca7fbfe0192 Add Interface to extend TsFileResource (#11362)
ca7fbfe0192 is described below
commit ca7fbfe019235304caa6fa57ee5e637648a6a9cd
Author: Haonan <[email protected]>
AuthorDate: Mon Oct 23 14:33:15 2023 +0800
Add Interface to extend TsFileResource (#11362)
---
.../dataregion/tsfile/TsFileResource.java | 55 +++-------------------
.../dataregion/tsfile/TsFileResourceBlockType.java | 52 ++++++++++++++++++++
2 files changed, 58 insertions(+), 49 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
index aceec04bdc3..ce49b700768 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResource.java
@@ -270,10 +270,10 @@ public class TsFileResource {
}
if (maxProgressIndex != null) {
- ReadWriteIOUtils.write(true, outputStream);
+ TsFileResourceBlockType.PROGRESS_INDEX.serialize(outputStream);
maxProgressIndex.serialize(outputStream);
} else {
- ReadWriteIOUtils.write(false, outputStream);
+ TsFileResourceBlockType.EMPTY_BLOCK.serialize(outputStream);
}
}
@@ -294,53 +294,10 @@ public class TsFileResource {
}
}
- if (inputStream.available() > 0) {
- final boolean hasMaxProgressIndex =
ReadWriteIOUtils.readBool(inputStream);
- if (hasMaxProgressIndex) {
- maxProgressIndex = ProgressIndexType.deserializeFrom(inputStream);
- }
- }
- }
- }
-
- /** deserialize tsfile resource from old file */
- public void deserializeFromOldFile() throws IOException {
- try (InputStream inputStream = fsFactory.getBufferedInputStream(file +
RESOURCE_SUFFIX)) {
- // deserialize old TsfileResource
- int size = ReadWriteIOUtils.readInt(inputStream);
- Map<String, Integer> deviceMap = new HashMap<>();
- long[] startTimesArray = new long[size];
- long[] endTimesArray = new long[size];
- for (int i = 0; i < size; i++) {
- String path = ReadWriteIOUtils.readString(inputStream);
- long time = ReadWriteIOUtils.readLong(inputStream);
- deviceMap.put(path.intern(), i);
- startTimesArray[i] = time;
- }
- size = ReadWriteIOUtils.readInt(inputStream);
- for (int i = 0; i < size; i++) {
- ReadWriteIOUtils.readString(inputStream); // String path
- long time = ReadWriteIOUtils.readLong(inputStream);
- endTimesArray[i] = time;
- }
- timeIndex = new DeviceTimeIndex(deviceMap, startTimesArray,
endTimesArray);
- if (inputStream.available() > 0) {
- int versionSize = ReadWriteIOUtils.readInt(inputStream);
- for (int i = 0; i < versionSize; i++) {
- // historicalVersions
- ReadWriteIOUtils.readLong(inputStream);
- }
- }
- if (inputStream.available() > 0) {
- String modFileName = ReadWriteIOUtils.readString(inputStream);
- if (modFileName != null) {
- File modF = new File(file.getParentFile(), modFileName);
- modFile = new ModificationFile(modF.getPath());
- }
- }
- if (inputStream.available() > 0) {
- final boolean hasMaxProgressIndex =
ReadWriteIOUtils.readBool(inputStream);
- if (hasMaxProgressIndex) {
+ while (inputStream.available() > 0) {
+ final TsFileResourceBlockType blockType =
+
TsFileResourceBlockType.deserialize(ReadWriteIOUtils.readByte(inputStream));
+ if (blockType == TsFileResourceBlockType.PROGRESS_INDEX) {
maxProgressIndex = ProgressIndexType.deserializeFrom(inputStream);
}
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceBlockType.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceBlockType.java
new file mode 100644
index 00000000000..62aeac776de
--- /dev/null
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceBlockType.java
@@ -0,0 +1,52 @@
+/*
+ * 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.storageengine.dataregion.tsfile;
+
+import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public enum TsFileResourceBlockType {
+ EMPTY_BLOCK((byte) 0),
+ PROGRESS_INDEX((byte) 1),
+ ;
+
+ private final byte type;
+
+ TsFileResourceBlockType(byte type) {
+ this.type = type;
+ }
+
+ public void serialize(OutputStream outputStream) throws IOException {
+ ReadWriteIOUtils.write(type, outputStream);
+ }
+
+ public static TsFileResourceBlockType deserialize(byte type) {
+ switch (type) {
+ case 0:
+ return EMPTY_BLOCK;
+ case 1:
+ return PROGRESS_INDEX;
+ default:
+ throw new IllegalArgumentException("Invalid input: " + type);
+ }
+ }
+}