This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch TsFileResource_scalability in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 45a5258bbd4283f2c9b429142b70879ed14a6ae6 Author: HTHou <[email protected]> AuthorDate: Mon Oct 23 11:37:32 2023 +0800 Add Interface to extend TsFileResource --- .../dataregion/tsfile/TsFileResource.java | 55 +++------------------- .../dataregion/tsfile/TsFileResourceBlockType.java | 51 ++++++++++++++++++++ 2 files changed, 57 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..dedc5ff0ea3 --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/TsFileResourceBlockType.java @@ -0,0 +1,51 @@ +/* + * 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 java.io.IOException; +import java.io.OutputStream; +import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils; + +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); + } + } +}
