This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 28942257d0c Remove ShardingCache (#38999)
28942257d0c is described below
commit 28942257d0cbaa22d0e9c6f3c40f2d5b7f338a67
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 5 04:49:43 2026 +0800
Remove ShardingCache (#38999)
---
.../api/config/ShardingRuleConfiguration.java | 3 -
.../config/cache/ShardingCacheConfiguration.java | 35 ---
.../cache/ShardingCacheOptionsConfiguration.java | 37 ----
.../sharding/cache/ShardingCache.java | 51 -----
.../checker/ShardingRouteCacheableCheckResult.java | 35 ---
.../checker/ShardingRouteCacheableChecker.java | 234 ---------------------
.../CacheableShardingAlgorithmChecker.java | 50 -----
.../cache/route/CachedShardingSQLRouter.java | 100 ---------
.../cache/route/cache/ShardingRouteCache.java | 64 ------
.../cache/route/cache/ShardingRouteCacheKey.java | 37 ----
.../cache/route/cache/ShardingRouteCacheValue.java | 85 --------
.../ShardingRuleConfigurationEmptyChecker.java | 2 +-
.../sharding/route/engine/ShardingSQLRouter.java | 14 --
.../shardingsphere/sharding/rule/ShardingRule.java | 13 --
.../changed/ShardingCacheChangedProcessor.java | 59 ------
.../yaml/config/YamlShardingRuleConfiguration.java | 4 -
.../cache/YamlShardingCacheConfiguration.java | 34 ---
.../YamlShardingCacheOptionsConfiguration.java | 36 ----
.../YamlShardingRuleConfigurationSwapper.java | 9 -
.../YamlShardingCacheConfigurationSwapper.java | 43 ----
...mlShardingCacheOptionsConfigurationSwapper.java | 42 ----
....spi.rule.RuleItemConfigurationChangedProcessor | 1 -
.../checker/ShardingRouteCacheableCheckerTest.java | 200 ------------------
.../cache/route/CachedShardingSQLRouterTest.java | 169 ---------------
.../cache/route/cache/ShardingRouteCacheTest.java | 39 ----
.../ShardingRuleConfigurationEmptyCheckerTest.java | 9 -
.../changed/ShardingCacheChangedProcessorTest.java | 104 ---------
...figurationYamlRuleNodeTupleSwapperEngineIT.java | 3 +-
.../yaml/ShardingRuleConfigurationYamlIT.java | 16 --
.../resources/yaml/sharding-rule-for-tuple.yaml | 7 -
.../src/test/resources/yaml/sharding-rule.yaml | 7 -
...arding-table-reference-rule-current-config.yaml | 7 -
.../reachability-metadata.json | 14 +-
33 files changed, 3 insertions(+), 1560 deletions(-)
diff --git
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
index 0ab866b3a67..ed3a06c0e6c 100644
---
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
+++
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
@@ -23,7 +23,6 @@ import lombok.Setter;
import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.config.rule.function.DistributedRuleConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -69,8 +68,6 @@ public final class ShardingRuleConfiguration implements
DatabaseRuleConfiguratio
private Map<String, AlgorithmConfiguration> auditors = new
LinkedHashMap<>();
- private ShardingCacheConfiguration shardingCache;
-
@Override
public Collection<String> getLogicTableNames() {
return new
CaseInsensitiveSet<>(tables.stream().map(ShardingTableRuleConfiguration::getLogicTable).collect(Collectors.toList()));
diff --git
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/cache/ShardingCacheConfiguration.java
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/cache/ShardingCacheConfiguration.java
deleted file mode 100644
index 583c8c4a799..00000000000
---
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/cache/ShardingCacheConfiguration.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.shardingsphere.sharding.api.config.cache;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
-
-/**
- * Configuration for sharding cache.
- */
-@RequiredArgsConstructor
-@Getter
-@ToString
-public final class ShardingCacheConfiguration {
-
- private final int allowedMaxSqlLength;
-
- private final ShardingCacheOptionsConfiguration routeCache;
-}
diff --git
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/cache/ShardingCacheOptionsConfiguration.java
b/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/cache/ShardingCacheOptionsConfiguration.java
deleted file mode 100644
index 124faf055ce..00000000000
---
a/features/sharding/api/src/main/java/org/apache/shardingsphere/sharding/api/config/cache/ShardingCacheOptionsConfiguration.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.shardingsphere.sharding.api.config.cache;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.ToString;
-
-/**
- * Options of sharding cache.
- */
-@RequiredArgsConstructor
-@Getter
-@ToString
-public final class ShardingCacheOptionsConfiguration {
-
- private final boolean softValues;
-
- private final int initialCapacity;
-
- private final int maximumSize;
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/ShardingCache.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/ShardingCache.java
deleted file mode 100644
index 030fbbd4eb0..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/ShardingCache.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache;
-
-import lombok.Getter;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.cache.checker.ShardingRouteCacheableChecker;
-import org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCache;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import org.apache.shardingsphere.timeservice.core.rule.TimestampServiceRule;
-import
org.apache.shardingsphere.timeservice.core.rule.builder.DefaultTimestampServiceConfigurationBuilder;
-
-/**
- * <strong>EXPERIMENTAL</strong> Sharding cache.
- */
-@Getter
-public final class ShardingCache {
-
- private final ShardingCacheConfiguration configuration;
-
- private final ShardingRule shardingRule;
-
- private final TimestampServiceRule timestampServiceRule;
-
- private final ShardingRouteCacheableChecker routeCacheableChecker;
-
- private final ShardingRouteCache routeCache;
-
- public ShardingCache(final ShardingCacheConfiguration config, final
ShardingRule shardingRule) {
- configuration = config;
- this.shardingRule = shardingRule;
- timestampServiceRule = new TimestampServiceRule(new
DefaultTimestampServiceConfigurationBuilder().build());
- routeCacheableChecker = new ShardingRouteCacheableChecker(this);
- routeCache = new ShardingRouteCache(config.getRouteCache());
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckResult.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckResult.java
deleted file mode 100644
index 6a1c9edebb3..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckResult.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.checker;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-import java.util.List;
-
-/**
- * Route cacheable check result.
- */
-@RequiredArgsConstructor
-@Getter
-public class ShardingRouteCacheableCheckResult {
-
- private final boolean probablyCacheable;
-
- private final List<Integer> shardingConditionParameterMarkerIndexes;
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableChecker.java
deleted file mode 100644
index 5c4a255daf7..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableChecker.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.checker;
-
-import com.github.benmanes.caffeine.cache.Caffeine;
-import com.github.benmanes.caffeine.cache.LoadingCache;
-import com.google.common.collect.Range;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import
org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.DeleteStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.UpdateStatementContext;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.session.query.QueryContext;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
-import org.apache.shardingsphere.sharding.cache.ShardingCache;
-import
org.apache.shardingsphere.sharding.cache.checker.algorithm.CacheableShardingAlgorithmChecker;
-import
org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
-import
org.apache.shardingsphere.sharding.route.engine.condition.engine.InsertClauseShardingConditionEngine;
-import
org.apache.shardingsphere.sharding.route.engine.condition.engine.WhereClauseShardingConditionEngine;
-import
org.apache.shardingsphere.sharding.route.engine.condition.value.ListShardingConditionValue;
-import
org.apache.shardingsphere.sharding.route.engine.condition.value.RangeShardingConditionValue;
-import
org.apache.shardingsphere.sharding.route.engine.condition.value.ShardingConditionValue;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import org.apache.shardingsphere.sharding.rule.ShardingTable;
-import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.InsertValuesSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
-import org.apache.shardingsphere.timeservice.core.rule.TimestampServiceRule;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-/**
- * Sharding route cacheable checker.
- */
-public final class ShardingRouteCacheableChecker {
-
- private final ShardingRule shardingRule;
-
- private final TimestampServiceRule timestampServiceRule;
-
- private final LoadingCache<Key, ShardingRouteCacheableCheckResult>
checkingCache;
-
- public ShardingRouteCacheableChecker(final ShardingCache shardingCache) {
- shardingRule = shardingCache.getShardingRule();
- timestampServiceRule = shardingCache.getTimestampServiceRule();
- checkingCache =
buildCache(shardingCache.getConfiguration().getRouteCache());
- }
-
- private LoadingCache<Key, ShardingRouteCacheableCheckResult>
buildCache(final ShardingCacheOptionsConfiguration cacheOptions) {
- Caffeine<Object, Object> result =
Caffeine.newBuilder().initialCapacity(cacheOptions.getInitialCapacity()).maximumSize(cacheOptions.getMaximumSize());
- if (cacheOptions.isSoftValues()) {
- result.softValues();
- }
- return result.build(this::load);
- }
-
- private ShardingRouteCacheableCheckResult load(final Key key) {
- SQLStatementContext sqlStatementContext = key.getSqlStatementContext();
- ShardingRouteCacheableCheckResult result;
- if (sqlStatementContext instanceof SelectStatementContext) {
- result = checkSelectCacheable((SelectStatementContext)
sqlStatementContext, key.getParameters(), key.getDatabase());
- } else if (sqlStatementContext instanceof UpdateStatementContext) {
- result = checkUpdateCacheable((UpdateStatementContext)
sqlStatementContext, key.getParameters(), key.getDatabase());
- } else if (sqlStatementContext instanceof InsertStatementContext) {
- result = checkInsertCacheable((InsertStatementContext)
sqlStatementContext, key.getParameters(), key.getDatabase());
- } else if (sqlStatementContext instanceof DeleteStatementContext) {
- result = checkDeleteCacheable((DeleteStatementContext)
sqlStatementContext, key.getParameters(), key.getDatabase());
- } else {
- result = new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- key.getParameters().clear();
- return result;
- }
-
- private ShardingRouteCacheableCheckResult checkSelectCacheable(final
SelectStatementContext statementContext, final List<Object> params, final
ShardingSphereDatabase database) {
- Collection<String> tableNames = new
HashSet<>(statementContext.getTablesContext().getTableNames());
- if (!shardingRule.isAllShardingTables(tableNames)) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- if (1 != tableNames.size() &&
!shardingRule.isAllConfigBindingTables(tableNames) ||
containsNonCacheableShardingAlgorithm(tableNames)) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- List<ShardingCondition> shardingConditions = new
WhereClauseShardingConditionEngine(database, shardingRule,
timestampServiceRule).createShardingConditions(statementContext, params);
- return checkShardingConditionsCacheable(shardingConditions);
- }
-
- private ShardingRouteCacheableCheckResult checkUpdateCacheable(final
UpdateStatementContext statementContext, final List<Object> params, final
ShardingSphereDatabase database) {
- return checkUpdateOrDeleteCacheable(statementContext, params,
database);
- }
-
- private ShardingRouteCacheableCheckResult checkInsertCacheable(final
InsertStatementContext statementContext, final List<Object> params, final
ShardingSphereDatabase database) {
- Collection<String> tableNames =
statementContext.getTablesContext().getTableNames();
- if (1 != tableNames.size() || null !=
statementContext.getInsertSelectContext() || null !=
statementContext.getOnDuplicateKeyUpdateValueContext()
- ||
statementContext.getGeneratedKeyContext().map(GeneratedKeyContext::isGenerated).orElse(false))
{
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- boolean isShardingTable = shardingRule.isAllShardingTables(tableNames);
- if (!isShardingTable ||
containsNonCacheableShardingAlgorithm(tableNames)) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- Collection<InsertValuesSegment> values =
statementContext.getSqlStatement().getValues();
- if (1 != values.size()) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- InsertValuesSegment valueSegment = values.iterator().next();
- for (ExpressionSegment each : valueSegment.getValues()) {
- if (!(each instanceof ParameterMarkerExpressionSegment || each
instanceof LiteralExpressionSegment)) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- }
- List<ShardingCondition> shardingConditions = new
InsertClauseShardingConditionEngine(database, shardingRule,
timestampServiceRule).createShardingConditions(statementContext, params);
- return checkShardingConditionsCacheable(shardingConditions);
- }
-
- private ShardingRouteCacheableCheckResult checkDeleteCacheable(final
DeleteStatementContext statementContext, final List<Object> params, final
ShardingSphereDatabase database) {
- return checkUpdateOrDeleteCacheable(statementContext, params,
database);
- }
-
- private ShardingRouteCacheableCheckResult
checkUpdateOrDeleteCacheable(final SQLStatementContext sqlStatementContext,
final List<Object> params, final ShardingSphereDatabase database) {
- Collection<String> tableNames =
sqlStatementContext.getTablesContext().getTableNames();
- if (1 != tableNames.size()) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- boolean isShardingTable = shardingRule.isAllShardingTables(tableNames);
- if (!isShardingTable ||
containsNonCacheableShardingAlgorithm(tableNames)) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- List<ShardingCondition> shardingConditions = new
WhereClauseShardingConditionEngine(database, shardingRule,
timestampServiceRule).createShardingConditions(sqlStatementContext, params);
- return checkShardingConditionsCacheable(shardingConditions);
- }
-
- private boolean containsNonCacheableShardingAlgorithm(final
Collection<String> logicTables) {
- for (String each : logicTables) {
- ShardingTable shardingTable = shardingRule.getShardingTable(each);
- String databaseShardingAlgorithmName =
shardingRule.getDatabaseShardingStrategyConfiguration(shardingTable).getShardingAlgorithmName();
- ShardingAlgorithm databaseShardingAlgorithm =
shardingRule.getShardingAlgorithms().get(databaseShardingAlgorithmName);
- if (null != databaseShardingAlgorithm &&
!CacheableShardingAlgorithmChecker.isCacheableShardingAlgorithm(databaseShardingAlgorithm))
{
- return true;
- }
- String tableShardingAlgorithmName =
shardingRule.getTableShardingStrategyConfiguration(shardingTable).getShardingAlgorithmName();
- ShardingAlgorithm tableShardingAlgorithm =
shardingRule.getShardingAlgorithms().get(tableShardingAlgorithmName);
- if (null != tableShardingAlgorithm &&
!CacheableShardingAlgorithmChecker.isCacheableShardingAlgorithm(tableShardingAlgorithm))
{
- return true;
- }
- }
- return false;
- }
-
- private static ShardingRouteCacheableCheckResult
checkShardingConditionsCacheable(final List<ShardingCondition>
shardingConditions) {
- Set<Integer> result = new TreeSet<>();
- for (ShardingCondition each : shardingConditions) {
- for (ShardingConditionValue conditionValue : each.getValues()) {
- if (!isConditionTypeCacheable(conditionValue)) {
- return new ShardingRouteCacheableCheckResult(false,
Collections.emptyList());
- }
- result.addAll(conditionValue.getParameterMarkerIndexes());
- }
- }
- return new ShardingRouteCacheableCheckResult(true, new
ArrayList<>(result));
- }
-
- private static boolean isConditionTypeCacheable(final
ShardingConditionValue conditionValue) {
- if (conditionValue instanceof ListShardingConditionValue<?>) {
- for (Object eachValue : ((ListShardingConditionValue<?>)
conditionValue).getValues()) {
- if (!(eachValue instanceof Number)) {
- return false;
- }
- }
- }
- if (conditionValue instanceof RangeShardingConditionValue<?>) {
- Range<?> range = ((RangeShardingConditionValue<?>)
conditionValue).getValueRange();
- return range.lowerEndpoint() instanceof Number &&
range.upperEndpoint() instanceof Number;
- }
- return true;
- }
-
- /**
- * Check if query is cacheable.
- *
- * @param database database
- * @param queryContext query context
- * @return is cacheable
- */
- public ShardingRouteCacheableCheckResult check(final
ShardingSphereDatabase database, final QueryContext queryContext) {
- return checkingCache.get(new Key(database, queryContext.getSql(),
queryContext.getSqlStatementContext(), queryContext.getParameters()));
- }
-
- @EqualsAndHashCode(of = "sql")
- @Getter
- private static final class Key {
-
- private final ShardingSphereDatabase database;
-
- private final String sql;
-
- private final SQLStatementContext sqlStatementContext;
-
- private final List<Object> parameters;
-
- private Key(final ShardingSphereDatabase database, final String sql,
final SQLStatementContext sqlStatementContext, final List<Object> params) {
- this.database = database;
- this.sql = sql;
- this.sqlStatementContext = sqlStatementContext;
- parameters = new ArrayList<>(params);
- }
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/algorithm/CacheableShardingAlgorithmChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/algorithm/CacheableShardingAlgorithmChecker.java
deleted file mode 100644
index c4a4e46647f..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/algorithm/CacheableShardingAlgorithmChecker.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.checker.algorithm;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.sharding.algorithm.sharding.mod.HashModShardingAlgorithm;
-import
org.apache.shardingsphere.sharding.algorithm.sharding.mod.ModShardingAlgorithm;
-import
org.apache.shardingsphere.sharding.algorithm.sharding.range.BoundaryBasedRangeShardingAlgorithm;
-import
org.apache.shardingsphere.sharding.algorithm.sharding.range.VolumeBasedRangeShardingAlgorithm;
-import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-/**
- * Cacheable sharding algorithm checker.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class CacheableShardingAlgorithmChecker {
-
- private static final Collection<Class<? extends ShardingAlgorithm>>
CACHEABLE_SHARDING_ALGORITHM_CLASSES = Arrays.asList(
- ModShardingAlgorithm.class, HashModShardingAlgorithm.class,
VolumeBasedRangeShardingAlgorithm.class,
BoundaryBasedRangeShardingAlgorithm.class);
-
- /**
- * Check if sharding algorithm is cacheable.
- *
- * @param shardingAlgorithm instance of sharding algorithm
- * @return is sharding algorithm cacheable
- */
- @SuppressWarnings("BooleanMethodIsAlwaysInverted")
- public static boolean isCacheableShardingAlgorithm(final ShardingAlgorithm
shardingAlgorithm) {
- return
CACHEABLE_SHARDING_ALGORITHM_CLASSES.contains(shardingAlgorithm.getClass());
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouter.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouter.java
deleted file mode 100644
index 74fc25e42a1..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouter.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.route;
-
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.infra.route.context.RouteContext;
-import org.apache.shardingsphere.infra.session.query.QueryContext;
-import org.apache.shardingsphere.sharding.cache.ShardingCache;
-import
org.apache.shardingsphere.sharding.cache.checker.ShardingRouteCacheableCheckResult;
-import
org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCacheKey;
-import
org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCacheValue;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Cached sharding SQL router.
- */
-public final class CachedShardingSQLRouter {
-
- /**
- * Find {@link RouteContext} from cache or calculate and try caching.
- *
- * @param originSQLRouter origin SQL router
- * @param queryContext query context
- * @param globalRuleMetaData global rule meta data
- * @param database database
- * @param shardingCache sharding cache
- * @param tableNames table names
- * @param props configuration properties
- * @return route context
- */
- public Optional<RouteContext> loadRouteContext(final OriginSQLRouter
originSQLRouter, final QueryContext queryContext, final RuleMetaData
globalRuleMetaData,
- final
ShardingSphereDatabase database, final ShardingCache shardingCache, final
Collection<String> tableNames, final ConfigurationProperties props) {
- if (queryContext.getSql().length() >
shardingCache.getConfiguration().getAllowedMaxSqlLength()) {
- return Optional.empty();
- }
- ShardingRouteCacheableCheckResult cacheableCheckResult =
shardingCache.getRouteCacheableChecker().check(database, queryContext);
- if (!cacheableCheckResult.isProbablyCacheable()) {
- return Optional.empty();
- }
- List<Object> shardingConditionParams = new
ArrayList<>(cacheableCheckResult.getShardingConditionParameterMarkerIndexes().size());
- for (int each :
cacheableCheckResult.getShardingConditionParameterMarkerIndexes()) {
- if (each >= queryContext.getParameters().size()) {
- return Optional.empty();
- }
-
shardingConditionParams.add(queryContext.getParameters().get(each));
- }
- Optional<RouteContext> cachedResult =
shardingCache.getRouteCache().get(new
ShardingRouteCacheKey(queryContext.getSql(), shardingConditionParams))
- .flatMap(ShardingRouteCacheValue::getCachedRouteContext);
- RouteContext result = cachedResult.orElseGet(() ->
originSQLRouter.createRouteContext(queryContext, globalRuleMetaData, database,
shardingCache.getShardingRule(), tableNames, props));
- if (!cachedResult.isPresent() && hitOneShardOnly(result)) {
- shardingCache.getRouteCache().put(new
ShardingRouteCacheKey(queryContext.getSql(), shardingConditionParams), new
ShardingRouteCacheValue(result));
- }
- return Optional.of(result);
- }
-
- private boolean hitOneShardOnly(final RouteContext routeContext) {
- return 1 == routeContext.getRouteUnits().size() && 1 ==
routeContext.getRouteUnits().iterator().next().getTableMappers().size()
- && 1 == routeContext.getOriginalDataNodes().size() && 1 ==
routeContext.getOriginalDataNodes().iterator().next().size();
- }
-
- @FunctionalInterface
- public interface OriginSQLRouter {
-
- /**
- * Create route context.
- *
- * @param queryContext query context
- * @param globalRuleMetaData global rule meta data
- * @param database database
- * @param rule rule
- * @param tableNames table names
- * @param props configuration properties
- * @return route context
- */
- RouteContext createRouteContext(QueryContext queryContext,
RuleMetaData globalRuleMetaData, ShardingSphereDatabase database, ShardingRule
rule, Collection<String> tableNames,
- ConfigurationProperties props);
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCache.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCache.java
deleted file mode 100644
index 7939b7b07c9..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCache.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.route.cache;
-
-import com.github.benmanes.caffeine.cache.Cache;
-import com.github.benmanes.caffeine.cache.Caffeine;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
-
-import java.util.Optional;
-
-/**
- * Cache for sharding route.
- */
-public final class ShardingRouteCache {
-
- private final Cache<ShardingRouteCacheKey, ShardingRouteCacheValue> cache;
-
- public ShardingRouteCache(final ShardingCacheOptionsConfiguration
cacheOptions) {
- cache = buildRouteCache(cacheOptions);
- }
-
- private Cache<ShardingRouteCacheKey, ShardingRouteCacheValue>
buildRouteCache(final ShardingCacheOptionsConfiguration cacheOptions) {
- Caffeine<Object, Object> result =
Caffeine.newBuilder().initialCapacity(cacheOptions.getInitialCapacity()).maximumSize(cacheOptions.getMaximumSize());
- if (cacheOptions.isSoftValues()) {
- result.softValues();
- }
- return result.build();
- }
-
- /**
- * Cache route result.
- *
- * @param key cache key
- * @param value cache value
- */
- public void put(final ShardingRouteCacheKey key, final
ShardingRouteCacheValue value) {
- cache.put(key, value);
- }
-
- /**
- * Get cached route result.
- *
- * @param key cache key
- * @return optional cached route result
- */
- public Optional<ShardingRouteCacheValue> get(final ShardingRouteCacheKey
key) {
- return Optional.ofNullable(cache.getIfPresent(key));
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheKey.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheKey.java
deleted file mode 100644
index d7f0e712586..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheKey.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.route.cache;
-
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-import java.util.List;
-
-/**
- * Key of sharding route cache.
- */
-@RequiredArgsConstructor
-@Getter
-@EqualsAndHashCode
-public final class ShardingRouteCacheKey {
-
- private final String sql;
-
- private final List<Object> shardingConditionParameters;
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheValue.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheValue.java
deleted file mode 100644
index fb1961a5bae..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheValue.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.route.cache;
-
-import lombok.AccessLevel;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.datanode.DataNode;
-import org.apache.shardingsphere.infra.route.context.RouteContext;
-import org.apache.shardingsphere.infra.route.context.RouteStageContext;
-import org.apache.shardingsphere.infra.route.context.RouteUnit;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * Value of sharding route cache.
- */
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShardingRouteCacheValue {
-
- private final boolean cacheable;
-
- private final RouteContext cachedRouteContext;
-
- public ShardingRouteCacheValue(final RouteContext routeContext) {
- this(null != routeContext, routeContext);
- }
-
- /**
- * Get cached route context.
- *
- * @return optional cached route context
- */
- public Optional<RouteContext> getCachedRouteContext() {
- return cacheable ? Optional.of(deepCopyRouteContext()) :
Optional.empty();
- }
-
- private RouteContext deepCopyRouteContext() {
- RouteContext result = new RouteContext();
- result.getOriginalDataNodes().addAll(deepCopyOriginalDataNodes());
- result.getRouteUnits().addAll(deepCopyRouteUnits());
- result.getRouteStageContexts().putAll(deepCopyRouteStageContext());
- return result;
- }
-
- private Collection<Collection<DataNode>> deepCopyOriginalDataNodes() {
- Collection<Collection<DataNode>> result = new
ArrayList<>(cachedRouteContext.getOriginalDataNodes().size());
- for (Collection<DataNode> eachDataNodes :
cachedRouteContext.getOriginalDataNodes()) {
- result.add(eachDataNodes.stream().map(each -> new
DataNode(each.getDataSourceName(), each.getSchemaName(),
each.getTableName())).collect(Collectors.toList()));
- }
- return result;
- }
-
- private Collection<RouteUnit> deepCopyRouteUnits() {
- Collection<RouteUnit> result = new
ArrayList<>(cachedRouteContext.getRouteUnits().size());
- for (RouteUnit each : cachedRouteContext.getRouteUnits()) {
- result.add(new RouteUnit(each.getDataSourceMapper(), new
ArrayList<>(each.getTableMappers())));
- }
- return result;
- }
-
- private Map<Class<? extends ShardingSphereRule>, ? extends
RouteStageContext> deepCopyRouteStageContext() {
- // TODO Implements deep copy for route stage contexts
- return cachedRouteContext.getRouteStageContexts();
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyChecker.java
index a565a551d25..9d8fa563989 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyChecker.java
@@ -33,7 +33,7 @@ public final class ShardingRuleConfigurationEmptyChecker
implements DatabaseRule
&& (null == ruleConfig.getDefaultShardingColumn() ||
ruleConfig.getDefaultShardingColumn().isEmpty())
&& ruleConfig.getKeyGenerateStrategies().isEmpty()
&& ruleConfig.getShardingAlgorithms().isEmpty() &&
ruleConfig.getKeyGenerators().isEmpty()
- && ruleConfig.getAuditors().isEmpty() && null ==
ruleConfig.getShardingCache();
+ && ruleConfig.getAuditors().isEmpty();
}
@Override
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java
index 014b1ac3e7b..589558caac0 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingSQLRouter.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.lifecycle.EntranceSQLRouter;
import org.apache.shardingsphere.infra.session.query.QueryContext;
-import org.apache.shardingsphere.sharding.cache.route.CachedShardingSQLRouter;
import org.apache.shardingsphere.sharding.constant.ShardingOrder;
import
org.apache.shardingsphere.sharding.route.engine.checker.ShardingRouteContextCheckerFactory;
import
org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
@@ -39,7 +38,6 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.DM
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Optional;
/**
* Sharding SQL router.
@@ -50,18 +48,6 @@ public final class ShardingSQLRouter implements
EntranceSQLRouter<ShardingRule>
@Override
public RouteContext createRouteContext(final QueryContext queryContext,
final RuleMetaData globalRuleMetaData, final ShardingSphereDatabase database,
final ShardingRule rule, final
Collection<String> tableNames, final ConfigurationProperties props) {
- if (rule.isShardingCacheEnabled()) {
- Optional<RouteContext> result = new CachedShardingSQLRouter()
- .loadRouteContext(this::createRouteContext0, queryContext,
globalRuleMetaData, database, rule.getShardingCache(), tableNames, props);
- if (result.isPresent()) {
- return result.get();
- }
- }
- return createRouteContext0(queryContext, globalRuleMetaData, database,
rule, tableNames, props);
- }
-
- private RouteContext createRouteContext0(final QueryContext queryContext,
final RuleMetaData globalRuleMetaData, final ShardingSphereDatabase database,
final ShardingRule rule,
- final Collection<String>
tableNames, final ConfigurationProperties props) {
Collection<String> logicTableNames =
rule.getShardingLogicTableNames(tableNames);
if (logicTableNames.isEmpty()) {
return new RouteContext();
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index dcc2df976a3..9829cf884c3 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -52,7 +52,6 @@ import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShard
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.sharding.ShardingAutoTableAlgorithm;
-import org.apache.shardingsphere.sharding.cache.ShardingCache;
import org.apache.shardingsphere.sharding.constant.ShardingOrder;
import
org.apache.shardingsphere.sharding.exception.metadata.ShardingTableRuleNotFoundException;
import
org.apache.shardingsphere.sharding.rule.attribute.ShardingDataNodeRuleAttribute;
@@ -113,8 +112,6 @@ public final class ShardingRule implements DatabaseRule {
private final String defaultShardingColumn;
- private final ShardingCache shardingCache;
-
private final RuleAttributes attributes;
private final ShardingRuleChecker shardingRuleChecker = new
ShardingRuleChecker(this);
@@ -142,7 +139,6 @@ public final class ShardingRule implements DatabaseRule {
if (defaultKeyGenerateAlgorithm instanceof
ComputeNodeInstanceContextAware && -1 ==
computeNodeInstanceContext.getWorkerId()) {
((ComputeNodeInstanceContextAware)
defaultKeyGenerateAlgorithm).setComputeNodeInstanceContext(computeNodeInstanceContext);
}
- shardingCache = null == ruleConfig.getShardingCache() ? null : new
ShardingCache(ruleConfig.getShardingCache(), this);
// TODO check sharding rule configuration according to aggregated data
sources
Map<String, DataSource> aggregatedDataSources = new
RuleMetaData(builtRules).findAttribute(AggregatedDataSourceRuleAttribute.class)
.map(AggregatedDataSourceRuleAttribute::getAggregatedDataSources).orElseGet(()
-> PhysicalDataSourceAggregator.getAggregatedDataSources(dataSources,
builtRules));
@@ -591,15 +587,6 @@ public final class ShardingRule implements DatabaseRule {
.orElseGet(Collections::emptyMap);
}
- /**
- * Is sharding cache enabled.
- *
- * @return is sharding cache enabled
- */
- public boolean isShardingCacheEnabled() {
- return null != shardingCache;
- }
-
private boolean isJoinConditionContainsShardingColumns(final
Collection<String> tableNames, final Collection<WhereSegment> whereSegments) {
Collection<String> databaseJoinConditionTables = new
CaseInsensitiveSet<>(tableNames.size(), 1F);
Collection<String> tableJoinConditionTables = new
CaseInsensitiveSet<>(tableNames.size(), 1F);
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessor.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessor.java
deleted file mode 100644
index 21bc2857b96..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessor.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.shardingsphere.sharding.rule.changed;
-
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import
org.apache.shardingsphere.mode.spi.rule.RuleItemConfigurationChangedProcessor;
-import org.apache.shardingsphere.mode.spi.rule.RuleChangedItemType;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.swapper.cache.YamlShardingCacheConfigurationSwapper;
-
-/**
- * Sharding cache changed processor.
- */
-public final class ShardingCacheChangedProcessor implements
RuleItemConfigurationChangedProcessor<ShardingRuleConfiguration,
ShardingCacheConfiguration> {
-
- @Override
- public ShardingCacheConfiguration swapRuleItemConfiguration(final String
itemName, final String yamlContent) {
- return new
YamlShardingCacheConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent,
YamlShardingCacheConfiguration.class));
- }
-
- @Override
- public ShardingRuleConfiguration findRuleConfiguration(final
ShardingSphereDatabase database) {
- return
database.getRuleMetaData().findSingleRule(ShardingRule.class).map(ShardingRule::getConfiguration).orElseGet(ShardingRuleConfiguration::new);
- }
-
- @Override
- public void changeRuleItemConfiguration(final String itemName, final
ShardingRuleConfiguration currentRuleConfig, final ShardingCacheConfiguration
toBeChangedItemConfig) {
- currentRuleConfig.setShardingCache(toBeChangedItemConfig);
- }
-
- @Override
- public void dropRuleItemConfiguration(final String itemName, final
ShardingRuleConfiguration currentRuleConfig) {
- currentRuleConfig.setShardingCache(null);
- }
-
- @Override
- public RuleChangedItemType getType() {
- return new RuleChangedItemType("sharding", "sharding_cache");
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
index 9c716d2b89f..44a054301c8 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
@@ -26,7 +26,6 @@ import
org.apache.shardingsphere.mode.node.rule.tuple.annotation.RuleNodeTupleEn
import
org.apache.shardingsphere.mode.node.rule.tuple.annotation.RuleNodeTupleField.Type;
import
org.apache.shardingsphere.mode.node.rule.tuple.annotation.RuleNodeTupleKeyListNameGenerator;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheConfiguration;
import
org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.yaml.config.strategy.audit.YamlShardingAuditStrategyConfiguration;
@@ -85,9 +84,6 @@ public final class YamlShardingRuleConfiguration implements
YamlRuleConfiguratio
@RuleNodeTupleField(type = Type.OTHER)
private String defaultShardingColumn;
- @RuleNodeTupleField(type = Type.OTHER)
- private YamlShardingCacheConfiguration shardingCache;
-
@Override
public Class<ShardingRuleConfiguration> getRuleConfigurationType() {
return ShardingRuleConfiguration.class;
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/cache/YamlShardingCacheConfiguration.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/cache/YamlShardingCacheConfiguration.java
deleted file mode 100644
index a8defae5a59..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/cache/YamlShardingCacheConfiguration.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.shardingsphere.sharding.yaml.config.cache;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
-
-/**
- * Sharding cache configuration for YAML.
- */
-@Getter
-@Setter
-public final class YamlShardingCacheConfiguration implements YamlConfiguration
{
-
- private int allowedMaxSqlLength;
-
- private YamlShardingCacheOptionsConfiguration routeCache;
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/cache/YamlShardingCacheOptionsConfiguration.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/cache/YamlShardingCacheOptionsConfiguration.java
deleted file mode 100644
index 10864744088..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/cache/YamlShardingCacheOptionsConfiguration.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.shardingsphere.sharding.yaml.config.cache;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.infra.util.yaml.YamlConfiguration;
-
-/**
- * Sharding cache options configuration for YAML.
- */
-@Getter
-@Setter
-public final class YamlShardingCacheOptionsConfiguration implements
YamlConfiguration {
-
- private boolean softValues;
-
- private int initialCapacity;
-
- private int maximumSize;
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingRuleConfigurationSwapper.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingRuleConfigurationSwapper.java
index ced1f062cd5..382cbc64258 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingRuleConfigurationSwapper.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingRuleConfigurationSwapper.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.sharding.constant.ShardingOrder;
import
org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.swapper.cache.YamlShardingCacheConfigurationSwapper;
import
org.apache.shardingsphere.sharding.yaml.swapper.rule.YamlShardingAutoTableRuleConfigurationSwapper;
import
org.apache.shardingsphere.sharding.yaml.swapper.rule.YamlShardingTableReferenceRuleConfigurationConverter;
import
org.apache.shardingsphere.sharding.yaml.swapper.rule.YamlShardingTableRuleConfigurationSwapper;
@@ -55,8 +54,6 @@ public final class YamlShardingRuleConfigurationSwapper
implements YamlRuleConfi
private final YamlShardingAutoTableRuleConfigurationSwapper
autoTableSwapper = new YamlShardingAutoTableRuleConfigurationSwapper();
- private final YamlShardingCacheConfigurationSwapper shardingCacheSwapper =
new YamlShardingCacheConfigurationSwapper();
-
@Override
public YamlShardingRuleConfiguration swapToYamlConfiguration(final
ShardingRuleConfiguration data) {
YamlShardingRuleConfiguration result = new
YamlShardingRuleConfiguration();
@@ -67,9 +64,6 @@ public final class YamlShardingRuleConfigurationSwapper
implements YamlRuleConfi
setYamlKeyGenerateStrategies(data, result);
setYamlAlgorithms(data, result);
result.setDefaultShardingColumn(data.getDefaultShardingColumn());
- if (null != data.getShardingCache()) {
-
result.setShardingCache(shardingCacheSwapper.swapToYamlConfiguration(data.getShardingCache()));
- }
return result;
}
@@ -124,9 +118,6 @@ public final class YamlShardingRuleConfigurationSwapper
implements YamlRuleConfi
setKeyGenerateStrategies(yamlConfig, result);
setAlgorithms(yamlConfig, result);
result.setDefaultShardingColumn(yamlConfig.getDefaultShardingColumn());
- if (null != yamlConfig.getShardingCache()) {
-
result.setShardingCache(shardingCacheSwapper.swapToObject(yamlConfig.getShardingCache()));
- }
return result;
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/cache/YamlShardingCacheConfigurationSwapper.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/cache/YamlShardingCacheConfigurationSwapper.java
deleted file mode 100644
index b604dbf4231..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/cache/YamlShardingCacheConfigurationSwapper.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.shardingsphere.sharding.yaml.swapper.cache;
-
-import
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheConfiguration;
-
-/**
- * YAML sharding cache configuration swapper.
- */
-public final class YamlShardingCacheConfigurationSwapper implements
YamlConfigurationSwapper<YamlShardingCacheConfiguration,
ShardingCacheConfiguration> {
-
- private final YamlShardingCacheOptionsConfigurationSwapper
cacheOptionsConfigurationSwapper = new
YamlShardingCacheOptionsConfigurationSwapper();
-
- @Override
- public YamlShardingCacheConfiguration swapToYamlConfiguration(final
ShardingCacheConfiguration data) {
- YamlShardingCacheConfiguration result = new
YamlShardingCacheConfiguration();
- result.setAllowedMaxSqlLength(data.getAllowedMaxSqlLength());
-
result.setRouteCache(cacheOptionsConfigurationSwapper.swapToYamlConfiguration(data.getRouteCache()));
- return result;
- }
-
- @Override
- public ShardingCacheConfiguration swapToObject(final
YamlShardingCacheConfiguration yamlConfig) {
- return new
ShardingCacheConfiguration(yamlConfig.getAllowedMaxSqlLength(),
cacheOptionsConfigurationSwapper.swapToObject(yamlConfig.getRouteCache()));
- }
-}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/cache/YamlShardingCacheOptionsConfigurationSwapper.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/cache/YamlShardingCacheOptionsConfigurationSwapper.java
deleted file mode 100644
index 03173a3489e..00000000000
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/cache/YamlShardingCacheOptionsConfigurationSwapper.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.shardingsphere.sharding.yaml.swapper.cache;
-
-import
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheOptionsConfiguration;
-
-/**
- * YAML sharding cache options configuration swapper.
- */
-public final class YamlShardingCacheOptionsConfigurationSwapper implements
YamlConfigurationSwapper<YamlShardingCacheOptionsConfiguration,
ShardingCacheOptionsConfiguration> {
-
- @Override
- public YamlShardingCacheOptionsConfiguration swapToYamlConfiguration(final
ShardingCacheOptionsConfiguration data) {
- YamlShardingCacheOptionsConfiguration result = new
YamlShardingCacheOptionsConfiguration();
- result.setSoftValues(data.isSoftValues());
- result.setInitialCapacity(data.getInitialCapacity());
- result.setMaximumSize(data.getMaximumSize());
- return result;
- }
-
- @Override
- public ShardingCacheOptionsConfiguration swapToObject(final
YamlShardingCacheOptionsConfiguration yamlConfig) {
- return new
ShardingCacheOptionsConfiguration(yamlConfig.isSoftValues(),
yamlConfig.getInitialCapacity(), yamlConfig.getMaximumSize());
- }
-}
diff --git
a/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.rule.RuleItemConfigurationChangedProcessor
b/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.rule.RuleItemConfigurationChangedProcessor
index b727518d499..01d9728f3bb 100644
---
a/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.rule.RuleItemConfigurationChangedProcessor
+++
b/features/sharding/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.rule.RuleItemConfigurationChangedProcessor
@@ -27,4 +27,3 @@
org.apache.shardingsphere.sharding.rule.changed.DefaultTableShardingStrategyChan
org.apache.shardingsphere.sharding.rule.changed.DefaultKeyGenerateStrategyChangedProcessor
org.apache.shardingsphere.sharding.rule.changed.DefaultShardingAuditorStrategyChangedProcessor
org.apache.shardingsphere.sharding.rule.changed.DefaultShardingColumnChangedProcessor
-org.apache.shardingsphere.sharding.rule.changed.ShardingCacheChangedProcessor
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
deleted file mode 100644
index 7206d67fbda..00000000000
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.checker;
-
-import org.apache.groovy.util.Maps;
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.hint.HintValueContext;
-import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
-import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
-import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
-import org.apache.shardingsphere.infra.session.query.QueryContext;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
-import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
-import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import org.apache.shardingsphere.sql.parser.engine.api.CacheOption;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
-import org.apache.shardingsphere.test.infra.fixture.jdbc.MockedDataSource;
-import
org.apache.shardingsphere.timeservice.config.TimestampServiceRuleConfiguration;
-import org.apache.shardingsphere.timeservice.core.rule.TimestampServiceRule;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
-import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.junit.jupiter.params.support.ParameterDeclarations;
-
-import java.sql.Types;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.function.Function;
-import java.util.stream.Stream;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class ShardingRouteCacheableCheckerTest {
-
- private static final String DATABASE_NAME = "sharding_db";
-
- private static final String SCHEMA_NAME = "public";
-
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
-
- @ParameterizedTest(name = "probably cacheable: {2}, SQL: {0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertCheckCacheable(final String sql, final List<Object> parameters,
final boolean expectedProbablyCacheable, final List<Integer>
expectedShardingConditionParameterMarkerIndexes) {
- ShardingRule shardingRule = createShardingRule();
- TimestampServiceRule timestampServiceRule = createTimeServiceRule();
- ShardingSphereDatabase database = createDatabase(shardingRule,
timestampServiceRule);
- ShardingRouteCacheableCheckResult actual = new
ShardingRouteCacheableChecker(shardingRule.getShardingCache()).check(database,
createQueryContext(database, sql, parameters));
- assertThat(actual.isProbablyCacheable(),
is(expectedProbablyCacheable));
- assertThat(actual.getShardingConditionParameterMarkerIndexes(),
is(expectedShardingConditionParameterMarkerIndexes));
- }
-
- private ShardingRule createShardingRule() {
- ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
- ruleConfig.getBindingTableGroups().add(new
ShardingTableReferenceRuleConfiguration("foo", "t_order,t_order_item"));
- ruleConfig.getShardingAlgorithms().put("mod", new
AlgorithmConfiguration("MOD", PropertiesBuilder.build(new
Property("sharding-count", "2"))));
- ruleConfig.getShardingAlgorithms().put("inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "ds_${id % 2}"))));
- ruleConfig.getShardingAlgorithms().put("table-inline",
- new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_non_cacheable_table_sharding_${id % 2}"))));
- ruleConfig.setDefaultDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("warehouse_id", "inline"));
- ShardingAutoTableRuleConfiguration warehouse = new
ShardingAutoTableRuleConfiguration("t_warehouse", "ds_${0..1}");
- warehouse.setShardingStrategy(new
StandardShardingStrategyConfiguration("id", "mod"));
- ruleConfig.getAutoTables().add(warehouse);
- ruleConfig.getTables().add(new
ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order"));
- ruleConfig.getTables().add(new
ShardingTableRuleConfiguration("t_order_item", "ds_${0..1}.t_order_item"));
- ShardingTableRuleConfiguration nonCacheableDatabaseSharding = new
ShardingTableRuleConfiguration("t_non_cacheable_database_sharding",
"ds_${0..1}.t_non_cacheable_database_sharding");
- nonCacheableDatabaseSharding.setDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("id", "inline"));
- ruleConfig.getTables().add(nonCacheableDatabaseSharding);
- ShardingTableRuleConfiguration nonCacheableTableSharding = new
ShardingTableRuleConfiguration("t_non_cacheable_table_sharding",
"ds_0.t_non_cacheable_table_sharding_${0..1}");
- nonCacheableTableSharding.setTableShardingStrategy(new
StandardShardingStrategyConfiguration("id", "table-inline"));
- ruleConfig.getTables().add(nonCacheableTableSharding);
- ruleConfig.setShardingCache(new ShardingCacheConfiguration(100, new
ShardingCacheOptionsConfiguration(true, 0, 0)));
- ComputeNodeInstanceContext instanceContext = new
ComputeNodeInstanceContext(mock(ComputeNodeInstance.class), null, null);
- instanceContext.init(props -> 0);
- return new ShardingRule(ruleConfig, Maps.of("ds_0", new
MockedDataSource(), "ds_1", new MockedDataSource()), instanceContext,
Collections.emptyList());
- }
-
- private TimestampServiceRule createTimeServiceRule() {
- return new TimestampServiceRule(new
TimestampServiceRuleConfiguration("System", new Properties()));
- }
-
- private ShardingSphereDatabase createDatabase(final ShardingRule
shardingRule, final TimestampServiceRule timestampServiceRule) {
- ShardingSphereSchema schema = new ShardingSphereSchema(SCHEMA_NAME,
mock(DatabaseType.class));
- schema.putTable(new ShardingSphereTable("t_warehouse", Arrays.asList(
- new ShardingSphereColumn("id", Types.INTEGER, true, false,
false, true, false, false),
- new ShardingSphereColumn("warehouse_name", Types.VARCHAR,
false, false, false, true, false, false)),
- Collections.emptyList(), Collections.emptyList()));
- schema.putTable(new ShardingSphereTable("t_order", Arrays.asList(
- new ShardingSphereColumn("warehouse_id", Types.INTEGER, false,
false, false, true, false, false),
- new ShardingSphereColumn("order_id", Types.INTEGER, true,
false, false, true, false, false)),
- Collections.emptyList(), Collections.emptyList()));
- schema.putTable(new ShardingSphereTable("t_order_item", Arrays.asList(
- new ShardingSphereColumn("warehouse_id", Types.INTEGER, false,
false, false, true, false, false),
- new ShardingSphereColumn("order_broadcast_table_id",
Types.INTEGER, true, false, false, true, false, false)),
- Collections.emptyList(), Collections.emptyList()));
- schema.putTable(new ShardingSphereTable("t_non_sharding_table",
Collections.singleton(
- new ShardingSphereColumn("id", Types.INTEGER, false, false,
false, true, false, false)),
- Collections.emptyList(), Collections.emptyList()));
- schema.putTable(new
ShardingSphereTable("t_non_cacheable_database_sharding", Collections.singleton(
- new ShardingSphereColumn("id", Types.INTEGER, false, false,
false, true, false, false)),
- Collections.emptyList(), Collections.emptyList()));
- schema.putTable(new
ShardingSphereTable("t_non_cacheable_table_sharding", Collections.singleton(
- new ShardingSphereColumn("id", Types.INTEGER, false, false,
false, true, false, false)),
- Collections.emptyList(), Collections.emptyList()));
- return new ShardingSphereDatabase(DATABASE_NAME, databaseType,
- new ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Arrays.asList(shardingRule, timestampServiceRule)),
Collections.singleton(schema),
- new ConfigurationProperties(new Properties()));
- }
-
- private QueryContext createQueryContext(final ShardingSphereDatabase
database, final String sql, final List<Object> params) {
- SQLStatementContext sqlStatementContext = new SQLBindEngine(
- new ShardingSphereMetaData(Collections.singleton(database),
mock(ResourceMetaData.class), mock(RuleMetaData.class),
mock(ConfigurationProperties.class)),
- DATABASE_NAME, new HintValueContext()).bind(parse(sql));
- return new QueryContext(sqlStatementContext, sql, params, new
HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- }
-
- private ConnectionContext mockConnectionContext() {
- ConnectionContext result = mock(ConnectionContext.class);
-
when(result.getCurrentDatabaseName()).thenReturn(Optional.of(DATABASE_NAME));
- return result;
- }
-
- private SQLStatement parse(final String sql) {
- SQLParserRule sqlParserRule = new SQLParserRule(new
SQLParserRuleConfiguration(new CacheOption(0, 0L), new CacheOption(0, 0L)));
- return sqlParserRule.getSQLParserEngine(databaseType).parse(sql,
false);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- Collection<? extends Arguments> probablyCacheableCases =
Arrays.asList(
- Arguments.of("INSERT INTO t_warehouse (id) VALUES (?)",
Collections.singletonList(1), true, Collections.singletonList(0)),
- Arguments.of("SELECT * FROM t_warehouse WHERE id = ?",
Collections.singletonList(1), true, Collections.singletonList(0)),
- Arguments.of("SELECT * FROM t_warehouse WHERE id in (?, ?,
?)", Arrays.asList(1, 2, 3), true, Arrays.asList(0, 1, 2)),
- Arguments.of("SELECT * FROM t_warehouse WHERE id BETWEEN ?
AND ?", Arrays.asList(1, 10), true, Arrays.asList(0, 1)),
- Arguments.of("SELECT * FROM t_warehouse WHERE id BETWEEN ?
AND ? LIMIT ? OFFSET ?", Arrays.asList(1, 10, 100, 50), true, Arrays.asList(0,
1)),
- Arguments.of("UPDATE t_warehouse SET warehouse_name = ?
WHERE id = ?", Arrays.asList("foo", 1), true, Collections.singletonList(1)),
- Arguments.of("DELETE FROM t_warehouse WHERE id = ?",
Collections.singletonList(1), true, Collections.singletonList(0)));
- Collection<? extends Arguments> nonCacheableCases = Arrays.asList(
- Arguments.of("CREATE TABLE t_warehouse_for_create (id int4
not null primary key)", Collections.emptyList(), false,
Collections.emptyList()),
- Arguments.of("INSERT INTO t_warehouse (id) SELECT
warehouse_id FROM t_order", Collections.emptyList(), false,
Collections.emptyList()),
- Arguments.of("INSERT INTO t_warehouse (id) VALUES (?),
(?)", Arrays.asList(1, 2), false, Collections.emptyList()),
- Arguments.of("INSERT INTO t_non_sharding_table (id) VALUES
(?)", Collections.singletonList(1), false, Collections.emptyList()),
- Arguments.of("INSERT INTO
t_non_cacheable_database_sharding (id) VALUES (?)",
Collections.singletonList(1), false, Collections.emptyList()),
- Arguments.of("INSERT INTO t_non_cacheable_table_sharding
(id) VALUES (?)", Collections.singletonList(1), false, Collections.emptyList()),
- Arguments.of("INSERT INTO t_warehouse (id) VALUES
(now())", Collections.emptyList(), false, Collections.emptyList()),
- Arguments.of("SELECT * FROM t_warehouse w JOIN t_order o
on w.id = o.warehouse_id WHERE w.id = ?", Collections.singletonList(1), false,
Collections.emptyList()),
- Arguments.of("UPDATE t_warehouse SET warehouse_name = ?
WHERE id = (SELECT max(warehouse_id) FROM t_order)",
Collections.singletonList("foo"), false, Collections.emptyList()),
- Arguments.of("DELETE FROM t_order WHERE warehouse_id in
(1, 2, now())", Collections.emptyList(), false, Collections.emptyList()),
- Arguments.of("DELETE FROM t_order WHERE warehouse_id
BETWEEN now() AND now()", Collections.emptyList(), false,
Collections.emptyList()),
- Arguments.of("DELETE FROM t_order o WHERE o.warehouse_id
IN (SELECT w.id FROM t_warehouse w)", Collections.emptyList(), false,
Collections.emptyList()));
- return Stream.of(probablyCacheableCases.stream(),
nonCacheableCases.stream()).flatMap(Function.identity());
- }
- }
-}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouterTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouterTest.java
deleted file mode 100644
index b1d32001da5..00000000000
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouterTest.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.route;
-
-import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.datanode.DataNode;
-import org.apache.shardingsphere.infra.hint.HintValueContext;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.infra.route.context.RouteContext;
-import org.apache.shardingsphere.infra.route.context.RouteMapper;
-import org.apache.shardingsphere.infra.route.context.RouteUnit;
-import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
-import org.apache.shardingsphere.infra.session.query.QueryContext;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import org.apache.shardingsphere.sharding.cache.ShardingCache;
-import
org.apache.shardingsphere.sharding.cache.checker.ShardingRouteCacheableCheckResult;
-import
org.apache.shardingsphere.sharding.cache.checker.ShardingRouteCacheableChecker;
-import
org.apache.shardingsphere.sharding.cache.route.CachedShardingSQLRouter.OriginSQLRouter;
-import org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCache;
-import
org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCacheKey;
-import
org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCacheValue;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.mockito.junit.jupiter.MockitoSettings;
-import org.mockito.quality.Strictness;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-@MockitoSettings(strictness = Strictness.LENIENT)
-class CachedShardingSQLRouterTest {
-
- @Mock
- private ShardingCache shardingCache;
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private SQLStatementContext sqlStatementContext;
-
- @Test
- void assertCreateRouteContextWithSQLExceedMaxAllowedLength() {
- when(shardingCache.getConfiguration()).thenReturn(new
ShardingCacheConfiguration(1, null));
-
when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
- QueryContext queryContext =
- new QueryContext(sqlStatementContext, "SELECT 1",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- Optional<RouteContext> actual = new
CachedShardingSQLRouter().loadRouteContext(null, queryContext,
mock(RuleMetaData.class), null, shardingCache, Collections.emptyList(), null);
- assertFalse(actual.isPresent());
- }
-
- private ConnectionContext mockConnectionContext() {
- ConnectionContext result = mock(ConnectionContext.class);
-
when(result.getCurrentDatabaseName()).thenReturn(Optional.of("foo_db"));
- return result;
- }
-
- @Test
- void assertCreateRouteContextWithNotCacheableQuery() {
- QueryContext queryContext =
- new QueryContext(sqlStatementContext, "INSERT INTO t VALUES
(?), (?)", Collections.emptyList(), new HintValueContext(),
mockConnectionContext(), mock(ShardingSphereMetaData.class));
- when(shardingCache.getConfiguration()).thenReturn(new
ShardingCacheConfiguration(100, null));
-
when(shardingCache.getRouteCacheableChecker()).thenReturn(mock(ShardingRouteCacheableChecker.class));
- when(shardingCache.getRouteCacheableChecker().check(null,
queryContext)).thenReturn(new ShardingRouteCacheableCheckResult(false,
Collections.emptyList()));
- Optional<RouteContext> actual = new
CachedShardingSQLRouter().loadRouteContext(null, queryContext,
mock(RuleMetaData.class), null, shardingCache, Collections.singletonList("t"),
null);
- assertFalse(actual.isPresent());
- }
-
- @Test
- void assertCreateRouteContextWithUnmatchedActualParameterSize() {
- QueryContext queryContext =
- new QueryContext(sqlStatementContext, "INSERT INTO t VALUES
(?, ?)", Collections.singletonList(0), new HintValueContext(),
mockConnectionContext(), mock(ShardingSphereMetaData.class));
- when(shardingCache.getConfiguration()).thenReturn(new
ShardingCacheConfiguration(100, null));
-
when(shardingCache.getRouteCacheableChecker()).thenReturn(mock(ShardingRouteCacheableChecker.class));
- when(shardingCache.getRouteCacheableChecker().check(null,
queryContext)).thenReturn(new ShardingRouteCacheableCheckResult(true,
Collections.singletonList(1)));
- Optional<RouteContext> actual = new
CachedShardingSQLRouter().loadRouteContext(null, queryContext,
mock(RuleMetaData.class), null, shardingCache, Collections.singletonList("t"),
null);
- assertFalse(actual.isPresent());
- }
-
- @Test
- void assertCreateRouteContextWithCacheableQueryButCacheMissed() {
- QueryContext queryContext =
- new QueryContext(sqlStatementContext, "INSERT INTO t VALUES
(?, ?)", Arrays.asList(0, 1), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- when(shardingCache.getConfiguration()).thenReturn(new
ShardingCacheConfiguration(100, null));
-
when(shardingCache.getRouteCacheableChecker()).thenReturn(mock(ShardingRouteCacheableChecker.class));
- when(shardingCache.getRouteCacheableChecker().check(null,
queryContext)).thenReturn(new ShardingRouteCacheableCheckResult(true,
Collections.singletonList(1)));
-
when(shardingCache.getRouteCache()).thenReturn(mock(ShardingRouteCache.class));
- RouteContext expected = new RouteContext();
- expected.getRouteUnits().add(new RouteUnit(new RouteMapper("ds_0",
"ds_0"), Collections.singletonList(new RouteMapper("t", "t"))));
- expected.getOriginalDataNodes().add(Collections.singletonList(new
DataNode("ds_0", (String) null, "t")));
-
when(shardingCache.getRouteCache().get(any(ShardingRouteCacheKey.class))).thenReturn(Optional.empty());
- OriginSQLRouter router = (unused, globalRuleMetaData, database, rule,
tableNames, props) -> expected;
- Collection<String> tableNames = Collections.singletonList("t");
- Optional<RouteContext> actual = new
CachedShardingSQLRouter().loadRouteContext(router, queryContext,
mock(RuleMetaData.class), null, shardingCache, tableNames, null);
- assertTrue(actual.isPresent());
- assertThat(actual.get(), is(expected));
-
verify(shardingCache.getRouteCache()).put(any(ShardingRouteCacheKey.class),
any(ShardingRouteCacheValue.class));
- }
-
- @Test
- void assertCreateRouteContextWithCacheHit() {
- QueryContext queryContext =
- new QueryContext(sqlStatementContext, "INSERT INTO t VALUES
(?, ?)", Arrays.asList(0, 1), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- when(shardingCache.getConfiguration()).thenReturn(new
ShardingCacheConfiguration(100, null));
-
when(shardingCache.getRouteCacheableChecker()).thenReturn(mock(ShardingRouteCacheableChecker.class));
- when(shardingCache.getRouteCacheableChecker().check(null,
queryContext)).thenReturn(new ShardingRouteCacheableCheckResult(true,
Collections.singletonList(1)));
-
when(shardingCache.getRouteCache()).thenReturn(mock(ShardingRouteCache.class));
- RouteContext expected = new RouteContext();
- expected.getRouteUnits().add(new RouteUnit(new RouteMapper("ds_0",
"ds_0"), Collections.singletonList(new RouteMapper("t", "t"))));
- expected.getOriginalDataNodes().add(Collections.singletonList(new
DataNode("ds_0", (String) null, "t")));
-
when(shardingCache.getRouteCache().get(any(ShardingRouteCacheKey.class))).thenReturn(Optional.of(new
ShardingRouteCacheValue(expected)));
- Optional<RouteContext> actual = new
CachedShardingSQLRouter().loadRouteContext(null, queryContext,
mock(RuleMetaData.class), null, shardingCache, Collections.singletonList("t"),
null);
- assertTrue(actual.isPresent());
- RouteContext actualRouteContext = actual.get();
- assertThat(actualRouteContext, not(expected));
- assertThat(actualRouteContext.getOriginalDataNodes(),
is(expected.getOriginalDataNodes()));
- assertThat(actualRouteContext.getRouteUnits(),
is(expected.getRouteUnits()));
- }
-
- @Test
- void assertCreateRouteContextWithQueryRoutedToMultiDataNodes() {
- QueryContext queryContext =
- new QueryContext(sqlStatementContext, "SELECT * FROM t",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- when(shardingCache.getConfiguration()).thenReturn(new
ShardingCacheConfiguration(100, null));
-
when(shardingCache.getRouteCacheableChecker()).thenReturn(mock(ShardingRouteCacheableChecker.class));
- when(shardingCache.getRouteCacheableChecker().check(null,
queryContext)).thenReturn(new ShardingRouteCacheableCheckResult(true,
Collections.emptyList()));
-
when(shardingCache.getRouteCache()).thenReturn(mock(ShardingRouteCache.class));
- RouteContext expected = new RouteContext();
- expected.getRouteUnits().add(new RouteUnit(new RouteMapper("ds_0",
"ds_0"), Arrays.asList(new RouteMapper("t", "t_0"), new RouteMapper("t",
"t_1"))));
- expected.getOriginalDataNodes().add(Collections.singletonList(new
DataNode("ds_0", (String) null, "t_0")));
- OriginSQLRouter router = (unused, globalRuleMetaData, database, rule,
tableNames, props) -> expected;
- RuleMetaData globalRuleMetaData = mock(RuleMetaData.class);
- Collection<String> tableNames = Collections.singletonList("t");
- Optional<RouteContext> actual = new
CachedShardingSQLRouter().loadRouteContext(router, queryContext,
globalRuleMetaData, null, shardingCache, tableNames, null);
- assertTrue(actual.isPresent());
- assertThat(actual.get(), is(expected));
- verify(shardingCache.getRouteCache(),
never()).put(any(ShardingRouteCacheKey.class),
any(ShardingRouteCacheValue.class));
- }
-}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheTest.java
deleted file mode 100644
index 70a202e5f84..00000000000
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/cache/ShardingRouteCacheTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.shardingsphere.sharding.cache.route.cache;
-
-import org.apache.shardingsphere.infra.route.context.RouteContext;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class ShardingRouteCacheTest {
-
- @Test
- void assertPutAndGet() {
- ShardingRouteCache cache = new ShardingRouteCache(new
ShardingCacheOptionsConfiguration(true, 1, 1));
- ShardingRouteCacheKey key = new ShardingRouteCacheKey("SELECT name
FROM t WHERE id = ?", Collections.singletonList(1));
- assertFalse(cache.get(key).isPresent());
- cache.put(key, new ShardingRouteCacheValue(new RouteContext()));
- assertTrue(cache.get(key).isPresent());
- }
-}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyCheckerTest.java
index 44ebbd12e62..da32cd9160d 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/config/ShardingRuleConfigurationEmptyCheckerTest.java
@@ -20,8 +20,6 @@ package org.apache.shardingsphere.sharding.checker.config;
import
org.apache.shardingsphere.infra.config.rule.checker.DatabaseRuleConfigurationEmptyChecker;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -131,13 +129,6 @@ class ShardingRuleConfigurationEmptyCheckerTest {
assertFalse(checker.isEmpty(ruleConfig));
}
- @Test
- void assertIsNotEmptyWithShardingCache() {
- ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
- ruleConfig.setShardingCache(new ShardingCacheConfiguration(1, new
ShardingCacheOptionsConfiguration(false, 1, 1)));
- assertFalse(checker.isEmpty(ruleConfig));
- }
-
@Test
void assertIsEmpty() {
assertTrue(checker.isEmpty(new ShardingRuleConfiguration()));
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessorTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessorTest.java
deleted file mode 100644
index 499551bc429..00000000000
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/changed/ShardingCacheChangedProcessorTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.shardingsphere.sharding.rule.changed;
-
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.spi.rule.RuleChangedItemType;
-import
org.apache.shardingsphere.mode.spi.rule.RuleItemConfigurationChangedProcessor;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
-import org.apache.shardingsphere.sharding.rule.ShardingRule;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheOptionsConfiguration;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-
-import static
org.apache.shardingsphere.test.infra.framework.matcher.ShardingSphereAssertionMatchers.deepEqual;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class ShardingCacheChangedProcessorTest {
-
- @SuppressWarnings("unchecked")
- private final
RuleItemConfigurationChangedProcessor<ShardingRuleConfiguration,
ShardingCacheConfiguration> processor = TypedSPILoader.getService(
- RuleItemConfigurationChangedProcessor.class, new
RuleChangedItemType("sharding", "sharding_cache"));
-
- @Test
- void assertSwapRuleItemConfiguration() {
- ShardingCacheConfiguration actual =
processor.swapRuleItemConfiguration(null, createYAMLContent());
- assertThat(actual, deepEqual(new ShardingCacheConfiguration(1, new
ShardingCacheOptionsConfiguration(true, 128, 1024))));
- }
-
- private String createYAMLContent() {
- YamlShardingCacheConfiguration yamlConfig = new
YamlShardingCacheConfiguration();
- yamlConfig.setAllowedMaxSqlLength(1);
- YamlShardingCacheOptionsConfiguration yamlCacheOptionsConfig = new
YamlShardingCacheOptionsConfiguration();
- yamlCacheOptionsConfig.setSoftValues(true);
- yamlCacheOptionsConfig.setInitialCapacity(128);
- yamlCacheOptionsConfig.setMaximumSize(1024);
- yamlConfig.setRouteCache(yamlCacheOptionsConfig);
- return YamlEngine.marshal(yamlConfig);
- }
-
- @Test
- void assertFindRuleConfiguration() {
- ShardingRuleConfiguration ruleConfig =
mock(ShardingRuleConfiguration.class);
- assertThat(processor.findRuleConfiguration(mockDatabase(ruleConfig)),
is(ruleConfig));
- }
-
- private ShardingSphereDatabase mockDatabase(final
ShardingRuleConfiguration ruleConfig) {
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.getConfiguration()).thenReturn(ruleConfig);
- ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
- when(result.getRuleMetaData()).thenReturn(new
RuleMetaData(Collections.singleton(rule)));
- return result;
- }
-
- @Test
- void assertChangeRuleItemConfiguration() {
- ShardingRuleConfiguration currentRuleConfig =
createCurrentRuleConfiguration();
- ShardingCacheConfiguration toBeChangedItemConfig = new
ShardingCacheConfiguration(2, new ShardingCacheOptionsConfiguration(false,
1280, 10240));
- processor.changeRuleItemConfiguration(null, currentRuleConfig,
toBeChangedItemConfig);
-
assertThat(currentRuleConfig.getShardingCache().getAllowedMaxSqlLength(),
is(2));
-
assertFalse(currentRuleConfig.getShardingCache().getRouteCache().isSoftValues());
-
assertThat(currentRuleConfig.getShardingCache().getRouteCache().getInitialCapacity(),
is(1280));
-
assertThat(currentRuleConfig.getShardingCache().getRouteCache().getMaximumSize(),
is(10240));
- }
-
- @Test
- void assertDropRuleItemConfiguration() {
- ShardingRuleConfiguration currentRuleConfig =
createCurrentRuleConfiguration();
- processor.dropRuleItemConfiguration(null, currentRuleConfig);
- assertNull(currentRuleConfig.getShardingCache());
- }
-
- private ShardingRuleConfiguration createCurrentRuleConfiguration() {
- ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- result.setShardingCache(new ShardingCacheConfiguration(1, new
ShardingCacheOptionsConfiguration(true, 128, 1024)));
- return result;
- }
-}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingConfigurationYamlRuleNodeTupleSwapperEngineIT.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingConfigurationYamlRuleNodeTupleSwapperEngineIT.java
index 64ef4a89872..bfd6b965196 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingConfigurationYamlRuleNodeTupleSwapperEngineIT.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingConfigurationYamlRuleNodeTupleSwapperEngineIT.java
@@ -36,7 +36,7 @@ class ShardingConfigurationYamlRuleNodeTupleSwapperEngineIT
extends YamlRuleNode
@Override
protected void assertRuleNodeTuples(final List<RuleNodeTuple>
actualTuples, final YamlRuleConfiguration expectedYamlRuleConfig) {
- assertThat(actualTuples.size(), is(21));
+ assertThat(actualTuples.size(), is(20));
assertRuleNodeTuple(actualTuples.get(0),
"sharding_algorithms/core_standard_fixture",
((YamlShardingRuleConfiguration)
expectedYamlRuleConfig).getShardingAlgorithms().get("core_standard_fixture"));
assertRuleNodeTuple(actualTuples.get(1),
@@ -61,6 +61,5 @@ class ShardingConfigurationYamlRuleNodeTupleSwapperEngineIT
extends YamlRuleNode
assertRuleNodeTuple(actualTuples.get(17),
"key_generate_strategies/t_order", ((YamlShardingRuleConfiguration)
expectedYamlRuleConfig).getKeyGenerateStrategies().get("t_order"));
assertRuleNodeTuple(actualTuples.get(18),
"key_generate_strategies/id_sequence", ((YamlShardingRuleConfiguration)
expectedYamlRuleConfig).getKeyGenerateStrategies().get("id_sequence"));
assertRuleNodeTuple(actualTuples.get(19), "default_sharding_column",
((YamlShardingRuleConfiguration)
expectedYamlRuleConfig).getDefaultShardingColumn());
- assertRuleNodeTuple(actualTuples.get(20), "sharding_cache",
((YamlShardingRuleConfiguration) expectedYamlRuleConfig).getShardingCache());
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingRuleConfigurationYamlIT.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingRuleConfigurationYamlIT.java
index 32f9fb10dd8..3b653880386 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingRuleConfigurationYamlIT.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/ShardingRuleConfigurationYamlIT.java
@@ -22,8 +22,6 @@ import
org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
@@ -36,8 +34,6 @@ import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShard
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import
org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheOptionsConfiguration;
import org.apache.shardingsphere.test.it.yaml.YamlRuleConfigurationIT;
import java.util.ArrayList;
@@ -46,7 +42,6 @@ import java.util.Properties;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
class ShardingRuleConfigurationYamlIT extends YamlRuleConfigurationIT {
@@ -85,7 +80,6 @@ class ShardingRuleConfigurationYamlIT extends
YamlRuleConfigurationIT {
result.getShardingAlgorithms().put("table_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "t_order_${order_id % 2}"))));
result.getKeyGenerators().put("snowflake", new
AlgorithmConfiguration("SNOWFLAKE", new Properties()));
result.getAuditors().put("sharding_key_required_auditor", new
AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
- result.setShardingCache(new ShardingCacheConfiguration(512, new
ShardingCacheOptionsConfiguration(true, 65536, 262144)));
return result;
}
@@ -103,7 +97,6 @@ class ShardingRuleConfigurationYamlIT extends
YamlRuleConfigurationIT {
assertTOrderItem(actual);
assertBindingTable(actual);
assertKeyGenerateStrategies(actual);
- assertShardingCache(actual);
assertThat(actual.getDefaultShardingColumn(), is("order_id"));
}
@@ -150,15 +143,6 @@ class ShardingRuleConfigurationYamlIT extends
YamlRuleConfigurationIT {
assertThat(actual.getKeyGenerateStrategies().get("id_sequence").getKeyGenerateSequence(),
is("sequence_name"));
}
- private void assertShardingCache(final YamlShardingRuleConfiguration
actual) {
- YamlShardingCacheConfiguration actualShardingCache =
actual.getShardingCache();
- assertThat(actualShardingCache.getAllowedMaxSqlLength(), is(512));
- YamlShardingCacheOptionsConfiguration actualRouteCacheConfig =
actualShardingCache.getRouteCache();
- assertThat(actualRouteCacheConfig.getInitialCapacity(), is(65536));
- assertThat(actualRouteCacheConfig.getMaximumSize(), is(262144));
- assertTrue(actualRouteCacheConfig.isSoftValues());
- }
-
private static KeyGenerateStrategiesConfiguration
createColumnKeyGenerateStrategyRuleConfiguration() {
return new ColumnKeyGenerateStrategiesRuleConfiguration("snowflake",
"t_order", "id");
}
diff --git
a/features/sharding/core/src/test/resources/yaml/sharding-rule-for-tuple.yaml
b/features/sharding/core/src/test/resources/yaml/sharding-rule-for-tuple.yaml
index 2097ae7eb39..65543a0a01c 100644
---
a/features/sharding/core/src/test/resources/yaml/sharding-rule-for-tuple.yaml
+++
b/features/sharding/core/src/test/resources/yaml/sharding-rule-for-tuple.yaml
@@ -99,10 +99,3 @@ rules:
auditors:
sharding_key_required_auditor:
type: DML_SHARDING_CONDITIONS
-
- shardingCache:
- allowedMaxSqlLength: 512
- routeCache:
- softValues: true
- initialCapacity: 65536
- maximumSize: 262144
diff --git a/features/sharding/core/src/test/resources/yaml/sharding-rule.yaml
b/features/sharding/core/src/test/resources/yaml/sharding-rule.yaml
index 973b906c49d..a94181a42b4 100644
--- a/features/sharding/core/src/test/resources/yaml/sharding-rule.yaml
+++ b/features/sharding/core/src/test/resources/yaml/sharding-rule.yaml
@@ -98,10 +98,3 @@ rules:
auditors:
sharding_key_required_auditor:
type: DML_SHARDING_CONDITIONS
-
- shardingCache:
- allowedMaxSqlLength: 512
- routeCache:
- softValues: true
- initialCapacity: 65536
- maximumSize: 262144
diff --git
a/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-reference-rule-current-config.yaml
b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-reference-rule-current-config.yaml
index fa7a8c9d9d8..0a53e49da38 100644
---
a/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-reference-rule-current-config.yaml
+++
b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-reference-rule-current-config.yaml
@@ -94,10 +94,3 @@ rules:
auditors:
sharding_key_required_auditor:
type: DML_SHARDING_CONDITIONS
-
- shardingCache:
- allowedMaxSqlLength: 512
- routeCache:
- softValues: true
- initialCapacity: 65536
- maximumSize: 262144
diff --git
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reachability-metadata.json
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reachability-metadata.json
index 4b0f04016c9..9b8cef5a22d 100644
---
a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reachability-metadata.json
+++
b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reachability-metadata.json
@@ -4651,12 +4651,6 @@
},
"type":
"org.apache.shardingsphere.sharding.rule.changed.ShardingAutoTableChangedProcessor"
},
- {
- "condition": {
- "typeReached":
"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"
- },
- "type":
"org.apache.shardingsphere.sharding.rule.changed.ShardingCacheChangedProcessor"
- },
{
"condition": {
"typeReached":
"org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.Portal"
@@ -4714,9 +4708,6 @@
{
"name": "shardingAlgorithms"
},
- {
- "name": "shardingCache"
- },
{
"name": "tables"
}
@@ -4761,9 +4752,6 @@
{
"name": "shardingAlgorithms"
},
- {
- "name": "shardingCache"
- },
{
"name": "tables"
}
@@ -8044,4 +8032,4 @@
"glob": "transactions.properties"
}
]
-}
\ No newline at end of file
+}