Skip to content

Commit 3e9353e

Browse files
committed
add plainObjectPath and configuration
1 parent a7b15f5 commit 3e9353e

File tree

8 files changed

+146
-18
lines changed

8 files changed

+146
-18
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,11 @@ public class IoTDBConfig {
11881188
private ConcurrentHashMap<String, EncryptParameter> tsFileDBToEncryptMap =
11891189
new ConcurrentHashMap<>(
11901190
Collections.singletonMap("root.__audit", new EncryptParameter("UNENCRYPTED", null)));
1191+
11911192
private long maxObjectSizeInByte = 4 * 1024 * 1024 * 1024L;
11921193

1194+
private boolean restrictObjectLimit = false;
1195+
11931196
IoTDBConfig() {}
11941197

11951198
public int getMaxLogEntriesNumPerBatch() {
@@ -4269,4 +4272,12 @@ public long getMaxObjectSizeInByte() {
42694272
public void setMaxObjectSizeInByte(long maxObjectSizeInByte) {
42704273
this.maxObjectSizeInByte = maxObjectSizeInByte;
42714274
}
4275+
4276+
public boolean getRestrictObjectLimit() {
4277+
return restrictObjectLimit;
4278+
}
4279+
4280+
public void setRestrictObjectLimit(boolean restrictObjectLimit) {
4281+
this.restrictObjectLimit = restrictObjectLimit;
4282+
}
42724283
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/ObjectNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
3030
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
3131
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode;
32+
import org.apache.iotdb.db.storageengine.dataregion.IObjectPath;
33+
import org.apache.iotdb.db.storageengine.dataregion.IObjectPath.Deserializer;
3234
import org.apache.iotdb.db.storageengine.dataregion.memtable.TsFileProcessor;
3335
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView;
3436
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntryType;
3537
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntryValue;
3638
import org.apache.iotdb.db.storageengine.rescon.disk.TierManager;
37-
import org.apache.iotdb.db.storageengine.dataregion.IObjectPath;
38-
import org.apache.iotdb.db.storageengine.dataregion.IObjectPath.Deserializer;
3939

4040
import org.apache.tsfile.utils.PublicBAOS;
4141
import org.apache.tsfile.utils.ReadWriteIOUtils;
@@ -134,7 +134,7 @@ public static ObjectNode deserializeFromWAL(DataInputStream stream) throws IOExc
134134
long searchIndex = stream.readLong();
135135
boolean isEOF = stream.readByte() == 1;
136136
long offset = stream.readLong();
137-
IObjectPath filePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(stream);
137+
IObjectPath filePath = Deserializer.DESERIALIZER.deserializeFrom(stream);
138138
int contentLength = stream.readInt();
139139
ObjectNode objectNode = new ObjectNode(isEOF, offset, contentLength, filePath);
140140
objectNode.setSearchIndex(searchIndex);
@@ -145,7 +145,7 @@ public static ObjectNode deserializeFromWAL(ByteBuffer buffer) {
145145
long searchIndex = buffer.getLong();
146146
boolean isEOF = buffer.get() == 1;
147147
long offset = buffer.getLong();
148-
IObjectPath filePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(buffer);
148+
IObjectPath filePath = Deserializer.DESERIALIZER.deserializeFrom(buffer);
149149
Optional<File> objectFile =
150150
TierManager.getInstance().getAbsoluteObjectFilePath(filePath.toString());
151151
int contentLength = buffer.getInt();
@@ -169,7 +169,7 @@ public static ObjectNode deserializeFromWAL(ByteBuffer buffer) {
169169
public static ObjectNode deserialize(ByteBuffer byteBuffer) {
170170
boolean isEoF = ReadWriteIOUtils.readBool(byteBuffer);
171171
long offset = ReadWriteIOUtils.readLong(byteBuffer);
172-
IObjectPath filePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(byteBuffer);
172+
IObjectPath filePath = Deserializer.DESERIALIZER.deserializeFrom(byteBuffer);
173173
int contentLength = ReadWriteIOUtils.readInt(byteBuffer);
174174
byte[] content = ReadWriteIOUtils.readBytes(byteBuffer, contentLength);
175175
return new ObjectNode(isEoF, offset, content, filePath);

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertRowsNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private void handleObjectValue(
211211
long offset = buffer.getLong();
212212
byte[] content = ReadWriteIOUtils.readBytes(buffer, buffer.remaining());
213213
IObjectPath relativePath =
214-
IObjectPath.Factory.DEFAULT_FACTORY.create(
214+
IObjectPath.Factory.FACTORY.create(
215215
dataRegionReplicaSet.getRegionId().getId(),
216216
insertRowNode.getTime(),
217217
insertRowNode.getDeviceID(),

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
3333
import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode;
3434
import org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TableDeviceSchemaCache;
35-
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView;
3635
import org.apache.iotdb.db.storageengine.dataregion.IObjectPath;
36+
import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView;
3737

3838
import org.apache.tsfile.enums.TSDataType;
3939
import org.apache.tsfile.file.metadata.IDeviceID;
@@ -469,7 +469,7 @@ private void handleObjectValue(
469469
long offset = buffer.getLong();
470470
byte[] content = ReadWriteIOUtils.readBytes(buffer, buffer.remaining());
471471
IObjectPath relativePath =
472-
IObjectPath.Factory.DEFAULT_FACTORY.create(
472+
IObjectPath.Factory.FACTORY.create(
473473
entry.getKey().getRegionId().getId(), times[j], getDeviceID(j), measurements[column]);
474474
ObjectNode objectNode = new ObjectNode(isEoF, offset, content, relativePath);
475475
objectNode.setDataRegionReplicaSet(entry.getKey());

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/Base32ObjectPath.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
public class Base32ObjectPath implements IObjectPath {
3636

37-
Path path;
38-
int serializedSize = -1;
37+
private final Path path;
38+
private int serializedSize = -1;
3939

4040
private static final Deserializer DESERIALIZER =
4141
new Deserializer() {
@@ -52,7 +52,7 @@ public IObjectPath deserializeFrom(InputStream inputStream) throws IOException {
5252

5353
private static final Factory FACTORY = Base32ObjectPath::new;
5454

55-
public Base32ObjectPath(String first, String... more) {
55+
private Base32ObjectPath(String first, String... more) {
5656
path = Paths.get(first, more);
5757
}
5858

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/IObjectPath.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package org.apache.iotdb.db.storageengine.dataregion;
2121

22+
import org.apache.iotdb.db.conf.IoTDBConfig;
23+
import org.apache.iotdb.db.conf.IoTDBDescriptor;
24+
2225
import org.apache.tsfile.file.metadata.IDeviceID;
2326

2427
import java.io.IOException;
@@ -28,6 +31,8 @@
2831

2932
public interface IObjectPath {
3033

34+
IoTDBConfig CONFIG = IoTDBDescriptor.getInstance().getConfig();
35+
3136
int serialize(ByteBuffer byteBuffer);
3237

3338
int serialize(OutputStream outputStream) throws IOException;
@@ -38,7 +43,10 @@ interface Factory {
3843

3944
IObjectPath create(int regionId, long time, IDeviceID iDeviceID, String measurement);
4045

41-
Factory DEFAULT_FACTORY = Base32ObjectPath.getFACTORY();
46+
Factory FACTORY =
47+
CONFIG.getRestrictObjectLimit()
48+
? Base32ObjectPath.getFACTORY()
49+
: PlainObjectPath.getFACTORY();
4250
}
4351

4452
interface Deserializer {
@@ -47,6 +55,9 @@ interface Deserializer {
4755

4856
IObjectPath deserializeFrom(InputStream inputStream) throws IOException;
4957

50-
Deserializer DEFAULT_DESERIALIZER = Base32ObjectPath.getDESERIALIZER();
58+
Deserializer DESERIALIZER =
59+
CONFIG.getRestrictObjectLimit()
60+
? Base32ObjectPath.getDESERIALIZER()
61+
: PlainObjectPath.getDESERIALIZER();
5162
}
5263
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.storageengine.dataregion;
21+
22+
import org.apache.tsfile.file.metadata.IDeviceID;
23+
import org.apache.tsfile.utils.ReadWriteIOUtils;
24+
25+
import java.io.File;
26+
import java.io.IOException;
27+
import java.io.InputStream;
28+
import java.io.OutputStream;
29+
import java.nio.ByteBuffer;
30+
31+
public class PlainObjectPath implements IObjectPath {
32+
33+
private final String filePath;
34+
35+
private static final Deserializer DESERIALIZER =
36+
new Deserializer() {
37+
@Override
38+
public IObjectPath deserializeFrom(ByteBuffer byteBuffer) {
39+
return deserialize(byteBuffer);
40+
}
41+
42+
@Override
43+
public IObjectPath deserializeFrom(InputStream inputStream) throws IOException {
44+
return deserialize(inputStream);
45+
}
46+
};
47+
48+
private static final Factory FACTORY = PlainObjectPath::new;
49+
50+
private PlainObjectPath(String filePath) {
51+
this.filePath = filePath;
52+
}
53+
54+
public PlainObjectPath(int regionId, long time, IDeviceID iDeviceID, String measurement) {
55+
String objectFileName = time + ".bin";
56+
Object[] segments = iDeviceID.getSegments();
57+
StringBuilder relativePathString =
58+
new StringBuilder(String.valueOf(regionId)).append(File.separator);
59+
for (Object segment : segments) {
60+
relativePathString
61+
.append(segment == null ? "null" : segment.toString().toLowerCase())
62+
.append(File.separator);
63+
}
64+
relativePathString.append(measurement).append(File.separator);
65+
relativePathString.append(objectFileName);
66+
this.filePath = relativePathString.toString();
67+
}
68+
69+
@Override
70+
public int serialize(ByteBuffer byteBuffer) {
71+
return ReadWriteIOUtils.write(filePath, byteBuffer);
72+
}
73+
74+
@Override
75+
public int serialize(OutputStream outputStream) throws IOException {
76+
return ReadWriteIOUtils.write(filePath, outputStream);
77+
}
78+
79+
@Override
80+
public int getSerializedSize() {
81+
return ReadWriteIOUtils.sizeToWrite(filePath);
82+
}
83+
84+
public static PlainObjectPath deserialize(ByteBuffer byteBuffer) {
85+
String filePath = ReadWriteIOUtils.readString(byteBuffer);
86+
return new PlainObjectPath(filePath);
87+
}
88+
89+
public static PlainObjectPath deserialize(InputStream stream) throws IOException {
90+
String filePath = ReadWriteIOUtils.readString(stream);
91+
return new PlainObjectPath(filePath);
92+
}
93+
94+
@Override
95+
public String toString() {
96+
return filePath;
97+
}
98+
99+
public static Factory getFACTORY() {
100+
return FACTORY;
101+
}
102+
103+
public static Deserializer getDESERIALIZER() {
104+
return DESERIALIZER;
105+
}
106+
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/ObjectTypeUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@
1919

2020
package org.apache.iotdb.db.utils;
2121

22-
import java.nio.ByteBuffer;
2322
import org.apache.iotdb.commons.exception.ObjectFileNotExist;
2423
import org.apache.iotdb.db.service.metrics.FileMetrics;
2524
import org.apache.iotdb.db.storageengine.dataregion.IObjectPath;
26-
import org.apache.iotdb.db.storageengine.dataregion.IObjectPath.Deserializer;
2725
import org.apache.iotdb.db.storageengine.rescon.disk.TierManager;
2826

29-
import org.apache.tsfile.common.conf.TSFileConfig;
3027
import org.apache.tsfile.utils.Binary;
3128
import org.slf4j.Logger;
3229
import org.slf4j.LoggerFactory;
3330

3431
import java.io.File;
3532
import java.io.IOException;
33+
import java.nio.ByteBuffer;
3634
import java.nio.file.Files;
3735
import java.util.Optional;
3836

@@ -46,7 +44,8 @@ private ObjectTypeUtils() {}
4644
public static File getObjectPathFromBinary(Binary binary) {
4745
byte[] bytes = binary.getValues();
4846
ByteBuffer buffer = ByteBuffer.wrap(bytes, 8, bytes.length - 8);
49-
String relativeObjectFilePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(buffer).toString();
47+
String relativeObjectFilePath =
48+
IObjectPath.Deserializer.DESERIALIZER.deserializeFrom(buffer).toString();
5049
Optional<File> file = TIER_MANAGER.getAbsoluteObjectFilePath(relativeObjectFilePath);
5150
if (!file.isPresent()) {
5251
throw new ObjectFileNotExist(relativeObjectFilePath);
@@ -58,7 +57,8 @@ public static Optional<File> getNullableObjectPathFromBinary(
5857
Binary binary, boolean needTempFile) {
5958
byte[] bytes = binary.getValues();
6059
ByteBuffer buffer = ByteBuffer.wrap(bytes, 8, bytes.length - 8);
61-
String relativeObjectFilePath = Deserializer.DEFAULT_DESERIALIZER.deserializeFrom(buffer).toString();
60+
String relativeObjectFilePath =
61+
IObjectPath.Deserializer.DESERIALIZER.deserializeFrom(buffer).toString();
6262
return TIER_MANAGER.getAbsoluteObjectFilePath(relativeObjectFilePath, needTempFile);
6363
}
6464

0 commit comments

Comments
 (0)