You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by xi...@apache.org on 2021/01/12 12:17:24 UTC

[shardingsphere] branch master updated: Stop scaling job after scaling result checked (#8998)

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

xiaoyu 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 0cf7562  Stop scaling job after scaling result checked (#8998)
0cf7562 is described below

commit 0cf75625005c14f49e2f3c67d43d43b0af5201e2
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Tue Jan 12 20:17:03 2021 +0800

    Stop scaling job after scaling result checked (#8998)
---
 .../governance/core/scaling/ScalingServiceHolder.java            | 9 +++++++++
 .../governance/core/scaling/callback/ScalingResultCallback.java  | 1 +
 .../java/org/apache/shardingsphere/infra/lock/LockContext.java   | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/ScalingServiceHolder.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/ScalingServiceHolder.java
index 1048c85..1a31236 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/ScalingServiceHolder.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/ScalingServiceHolder.java
@@ -101,4 +101,13 @@ public final class ScalingServiceHolder {
         }
         return false;
     }
+    
+    /**
+     * Stop scaling job.
+     * 
+     * @param jobId job id
+     */
+    public void stopScalingJob(final long jobId) {
+        scalingJobService.stop(jobId);
+    }
 }
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/callback/ScalingResultCallback.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/callback/ScalingResultCallback.java
index 971d430..6669979 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/callback/ScalingResultCallback.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/scaling/callback/ScalingResultCallback.java
@@ -45,6 +45,7 @@ public final class ScalingResultCallback implements ScalingCallback {
             try {
                 Thread.sleep(30000L);
                 if (ScalingServiceHolder.getInstance().checkScalingResult(jobId)) {
+                    ScalingServiceHolder.getInstance().stopScalingJob(jobId);
                     ShardingSphereEventBus.getInstance().post(new SwitchRuleConfigurationEvent(schemaName, ruleConfigurationCacheId));
                 }  
             } catch (final InterruptedException ignored) {
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java
index 16a0f9b..610f885 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java
@@ -51,7 +51,7 @@ public final class LockContext {
      * @param lockStrategyType lock strategy type
      */
     public static void init(final LockStrategyType lockStrategyType) {
-        LOCK_STRATEGY.set(TypedSPIRegistry.getRegisteredService(LockStrategy.class, lockStrategyType.name(), new Properties()));
+        LOCK_STRATEGY.compareAndSet(null, TypedSPIRegistry.getRegisteredService(LockStrategy.class, lockStrategyType.name(), new Properties()));
     }
     
     /**