You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2026/06/09 10:20:53 UTC
(iotdb) 01/03: Add cache
This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch add_measurement_cache
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c6706b77976e0e744c34f16d9cbde41a22c6795e
Author: Tian Jiang <jt...@163.com>
AuthorDate: Thu Jun 4 16:29:05 2026 +0800
Add cache
---
.../conf/iotdb-system.properties.template | 6 +++
.../apache/iotdb/commons/conf/CommonConfig.java | 10 ++++
.../iotdb/commons/conf/CommonDescriptor.java | 9 ++++
.../org/apache/iotdb/commons/utils/PathUtils.java | 56 ++++++++++++++++++++--
4 files changed, 77 insertions(+), 4 deletions(-)
diff --git a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
index 531cbac91a8..9910dace7d8 100644
--- a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
+++ b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template
@@ -909,6 +909,12 @@ tag_attribute_flush_interval=1000
# Datatype: int
tag_attribute_total_size=700
+# The maximum number of single measurement check results cached by PathUtils.
+# Set to 0 to disable this cache.
+# effectiveMode: restart
+# Datatype: int
+single_measurement_check_cache_size=10000
+
# max measurement num of internal request
# When creating timeseries with Session.createMultiTimeseries, the user input plan, the timeseries num of
# which exceeds this num, will be split to several plans with timeseries no more than this num.
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
index 6a8956e423b..830659f7e17 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
@@ -407,6 +407,8 @@ public class CommonConfig {
// Max size for tag and attribute of one time series
private int tagAttributeTotalSize = 700;
+ private int singleMeasurementCheckCacheSize = 10_000;
+
// maximum number of Cluster Databases allowed
private int databaseLimitThreshold = -1;
@@ -2611,6 +2613,14 @@ public class CommonConfig {
this.tagAttributeTotalSize = tagAttributeTotalSize;
}
+ public int getSingleMeasurementCheckCacheSize() {
+ return singleMeasurementCheckCacheSize;
+ }
+
+ public void setSingleMeasurementCheckCacheSize(int singleMeasurementCheckCacheSize) {
+ this.singleMeasurementCheckCacheSize = singleMeasurementCheckCacheSize;
+ }
+
public int getDatabaseLimitThreshold() {
return databaseLimitThreshold;
}
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
index 5cd954a09f7..3215d29843f 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
@@ -276,6 +276,15 @@ public class CommonDescriptor {
properties.getProperty(
"tag_attribute_total_size", String.valueOf(config.getTagAttributeTotalSize()))));
+ int singleMeasurementCheckCacheSize =
+ Integer.parseInt(
+ properties.getProperty(
+ "single_measurement_check_cache_size",
+ String.valueOf(config.getSingleMeasurementCheckCacheSize())));
+ if (singleMeasurementCheckCacheSize >= 0) {
+ config.setSingleMeasurementCheckCacheSize(singleMeasurementCheckCacheSize);
+ }
+
config.setTimePartitionOrigin(
Long.parseLong(
properties.getProperty(
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java
index 615bd62453f..1803ebb68ca 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java
@@ -18,10 +18,13 @@
*/
package org.apache.iotdb.commons.utils;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.MetadataException;
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.tsfile.common.constant.TsFileConstant;
import org.apache.tsfile.exception.PathParseException;
import org.apache.tsfile.file.metadata.IDeviceID;
@@ -35,6 +38,12 @@ import java.util.Map;
public class PathUtils {
+ private static final Cache<String, SingleMeasurementCheckResult> SINGLE_MEASUREMENT_CHECK_CACHE =
+ Caffeine.newBuilder()
+ .maximumSize(
+ CommonDescriptor.getInstance().getConfig().getSingleMeasurementCheckCacheSize())
+ .build();
+
/**
* @param path the path will split. ex, root.ln.
* @return string array. ex, [root, ln]
@@ -162,20 +171,29 @@ public class PathUtils {
if (measurement == null) {
return null;
}
+ SingleMeasurementCheckResult result =
+ SINGLE_MEASUREMENT_CHECK_CACHE.get(measurement, PathUtils::checkSingleMeasurement);
+ if (result.isLegal()) {
+ return result.getMeasurement();
+ }
+ throw new IllegalPathException(measurement);
+ }
+
+ private static SingleMeasurementCheckResult checkSingleMeasurement(String measurement) {
if (measurement.startsWith(TsFileConstant.BACK_QUOTE_STRING)
&& measurement.endsWith(TsFileConstant.BACK_QUOTE_STRING)) {
if (checkBackQuotes(measurement.substring(1, measurement.length() - 1))) {
- return removeBackQuotesIfNecessary(measurement);
+ return SingleMeasurementCheckResult.legal(removeBackQuotesIfNecessary(measurement));
} else {
- throw new IllegalPathException(measurement);
+ return SingleMeasurementCheckResult.illegal();
}
}
if (IoTDBConstant.reservedWords.contains(measurement.toUpperCase())
|| isRealNumber(measurement)
|| !TsFileConstant.NODE_NAME_PATTERN.matcher(measurement).matches()) {
- throw new IllegalPathException(measurement);
+ return SingleMeasurementCheckResult.illegal();
}
- return measurement;
+ return SingleMeasurementCheckResult.legal(measurement);
}
/** Return true if the str is a real number. Examples: 1.0; +1.0; -1.0; 0011; 011e3; +23e-3 */
@@ -225,4 +243,34 @@ public class PathUtils {
public static boolean isTableModelDatabase(final String databaseName) {
return !databaseName.startsWith("root.");
}
+
+ private static class SingleMeasurementCheckResult {
+
+ private static final SingleMeasurementCheckResult ILLEGAL =
+ new SingleMeasurementCheckResult(false, null);
+
+ private final boolean legal;
+ private final String measurement;
+
+ private SingleMeasurementCheckResult(boolean legal, String measurement) {
+ this.legal = legal;
+ this.measurement = measurement;
+ }
+
+ private static SingleMeasurementCheckResult legal(String measurement) {
+ return new SingleMeasurementCheckResult(true, measurement);
+ }
+
+ private static SingleMeasurementCheckResult illegal() {
+ return ILLEGAL;
+ }
+
+ private boolean isLegal() {
+ return legal;
+ }
+
+ private String getMeasurement() {
+ return measurement;
+ }
+ }
}