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 f28a2e0a06314..f37ef73685182 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 59f99fe57cb03..b9aac92a16504 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 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 @@ protected void initActionMapBuilder() { client.flush((TFlushReq) req, (DataNodeTSStatusRPCHandler) handler)); actionMapBuilder.put( CnToDnAsyncRequestType.CLEAR_CACHE, - (req, client, handler) -> client.clearCache((DataNodeTSStatusRPCHandler) handler)); + (req, client, handler) -> + client.clearCache((Set) 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 b9613de8ed785..2d34c20e8ae34 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 TSStatus flushOnSpecificDN( } @Override - public TSStatus clearCache() { + public TSStatus clearCache(final Set 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 88731538be29d..326182fbef36a 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 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 @@ TDataPartitionTableResp getOrCreateDataPartition( TSStatus flushOnSpecificDN(TFlushReq req, Map dataNodeLocationMap); /** Clear cache on all DataNodes. */ - TSStatus clearCache(); + TSStatus clearCache(Set 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 8925375d573b5..2e0ac35d5df98 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 List flushOnSpecificDN( return clientHandler.getResponseList(); } - public List clearCache() { - Map dataNodeLocationMap = + public List clearCache(final Set clearCacheOptions) { + final Map dataNodeLocationMap = configManager.getNodeManager().getRegisteredDataNodeLocations(); - DataNodeAsyncRequestContext clientHandler = - new DataNodeAsyncRequestContext<>(CnToDnAsyncRequestType.CLEAR_CACHE, dataNodeLocationMap); + final DataNodeAsyncRequestContext, 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 21dbccd07a75a..289e40ecec3f7 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.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 TSStatus flush(TFlushReq req) throws TException { } @Override - public TSStatus clearCache() { - return configManager.clearCache(); + public TSStatus clearCache(final Set 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 TSStatus startRepairData() { } @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 2825eefaf4c4d..948afb1d563c5 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 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 TSStatus flush(TFlushReq req) throws TException { } @Override - public TSStatus clearCache() throws TException { + public TSStatus clearCache(final Set 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 d4c35b700cbc7..6ba0c45fe7b4a 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.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 TSStatus flush(TFlushReq req) throws TException { } @Override - public TSStatus clearCache() throws TException { + public TSStatus clearCache(final Set clearCacheOptions) throws TException { + return clearCacheImpl( + clearCacheOptions.stream() + .map(i -> CacheClearOptions.values()[i]) + .collect(Collectors.toSet())); + } + + public TSStatus clearCacheImpl(final Set 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 9dea7d92193bb..75a7e3f158d2e 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.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.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 SettableFuture flush(TFlushReq tFlushReq, boolean onClu } @Override - public SettableFuture clearCache(boolean onCluster) { + public SettableFuture clearCache( + boolean onCluster, final Set options) { SettableFuture 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 0b800a949a0e0..7ce0e4a8cada8 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.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 com.google.common.util.concurrent.SettableFuture; +import java.util.Set; + public interface IConfigTaskExecutor { SettableFuture setDatabase(DatabaseSchemaStatement databaseSchemaStatement); @@ -128,7 +131,7 @@ public interface IConfigTaskExecutor { SettableFuture flush(TFlushReq tFlushReq, boolean onCluster); - SettableFuture clearCache(boolean onCluster); + SettableFuture clearCache(boolean onCluster, Set options); SettableFuture 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 55e6bcd8dc32a..ff70081ecee0c 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 ClearCacheTask(ClearCacheStatement clearCacheStatement) { } @Override - public ListenableFuture execute(IConfigTaskExecutor configTaskExecutor) + public ListenableFuture 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 83304b0c6c2c1..62e7e803b5e95 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.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 Statement visitFlush(IoTDBSqlParser.FlushContext ctx) { @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 29f31d0204088..e1ce60828520b 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 java.util.Collections; import java.util.List; +import java.util.Set; public class ClearCacheStatement extends Statement implements IConfigStatement { private boolean onCluster; + private Set options; public ClearCacheStatement(StatementType clearCacheType) { this.statementType = clearCacheType; @@ -45,6 +48,14 @@ public void setOnCluster(boolean onCluster) { this.onCluster = onCluster; } + public Set getOptions() { + return options; + } + + public void setOptions(final Set 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 83e4869531f11..9c8be161d8547 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 int getBindPort() { 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 0000000000000..3ee5ba02f7786 --- /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 b8bd8e7f93159..70c32ca4801d8 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.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 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 void setUp() throws StartupException, TException { 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 void borrowNullTest() { Assert.assertEquals(0, asyncClusterManager.getPool().getNumIdle(endPoint)); } - public void syncClientTimeoutTest() throws Exception { + public void syncClientTimeoutTest() { // init syncClientManager ClientManager syncClusterManager = (ClientManager) @@ -529,7 +531,7 @@ public void syncClientTimeoutTest() throws Exception { // 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 void onError(Exception exception) { AtomicBoolean finalFailed1 = failed; CountDownLatch finalLatch1 = latch; asyncClient.clearCache( + Collections.singleton(CacheClearOptions.DEFAULT.ordinal()), new AsyncMethodCallback() { @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 87a154e235eb9..d6e0b186aad22 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 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 da5fac7066429..989d624f3378d 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 cacheClearOptions) common.TShowConfigurationResp showConfiguration()