Skip to content

Commit b46f637

Browse files
authored
[To dev/1.3] Optimize the efficiency of DualKeyCacheImpl's mayEvict (#16445) (#16669)
1 parent dbc0133 commit b46f637

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,12 @@ 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+
10541060
private int schemaThreadCount = 5;
10551061

10561062
private String readConsistencyLevel = "strong";
@@ -3506,6 +3512,15 @@ public void setDataNodeSchemaCacheEvictionPolicy(String dataNodeSchemaCacheEvict
35063512
this.dataNodeSchemaCacheEvictionPolicy = dataNodeSchemaCacheEvictionPolicy;
35073513
}
35083514

3515+
public int getCacheEvictionMemoryComputationThreshold() {
3516+
return cacheEvictionMemoryComputationThreshold;
3517+
}
3518+
3519+
public void setCacheEvictionMemoryComputationThreshold(
3520+
int cacheEvictionMemoryComputationThreshold) {
3521+
this.cacheEvictionMemoryComputationThreshold = cacheEvictionMemoryComputationThreshold;
3522+
}
3523+
35093524
public int getSchemaThreadCount() {
35103525
return schemaThreadCount;
35113526
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,12 @@ 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+
11001106
conf.setSchemaThreadCount(
11011107
Integer.parseInt(
11021108
properties.getProperty(
@@ -2076,6 +2082,13 @@ public synchronized void loadHotModifiedProps(TrimProperties properties)
20762082
// update trusted_uri_pattern
20772083
loadTrustedUriPattern(properties);
20782084

2085+
// update cache_eviction_memory_computation_threshold
2086+
conf.setCacheEvictionMemoryComputationThreshold(
2087+
Integer.parseInt(
2088+
properties.getProperty(
2089+
"cache_eviction_memory_computation_threshold",
2090+
String.valueOf(conf.getCacheEvictionMemoryComputationThreshold()))));
2091+
20792092
// tvlist_sort_threshold
20802093
conf.setTVListSortThreshold(
20812094
Integer.parseInt(

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

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

2020
package org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.dualkeycache.impl;
2121

22+
import org.apache.iotdb.db.conf.IoTDBDescriptor;
2223
import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.dualkeycache.IDualKeyCache;
2324
import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.dualkeycache.IDualKeyCacheStats;
2425

@@ -199,12 +200,13 @@ public void update(
199200

200201
private void mayEvict() {
201202
long exceedMemory;
203+
final int threshold =
204+
IoTDBDescriptor.getInstance().getConfig().getCacheEvictionMemoryComputationThreshold();
202205
while ((exceedMemory = cacheStats.getExceedMemory()) > 0) {
203206
// Not compute each time to save time when FK is too many
204-
// The hard-coded size is 100
205207
do {
206208
exceedMemory -= evictOneCacheEntry();
207-
} while (exceedMemory > 0 && firstKeyMap.size() > 100);
209+
} while (exceedMemory > 0 && firstKeyMap.size() > threshold);
208210
}
209211
}
210212

0 commit comments

Comments
 (0)