You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/02/04 02:13:44 UTC

[shardingsphere] branch master updated: Adjust sequence of JobRateLimitAlgorithm (#23987)

This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 bcf902d7b18 Adjust sequence of JobRateLimitAlgorithm (#23987)
bcf902d7b18 is described below

commit bcf902d7b18227b6822c91bedc7678919ce11d1c
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Feb 4 10:13:29 2023 +0800

    Adjust sequence of JobRateLimitAlgorithm (#23987)
    
    * Adjust sequence of JobRateLimitAlgorithm
    
    * Remove FixtureDataSourcePreparer
    
    * Refactor ClusterModeContextManager
    
    * Refactor ClusterModeContextManager
    
    * Refactor ClusterContextManagerBuilder
---
 .../core/ratelimit/QPSJobRateLimitAlgorithm.java   | 10 +++----
 .../core/ratelimit/TPSJobRateLimitAlgorithm.java   | 10 +++----
 .../InputJobRateLimitAlgorithmFixture.java         |  6 ++--
 .../OutputJobRateLimitAlgorithmFixture.java        |  6 ++--
 .../DistSQLTrafficLoadBalanceAlgorithmFixture.java |  8 +++---
 .../cluster/ClusterContextManagerBuilder.java      |  3 +-
 .../manager/cluster/ClusterModeContextManager.java | 12 ++++----
 .../core/fixture/FixtureDataSourcePreparer.java    | 33 ----------------------
 8 files changed, 28 insertions(+), 60 deletions(-)

diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/QPSJobRateLimitAlgorithm.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/QPSJobRateLimitAlgorithm.java
index 57df2c5df9d..30000c269a6 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/QPSJobRateLimitAlgorithm.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/QPSJobRateLimitAlgorithm.java
@@ -44,11 +44,6 @@ public final class QPSJobRateLimitAlgorithm implements JobRateLimitAlgorithm {
         rateLimiter = RateLimiter.create(qps);
     }
     
-    @Override
-    public String getType() {
-        return "QPS";
-    }
-    
     @Override
     public void intercept(final JobOperationType type, final Number data) {
         if (type != JobOperationType.SELECT) {
@@ -56,4 +51,9 @@ public final class QPSJobRateLimitAlgorithm implements JobRateLimitAlgorithm {
         }
         rateLimiter.acquire(null != data ? data.intValue() : 1);
     }
+    
+    @Override
+    public String getType() {
+        return "QPS";
+    }
 }
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/TPSJobRateLimitAlgorithm.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/TPSJobRateLimitAlgorithm.java
index a43ed28bd23..7a961486f0b 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/TPSJobRateLimitAlgorithm.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ratelimit/TPSJobRateLimitAlgorithm.java
@@ -44,11 +44,6 @@ public final class TPSJobRateLimitAlgorithm implements JobRateLimitAlgorithm {
         rateLimiter = RateLimiter.create(tps);
     }
     
-    @Override
-    public String getType() {
-        return "TPS";
-    }
-    
     @Override
     public void intercept(final JobOperationType type, final Number data) {
         switch (type) {
@@ -60,4 +55,9 @@ public final class TPSJobRateLimitAlgorithm implements JobRateLimitAlgorithm {
             default:
         }
     }
+    
+    @Override
+    public String getType() {
+        return "TPS";
+    }
 }
diff --git a/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/InputJobRateLimitAlgorithmFixture.java b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/InputJobRateLimitAlgorithmFixture.java
index 378386d7408..261f35241c2 100644
--- a/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/InputJobRateLimitAlgorithmFixture.java
+++ b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/InputJobRateLimitAlgorithmFixture.java
@@ -22,11 +22,11 @@ import org.apache.shardingsphere.data.pipeline.api.job.JobOperationType;
 public final class InputJobRateLimitAlgorithmFixture implements JobRateLimitAlgorithm {
     
     @Override
-    public String getType() {
-        return "FIXTURE_INPUT";
+    public void intercept(final JobOperationType type, final Number data) {
     }
     
     @Override
-    public void intercept(final JobOperationType type, final Number data) {
+    public String getType() {
+        return "FIXTURE_INPUT";
     }
 }
diff --git a/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/OutputJobRateLimitAlgorithmFixture.java b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/OutputJobRateLimitAlgorithmFixture.java
index 3d292996adc..1f4f0fd5bfb 100644
--- a/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/OutputJobRateLimitAlgorithmFixture.java
+++ b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/data/pipeline/spi/ratelimit/OutputJobRateLimitAlgorithmFixture.java
@@ -22,11 +22,11 @@ import org.apache.shardingsphere.data.pipeline.api.job.JobOperationType;
 public final class OutputJobRateLimitAlgorithmFixture implements JobRateLimitAlgorithm {
     
     @Override
-    public String getType() {
-        return "FIXTURE_OUTPUT";
+    public void intercept(final JobOperationType type, final Number data) {
     }
     
     @Override
-    public void intercept(final JobOperationType type, final Number data) {
+    public String getType() {
+        return "FIXTURE_OUTPUT";
     }
 }
diff --git a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/fixture/DistSQLTrafficLoadBalanceAlgorithmFixture.java b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/fixture/DistSQLTrafficLoadBalanceAlgorithmFixture.java
index 35e498742a0..fc86ce430bf 100644
--- a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/fixture/DistSQLTrafficLoadBalanceAlgorithmFixture.java
+++ b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/fixture/DistSQLTrafficLoadBalanceAlgorithmFixture.java
@@ -25,12 +25,12 @@ import java.util.List;
 public final class DistSQLTrafficLoadBalanceAlgorithmFixture implements TrafficLoadBalanceAlgorithm {
     
     @Override
-    public String getType() {
-        return "DISTSQL.FIXTURE";
+    public InstanceMetaData getInstanceId(final String name, final List<InstanceMetaData> instances) {
+        return null;
     }
     
     @Override
-    public InstanceMetaData getInstanceId(final String name, final List<InstanceMetaData> instances) {
-        return null;
+    public String getType() {
+        return "DISTSQL.FIXTURE";
     }
 }
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index ecd946f1add..b8fb20d4a1d 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.mode.lock.GlobalLockContext;
 import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.manager.ContextManagerAware;
 import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
 import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
 import org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter;
@@ -87,7 +88,7 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
     }
     
     private void setContextManagerAware(final ContextManager contextManager) {
-        ((ClusterModeContextManager) contextManager.getInstanceContext().getModeContextManager()).setContextManagerAware(contextManager);
+        ((ContextManagerAware) contextManager.getInstanceContext().getModeContextManager()).setContextManagerAware(contextManager);
     }
     
     private void registerOnline(final MetaDataPersistService persistService, final RegistryCenter registryCenter, final ContextManagerBuilderParameter param, final ContextManager contextManager) {
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java
index 6d569ae0e94..99d7c2e51a5 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterModeContextManager.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.mode.manager.cluster;
 
-import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
 import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
 import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
@@ -38,7 +37,6 @@ import java.util.stream.Collectors;
 /**
  * Cluster mode context manager.
  */
-@RequiredArgsConstructor
 public final class ClusterModeContextManager implements ModeContextManager, ContextManagerAware {
     
     private ContextManager contextManager;
@@ -60,11 +58,13 @@ public final class ClusterModeContextManager implements ModeContextManager, Cont
     
     @Override
     public void alterSchema(final AlterSchemaPOJO alterSchemaPOJO) {
-        ShardingSphereSchema schema = contextManager.getMetaDataContexts().getMetaData().getDatabase(alterSchemaPOJO.getDatabaseName()).getSchema(alterSchemaPOJO.getSchemaName());
+        String databaseName = alterSchemaPOJO.getDatabaseName();
+        String schemaName = alterSchemaPOJO.getSchemaName();
+        ShardingSphereSchema schema = contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getSchema(schemaName);
         DatabaseMetaDataPersistService databaseMetaDataService = contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService();
-        databaseMetaDataService.persist(alterSchemaPOJO.getDatabaseName(), alterSchemaPOJO.getRenameSchemaName(), schema);
-        databaseMetaDataService.getViewMetaDataPersistService().persist(alterSchemaPOJO.getDatabaseName(), alterSchemaPOJO.getRenameSchemaName(), schema.getViews());
-        databaseMetaDataService.dropSchema(alterSchemaPOJO.getDatabaseName(), alterSchemaPOJO.getSchemaName());
+        databaseMetaDataService.persist(databaseName, alterSchemaPOJO.getRenameSchemaName(), schema);
+        databaseMetaDataService.getViewMetaDataPersistService().persist(databaseName, alterSchemaPOJO.getRenameSchemaName(), schema.getViews());
+        databaseMetaDataService.dropSchema(databaseName, schemaName);
     }
     
     @Override
diff --git a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/FixtureDataSourcePreparer.java b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/FixtureDataSourcePreparer.java
deleted file mode 100644
index e5a43feb4d0..00000000000
--- a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/fixture/FixtureDataSourcePreparer.java
+++ /dev/null
@@ -1,33 +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.test.it.data.pipeline.core.fixture;
-
-import org.apache.shardingsphere.data.pipeline.core.prepare.datasource.DataSourcePreparer;
-import org.apache.shardingsphere.data.pipeline.core.prepare.datasource.PrepareTargetSchemasParameter;
-import org.apache.shardingsphere.data.pipeline.core.prepare.datasource.PrepareTargetTablesParameter;
-
-public final class FixtureDataSourcePreparer implements DataSourcePreparer {
-    
-    @Override
-    public void prepareTargetSchemas(final PrepareTargetSchemasParameter param) {
-    }
-    
-    @Override
-    public void prepareTargetTables(final PrepareTargetTablesParameter param) {
-    }
-}