This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch add_base32_path in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a7b15f53bc0d7da9841451f8c8ef4205a230ea81 Author: HTHou <[email protected]> AuthorDate: Wed Dec 3 17:38:07 2025 +0800 add base32 Object Path --- .../plan/planner/plan/node/write/ObjectNode.java | 43 +++--- .../plan/node/write/RelationalInsertRowsNode.java | 25 ++-- .../node/write/RelationalInsertTabletNode.java | 18 +-- .../storageengine/dataregion/Base32ObjectPath.java | 146 +++++++++++++++++++++ .../db/storageengine/dataregion/DataRegion.java | 6 +- .../db/storageengine/dataregion/IObjectPath.java | 52 ++++++++ .../tsfile/generator/TsFileNameGenerator.java | 17 --- .../db/storageengine/rescon/disk/TierManager.java | 11 -- .../org/apache/iotdb/db/utils/ObjectTypeUtils.java | 11 +- 9 files changed, 253 insertions(+), 76 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/ObjectNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/ObjectNode.java index 10fb9bc3443..cef10d612fa 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/ObjectNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/ObjectNode.java @@ -33,8 +33,9 @@ import org.apache.iotdb.db.storageengine.dataregion.memtable.TsFileProcessor; import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView; import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntryType; import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntryValue; -import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALWriteUtils; import org.apache.iotdb.db.storageengine.rescon.disk.TierManager; +import org.apache.iotdb.db.storageengine.dataregion.IObjectPath; +import org.apache.iotdb.db.storageengine.dataregion.IObjectPath.Deserializer; import org.apache.tsfile.utils.PublicBAOS; import org.apache.tsfile.utils.ReadWriteIOUtils; @@ -60,7 +61,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { private byte[] content; - private String filePath; + private IObjectPath filePath; private final int contentLength; @@ -68,7 +69,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { private boolean isGeneratedByRemoteConsensusLeader; - public ObjectNode(boolean isEOF, long offset, byte[] content, String filePath) { + public ObjectNode(boolean isEOF, long offset, byte[] content, IObjectPath filePath) { super(new PlanNodeId("")); this.isEOF = isEOF; this.offset = offset; @@ -77,7 +78,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { this.contentLength = content.length; } - public ObjectNode(boolean isEOF, long offset, int contentLength, String filePath) { + public ObjectNode(boolean isEOF, long offset, int contentLength, IObjectPath filePath) { super(new PlanNodeId("")); this.isEOF = isEOF; this.offset = offset; @@ -97,12 +98,12 @@ public class ObjectNode extends SearchNode implements WALEntryValue { return offset; } - public void setFilePath(String filePath) { + public void setFilePath(IObjectPath filePath) { this.filePath = filePath; } - public String getFilePath() { - return filePath; + public String getFilePathString() { + return filePath.toString(); } @Override @@ -111,7 +112,11 @@ public class ObjectNode extends SearchNode implements WALEntryValue { buffer.putLong(searchIndex); buffer.put((byte) (isEOF ? 1 : 0)); buffer.putLong(offset); - WALWriteUtils.write(filePath, buffer); + try { + filePath.serialize(buffer); + } catch (IOException e) { + throw new RuntimeException(e); + } buffer.putInt(content.length); } @@ -122,14 +127,14 @@ public class ObjectNode extends SearchNode implements WALEntryValue { + Byte.BYTES + Long.BYTES + Integer.BYTES - + ReadWriteIOUtils.sizeToWrite(filePath); + + filePath.getSerializedSize(); } public static ObjectNode deserializeFromWAL(DataInputStream stream) throws IOException { long searchIndex = stream.readLong(); boolean isEOF = stream.readByte() == 1; long offset = stream.readLong(); - String filePath = ReadWriteIOUtils.readString(stream); + IObjectPath filePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(stream); int contentLength = stream.readInt(); ObjectNode objectNode = new ObjectNode(isEOF, offset, contentLength, filePath); objectNode.setSearchIndex(searchIndex); @@ -140,8 +145,9 @@ public class ObjectNode extends SearchNode implements WALEntryValue { long searchIndex = buffer.getLong(); boolean isEOF = buffer.get() == 1; long offset = buffer.getLong(); - String filePath = ReadWriteIOUtils.readString(buffer); - Optional<File> objectFile = TierManager.getInstance().getAbsoluteObjectFilePath(filePath); + IObjectPath filePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(buffer); + Optional<File> objectFile = + TierManager.getInstance().getAbsoluteObjectFilePath(filePath.toString()); int contentLength = buffer.getInt(); byte[] contents = new byte[contentLength]; if (objectFile.isPresent()) { @@ -152,7 +158,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { throw new RuntimeException(e); } } else { - throw new ObjectFileNotExist(filePath); + throw new ObjectFileNotExist(filePath.toString()); } ObjectNode objectNode = new ObjectNode(isEOF, offset, contents, filePath); @@ -163,7 +169,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { public static ObjectNode deserialize(ByteBuffer byteBuffer) { boolean isEoF = ReadWriteIOUtils.readBool(byteBuffer); long offset = ReadWriteIOUtils.readLong(byteBuffer); - String filePath = ReadWriteIOUtils.readString(byteBuffer); + IObjectPath filePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(byteBuffer); int contentLength = ReadWriteIOUtils.readInt(byteBuffer); byte[] content = ReadWriteIOUtils.readBytes(byteBuffer, contentLength); return new ObjectNode(isEoF, offset, content, filePath); @@ -227,7 +233,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { getType().serialize(byteBuffer); ReadWriteIOUtils.write(isEOF, byteBuffer); ReadWriteIOUtils.write(offset, byteBuffer); - ReadWriteIOUtils.write(filePath, byteBuffer); + filePath.serialize(byteBuffer); ReadWriteIOUtils.write(contentLength, byteBuffer); byteBuffer.put(content); } @@ -237,7 +243,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { getType().serialize(stream); ReadWriteIOUtils.write(isEOF, stream); ReadWriteIOUtils.write(offset, stream); - ReadWriteIOUtils.write(filePath, stream); + filePath.serialize(stream); ReadWriteIOUtils.write(contentLength, stream); stream.write(content); } @@ -251,7 +257,8 @@ public class ObjectNode extends SearchNode implements WALEntryValue { byte[] contents = new byte[contentLength]; boolean readSuccess = false; for (int i = 0; i < 2; i++) { - Optional<File> objectFile = TierManager.getInstance().getAbsoluteObjectFilePath(filePath); + Optional<File> objectFile = + TierManager.getInstance().getAbsoluteObjectFilePath(filePath.toString()); if (objectFile.isPresent()) { try { readContentFromFile(objectFile.get(), contents); @@ -279,7 +286,7 @@ public class ObjectNode extends SearchNode implements WALEntryValue { } ReadWriteIOUtils.write(readSuccess && isEOF, stream); ReadWriteIOUtils.write(offset, stream); - ReadWriteIOUtils.write(filePath, stream); + filePath.serialize(stream); ReadWriteIOUtils.write(contentLength, stream); stream.write(contents); return ByteBuffer.wrap(byteArrayOutputStream.getBuf(), 0, byteArrayOutputStream.size()); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertRowsNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertRowsNode.java index 83f6bbec63e..2d457cc9366 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertRowsNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertRowsNode.java @@ -27,19 +27,17 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode; -import org.apache.iotdb.db.storageengine.dataregion.tsfile.generator.TsFileNameGenerator; +import org.apache.iotdb.db.storageengine.dataregion.IObjectPath; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.file.metadata.IDeviceID; import org.apache.tsfile.file.metadata.IDeviceID.Factory; import org.apache.tsfile.utils.Binary; -import org.apache.tsfile.utils.BytesUtils; import org.apache.tsfile.utils.ReadWriteIOUtils; import java.io.DataInputStream; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -212,22 +210,25 @@ public class RelationalInsertRowsNode extends InsertRowsNode { boolean isEoF = buffer.get() == 1; long offset = buffer.getLong(); byte[] content = ReadWriteIOUtils.readBytes(buffer, buffer.remaining()); - String relativePath = - TsFileNameGenerator.generateObjectFilePath( + IObjectPath relativePath = + IObjectPath.Factory.DEFAULT_FACTORY.create( dataRegionReplicaSet.getRegionId().getId(), insertRowNode.getTime(), insertRowNode.getDeviceID(), insertRowNode.getMeasurements()[j]); ObjectNode objectNode = new ObjectNode(isEoF, offset, content, relativePath); objectNode.setDataRegionReplicaSet(dataRegionReplicaSet); - byte[] filePathBytes = relativePath.getBytes(StandardCharsets.UTF_8); - byte[] valueBytes = new byte[filePathBytes.length + Long.BYTES]; - System.arraycopy( - BytesUtils.longToBytes(offset + content.length), 0, valueBytes, 0, Long.BYTES); - System.arraycopy(filePathBytes, 0, valueBytes, Long.BYTES, filePathBytes.length); - ((Binary) values[j]).setValues(valueBytes); - insertRowNode.setValues(values); writePlanNodeList.add(objectNode); + if (isEoF) { + ByteBuffer valueBytes = + ByteBuffer.allocate(relativePath.getSerializedSize() + Long.BYTES); + valueBytes.putLong(offset + content.length); + relativePath.serialize(valueBytes); + ((Binary) values[j]).setValues(valueBytes.array()); + insertRowNode.setValues(values); + } else { + values[j] = null; + } } } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java index e3a114211e1..cc4cdcff01c 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java @@ -32,8 +32,8 @@ import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor; import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode; import org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceSchemaCache; -import org.apache.iotdb.db.storageengine.dataregion.tsfile.generator.TsFileNameGenerator; import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView; +import org.apache.iotdb.db.storageengine.dataregion.IObjectPath; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.file.metadata.IDeviceID; @@ -41,7 +41,6 @@ import org.apache.tsfile.file.metadata.IDeviceID.Factory; import org.apache.tsfile.read.TimeValuePair; import org.apache.tsfile.utils.Binary; import org.apache.tsfile.utils.BitMap; -import org.apache.tsfile.utils.BytesUtils; import org.apache.tsfile.utils.Pair; import org.apache.tsfile.utils.ReadWriteIOUtils; import org.apache.tsfile.write.schema.MeasurementSchema; @@ -50,7 +49,6 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -470,19 +468,17 @@ public class RelationalInsertTabletNode extends InsertTabletNode { boolean isEoF = buffer.get() == 1; long offset = buffer.getLong(); byte[] content = ReadWriteIOUtils.readBytes(buffer, buffer.remaining()); - String relativePath = - TsFileNameGenerator.generateObjectFilePath( + IObjectPath relativePath = + IObjectPath.Factory.DEFAULT_FACTORY.create( entry.getKey().getRegionId().getId(), times[j], getDeviceID(j), measurements[column]); ObjectNode objectNode = new ObjectNode(isEoF, offset, content, relativePath); objectNode.setDataRegionReplicaSet(entry.getKey()); result.add(objectNode); if (isEoF) { - byte[] filePathBytes = relativePath.getBytes(StandardCharsets.UTF_8); - byte[] valueBytes = new byte[filePathBytes.length + Long.BYTES]; - System.arraycopy( - BytesUtils.longToBytes(offset + content.length), 0, valueBytes, 0, Long.BYTES); - System.arraycopy(filePathBytes, 0, valueBytes, Long.BYTES, filePathBytes.length); - ((Binary[]) columns[column])[j] = new Binary(valueBytes); + ByteBuffer valueBytes = ByteBuffer.allocate(relativePath.getSerializedSize() + Long.BYTES); + valueBytes.putLong(offset + content.length); + relativePath.serialize(valueBytes); + ((Binary[]) columns[column])[j] = new Binary(valueBytes.array()); } else { ((Binary[]) columns[column])[j] = null; if (bitMaps == null) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/Base32ObjectPath.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/Base32ObjectPath.java new file mode 100644 index 00000000000..728df25e007 --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/Base32ObjectPath.java @@ -0,0 +1,146 @@ +/* + * 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; + +import com.google.common.io.BaseEncoding; +import org.apache.tsfile.file.metadata.IDeviceID; +import org.apache.tsfile.utils.ReadWriteForEncodingUtils; +import org.apache.tsfile.utils.ReadWriteIOUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class Base32ObjectPath implements IObjectPath { + + Path path; + int serializedSize = -1; + + private static final Deserializer DESERIALIZER = + new Deserializer() { + @Override + public IObjectPath deserializeFrom(ByteBuffer byteBuffer) { + return deserialize(byteBuffer); + } + + @Override + public IObjectPath deserializeFrom(InputStream inputStream) throws IOException { + return deserialize(inputStream); + } + }; + + private static final Factory FACTORY = Base32ObjectPath::new; + + public Base32ObjectPath(String first, String... more) { + path = Paths.get(first, more); + } + + public Base32ObjectPath(int regionId, long time, IDeviceID iDeviceID, String measurement) { + Object[] segments = iDeviceID.getSegments(); + String[] pathSegments = new String[segments.length + 2]; + for (int i = 0; i < segments.length; i++) { + Object segment = segments[i]; + String segmentString = segment == null ? "null" : segment.toString(); + pathSegments[i] = + BaseEncoding.base32() + .omitPadding() + .encode(segmentString.getBytes(StandardCharsets.UTF_8)); + } + pathSegments[pathSegments.length - 2] = + BaseEncoding.base32().omitPadding().encode(measurement.getBytes(StandardCharsets.UTF_8)); + pathSegments[pathSegments.length - 1] = time + ".bin"; + path = Paths.get(String.valueOf(regionId), pathSegments); + } + + @Override + public int serialize(ByteBuffer byteBuffer) { + int cnt = 0; + cnt += ReadWriteForEncodingUtils.writeUnsignedVarInt(path.getNameCount(), byteBuffer); + for (Path segment : path) { + cnt += ReadWriteIOUtils.writeVar(segment.toString(), byteBuffer); + } + return cnt; + } + + @Override + public int serialize(OutputStream outputStream) throws IOException { + int cnt = 0; + cnt += ReadWriteForEncodingUtils.writeUnsignedVarInt(path.getNameCount(), outputStream); + for (Path segment : path) { + cnt += ReadWriteIOUtils.writeVar(segment.toString(), outputStream); + } + return cnt; + } + + @Override + public int getSerializedSize() { + if (serializedSize != -1) { + return serializedSize; + } + int cnt = ReadWriteForEncodingUtils.varIntSize(path.getNameCount()); + for (Path segment : path) { + byte[] bytes = segment.toString().getBytes(StandardCharsets.UTF_8); + cnt += ReadWriteForEncodingUtils.varIntSize(bytes.length); + cnt += bytes.length; + } + serializedSize = cnt; + return cnt; + } + + public static Base32ObjectPath deserialize(ByteBuffer byteBuffer) { + int cnt = ReadWriteForEncodingUtils.readUnsignedVarInt(byteBuffer); + String first = ReadWriteIOUtils.readVarIntString(byteBuffer); + String[] more = new String[cnt - 1]; + + for (int i = 0; i < cnt - 1; ++i) { + more[i] = ReadWriteIOUtils.readVarIntString(byteBuffer); + } + return new Base32ObjectPath(first, more); + } + + public static Base32ObjectPath deserialize(InputStream stream) throws IOException { + int cnt = ReadWriteForEncodingUtils.readUnsignedVarInt(stream); + String first = ReadWriteIOUtils.readVarIntString(stream); + String[] more = new String[cnt - 1]; + + for (int i = 0; i < cnt - 1; ++i) { + more[i] = ReadWriteIOUtils.readVarIntString(stream); + } + + return new Base32ObjectPath(first, more); + } + + @Override + public String toString() { + return path.toString(); + } + + public static Factory getFACTORY() { + return FACTORY; + } + + public static Deserializer getDESERIALIZER() { + return DESERIALIZER; + } +} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java index 1124e33a7df..a3427defdbf 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/DataRegion.java @@ -3582,7 +3582,7 @@ public class DataRegion implements IDataRegionForQuery { public void writeObject(ObjectNode objectNode) throws Exception { writeLock("writeObject"); try { - String relativeTmpPathString = objectNode.getFilePath() + ".tmp"; + String relativeTmpPathString = objectNode.getFilePathString() + ".tmp"; String objectFileDir = TierManager.getInstance().getNextFolderForObjectFile(); File objectTmpFile = FSFactoryProducer.getFSFactory().getFile(objectFileDir, relativeTmpPathString); @@ -3594,9 +3594,9 @@ public class DataRegion implements IDataRegionForQuery { } if (objectNode.isEOF()) { File objectFile = - FSFactoryProducer.getFSFactory().getFile(objectFileDir, objectNode.getFilePath()); + FSFactoryProducer.getFSFactory().getFile(objectFileDir, objectNode.getFilePathString()); if (objectFile.exists()) { - String relativeBackPathString = objectNode.getFilePath() + ".back"; + String relativeBackPathString = objectNode.getFilePathString() + ".back"; File objectBackFile = FSFactoryProducer.getFSFactory().getFile(objectFileDir, relativeBackPathString); Files.move( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/IObjectPath.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/IObjectPath.java new file mode 100644 index 00000000000..ee0613a1c85 --- /dev/null +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/IObjectPath.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; + +import org.apache.tsfile.file.metadata.IDeviceID; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +public interface IObjectPath { + + int serialize(ByteBuffer byteBuffer); + + int serialize(OutputStream outputStream) throws IOException; + + int getSerializedSize(); + + interface Factory { + + IObjectPath create(int regionId, long time, IDeviceID iDeviceID, String measurement); + + Factory DEFAULT_FACTORY = Base32ObjectPath.getFACTORY(); + } + + interface Deserializer { + + IObjectPath deserializeFrom(ByteBuffer byteBuffer); + + IObjectPath deserializeFrom(InputStream inputStream) throws IOException; + + Deserializer DEFAULT_DESERIALIZER = Base32ObjectPath.getDESERIALIZER(); + } +} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/generator/TsFileNameGenerator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/generator/TsFileNameGenerator.java index 8ad353a96ef..16be82188e9 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/generator/TsFileNameGenerator.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/tsfile/generator/TsFileNameGenerator.java @@ -28,7 +28,6 @@ import org.apache.iotdb.db.storageengine.rescon.disk.FolderManager; import org.apache.iotdb.db.storageengine.rescon.disk.TierManager; import org.apache.tsfile.common.constant.TsFileConstant; -import org.apache.tsfile.file.metadata.IDeviceID; import org.apache.tsfile.fileSystem.FSFactoryProducer; import org.apache.tsfile.fileSystem.fsFactory.FSFactory; import org.slf4j.Logger; @@ -176,22 +175,6 @@ public class TsFileNameGenerator { } } - public static String generateObjectFilePath( - int regionId, long time, IDeviceID iDeviceID, String measurement) { - String objectFileName = time + ".bin"; - Object[] segments = iDeviceID.getSegments(); - StringBuilder relativePathString = - new StringBuilder(String.valueOf(regionId)).append(File.separator); - for (Object segment : segments) { - relativePathString - .append(segment == null ? "null" : segment.toString().toLowerCase()) - .append(File.separator); - } - relativePathString.append(measurement).append(File.separator); - relativePathString.append(objectFileName); - return relativePathString.toString(); - } - @TestOnly public static TsFileResource increaseCrossCompactionCnt(TsFileResource tsFileResource) throws IOException { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/TierManager.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/TierManager.java index 6355880cebd..a5fa8b54e7b 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/TierManager.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/TierManager.java @@ -19,7 +19,6 @@ package org.apache.iotdb.db.storageengine.rescon.disk; import org.apache.iotdb.commons.conf.IoTDBConstant; -import org.apache.iotdb.commons.exception.ObjectFileNotExist; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.DiskSpaceInsufficientException; @@ -345,16 +344,6 @@ public class TierManager { return tierDiskSpace; } - public File getObjectFile(String relativePath) { - for (String folder : objectDirs) { - File file = new File(folder, relativePath); - if (file.exists()) { - return file; - } - } - throw new ObjectFileNotExist(relativePath); - } - private enum DiskSpaceType { TOTAL, USABLE, diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ObjectTypeUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ObjectTypeUtils.java index c153061a90d..2c2ce69ac19 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ObjectTypeUtils.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ObjectTypeUtils.java @@ -19,8 +19,11 @@ package org.apache.iotdb.db.utils; +import java.nio.ByteBuffer; import org.apache.iotdb.commons.exception.ObjectFileNotExist; import org.apache.iotdb.db.service.metrics.FileMetrics; +import org.apache.iotdb.db.storageengine.dataregion.IObjectPath; +import org.apache.iotdb.db.storageengine.dataregion.IObjectPath.Deserializer; import org.apache.iotdb.db.storageengine.rescon.disk.TierManager; import org.apache.tsfile.common.conf.TSFileConfig; @@ -42,8 +45,8 @@ public class ObjectTypeUtils { public static File getObjectPathFromBinary(Binary binary) { byte[] bytes = binary.getValues(); - String relativeObjectFilePath = - new String(bytes, 8, bytes.length - 8, TSFileConfig.STRING_CHARSET); + ByteBuffer buffer = ByteBuffer.wrap(bytes, 8, bytes.length - 8); + String relativeObjectFilePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(buffer).toString(); Optional<File> file = TIER_MANAGER.getAbsoluteObjectFilePath(relativeObjectFilePath); if (!file.isPresent()) { throw new ObjectFileNotExist(relativeObjectFilePath); @@ -54,8 +57,8 @@ public class ObjectTypeUtils { public static Optional<File> getNullableObjectPathFromBinary( Binary binary, boolean needTempFile) { byte[] bytes = binary.getValues(); - String relativeObjectFilePath = - new String(bytes, 8, bytes.length - 8, TSFileConfig.STRING_CHARSET); + ByteBuffer buffer = ByteBuffer.wrap(bytes, 8, bytes.length - 8); + String relativeObjectFilePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(buffer).toString(); return TIER_MANAGER.getAbsoluteObjectFilePath(relativeObjectFilePath, needTempFile); }
