This is an automated email from the ASF dual-hosted git repository.
justinchen pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new 52041d076e4 [To dev/1.3] Implemented clear last cache / schema cache
option in clear cache (#16349)
52041d076e4 is described below
commit 52041d076e4bc3f53f430ec726fb286546e69c03
Author: Caideyipi <[email protected]>
AuthorDate: Mon Sep 8 14:11:32 2025 +0800
[To dev/1.3] Implemented clear last cache / schema cache option in clear
cache (#16349)
* fix-cache
* fix
---
.../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 | 2 +-
.../CnToDnInternalServiceAsyncRequestManager.java | 5 ++++-
.../iotdb/confignode/manager/ConfigManager.java | 4 ++--
.../apache/iotdb/confignode/manager/IManager.java | 3 ++-
.../iotdb/confignode/manager/node/NodeManager.java | 9 ++++----
.../thrift/ConfigNodeRPCServiceProcessor.java | 9 ++++----
.../iotdb/db/protocol/client/ConfigNodeClient.java | 5 +++--
.../impl/DataNodeInternalRPCServiceImpl.java | 25 ++++++++++++++++++---
.../config/executor/ClusterConfigTaskExecutor.java | 16 ++++++-------
.../config/executor/IConfigTaskExecutor.java | 5 ++++-
.../plan/execution/config/sys/ClearCacheTask.java | 5 +++--
.../db/queryengine/plan/parser/ASTVisitor.java | 16 ++++++++++++-
.../plan/statement/sys/ClearCacheStatement.java | 11 +++++++++
.../db/service/DataNodeInternalRPCService.java | 4 ++++
.../commons/schema/cache/CacheClearOptions.java | 26 ++++++++++++++++++++++
.../iotdb/commons/client/ClientManagerTest.java | 9 +++++---
.../src/main/thrift/confignode.thrift | 4 ++--
.../src/main/thrift/datanode.thrift | 2 +-
18 files changed, 124 insertions(+), 36 deletions(-)
diff --git
a/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
b/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index f28a2e0a063..f37ef736851 100644
---
a/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++
b/iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -1061,7 +1061,7 @@ flush
// Clear Cache
clearCache
- : CLEAR CACHE (ON (LOCAL | CLUSTER))?
+ : CLEAR (SCHEMA | QUERY | ALL)? CACHE (ON (LOCAL | CLUSTER))?
;
// Set Configuration
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/CnToDnInternalServiceAsyncRequestManager.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/CnToDnInternalServiceAsyncRequestManager.java
index 59f99fe57cb..b9aac92a165 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/CnToDnInternalServiceAsyncRequestManager.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/client/async/CnToDnInternalServiceAsyncRequestManager.java
@@ -95,6 +95,7 @@ import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
/** Asynchronously send RPC requests to DataNodes. See queryengine.thrift for
more details. */
@@ -104,6 +105,7 @@ public class CnToDnInternalServiceAsyncRequestManager
private static final Logger LOGGER =
LoggerFactory.getLogger(CnToDnInternalServiceAsyncRequestManager.class);
+ @SuppressWarnings("unchecked")
@Override
protected void initActionMapBuilder() {
actionMapBuilder.put(
@@ -223,7 +225,8 @@ public class CnToDnInternalServiceAsyncRequestManager
client.flush((TFlushReq) req, (DataNodeTSStatusRPCHandler)
handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.CLEAR_CACHE,
- (req, client, handler) ->
client.clearCache((DataNodeTSStatusRPCHandler) handler));
+ (req, client, handler) ->
+ client.clearCache((Set<Integer>) req, (DataNodeTSStatusRPCHandler)
handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.START_REPAIR_DATA,
(req, client, handler) ->
client.startRepairData((DataNodeTSStatusRPCHandler) handler));
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
index b9613de8ed7..2d34c20e8ae 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
@@ -1581,10 +1581,10 @@ public class ConfigManager implements IManager {
}
@Override
- public TSStatus clearCache() {
+ public TSStatus clearCache(final Set<Integer> clearCacheOptions) {
TSStatus status = confirmLeader();
return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
- ? RpcUtils.squashResponseStatusList(nodeManager.clearCache())
+ ?
RpcUtils.squashResponseStatusList(nodeManager.clearCache(clearCacheOptions))
: status;
}
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java
index 88731538be2..326182fbef3 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/IManager.java
@@ -149,6 +149,7 @@ import org.apache.iotdb.rpc.TSStatusCode;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* A subset of services provided by {@link ConfigManager}. For use internally
only, passed to
@@ -544,7 +545,7 @@ public interface IManager {
TSStatus flushOnSpecificDN(TFlushReq req, Map<Integer, TDataNodeLocation>
dataNodeLocationMap);
/** Clear cache on all DataNodes. */
- TSStatus clearCache();
+ TSStatus clearCache(Set<Integer> clearCacheOptions);
/** Set Configuration. */
TSStatus setConfiguration(TSetConfigurationReq req);
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
index 8925375d573..2e0ac35d5df 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/node/NodeManager.java
@@ -904,11 +904,12 @@ public class NodeManager {
return clientHandler.getResponseList();
}
- public List<TSStatus> clearCache() {
- Map<Integer, TDataNodeLocation> dataNodeLocationMap =
+ public List<TSStatus> clearCache(final Set<Integer> clearCacheOptions) {
+ final Map<Integer, TDataNodeLocation> dataNodeLocationMap =
configManager.getNodeManager().getRegisteredDataNodeLocations();
- DataNodeAsyncRequestContext<Object, TSStatus> clientHandler =
- new DataNodeAsyncRequestContext<>(CnToDnAsyncRequestType.CLEAR_CACHE,
dataNodeLocationMap);
+ final DataNodeAsyncRequestContext<Set<Integer>, TSStatus> clientHandler =
+ new DataNodeAsyncRequestContext<>(
+ CnToDnAsyncRequestType.CLEAR_CACHE, clearCacheOptions,
dataNodeLocationMap);
CnToDnInternalServiceAsyncRequestManager.getInstance().sendAsyncRequestWithRetry(clientHandler);
return clientHandler.getResponseList();
}
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
index 21dbccd07a7..289e40ecec3 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java
@@ -216,6 +216,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
/** ConfigNodeRPCServer exposes the interface that interacts with the DataNode
*/
@@ -912,12 +913,12 @@ public class ConfigNodeRPCServiceProcessor implements
IConfigNodeRPCService.Ifac
}
@Override
- public TSStatus clearCache() {
- return configManager.clearCache();
+ public TSStatus clearCache(final Set<Integer> clearCacheOptions) {
+ return configManager.clearCache(clearCacheOptions);
}
@Override
- public TSStatus setConfiguration(TSetConfigurationReq req) throws TException
{
+ public TSStatus setConfiguration(TSetConfigurationReq req) {
return configManager.setConfiguration(req);
}
@@ -927,7 +928,7 @@ public class ConfigNodeRPCServiceProcessor implements
IConfigNodeRPCService.Ifac
}
@Override
- public TSStatus stopRepairData() throws TException {
+ public TSStatus stopRepairData() {
return configManager.stopRepairData();
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
index 2825eefaf4c..948afb1d563 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
@@ -180,6 +180,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import java.util.function.Predicate;
public class ConfigNodeClient implements IConfigNodeRPCService.Iface,
ThriftClient, AutoCloseable {
@@ -727,9 +728,9 @@ public class ConfigNodeClient implements
IConfigNodeRPCService.Iface, ThriftClie
}
@Override
- public TSStatus clearCache() throws TException {
+ public TSStatus clearCache(final Set<Integer> clearCacheOptions) throws
TException {
return executeRemoteCallWithRetry(
- () -> client.clearCache(), status -> !updateConfigNodeLeader(status));
+ () -> client.clearCache(clearCacheOptions), status ->
!updateConfigNodeLeader(status));
}
@Override
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeInternalRPCServiceImpl.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeInternalRPCServiceImpl.java
index d4c35b700cb..6ba0c45fe7b 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeInternalRPCServiceImpl.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/DataNodeInternalRPCServiceImpl.java
@@ -62,6 +62,7 @@ import
org.apache.iotdb.commons.pipe.agent.plugin.meta.PipePluginMeta;
import org.apache.iotdb.commons.pipe.agent.task.PipeTaskAgent;
import org.apache.iotdb.commons.pipe.agent.task.meta.PipeMeta;
import org.apache.iotdb.commons.schema.SchemaConstant;
+import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
import org.apache.iotdb.commons.schema.view.viewExpression.ViewExpression;
import org.apache.iotdb.commons.service.metric.MetricService;
import org.apache.iotdb.commons.service.metric.enums.Tag;
@@ -1959,10 +1960,28 @@ public class DataNodeInternalRPCServiceImpl implements
IDataNodeRPCService.Iface
}
@Override
- public TSStatus clearCache() throws TException {
+ public TSStatus clearCache(final Set<Integer> clearCacheOptions) throws
TException {
+ return clearCacheImpl(
+ clearCacheOptions.stream()
+ .map(i -> CacheClearOptions.values()[i])
+ .collect(Collectors.toSet()));
+ }
+
+ public TSStatus clearCacheImpl(final Set<CacheClearOptions> options) {
try {
- storageEngine.clearCache();
- } catch (Exception e) {
+ final DataNodeSchemaCache schemaCache =
DataNodeSchemaCache.getInstance();
+ if (options.contains(CacheClearOptions.DEFAULT)
+ || options.contains(CacheClearOptions.QUERY)) {
+ storageEngine.clearCache();
+ }
+ if (options.contains(CacheClearOptions.TREE_SCHEMA)) {
+ schemaCache.invalidateAll();
+ return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
+ }
+ if (options.contains(CacheClearOptions.QUERY)) {
+ schemaCache.invalidateLastCache(new PartialPath("root.**"));
+ }
+ } catch (final Exception e) {
return RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR,
e.getMessage());
}
return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
index 9dea7d92193..75a7e3f158d 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
@@ -53,6 +53,7 @@ import
org.apache.iotdb.commons.pipe.agent.task.meta.PipeStaticMeta;
import org.apache.iotdb.commons.pipe.config.PipeConfig;
import org.apache.iotdb.commons.pipe.config.constant.PipeSourceConstant;
import
org.apache.iotdb.commons.pipe.sink.payload.airgap.AirGapPseudoTPipeTransferRequest;
+import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
import org.apache.iotdb.commons.schema.view.viewExpression.ViewExpression;
import org.apache.iotdb.commons.subscription.config.SubscriptionConfig;
@@ -245,6 +246,7 @@ import org.apache.iotdb.db.schemaengine.template.Template;
import org.apache.iotdb.db.schemaengine.template.TemplateAlterOperationType;
import
org.apache.iotdb.db.schemaengine.template.alter.TemplateAlterOperationUtil;
import org.apache.iotdb.db.schemaengine.template.alter.TemplateExtendInfo;
+import org.apache.iotdb.db.service.DataNodeInternalRPCService;
import org.apache.iotdb.db.storageengine.StorageEngine;
import
org.apache.iotdb.db.storageengine.dataregion.compaction.repair.RepairTaskStatus;
import
org.apache.iotdb.db.storageengine.dataregion.compaction.schedule.CompactionScheduleTaskManager;
@@ -1059,24 +1061,22 @@ public class ClusterConfigTaskExecutor implements
IConfigTaskExecutor {
}
@Override
- public SettableFuture<ConfigTaskResult> clearCache(boolean onCluster) {
+ public SettableFuture<ConfigTaskResult> clearCache(
+ boolean onCluster, final Set<CacheClearOptions> options) {
SettableFuture<ConfigTaskResult> future = SettableFuture.create();
TSStatus tsStatus = new TSStatus();
if (onCluster) {
try (ConfigNodeClient client =
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
// Send request to some API server
- tsStatus = client.clearCache();
+ tsStatus =
+ client.clearCache(
+
options.stream().map(CacheClearOptions::ordinal).collect(Collectors.toSet()));
} catch (ClientManagerException | TException e) {
future.setException(e);
}
} else {
- try {
- StorageEngine.getInstance().clearCache();
- tsStatus = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
- } catch (Exception e) {
- tsStatus = RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR,
e.getMessage());
- }
+ tsStatus =
DataNodeInternalRPCService.getInstance().getImpl().clearCacheImpl(options);
}
if (tsStatus.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java
index 0b800a949a0..7ce0e4a8cad 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/IConfigTaskExecutor.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.common.rpc.thrift.TFlushReq;
import org.apache.iotdb.common.rpc.thrift.TSStatus;
import org.apache.iotdb.common.rpc.thrift.TSetConfigurationReq;
import org.apache.iotdb.commons.cluster.NodeStatus;
+import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
import org.apache.iotdb.confignode.rpc.thrift.TSpaceQuotaResp;
import org.apache.iotdb.confignode.rpc.thrift.TThrottleQuotaResp;
import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
@@ -88,6 +89,8 @@ import org.apache.iotdb.service.rpc.thrift.TPipeTransferResp;
import com.google.common.util.concurrent.SettableFuture;
+import java.util.Set;
+
public interface IConfigTaskExecutor {
SettableFuture<ConfigTaskResult> setDatabase(DatabaseSchemaStatement
databaseSchemaStatement);
@@ -128,7 +131,7 @@ public interface IConfigTaskExecutor {
SettableFuture<ConfigTaskResult> flush(TFlushReq tFlushReq, boolean
onCluster);
- SettableFuture<ConfigTaskResult> clearCache(boolean onCluster);
+ SettableFuture<ConfigTaskResult> clearCache(boolean onCluster,
Set<CacheClearOptions> options);
SettableFuture<ConfigTaskResult> setConfiguration(TSetConfigurationReq
tSetConfigurationReq);
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/sys/ClearCacheTask.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/sys/ClearCacheTask.java
index 55e6bcd8dc3..ff70081ecee 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/sys/ClearCacheTask.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/sys/ClearCacheTask.java
@@ -35,10 +35,11 @@ public class ClearCacheTask implements IConfigTask {
}
@Override
- public ListenableFuture<ConfigTaskResult> execute(IConfigTaskExecutor
configTaskExecutor)
+ public ListenableFuture<ConfigTaskResult> execute(final IConfigTaskExecutor
configTaskExecutor)
throws InterruptedException {
// If the action is executed successfully, return the Future.
// If your operation is async, you can return the corresponding future
directly.
- return configTaskExecutor.clearCache(clearCacheStatement.isOnCluster());
+ return configTaskExecutor.clearCache(
+ clearCacheStatement.isOnCluster(), clearCacheStatement.getOptions());
}
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index 83304b0c6c2..62e7e803b5e 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -29,6 +29,7 @@ import org.apache.iotdb.commons.conf.IoTDBConstant;
import org.apache.iotdb.commons.cq.TimeoutPolicy;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
import org.apache.iotdb.commons.schema.filter.SchemaFilter;
import org.apache.iotdb.commons.schema.filter.SchemaFilterFactory;
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
@@ -3350,8 +3351,21 @@ public class ASTVisitor extends
IoTDBSqlParserBaseVisitor<Statement> {
@Override
public Statement visitClearCache(IoTDBSqlParser.ClearCacheContext ctx) {
- ClearCacheStatement clearCacheStatement = new
ClearCacheStatement(StatementType.CLEAR_CACHE);
+ final ClearCacheStatement clearCacheStatement =
+ new ClearCacheStatement(StatementType.CLEAR_CACHE);
clearCacheStatement.setOnCluster(ctx.LOCAL() == null);
+
+ if (ctx.SCHEMA() != null) {
+
clearCacheStatement.setOptions(Collections.singleton(CacheClearOptions.TREE_SCHEMA));
+ } else if (ctx.QUERY() != null) {
+
clearCacheStatement.setOptions(Collections.singleton(CacheClearOptions.QUERY));
+ } else if (ctx.ALL() != null) {
+ clearCacheStatement.setOptions(
+ new HashSet<>(Arrays.asList(CacheClearOptions.TREE_SCHEMA,
CacheClearOptions.QUERY)));
+ } else {
+
clearCacheStatement.setOptions(Collections.singleton(CacheClearOptions.DEFAULT));
+ }
+
return clearCacheStatement;
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/sys/ClearCacheStatement.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/sys/ClearCacheStatement.java
index 29f31d02040..e1ce6082852 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/sys/ClearCacheStatement.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/sys/ClearCacheStatement.java
@@ -20,6 +20,7 @@
package org.apache.iotdb.db.queryengine.plan.statement.sys;
import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
import org.apache.iotdb.db.queryengine.plan.analyze.QueryType;
import org.apache.iotdb.db.queryengine.plan.statement.IConfigStatement;
import org.apache.iotdb.db.queryengine.plan.statement.Statement;
@@ -28,10 +29,12 @@ import
org.apache.iotdb.db.queryengine.plan.statement.StatementVisitor;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
public class ClearCacheStatement extends Statement implements IConfigStatement
{
private boolean onCluster;
+ private Set<CacheClearOptions> options;
public ClearCacheStatement(StatementType clearCacheType) {
this.statementType = clearCacheType;
@@ -45,6 +48,14 @@ public class ClearCacheStatement extends Statement
implements IConfigStatement {
this.onCluster = onCluster;
}
+ public Set<CacheClearOptions> getOptions() {
+ return options;
+ }
+
+ public void setOptions(final Set<CacheClearOptions> options) {
+ this.options = options;
+ }
+
@Override
public QueryType getQueryType() {
return QueryType.WRITE;
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCService.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCService.java
index 83e4869531f..9c8be161d85 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCService.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNodeInternalRPCService.java
@@ -88,6 +88,10 @@ public class DataNodeInternalRPCService extends ThriftService
return IoTDBDescriptor.getInstance().getConfig().getInternalPort();
}
+ public DataNodeInternalRPCServiceImpl getImpl() {
+ return impl;
+ }
+
private static class DataNodeInternalRPCServiceHolder {
private static final DataNodeInternalRPCService INSTANCE = new
DataNodeInternalRPCService();
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/cache/CacheClearOptions.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/cache/CacheClearOptions.java
new file mode 100644
index 00000000000..3ee5ba02f77
--- /dev/null
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/cache/CacheClearOptions.java
@@ -0,0 +1,26 @@
+/*
+ * 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.commons.schema.cache;
+
+public enum CacheClearOptions {
+ TREE_SCHEMA,
+ QUERY,
+ DEFAULT,
+}
diff --git
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/ClientManagerTest.java
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/ClientManagerTest.java
index b8bd8e7f931..70c32ca4801 100644
---
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/ClientManagerTest.java
+++
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/client/ClientManagerTest.java
@@ -30,6 +30,7 @@ import
org.apache.iotdb.commons.client.property.ThriftClientProperty;
import org.apache.iotdb.commons.client.sync.SyncDataNodeInternalServiceClient;
import org.apache.iotdb.commons.concurrent.ThreadName;
import org.apache.iotdb.commons.exception.StartupException;
+import org.apache.iotdb.commons.schema.cache.CacheClearOptions;
import org.apache.iotdb.mpp.rpc.thrift.IDataNodeRPCService;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
@@ -42,6 +43,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.CountDownLatch;
@@ -65,7 +67,7 @@ public class ClientManagerTest {
service = new MockInternalRPCService(endPoint);
IDataNodeRPCService.Iface processor =
mock(IDataNodeRPCService.Iface.class);
// timeout method
- when(processor.clearCache())
+
when(processor.clearCache(Collections.singleton(CacheClearOptions.DEFAULT.ordinal())))
.thenAnswer(
invocation -> {
Thread.sleep(CONNECTION_TIMEOUT + 1000);
@@ -511,7 +513,7 @@ public class ClientManagerTest {
Assert.assertEquals(0, asyncClusterManager.getPool().getNumIdle(endPoint));
}
- public void syncClientTimeoutTest() throws Exception {
+ public void syncClientTimeoutTest() {
// init syncClientManager
ClientManager<TEndPoint, SyncDataNodeInternalServiceClient>
syncClusterManager =
(ClientManager<TEndPoint, SyncDataNodeInternalServiceClient>)
@@ -529,7 +531,7 @@ public class ClientManagerTest {
// timeout RPC
try (SyncDataNodeInternalServiceClient syncClient =
syncClusterManager.borrowClient(endPoint)) {
- syncClient.clearCache();
+
syncClient.clearCache(Collections.singleton(CacheClearOptions.DEFAULT.ordinal()));
Assert.fail("A timeout exception should occur here");
} catch (Exception ignored) {
// no handling
@@ -580,6 +582,7 @@ public class ClientManagerTest {
AtomicBoolean finalFailed1 = failed;
CountDownLatch finalLatch1 = latch;
asyncClient.clearCache(
+ Collections.singleton(CacheClearOptions.DEFAULT.ordinal()),
new AsyncMethodCallback<TSStatus>() {
@Override
public void onComplete(TSStatus response) {
diff --git a/iotdb-protocol/thrift-confignode/src/main/thrift/confignode.thrift
b/iotdb-protocol/thrift-confignode/src/main/thrift/confignode.thrift
index 87a154e235e..d6e0b186aad 100644
--- a/iotdb-protocol/thrift-confignode/src/main/thrift/confignode.thrift
+++ b/iotdb-protocol/thrift-confignode/src/main/thrift/confignode.thrift
@@ -1465,8 +1465,8 @@ service IConfigNodeRPCService {
/** Persist all the data points in the memory table of the database to the
disk, and seal the data file on all DataNodes */
common.TSStatus flush(common.TFlushReq req)
- /** Clear the cache of chunk, chunk metadata and timeseries metadata to
release the memory footprint on all DataNodes */
- common.TSStatus clearCache()
+ /** Clear the specific caches of all DataNodes */
+ common.TSStatus clearCache(set<i32> cacheClearOptions)
/** Set configuration on specified node */
common.TSStatus setConfiguration(common.TSetConfigurationReq req)
diff --git a/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift
b/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift
index da5fac70664..989d624f337 100644
--- a/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift
+++ b/iotdb-protocol/thrift-datanode/src/main/thrift/datanode.thrift
@@ -906,7 +906,7 @@ service IDataNodeRPCService {
common.TSStatus stopRepairData()
- common.TSStatus clearCache()
+ common.TSStatus clearCache(set<i32> cacheClearOptions)
common.TShowConfigurationResp showConfiguration()