Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ flush

// Clear Cache
clearCache
: CLEAR CACHE (ON (LOCAL | CLUSTER))?
: CLEAR (SCHEMA | QUERY | ALL)? CACHE (ON (LOCAL | CLUSTER))?
;

// Set Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -104,6 +105,7 @@ public class CnToDnInternalServiceAsyncRequestManager
private static final Logger LOGGER =
LoggerFactory.getLogger(CnToDnInternalServiceAsyncRequestManager.class);

@SuppressWarnings("unchecked")
@Override
protected void initActionMapBuilder() {
actionMapBuilder.put(
Expand Down Expand Up @@ -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<Integer>) req, (DataNodeTSStatusRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.START_REPAIR_DATA,
(req, client, handler) -> client.startRepairData((DataNodeTSStatusRPCHandler) handler));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1581,10 +1581,10 @@ public TSStatus flushOnSpecificDN(
}

@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -544,7 +545,7 @@ TDataPartitionTableResp getOrCreateDataPartition(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,11 +904,12 @@ public List<TSStatus> flushOnSpecificDN(
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -912,12 +913,12 @@ public TSStatus flush(TFlushReq req) throws TException {
}

@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);
}

Expand All @@ -927,7 +928,7 @@ public TSStatus startRepairData() {
}

@Override
public TSStatus stopRepairData() throws TException {
public TSStatus stopRepairData() {
return configManager.stopRepairData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -727,9 +728,9 @@ public TSStatus flush(TFlushReq req) throws TException {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1959,10 +1960,28 @@ public TSStatus flush(TFlushReq req) throws TException {
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1059,24 +1061,22 @@ public SettableFuture<ConfigTaskResult> flush(TFlushReq tFlushReq, boolean onClu
}

@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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +89,8 @@

import com.google.common.util.concurrent.SettableFuture;

import java.util.Set;

public interface IConfigTaskExecutor {

SettableFuture<ConfigTaskResult> setDatabase(DatabaseSchemaStatement databaseSchemaStatement);
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public ClearCacheTask(ClearCacheStatement clearCacheStatement) {
}

@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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CacheClearOptions> options;

public ClearCacheStatement(StatementType clearCacheType) {
this.statementType = clearCacheType;
Expand All @@ -45,6 +48,14 @@ public void setOnCluster(boolean onCluster) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
Loading
Loading