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/22 09:05:30 UTC

[shardingsphere] branch master updated: Rename tryLock to tryGlobalLock (#9131)

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 a7df5c7  Rename tryLock to tryGlobalLock (#9131)
a7df5c7 is described below

commit a7df5c7c9c12f6a7ed0c7819bb7747019540ee4e
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Fri Jan 22 17:05:11 2021 +0800

    Rename tryLock to tryGlobalLock (#9131)
---
 .../core/lock/strategy/GovernanceLockStrategy.java           |  4 ++--
 .../core/lock/strategy/GovernanceLockStrategyTest.java       |  4 ++--
 .../org/apache/shardingsphere/infra/lock/LockStrategy.java   |  4 ++--
 .../shardingsphere/infra/lock/StandardLockStrategy.java      |  4 ++--
 .../shardingsphere/infra/lock/StandardLockStrategyTest.java  |  8 ++++----
 .../infra/lock/fixture/FixtureLockStrategy.java              | 12 ++++++------
 .../shardingsphere/driver/executor/DriverJDBCExecutor.java   | 12 ++++++------
 .../backend/communication/DatabaseCommunicationEngine.java   | 12 ++++++------
 .../scaling/elasticjob/job/FinishedCheckJob.java             |  4 ++--
 9 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategy.java b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategy.java
index c863864..f573a0f 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategy.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategy.java
@@ -48,12 +48,12 @@ public final class GovernanceLockStrategy implements LockStrategy {
     }
     
     @Override
-    public boolean tryLock(final long timeout, final TimeUnit timeUnit) {
+    public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
         return registryCenter.tryGlobalLock(timeout, timeUnit);
     }
     
     @Override
-    public void releaseLock() {
+    public void releaseGlobalLock() {
         registryCenter.releaseGlobalLock();
     }
     
diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategyTest.java b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategyTest.java
index a25925f..de1cd04 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategyTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/lock/strategy/GovernanceLockStrategyTest.java
@@ -47,13 +47,13 @@ public final class GovernanceLockStrategyTest {
     
     @Test
     public void assertTryLock() {
-        lockStrategy.tryLock(50L, TimeUnit.MILLISECONDS);
+        lockStrategy.tryGlobalLock(50L, TimeUnit.MILLISECONDS);
         verify(registryCenter).tryGlobalLock(eq(50L), eq(TimeUnit.MILLISECONDS));
     }
     
     @Test
     public void assertReleaseLock() {
-        lockStrategy.releaseLock();
+        lockStrategy.releaseGlobalLock();
         verify(registryCenter).releaseGlobalLock();
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategy.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategy.java
index 076a199..66284e6 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategy.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockStrategy.java
@@ -33,10 +33,10 @@ public interface LockStrategy extends TypedSPI {
      * @param timeUnit time unit
      * @return true if get the lock, false if not
      */
-    boolean tryLock(long timeout, TimeUnit timeUnit);
+    boolean tryGlobalLock(long timeout, TimeUnit timeUnit);
     
     /**
      * Release lock.
      */
-    void releaseLock();
+    void releaseGlobalLock();
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLockStrategy.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLockStrategy.java
index 2ad844d..303a00b 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLockStrategy.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/StandardLockStrategy.java
@@ -32,7 +32,7 @@ public final class StandardLockStrategy implements LockStrategy {
     private final ReentrantLock lock = new ReentrantLock();
     
     @Override
-    public boolean tryLock(final long timeout, final TimeUnit timeUnit) {
+    public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
         boolean result = false;
         try {
             result = lock.tryLock(timeout, timeUnit);
@@ -47,7 +47,7 @@ public final class StandardLockStrategy implements LockStrategy {
     }
     
     @Override
-    public void releaseLock() {
+    public void releaseGlobalLock() {
         lock.unlock();
         StateContext.switchState(new StateEvent(StateType.LOCK, false));
     }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockStrategyTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockStrategyTest.java
index c3e3852..aa4c66a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockStrategyTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/StandardLockStrategyTest.java
@@ -33,16 +33,16 @@ public final class StandardLockStrategyTest {
     
     @Test
     public void assertTryLock() {
-        assertTrue(lockStrategy.tryLock(50L, TimeUnit.MILLISECONDS));
+        assertTrue(lockStrategy.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
         assertThat(StateContext.getCurrentState(), is(StateType.LOCK));
-        lockStrategy.releaseLock();
+        lockStrategy.releaseGlobalLock();
     }
     
     @Test
     public void assertReleaseLock() {
-        assertTrue(lockStrategy.tryLock(50L, TimeUnit.MILLISECONDS));
+        assertTrue(lockStrategy.tryGlobalLock(50L, TimeUnit.MILLISECONDS));
         assertThat(StateContext.getCurrentState(), is(StateType.LOCK));
-        lockStrategy.releaseLock();
+        lockStrategy.releaseGlobalLock();
         assertThat(StateContext.getCurrentState(), is(StateType.OK));
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/fixture/FixtureLockStrategy.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/fixture/FixtureLockStrategy.java
index e2ce3a2..c04d4b2 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/fixture/FixtureLockStrategy.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/fixture/FixtureLockStrategy.java
@@ -23,18 +23,18 @@ import org.apache.shardingsphere.infra.lock.LockStrategyType;
 import java.util.concurrent.TimeUnit;
 
 public final class FixtureLockStrategy implements LockStrategy {
+    
     @Override
-    public boolean tryLock(final long timeout, final TimeUnit timeUnit) {
-        return false;
+    public String getType() {
+        return LockStrategyType.STANDARD.name();
     }
     
     @Override
-    public void releaseLock() {
-        
+    public boolean tryGlobalLock(final long timeout, final TimeUnit timeUnit) {
+        return false;
     }
     
     @Override
-    public String getType() {
-        return LockStrategyType.STANDARD.name();
+    public void releaseGlobalLock() {
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
index 5ee0186..ec19c5d 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java
@@ -128,20 +128,20 @@ public final class DriverJDBCExecutor {
         List<T> results;
         boolean locked = false;
         try {
-            locked = tryLock(sqlStatement, metaDataContexts.getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS));
+            locked = tryGlobalLock(sqlStatement, metaDataContexts.getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS));
             results = jdbcExecutor.execute(executionGroups, callback);
             refreshSchema(metaDataContexts.getDefaultMetaData(), sqlStatement, routeUnits);
         } finally {
             if (locked) {
-                releaseLock();
+                releaseGlobalLock();
             }
         }
         return results;
     }
     
-    private boolean tryLock(final SQLStatement sqlStatement, final long lockTimeoutMilliseconds) {
+    private boolean tryGlobalLock(final SQLStatement sqlStatement, final long lockTimeoutMilliseconds) {
         if (needLock(sqlStatement)) {
-            if (!LockContext.getLockStrategy().tryLock(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
+            if (!LockContext.getLockStrategy().tryGlobalLock(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
                 throw new ShardingSphereException("Service lock wait timeout of %s ms exceeded", lockTimeoutMilliseconds);
             }
             return true;
@@ -169,7 +169,7 @@ public final class DriverJDBCExecutor {
         OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(schema), SchemaChangedNotifier.class).values().forEach(each -> each.notify(DefaultSchema.LOGIC_NAME, schema));
     }
     
-    private void releaseLock() {
-        LockContext.getLockStrategy().releaseLock();
+    private void releaseGlobalLock() {
+        LockContext.getLockStrategy().releaseGlobalLock();
     }
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 1870d4a..a9a6ef3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -112,13 +112,13 @@ public final class DatabaseCommunicationEngine {
         boolean locked = false;
         Collection<ExecuteResult> executeResults;
         try {
-            locked = tryLock(executionContext, ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS));
+            locked = tryGlobalLock(executionContext, ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS));
             proxySQLExecutor.checkExecutePrerequisites(executionContext);
             executeResults = proxySQLExecutor.execute(executionContext);
             refreshSchema(executionContext);
         } finally {
             if (locked) {
-                releaseLock();
+                releaseGlobalLock();
             }
         }
         ExecuteResult executeResultSample = executeResults.iterator().next();
@@ -127,9 +127,9 @@ public final class DatabaseCommunicationEngine {
                 : processExecuteUpdate(executionContext, executeResults.stream().map(each -> (UpdateResult) each).collect(Collectors.toList()));
     }
     
-    private boolean tryLock(final ExecutionContext executionContext, final Long lockTimeoutMilliseconds) {
+    private boolean tryGlobalLock(final ExecutionContext executionContext, final Long lockTimeoutMilliseconds) {
         if (needLock(executionContext)) {
-            if (!LockContext.getLockStrategy().tryLock(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
+            if (!LockContext.getLockStrategy().tryGlobalLock(lockTimeoutMilliseconds, TimeUnit.MILLISECONDS)) {
                 throw new LockWaitTimeoutException(lockTimeoutMilliseconds);
             }
             return true;
@@ -141,8 +141,8 @@ public final class DatabaseCommunicationEngine {
         return SchemaRefresherFactory.newInstance(executionContext.getSqlStatementContext().getSqlStatement()).isPresent();
     }
     
-    private void releaseLock() {
-        LockContext.getLockStrategy().releaseLock();
+    private void releaseGlobalLock() {
+        LockContext.getLockStrategy().releaseGlobalLock();
     }
     
     private QueryResponseHeader processExecuteQuery(final ExecutionContext executionContext, final List<QueryResult> queryResults, final QueryResult queryResultSample) throws SQLException {
diff --git a/shardingsphere-scaling/shardingsphere-scaling-elasticjob/src/main/java/org/apache/shardingsphere/scaling/elasticjob/job/FinishedCheckJob.java b/shardingsphere-scaling/shardingsphere-scaling-elasticjob/src/main/java/org/apache/shardingsphere/scaling/elasticjob/job/FinishedCheckJob.java
index 90edb7b..4b3c127 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-elasticjob/src/main/java/org/apache/shardingsphere/scaling/elasticjob/job/FinishedCheckJob.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-elasticjob/src/main/java/org/apache/shardingsphere/scaling/elasticjob/job/FinishedCheckJob.java
@@ -67,7 +67,7 @@ public final class FinishedCheckJob implements SimpleJob {
     }
     
     private void trySwitch(final long jobId, final WorkflowConfiguration workflowConfig) {
-        if (LockContext.getLockStrategy().tryLock(30L, TimeUnit.SECONDS)) {
+        if (LockContext.getLockStrategy().tryGlobalLock(30L, TimeUnit.SECONDS)) {
             try {
                 ThreadUtil.sleep(10 * 1000L);
                 if (ScalingServiceHolder.getInstance().checkScalingResult(jobId)) {
@@ -75,7 +75,7 @@ public final class FinishedCheckJob implements SimpleJob {
                     ShardingSphereEventBus.getInstance().post(new SwitchRuleConfigurationEvent(workflowConfig.getSchemaName(), workflowConfig.getRuleCacheId()));
                 }
             } finally {
-                LockContext.getLockStrategy().releaseLock();
+                LockContext.getLockStrategy().releaseGlobalLock();
             }
         } else {
             log.warn("can not get lock.");