Skip to content

Commit abb25f4

Browse files
authored
Removed the useless first key in schema cache (#16881)
* refactor * fix * fix * sonar
1 parent d5c1834 commit abb25f4

30 files changed

+505
-1094
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,6 @@ public class IoTDBConfig {
10511051
/** Policy of DataNodeSchemaCache eviction */
10521052
private String dataNodeSchemaCacheEvictionPolicy = "FIFO";
10531053

1054-
/**
1055-
* Threshold for cache size in mayEvict. When cache size exceeds this threshold, the system will
1056-
* compute total memory in each eviction iteration to ensure accurate memory management.
1057-
*/
1058-
private int cacheEvictionMemoryComputationThreshold = 20;
1059-
10601054
private int schemaThreadCount = 5;
10611055

10621056
private String readConsistencyLevel = "strong";
@@ -3511,15 +3505,6 @@ public void setDataNodeSchemaCacheEvictionPolicy(String dataNodeSchemaCacheEvict
35113505
this.dataNodeSchemaCacheEvictionPolicy = dataNodeSchemaCacheEvictionPolicy;
35123506
}
35133507

3514-
public int getCacheEvictionMemoryComputationThreshold() {
3515-
return cacheEvictionMemoryComputationThreshold;
3516-
}
3517-
3518-
public void setCacheEvictionMemoryComputationThreshold(
3519-
int cacheEvictionMemoryComputationThreshold) {
3520-
this.cacheEvictionMemoryComputationThreshold = cacheEvictionMemoryComputationThreshold;
3521-
}
3522-
35233508
public int getSchemaThreadCount() {
35243509
return schemaThreadCount;
35253510
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,12 +1097,6 @@ public void loadProperties(TrimProperties properties) throws BadNodeUrlException
10971097
properties.getProperty(
10981098
"datanode_schema_cache_eviction_policy", conf.getDataNodeSchemaCacheEvictionPolicy()));
10991099

1100-
conf.setCacheEvictionMemoryComputationThreshold(
1101-
Integer.parseInt(
1102-
properties.getProperty(
1103-
"cache_eviction_memory_computation_threshold",
1104-
String.valueOf(conf.getCacheEvictionMemoryComputationThreshold()))));
1105-
11061100
conf.setSchemaThreadCount(
11071101
Integer.parseInt(
11081102
properties.getProperty(
@@ -2088,13 +2082,6 @@ public synchronized void loadHotModifiedProps(TrimProperties properties)
20882082
// update trusted_uri_pattern
20892083
loadTrustedUriPattern(properties);
20902084

2091-
// update cache_eviction_memory_computation_threshold
2092-
conf.setCacheEvictionMemoryComputationThreshold(
2093-
Integer.parseInt(
2094-
properties.getProperty(
2095-
"cache_eviction_memory_computation_threshold",
2096-
String.valueOf(conf.getCacheEvictionMemoryComputationThreshold()))));
2097-
20982085
// tvlist_sort_threshold
20992086
conf.setTVListSortThreshold(
21002087
Integer.parseInt(

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public Response executeFastLastQueryStatement(
111111

112112
PartialPath prefixPath =
113113
new PartialPath(prefixPathList.getPrefixPaths().toArray(new String[0]));
114-
final Map<String, Map<PartialPath, Map<String, TimeValuePair>>> resultMap = new HashMap<>();
114+
final Map<PartialPath, Map<String, TimeValuePair>> resultMap = new HashMap<>();
115115

116116
final String prefixString = prefixPath.toString();
117117
for (ISchemaRegion region : SchemaEngine.getInstance().getAllSchemaRegions()) {
@@ -170,21 +170,18 @@ public Response executeFastLastQueryStatement(
170170
List<Object> timeseries = new ArrayList<>();
171171
List<Object> valueList = new ArrayList<>();
172172
List<Object> dataTypeList = new ArrayList<>();
173-
for (Map.Entry<String, Map<PartialPath, Map<String, TimeValuePair>>> entry :
173+
for (final Map.Entry<PartialPath, Map<String, TimeValuePair>> device2MeasurementLastEntry :
174174
resultMap.entrySet()) {
175-
for (final Map.Entry<PartialPath, Map<String, TimeValuePair>> device2MeasurementLastEntry :
176-
entry.getValue().entrySet()) {
177-
final String deviceWithSeparator =
178-
device2MeasurementLastEntry.getKey() + TsFileConstant.PATH_SEPARATOR;
179-
for (Map.Entry<String, TimeValuePair> measurementEntry :
180-
device2MeasurementLastEntry.getValue().entrySet()) {
181-
final TimeValuePair tvPair = measurementEntry.getValue();
182-
if (tvPair != DeviceLastCache.EMPTY_TIME_VALUE_PAIR) {
183-
valueList.add(tvPair.getValue().getStringValue());
184-
dataTypeList.add(tvPair.getValue().getDataType().name());
185-
targetDataSet.addTimestampsItem(tvPair.getTimestamp());
186-
timeseries.add(deviceWithSeparator + measurementEntry.getKey());
187-
}
175+
final String deviceWithSeparator =
176+
device2MeasurementLastEntry.getKey() + TsFileConstant.PATH_SEPARATOR;
177+
for (Map.Entry<String, TimeValuePair> measurementEntry :
178+
device2MeasurementLastEntry.getValue().entrySet()) {
179+
final TimeValuePair tvPair = measurementEntry.getValue();
180+
if (tvPair != DeviceLastCache.EMPTY_TIME_VALUE_PAIR) {
181+
valueList.add(tvPair.getValue().getStringValue());
182+
dataTypeList.add(tvPair.getValue().getDataType().name());
183+
targetDataSet.addTimestampsItem(tvPair.getTimestamp());
184+
timeseries.add(deviceWithSeparator + measurementEntry.getKey());
188185
}
189186
}
190187
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ public TSExecuteStatementResp executeFastLastDataQueryForOnePrefixPath(
818818
"The \"executeFastLastDataQueryForOnePrefixPath\" dos not support wildcards."));
819819
}
820820

821-
final Map<String, Map<PartialPath, Map<String, TimeValuePair>>> resultMap = new HashMap<>();
821+
final Map<PartialPath, Map<String, TimeValuePair>> resultMap = new HashMap<>();
822822
int sensorNum = 0;
823823

824824
final String prefixString = prefixPath.toString();
@@ -839,25 +839,22 @@ public TSExecuteStatementResp executeFastLastDataQueryForOnePrefixPath(
839839
// 2.2 all sensors hit cache, return response ~= 20ms
840840
final TsBlockBuilder builder = LastQueryUtil.createTsBlockBuilder(sensorNum);
841841

842-
for (final Map.Entry<String, Map<PartialPath, Map<String, TimeValuePair>>> result :
842+
for (final Map.Entry<PartialPath, Map<String, TimeValuePair>> device2MeasurementLastEntry :
843843
resultMap.entrySet()) {
844-
for (final Map.Entry<PartialPath, Map<String, TimeValuePair>> device2MeasurementLastEntry :
845-
result.getValue().entrySet()) {
846-
final String deviceWithSeparator =
847-
device2MeasurementLastEntry.getKey() + TsFileConstant.PATH_SEPARATOR;
848-
for (final Map.Entry<String, TimeValuePair> measurementLastEntry :
849-
device2MeasurementLastEntry.getValue().entrySet()) {
850-
final TimeValuePair tvPair = measurementLastEntry.getValue();
851-
if (tvPair != DeviceLastCache.EMPTY_TIME_VALUE_PAIR) {
852-
LastQueryUtil.appendLastValue(
853-
builder,
854-
tvPair.getTimestamp(),
855-
new Binary(
856-
deviceWithSeparator + measurementLastEntry.getKey(),
857-
TSFileConfig.STRING_CHARSET),
858-
tvPair.getValue().getStringValue(),
859-
tvPair.getValue().getDataType().name());
860-
}
844+
final String deviceWithSeparator =
845+
device2MeasurementLastEntry.getKey() + TsFileConstant.PATH_SEPARATOR;
846+
for (final Map.Entry<String, TimeValuePair> measurementLastEntry :
847+
device2MeasurementLastEntry.getValue().entrySet()) {
848+
final TimeValuePair tvPair = measurementLastEntry.getValue();
849+
if (tvPair != DeviceLastCache.EMPTY_TIME_VALUE_PAIR) {
850+
LastQueryUtil.appendLastValue(
851+
builder,
852+
tvPair.getTimestamp(),
853+
new Binary(
854+
deviceWithSeparator + measurementLastEntry.getKey(),
855+
TSFileConfig.STRING_CHARSET),
856+
tvPair.getValue().getStringValue(),
857+
tvPair.getValue().getDataType().name());
861858
}
862859
}
863860
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeInternalRPCServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public TSStatus invalidatePartitionCache(final TInvalidateCacheReq req) {
537537

538538
@Override
539539
public TSStatus invalidateLastCache(final String database) {
540-
DataNodeSchemaCache.getInstance().invalidateDatabaseLastCache(database);
540+
DataNodeSchemaCache.getInstance().getDeviceSchemaCache().invalidateLastCache();
541541
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
542542
}
543543

@@ -546,7 +546,7 @@ public TSStatus invalidateSchemaCache(final TInvalidateCacheReq req) {
546546
DataNodeSchemaCache.getInstance().takeWriteLock();
547547
try {
548548
// req.getFullPath() is a database path
549-
DataNodeSchemaCache.getInstance().getDeviceSchemaCache().invalidate(req.getFullPath());
549+
DataNodeSchemaCache.getInstance().getDeviceSchemaCache().invalidateAll();
550550
ClusterTemplateManager.getInstance().invalid(req.getFullPath());
551551
LOGGER.info("Schema cache of {} has been invalidated", req.getFullPath());
552552
return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/schema/DataNodeSchemaCache.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,6 @@ public void invalidateLastCache(final PartialPath path) {
306306
deviceSchemaCache.invalidateLastCache(path.getDevicePath(), path.getMeasurement());
307307
}
308308

309-
public void invalidateDatabaseLastCache(final String database) {
310-
if (!CommonDescriptor.getInstance().getConfig().isLastCacheEnable()) {
311-
return;
312-
}
313-
deviceSchemaCache.invalidateLastCache(database);
314-
}
315-
316309
/**
317310
* Update the {@link DeviceLastCache} in writing. If a measurement is with all {@code null}s, its
318311
* {@link TimeValuePair}[] shall be {@code null}. For correctness, this will put the {@link

0 commit comments

Comments
 (0)