This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 505d21a99b4 Refactor lock context interface (#18062)
505d21a99b4 is described below
commit 505d21a99b41c1064fc31f83c2a9e0b0cee8908d
Author: gin <[email protected]>
AuthorDate: Mon May 30 18:34:21 2022 +0800
Refactor lock context interface (#18062)
---
.../shardingsphere/infra/lock/LockContext.java | 42 +++++++++++++--------
.../apache/shardingsphere/infra/lock/LockMode.java | 8 ++--
.../core/api/impl/RuleAlteredJobAPIImpl.java | 5 ++-
.../pipeline/core/lock/PipelineSimpleLock.java | 4 +-
.../rulealtered/RuleAlteredJobPreparer.java | 2 +-
.../scenario/rulealtered/RuleAlteredJobWorker.java | 2 +-
.../cluster/ClusterContextManagerBuilder.java | 6 +--
...ava => AbstractDistributedLockNodeService.java} | 4 +-
...ockContext.java => DistributedLockContext.java} | 33 +++++++++--------
.../database/node/DatabaseLockNodeService.java | 4 +-
.../ShardingSphereDistributedLock.java} | 26 +++++++------
.../event/DistributedAckLockReleasedEvent.java} | 8 ++--
.../event/DistributedAckLockedEvent.java} | 8 ++--
.../event/DistributedLockReleasedEvent.java} | 6 +--
.../event/DistributedLockedEvent.java} | 6 +--
.../node/DistributedLockNodeService.java} | 12 +++---
.../watcher/DistributedLockChangedWatcher.java} | 22 +++++------
...ockManager.java => DistributedLockManager.java} | 35 ++++++++++++------
.../lock/manager/ShardingSphereLockManager.java | 43 ++++++++++++----------
.../mutex/ShardingSphereInterMutexLockHolder.java | 2 +-
.../coordinator/lock/util/LockNodeType.java | 2 +-
...anager.cluster.coordinator.lock.LockNodeService | 2 +-
...rdinator.lock.manager.ShardingSphereLockManager | 2 +-
....cluster.coordinator.registry.GovernanceWatcher | 2 +-
...=> AbstractDistributedLockNodeServiceTest.java} | 16 ++++----
...xtTest.java => DistributedLockContextTest.java} | 28 +++++++-------
.../node/DistributedLockNodeServiceTest.java} | 10 ++---
.../DistributedLockChangedWatcherTest.java} | 40 ++++++++++----------
.../manager/memory/lock/MemoryLockContext.java | 41 ++++++---------------
.../standalone/lock/StandaloneLockContext.java | 41 ++++++---------------
30 files changed, 227 insertions(+), 235 deletions(-)
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 74bae25c423..bfa872cafc2 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
@@ -35,54 +35,62 @@ public interface LockContext {
}
/**
- * Get or create mutex lock.
+ * Get lock.
*
- * @return mutex lock
+ * @return lock
*/
- ShardingSphereLock getMutexLock();
+ ShardingSphereLock getLock();
/**
- * Lock write for database.
+ * Try lock for database.
*
* @param databaseName database name
+ * @param lockMode lock mode
* @return is locked or not
*/
- boolean lockWrite(String databaseName);
+ boolean tryLock(String databaseName, LockMode lockMode);
/**
- * Lock write for schemas.
+ * Try Lock write for database.
*
* @param databaseName database name
- * @param schemaNames schema names
+ * @param lockMode lock mode
+ * @param timeoutMilliseconds timeout milliseconds
* @return is locked or not
*/
- boolean lockWrite(String databaseName, Set<String> schemaNames);
+ boolean tryLock(String databaseName, LockMode lockMode, long
timeoutMilliseconds);
/**
- * Try Lock write for database.
+ * Try lock for schemas.
*
* @param databaseName database name
- * @param timeoutMilliseconds timeout milliseconds
+ * @param schemaNames schema names
+ * @param lockMode lock mode
* @return is locked or not
*/
- boolean tryLockWrite(String databaseName, long timeoutMilliseconds);
+ default boolean tryLock(String databaseName, Set<String> schemaNames,
LockMode lockMode) {
+ throw new UnsupportedOperationException();
+ }
/**
- * Try lock write for schemas.
+ * Try lock for schemas.
*
* @param databaseName database name
* @param schemaNames schema names
+ * @param lockMode lock mode
* @param timeoutMilliseconds timeout milliseconds
* @return is locked or not
*/
- boolean tryLockWrite(String databaseName, Set<String> schemaNames, long
timeoutMilliseconds);
+ default boolean tryLock(String databaseName, Set<String> schemaNames,
LockMode lockMode, long timeoutMilliseconds) {
+ throw new UnsupportedOperationException();
+ }
/**
- * Release lock write of database.
+ * Release lock for database.
*
* @param databaseName database name
*/
- void releaseLockWrite(String databaseName);
+ void releaseLock(String databaseName);
/**
* Release lock write for schemas.
@@ -90,7 +98,9 @@ public interface LockContext {
* @param databaseName database name
* @param schemaName schema name
*/
- void releaseLockWrite(String databaseName, String schemaName);
+ default void releaseLock(String databaseName, String schemaName) {
+ throw new UnsupportedOperationException();
+ }
/**
* Is locked database.
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeType.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockMode.java
similarity index 84%
copy from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeType.java
copy to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockMode.java
index 9f227ec9b4e..84436b2c815 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeType.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockMode.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util;
+package org.apache.shardingsphere.infra.lock;
/**
- * Lock node type.
+ * Lock mode.
*/
-public enum LockNodeType {
+public enum LockMode {
- MUTEX, DATABASE, SCHEMA
+ READ, WRITE
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/RuleAlteredJobAPIImpl.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/RuleAlteredJobAPIImpl.java
index 72ee8aba226..857086a646b 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/RuleAlteredJobAPIImpl.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/impl/RuleAlteredJobAPIImpl.java
@@ -48,6 +48,7 @@ import
org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.JobBriefInfo;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.lock.LockContext;
+import org.apache.shardingsphere.infra.lock.LockMode;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.ScalingTaskFinishedEvent;
import
org.apache.shardingsphere.scaling.core.job.environment.ScalingEnvironmentManager;
@@ -189,7 +190,7 @@ public final class RuleAlteredJobAPIImpl extends
AbstractPipelineJobAPIImpl impl
log.info("stopClusterWriteDB, already stopped");
return;
}
- if (lockContext.lockWrite(databaseName)) {
+ if (lockContext.tryLock(databaseName, LockMode.READ)) {
log.info("stopClusterWriteDB, tryLockSuccess=true");
return;
}
@@ -212,7 +213,7 @@ public final class RuleAlteredJobAPIImpl extends
AbstractPipelineJobAPIImpl impl
LockContext lockContext =
PipelineContext.getContextManager().getInstanceContext().getLockContext();
if (lockContext.isLocked(databaseName)) {
log.info("restoreClusterWriteDB, before releaseLock,
databaseName={}, jobId={}", databaseName, jobId);
- lockContext.releaseLockWrite(databaseName);
+ lockContext.releaseLock(databaseName);
return;
}
log.info("restoreClusterWriteDB, isLocked false, databaseName={}",
databaseName);
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLock.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLock.java
index 11bbe7393e2..d2fc0a51faa 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLock.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/lock/PipelineSimpleLock.java
@@ -68,7 +68,7 @@ public final class PipelineSimpleLock {
*/
public boolean tryLock(final String lockName, final long timeoutMills) {
String realLockName = decorateLockName(lockName);
- boolean result = lockContext.getMutexLock().tryLock(realLockName,
timeoutMills);
+ boolean result = lockContext.getLock().tryLock(realLockName,
timeoutMills);
if (result) {
lockNameLockedMap.put(realLockName, true);
}
@@ -86,7 +86,7 @@ public final class PipelineSimpleLock {
log.info("releaseLock, lockName={}", realLockName);
if (lockNameLockedMap.getOrDefault(realLockName, false)) {
lockNameLockedMap.remove(realLockName);
- lockContext.getMutexLock().releaseLock(realLockName);
+ lockContext.getLock().releaseLock(realLockName);
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java
index 6455944a0fe..54e36d99597 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobPreparer.java
@@ -102,7 +102,7 @@ public final class RuleAlteredJobPreparer {
RuleAlteredJobConfiguration jobConfig = jobContext.getJobConfig();
// TODO the lock will be replaced
String lockName = "prepare-" + jobConfig.getJobId();
- ShardingSphereLock lock =
PipelineContext.getContextManager().getInstanceContext().getLockContext().getMutexLock();
+ ShardingSphereLock lock =
PipelineContext.getContextManager().getInstanceContext().getLockContext().getLock();
if (lock.tryLock(lockName, 3000)) {
try {
prepareAndCheckTarget(jobContext);
diff --git
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
index d65e651de40..b2e779f2d45 100644
---
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
+++
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
@@ -298,7 +298,7 @@ public final class RuleAlteredJobWorker {
LockContext lockContext =
PipelineContext.getContextManager().getInstanceContext().getLockContext();
if (lockContext.isLocked(databaseName)) {
log.info("Source writing is still stopped on database '{}',
restore it now", databaseName);
- lockContext.releaseLockWrite(databaseName);
+ lockContext.releaseLock(databaseName);
}
}
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index d8c70beabec..e33a314f4f3 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -33,7 +33,7 @@ import
org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.DistributeLockContext;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.DistributedLockContext;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.workerid.generator.ClusterWorkerIdGenerator;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
@@ -146,8 +146,8 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
final InstanceDefinition
instanceDefinition, final MetaDataContexts metaDataContexts,
final Properties
transactionProps, final ModeConfiguration modeConfig) {
ClusterWorkerIdGenerator clusterWorkerIdGenerator = new
ClusterWorkerIdGenerator(repository, registryCenter, instanceDefinition);
- DistributeLockContext distributeLockContext = new
DistributeLockContext(repository);
- InstanceContext instanceContext = new InstanceContext(new
ComputeNodeInstance(instanceDefinition), clusterWorkerIdGenerator, modeConfig,
distributeLockContext);
+ DistributedLockContext distributedLockContext = new
DistributedLockContext(repository);
+ InstanceContext instanceContext = new InstanceContext(new
ComputeNodeInstance(instanceDefinition), clusterWorkerIdGenerator, modeConfig,
distributedLockContext);
repository.watchSessionConnection(instanceContext);
generateTransactionConfigurationFile(instanceContext,
metaDataContexts, transactionProps);
TransactionContexts transactionContexts = new
TransactionContextsBuilder(
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributedLockNodeService.java
similarity index 94%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeService.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributedLockNodeService.java
index 650c52a9562..8eb668f2386 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeService.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributedLockNodeService.java
@@ -22,9 +22,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * Abstract distribute lock node service.
+ * Abstract distributed lock node service.
*/
-public abstract class AbstractDistributeLockNodeService implements
LockNodeService {
+public abstract class AbstractDistributedLockNodeService implements
LockNodeService {
@Override
public String getLocksNodePath() {
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContext.java
similarity index 69%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContext.java
index 7f2be2102ab..bdcc22ec056 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContext.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.lock.LockContext;
+import org.apache.shardingsphere.infra.lock.LockMode;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager.ShardingSphereLockManager;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.ShardingSphereInterMutexLockHolder;
@@ -30,10 +31,10 @@ import
org.apache.shardingsphere.spi.type.required.RequiredSPIRegistry;
import java.util.Set;
/**
- * Distribute lock context.
+ * Distributed lock context.
*/
@RequiredArgsConstructor
-public final class DistributeLockContext implements LockContext {
+public final class DistributedLockContext implements LockContext {
static {
ShardingSphereServiceLoader.register(ShardingSphereLockManager.class);
@@ -54,38 +55,38 @@ public final class DistributeLockContext implements
LockContext {
}
@Override
- public ShardingSphereLock getMutexLock() {
- return lockManager.getMutexLock();
+ public ShardingSphereLock getLock() {
+ return lockManager.getDistributedLock();
}
@Override
- public boolean lockWrite(final String databaseName) {
- return lockManager.lockWrite(databaseName);
+ public boolean tryLock(final String databaseName, final LockMode lockMode)
{
+ return lockManager.tryLock(databaseName, lockMode);
}
@Override
- public boolean lockWrite(final String databaseName, final Set<String>
schemaNames) {
- return lockManager.lockWrite(databaseName, schemaNames);
+ public boolean tryLock(final String databaseName, final Set<String>
schemaNames, final LockMode lockMode) {
+ return lockManager.tryLock(databaseName, schemaNames, lockMode);
}
@Override
- public boolean tryLockWrite(final String databaseName, final long
timeoutMilliseconds) {
- return lockManager.tryLockWrite(databaseName, timeoutMilliseconds);
+ public boolean tryLock(final String databaseName, final LockMode lockMode,
final long timeoutMilliseconds) {
+ return lockManager.tryLock(databaseName, lockMode,
timeoutMilliseconds);
}
@Override
- public boolean tryLockWrite(final String databaseName, final Set<String>
schemaNames, final long timeoutMilliseconds) {
- return lockManager.tryLockWrite(databaseName, schemaNames,
timeoutMilliseconds);
+ public boolean tryLock(final String databaseName, final Set<String>
schemaNames, final LockMode lockMode, final long timeoutMilliseconds) {
+ return lockManager.tryLock(databaseName, schemaNames, lockMode,
timeoutMilliseconds);
}
@Override
- public void releaseLockWrite(final String databaseName) {
- lockManager.releaseLockWrite(databaseName);
+ public void releaseLock(final String databaseName) {
+ lockManager.releaseLock(databaseName);
}
@Override
- public void releaseLockWrite(final String databaseName, final String
schemaName) {
- lockManager.releaseLockWrite(databaseName, schemaName);
+ public void releaseLock(final String databaseName, final String
schemaName) {
+ lockManager.releaseLock(databaseName, schemaName);
}
@Override
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java
index 0498e8627bc..b16904ba6c8 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/database/node/DatabaseLockNodeService.java
@@ -17,13 +17,13 @@
package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.database.node;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.AbstractDistributeLockNodeService;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.AbstractDistributedLockNodeService;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.LockNodeType;
/**
* Database lock node service.
*/
-public final class DatabaseLockNodeService extends
AbstractDistributeLockNodeService {
+public final class DatabaseLockNodeService extends
AbstractDistributedLockNodeService {
@Override
public String getSequenceNodePath() {
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/ShardingSphereDistributeMutexLock.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/ShardingSphereDistributedLock.java
similarity index 82%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/ShardingSphereDistributeMutexLock.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/ShardingSphereDistributedLock.java
index 485b0a568fd..51be60de7e1 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/ShardingSphereDistributeMutexLock.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/ShardingSphereDistributedLock.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed;
import com.google.common.eventbus.Subscribe;
import lombok.extern.slf4j.Slf4j;
@@ -23,10 +23,12 @@ import
org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeService;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeServiceFactory;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexAckLockReleasedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexAckLockedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexLockReleasedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexLockedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.InterMutexLock;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.ShardingSphereInterMutexLockHolder;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedAckLockReleasedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedAckLockedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedLockReleasedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedLockedEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.LockNodeType;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.TimeoutMilliseconds;
@@ -36,13 +38,13 @@ import java.util.Optional;
* Distribute mutex lock of ShardingSphere.
*/
@Slf4j
-public final class ShardingSphereDistributeMutexLock implements
ShardingSphereLock {
+public final class ShardingSphereDistributedLock implements ShardingSphereLock
{
- private final LockNodeService lockNodeService =
LockNodeServiceFactory.getInstance().getLockNodeService(LockNodeType.MUTEX);
+ private final LockNodeService lockNodeService =
LockNodeServiceFactory.getInstance().getLockNodeService(LockNodeType.DISTRIBUTED);
private final ShardingSphereInterMutexLockHolder lockHolder;
- public ShardingSphereDistributeMutexLock(final
ShardingSphereInterMutexLockHolder lockHolder) {
+ public ShardingSphereDistributedLock(final
ShardingSphereInterMutexLockHolder lockHolder) {
this.lockHolder = lockHolder;
ShardingSphereEventBus.getInstance().register(this);
syncMutexLockStatus();
@@ -86,7 +88,7 @@ public final class ShardingSphereDistributeMutexLock
implements ShardingSphereLo
* @param event mutex locked event
*/
@Subscribe
- public synchronized void locked(final MutexLockedEvent event) {
+ public synchronized void locked(final DistributedLockedEvent event) {
String lockName = event.getLockedName();
String lockedInstanceId = lockHolder.getCurrentInstanceId();
InterMutexLock interMutexLock =
lockHolder.getOrCreateInterMutexLock(lockNodeService.generateLocksName(lockName));
@@ -99,7 +101,7 @@ public final class ShardingSphereDistributeMutexLock
implements ShardingSphereLo
* @param event mutex lock released event
*/
@Subscribe
- public synchronized void lockReleased(final MutexLockReleasedEvent event) {
+ public synchronized void lockReleased(final DistributedLockReleasedEvent
event) {
String lockName = event.getLockedName();
String lockedInstanceId = lockHolder.getCurrentInstanceId();
getInterMutexLock(lockName).ifPresent(mutexLock ->
mutexLock.releaseAckLock(lockNodeService.generateAckLockName(lockName,
lockedInstanceId), lockedInstanceId));
@@ -111,7 +113,7 @@ public final class ShardingSphereDistributeMutexLock
implements ShardingSphereLo
* @param event mutex ack locked event
*/
@Subscribe
- public synchronized void ackLocked(final MutexAckLockedEvent event) {
+ public synchronized void ackLocked(final DistributedAckLockedEvent event) {
getInterMutexLock(event.getLockName()).ifPresent(mutexLock ->
mutexLock.addLockedInstance(event.getLockedInstance()));
}
@@ -121,7 +123,7 @@ public final class ShardingSphereDistributeMutexLock
implements ShardingSphereLo
* @param event mutex ack lock released event
*/
@Subscribe
- public synchronized void ackLockReleased(final MutexAckLockReleasedEvent
event) {
+ public synchronized void ackLockReleased(final
DistributedAckLockReleasedEvent event) {
getInterMutexLock(event.getLockName()).ifPresent(mutexLock ->
mutexLock.removeLockedInstance(event.getLockedInstance()));
}
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexAckLockedEvent.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedAckLockReleasedEvent.java
similarity index 86%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexAckLockedEvent.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedAckLockReleasedEvent.java
index 952e150d775..2eba45ab9fa 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexAckLockedEvent.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedAckLockReleasedEvent.java
@@ -15,23 +15,23 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event;
import lombok.Getter;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.LockNodeUtil;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
/**
- * Mutex ack locked event.
+ * Distributed ack released Lock event.
*/
@Getter
-public final class MutexAckLockedEvent implements GovernanceEvent {
+public final class DistributedAckLockReleasedEvent implements GovernanceEvent {
private final String lockName;
private final String lockedInstance;
- public MutexAckLockedEvent(final String ackLockName) {
+ public DistributedAckLockReleasedEvent(final String ackLockName) {
String[] lockNameInstance = LockNodeUtil.parseAckLockName(ackLockName);
lockName = lockNameInstance[0];
lockedInstance = lockNameInstance[1];
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexAckLockReleasedEvent.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedAckLockedEvent.java
similarity index 87%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexAckLockReleasedEvent.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedAckLockedEvent.java
index 9a4d91bdef0..22d0f4d05ca 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexAckLockReleasedEvent.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedAckLockedEvent.java
@@ -15,23 +15,23 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event;
import lombok.Getter;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.LockNodeUtil;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
/**
- * Mutex ack released Lock event.
+ * Distributed ack locked event.
*/
@Getter
-public final class MutexAckLockReleasedEvent implements GovernanceEvent {
+public final class DistributedAckLockedEvent implements GovernanceEvent {
private final String lockName;
private final String lockedInstance;
- public MutexAckLockReleasedEvent(final String ackLockName) {
+ public DistributedAckLockedEvent(final String ackLockName) {
String[] lockNameInstance = LockNodeUtil.parseAckLockName(ackLockName);
lockName = lockNameInstance[0];
lockedInstance = lockNameInstance[1];
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexLockedEvent.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedLockReleasedEvent.java
similarity index 88%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexLockedEvent.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedLockReleasedEvent.java
index 237d8f90d99..ebd769e6e5f 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexLockedEvent.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedLockReleasedEvent.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
/**
- * Mutex locked event.
+ * Distributed lock released event.
*/
@RequiredArgsConstructor
@Getter
-public final class MutexLockedEvent implements GovernanceEvent {
+public final class DistributedLockReleasedEvent implements GovernanceEvent {
private final String lockedName;
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexLockReleasedEvent.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedLockedEvent.java
similarity index 90%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexLockReleasedEvent.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedLockedEvent.java
index 90dda64a7b5..b1c59e4c860 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/event/MutexLockReleasedEvent.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/event/DistributedLockedEvent.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
/**
- * Mutex lock released event.
+ * Distributed locked event.
*/
@RequiredArgsConstructor
@Getter
-public final class MutexLockReleasedEvent implements GovernanceEvent {
+public final class DistributedLockedEvent implements GovernanceEvent {
private final String lockedName;
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeService.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/node/DistributedLockNodeService.java
similarity index 83%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeService.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/node/DistributedLockNodeService.java
index 3ebd045ae90..20c1f4212dc 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeService.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/node/DistributedLockNodeService.java
@@ -15,15 +15,15 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.node;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.node;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.AbstractDistributeLockNodeService;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.AbstractDistributedLockNodeService;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.LockNodeType;
/**
- * Mutex lock node service.
+ * Distributed lock node service.
*/
-public final class MutexLockNodeService extends
AbstractDistributeLockNodeService {
+public final class DistributedLockNodeService extends
AbstractDistributedLockNodeService {
@Override
public String getSequenceNodePath() {
@@ -32,11 +32,11 @@ public final class MutexLockNodeService extends
AbstractDistributeLockNodeServic
@Override
protected String getLockTypeName() {
- return "mutex";
+ return "distributed";
}
@Override
public LockNodeType getType() {
- return LockNodeType.MUTEX;
+ return LockNodeType.DISTRIBUTED;
}
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/watcher/MutexLockChangedWatcher.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/watcher/DistributedLockChangedWatcher.java
similarity index 82%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/watcher/MutexLockChangedWatcher.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/watcher/DistributedLockChangedWatcher.java
index 04c7d8c8a74..43bcca30126 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/watcher/MutexLockChangedWatcher.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/watcher/DistributedLockChangedWatcher.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.watcher;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.watcher;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeService;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeServiceFactory;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexAckLockReleasedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexAckLockedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexLockReleasedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexLockedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedAckLockReleasedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedAckLockedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedLockReleasedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedLockedEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.LockNodeType;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
@@ -34,9 +34,9 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
-public final class MutexLockChangedWatcher implements
GovernanceWatcher<GovernanceEvent> {
+public final class DistributedLockChangedWatcher implements
GovernanceWatcher<GovernanceEvent> {
- private final LockNodeService lockNode =
LockNodeServiceFactory.getInstance().getLockNodeService(LockNodeType.MUTEX);
+ private final LockNodeService lockNode =
LockNodeServiceFactory.getInstance().getLockNodeService(LockNodeType.DISTRIBUTED);
@Override
public Collection<String> getWatchingKeys() {
@@ -63,18 +63,18 @@ public final class MutexLockChangedWatcher implements
GovernanceWatcher<Governan
private Optional<GovernanceEvent> handleMutexLocksEvent(final Type
eventType, final String lockedName) {
if (Type.ADDED == eventType) {
- return Optional.of(new MutexLockedEvent(lockedName));
+ return Optional.of(new DistributedLockedEvent(lockedName));
} else if (Type.DELETED == eventType) {
- return Optional.of(new MutexLockReleasedEvent(lockedName));
+ return Optional.of(new DistributedLockReleasedEvent(lockedName));
}
return Optional.empty();
}
private Optional<GovernanceEvent> handleMutexLocksAckEvent(final Type
eventType, final String ackLockedName) {
if (Type.ADDED == eventType) {
- return Optional.of(new MutexAckLockedEvent(ackLockedName));
+ return Optional.of(new DistributedAckLockedEvent(ackLockedName));
} else if (Type.DELETED == eventType) {
- return Optional.of(new MutexAckLockReleasedEvent(ackLockedName));
+ return Optional.of(new
DistributedAckLockReleasedEvent(ackLockedName));
}
return Optional.empty();
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributeLockManager.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributedLockManager.java
similarity index 66%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributeLockManager.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributedLockManager.java
index c477d7f2c02..0a3c271e218 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributeLockManager.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/DistributedLockManager.java
@@ -19,9 +19,10 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager;
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.lock.LockMode;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.database.ShardingSphereDistributeDatabaseLock;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.ShardingSphereDistributeMutexLock;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.ShardingSphereDistributedLock;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.ShardingSphereInterMutexLockHolder;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.TimeoutMilliseconds;
@@ -29,41 +30,51 @@ import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util.Time
* Distribute lock manager.
*/
@Slf4j
-public final class DistributeLockManager implements ShardingSphereLockManager {
+public final class DistributedLockManager implements ShardingSphereLockManager
{
- private ShardingSphereDistributeMutexLock mutexLock;
+ private ShardingSphereDistributedLock distributedLock;
private ShardingSphereDistributeDatabaseLock databaseLock;
@Override
public void init(final ShardingSphereInterMutexLockHolder lockHolder) {
- mutexLock = new ShardingSphereDistributeMutexLock(lockHolder);
+ distributedLock = new ShardingSphereDistributedLock(lockHolder);
databaseLock = new ShardingSphereDistributeDatabaseLock(lockHolder);
}
@Override
- public ShardingSphereLock getMutexLock() {
- return mutexLock;
+ public ShardingSphereLock getDistributedLock() {
+ return distributedLock;
}
@Override
- public boolean lockWrite(final String databaseName) {
- return tryLockWrite(databaseName, TimeoutMilliseconds.MAX_TRY_LOCK);
+ public boolean tryLock(final String databaseName, final LockMode lockMode)
{
+ return innerTryLock(databaseName, lockMode,
TimeoutMilliseconds.MAX_TRY_LOCK);
}
@Override
- public boolean tryLockWrite(final String databaseName, final long
timeoutMilliseconds) {
- return innerDatabaseTryLock(databaseName, timeoutMilliseconds);
+ public boolean tryLock(final String databaseName, final LockMode lockMode,
final long timeoutMilliseconds) {
+ return innerTryLock(databaseName, lockMode, timeoutMilliseconds);
}
- private synchronized boolean innerDatabaseTryLock(final String
databaseName, final long timeoutMilliseconds) {
+ private synchronized boolean innerTryLock(final String databaseName, final
LockMode lockMode, final long timeoutMilliseconds) {
+ switch (lockMode) {
+ case READ:
+ return innerDatabaseTryLock(databaseName, timeoutMilliseconds);
+ case WRITE:
+ default:
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private boolean innerDatabaseTryLock(final String databaseName, final long
timeoutMilliseconds) {
Preconditions.checkNotNull(databaseName, "Try Lock write for database
args database name can not be null.");
log.debug("Distribute database lock acquire sequenced success,
database name: {}", databaseName);
return databaseLock.tryLock(databaseName, timeoutMilliseconds -
TimeoutMilliseconds.DEFAULT_REGISTRY);
}
@Override
- public void releaseLockWrite(final String databaseName) {
+ public void releaseLock(final String databaseName) {
Preconditions.checkNotNull(databaseName, "Release lock write args
database name can not be null.");
databaseLock.releaseLock(databaseName);
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java
index 11918dbef5b..61d74d8ed86 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/manager/ShardingSphereLockManager.java
@@ -17,6 +17,7 @@
package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager;
+import org.apache.shardingsphere.infra.lock.LockMode;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.ShardingSphereInterMutexLockHolder;
import org.apache.shardingsphere.spi.annotation.SingletonSPI;
@@ -38,66 +39,70 @@ public interface ShardingSphereLockManager extends
RequiredSPI {
void init(ShardingSphereInterMutexLockHolder lockHolder);
/**
- * Get mutex lock.
+ * Get distributed lock.
*
- * @return mutex lock
+ * @return distributed lock
*/
- ShardingSphereLock getMutexLock();
+ ShardingSphereLock getDistributedLock();
/**
- * Lock write for database.
+ * Try lock for database.
*
* @param databaseName database name
+ * @param lockMode lock mode
* @return is locked or not
*/
- boolean lockWrite(String databaseName);
+ boolean tryLock(String databaseName, LockMode lockMode);
/**
- * Lock write for schemas.
+ * Try lock write for database.
*
* @param databaseName database name
- * @param schemaNames schema names
+ * @param lockMode lock mode
+ * @param timeoutMilliseconds timeout milliseconds
* @return is locked or not
*/
- default boolean lockWrite(String databaseName, Set<String> schemaNames) {
- throw new UnsupportedOperationException();
- }
+ boolean tryLock(String databaseName, LockMode lockMode, long
timeoutMilliseconds);
/**
- * Try lock write for database.
+ * Try lock for schemas.
*
* @param databaseName database name
- * @param timeoutMilliseconds timeout milliseconds
+ * @param schemaNames schema names
+ * @param lockMode lock mode
* @return is locked or not
*/
- boolean tryLockWrite(String databaseName, long timeoutMilliseconds);
+ default boolean tryLock(String databaseName, Set<String> schemaNames,
LockMode lockMode) {
+ throw new UnsupportedOperationException();
+ }
/**
- * Try lock write for schemas.
+ * Try lock for schemas.
*
* @param databaseName database name
* @param schemaNames schema names
+ * @param lockMode lock mode
* @param timeoutMilliseconds timeout milliseconds
* @return is locked or not
*/
- default boolean tryLockWrite(String databaseName, Set<String> schemaNames,
long timeoutMilliseconds) {
+ default boolean tryLock(String databaseName, Set<String> schemaNames,
LockMode lockMode, long timeoutMilliseconds) {
throw new UnsupportedOperationException();
}
/**
- * Release lock write for database.
+ * Release lock for database.
*
* @param databaseName database name
*/
- void releaseLockWrite(String databaseName);
+ void releaseLock(String databaseName);
/**
- * Try lock write for schemas.
+ * Release lock for schemas.
*
* @param databaseName database name
* @param schemaName schema name
*/
- default void releaseLockWrite(String databaseName, String schemaName) {
+ default void releaseLock(String databaseName, String schemaName) {
throw new UnsupportedOperationException();
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/ShardingSphereInterMutexLockHolder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/ShardingSphereInterMutexLockHolder.java
index 5462dafd294..482a76de436 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/ShardingSphereInterMutexLockHolder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/ShardingSphereInterMutexLockHolder.java
@@ -106,7 +106,7 @@ public final class ShardingSphereInterMutexLockHolder {
public void synchronizeMutexLock(final LockNodeService lockNodeService) {
Collection<String> allGlobalLock =
repository.getChildrenKeys(lockNodeService.getLocksNodePath());
if (allGlobalLock.isEmpty()) {
- if (LockNodeType.MUTEX == lockNodeService.getType()) {
+ if (LockNodeType.DISTRIBUTED == lockNodeService.getType()) {
return;
}
repository.persist(lockNodeService.getLocksNodePath(), "");
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeType.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeType.java
index 9f227ec9b4e..362343ef19b 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeType.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/util/LockNodeType.java
@@ -22,5 +22,5 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.util;
*/
public enum LockNodeType {
- MUTEX, DATABASE, SCHEMA
+ DISTRIBUTED, DATABASE, SCHEMA
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeService
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeService
index 980b2f0a60f..0d95206b2db 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeService
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.LockNodeService
@@ -15,5 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.node.MutexLockNodeService
+org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.node.DistributedLockNodeService
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.database.node.DatabaseLockNodeService
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager.ShardingSphereLockManager
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager.ShardingSphereLockManager
index 01b65f820dd..cef0a9c6f82 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager.ShardingSphereLockManager
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager.ShardingSphereLockManager
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager.DistributeLockManager
+org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.manager.DistributedLockManager
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
index 614a8158b81..6bac8887d99 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
@@ -20,5 +20,5 @@
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.wat
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher.GlobalRuleChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher.PropertiesChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.watcher.ComputeNodeStateChangedWatcher
-org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.watcher.MutexLockChangedWatcher
+org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.watcher.DistributedLockChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.database.watcher.DatabaseLockChangedWatcher
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeServiceTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributedLockNodeServiceTest.java
similarity index 77%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeServiceTest.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributedLockNodeServiceTest.java
index 173103c1cd9..e6ba1f9fd65 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributeLockNodeServiceTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/AbstractDistributedLockNodeServiceTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.lock;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.node.MutexLockNodeService;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.node.DistributedLockNodeService;
import org.junit.Test;
import java.util.Optional;
@@ -26,31 +26,31 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-public final class AbstractDistributeLockNodeServiceTest {
+public final class AbstractDistributedLockNodeServiceTest {
- private static final AbstractDistributeLockNodeService SERVICE = new
MutexLockNodeService();
+ private static final AbstractDistributedLockNodeService SERVICE = new
DistributedLockNodeService();
@Test
public void assertGetLocksNodePath() {
String locksNodePath = SERVICE.getLocksNodePath();
- assertThat(locksNodePath, is("/lock/mutex/locks"));
+ assertThat(locksNodePath, is("/lock/distributed/locks"));
}
@Test
public void assertGenerateLocksName() {
String locksName = SERVICE.generateLocksName("sharding_db");
- assertThat(locksName, is("/lock/mutex/locks/sharding_db"));
+ assertThat(locksName, is("/lock/distributed/locks/sharding_db"));
}
@Test
public void assertGenerateAckLockName() {
String globalLockedAckNodePath =
SERVICE.generateAckLockName("locksName", "127.0.0.1@3307");
- assertThat(globalLockedAckNodePath,
is("/lock/mutex/locks/locksName/ack/127.0.0.1@3307"));
+ assertThat(globalLockedAckNodePath,
is("/lock/distributed/locks/locksName/ack/127.0.0.1@3307"));
}
@Test
public void assertParseLocksNodePath() {
- String nodePath = "/lock/mutex/locks/sharding_db/leases/c_l_00000000";
+ String nodePath =
"/lock/distributed/locks/sharding_db/leases/c_l_00000000";
Optional<String> globalLocksNodePath =
SERVICE.parseLocksNodePath(nodePath);
assertTrue(globalLocksNodePath.isPresent());
assertThat(globalLocksNodePath.get(), is("sharding_db"));
@@ -58,7 +58,7 @@ public final class AbstractDistributeLockNodeServiceTest {
@Test
public void assertParseLocksAckNodePath() {
- String nodePath = "/lock/mutex/locks/sharding_db/ack/127.0.0.1@3307";
+ String nodePath =
"/lock/distributed/locks/sharding_db/ack/127.0.0.1@3307";
Optional<String> locksAckNodePath =
SERVICE.parseLocksAckNodePath(nodePath);
assertTrue(locksAckNodePath.isPresent());
assertThat(locksAckNodePath.get(), is("sharding_db#@#127.0.0.1@3307"));
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContextTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContextTest.java
similarity index 69%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContextTest.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContextTest.java
index 7839389e34f..3a41c552f6a 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContextTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributedLockContextTest.java
@@ -32,38 +32,38 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-public final class DistributeLockContextTest {
+public final class DistributedLockContextTest {
@Test
public void assertTryLockWriteDatabase() {
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
- DistributeLockContext distributeLockContext = new
DistributeLockContext(mock(ClusterPersistRepository.class));
- new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributeLockContext).initLockContext();
- assertNotNull(distributeLockContext.getMutexLock());
+ DistributedLockContext distributedLockContext = new
DistributedLockContext(mock(ClusterPersistRepository.class));
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributedLockContext).initLockContext();
+ assertNotNull(distributedLockContext.getLock());
}
@Test
public void assertReleaseLockWriteDatabase() {
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
- DistributeLockContext distributeLockContext = new
DistributeLockContext(mock(ClusterPersistRepository.class));
- new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributeLockContext).initLockContext();
- distributeLockContext.releaseLockWrite("database");
+ DistributedLockContext distributedLockContext = new
DistributedLockContext(mock(ClusterPersistRepository.class));
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributedLockContext).initLockContext();
+ distributedLockContext.releaseLock("database");
}
@Test
public void assertIsLockedDatabase() {
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
- DistributeLockContext distributeLockContext = new
DistributeLockContext(mock(ClusterPersistRepository.class));
- new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributeLockContext).initLockContext();
- distributeLockContext.isLocked("database");
+ DistributedLockContext distributedLockContext = new
DistributedLockContext(mock(ClusterPersistRepository.class));
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributedLockContext).initLockContext();
+ distributedLockContext.isLocked("database");
}
@Test
public void assertGetMutexLock() {
- DistributeLockContext distributeLockContext = new
DistributeLockContext(mock(ClusterPersistRepository.class));
+ DistributedLockContext distributedLockContext = new
DistributedLockContext(mock(ClusterPersistRepository.class));
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new
InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
- new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributeLockContext).initLockContext();
- distributeLockContext.getMutexLock();
- assertThat(distributeLockContext.getMutexLock(),
instanceOf(ShardingSphereLock.class));
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class),
mock(ModeConfiguration.class), distributedLockContext).initLockContext();
+ distributedLockContext.getLock();
+ assertThat(distributedLockContext.getLock(),
instanceOf(ShardingSphereLock.class));
}
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeServiceTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/node/DistributedLockNodeServiceTest.java
similarity index 77%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeServiceTest.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/node/DistributedLockNodeServiceTest.java
index 1e9b42100b0..1c9cf9aac58 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/node/MutexLockNodeServiceTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/node/DistributedLockNodeServiceTest.java
@@ -15,24 +15,24 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.node;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.node;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-public final class MutexLockNodeServiceTest {
+public final class DistributedLockNodeServiceTest {
- private static final MutexLockNodeService SERVICE = new
MutexLockNodeService();
+ private static final DistributedLockNodeService SERVICE = new
DistributedLockNodeService();
@Test
public void assertGetSequenceNodePath() {
- assertThat(SERVICE.getSequenceNodePath(), is("/lock/mutex/sequence"));
+ assertThat(SERVICE.getSequenceNodePath(),
is("/lock/distributed/sequence"));
}
@Test
public void assertGetLockLevel() {
- assertThat(SERVICE.getLockTypeName(), is("mutex"));
+ assertThat(SERVICE.getLockTypeName(), is("distributed"));
}
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/watcher/MutexLockChangedWatcherTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/watcher/DistributedLockChangedWatcherTest.java
similarity index 73%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/watcher/MutexLockChangedWatcherTest.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/watcher/DistributedLockChangedWatcherTest.java
index 7868bea3190..45153da125d 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/mutex/watcher/MutexLockChangedWatcherTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/distributed/watcher/DistributedLockChangedWatcherTest.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.watcher;
+package
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.watcher;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexAckLockReleasedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexAckLockedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexLockReleasedEvent;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.mutex.event.MutexLockedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedAckLockReleasedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedAckLockedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedLockReleasedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.distributed.event.DistributedLockedEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
import org.junit.Test;
@@ -35,15 +35,15 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-public final class MutexLockChangedWatcherTest {
+public final class DistributedLockChangedWatcherTest {
- private final MutexLockChangedWatcher watcher = new
MutexLockChangedWatcher();
+ private final DistributedLockChangedWatcher watcher = new
DistributedLockChangedWatcher();
@Test
public void assertGetWatchingKeys() {
Collection<String> keys = watcher.getWatchingKeys();
assertThat(keys.size(), is(1));
- assertThat("/lock/mutex/locks", is(keys.iterator().next()));
+ assertThat("/lock/distributed/locks", is(keys.iterator().next()));
}
@Test
@@ -57,17 +57,17 @@ public final class MutexLockChangedWatcherTest {
@Test
public void assertLocksCreateGovernanceEvent() {
- String eventKey = "/lock/mutex/locks/lockName/leases/c_l_0000000";
+ String eventKey =
"/lock/distributed/locks/lockName/leases/c_l_0000000";
DataChangedEvent addDataChangedEvent = new DataChangedEvent(eventKey,
"127.0.0.1@3307", DataChangedEvent.Type.ADDED);
Optional<GovernanceEvent> addGovernanceEvent =
watcher.createGovernanceEvent(addDataChangedEvent);
assertTrue(addGovernanceEvent.isPresent());
- assertThat(addGovernanceEvent.get(),
instanceOf(MutexLockedEvent.class));
- assertThat(((MutexLockedEvent)
addGovernanceEvent.get()).getLockedName(), is("lockName"));
+ assertThat(addGovernanceEvent.get(),
instanceOf(DistributedLockedEvent.class));
+ assertThat(((DistributedLockedEvent)
addGovernanceEvent.get()).getLockedName(), is("lockName"));
DataChangedEvent deleteDataChangedEvent = new
DataChangedEvent(eventKey, "127.0.0.1@3307", DataChangedEvent.Type.DELETED);
Optional<GovernanceEvent> deleteGovernanceEvent =
watcher.createGovernanceEvent(deleteDataChangedEvent);
assertTrue(deleteGovernanceEvent.isPresent());
- assertThat(deleteGovernanceEvent.get(),
instanceOf(MutexLockReleasedEvent.class));
- assertThat(((MutexLockReleasedEvent)
deleteGovernanceEvent.get()).getLockedName(), is("lockName"));
+ assertThat(deleteGovernanceEvent.get(),
instanceOf(DistributedLockReleasedEvent.class));
+ assertThat(((DistributedLockReleasedEvent)
deleteGovernanceEvent.get()).getLockedName(), is("lockName"));
DataChangedEvent updateDataChangedEvent = new
DataChangedEvent(eventKey, "127.0.0.1@3307", DataChangedEvent.Type.UPDATED);
Optional<GovernanceEvent> updateGovernanceEvent =
watcher.createGovernanceEvent(updateDataChangedEvent);
assertFalse(updateGovernanceEvent.isPresent());
@@ -78,19 +78,19 @@ public final class MutexLockChangedWatcherTest {
@Test
public void assertLocksAckCreateGovernanceEvent() {
- String eventKey = "/lock/mutex/locks/lockName/ack/127.0.0.1@3307";
+ String eventKey =
"/lock/distributed/locks/lockName/ack/127.0.0.1@3307";
DataChangedEvent addDataChangedEvent = new DataChangedEvent(eventKey,
"127.0.0.1@3307", DataChangedEvent.Type.ADDED);
Optional<GovernanceEvent> addGovernanceEvent =
watcher.createGovernanceEvent(addDataChangedEvent);
assertTrue(addGovernanceEvent.isPresent());
- assertThat(addGovernanceEvent.get(),
instanceOf(MutexAckLockedEvent.class));
- assertThat(((MutexAckLockedEvent)
addGovernanceEvent.get()).getLockName(), is("lockName"));
- assertThat(((MutexAckLockedEvent)
addGovernanceEvent.get()).getLockedInstance(), is("127.0.0.1@3307"));
+ assertThat(addGovernanceEvent.get(),
instanceOf(DistributedAckLockedEvent.class));
+ assertThat(((DistributedAckLockedEvent)
addGovernanceEvent.get()).getLockName(), is("lockName"));
+ assertThat(((DistributedAckLockedEvent)
addGovernanceEvent.get()).getLockedInstance(), is("127.0.0.1@3307"));
DataChangedEvent deleteDataChangedEvent = new
DataChangedEvent(eventKey, "127.0.0.1@3307", DataChangedEvent.Type.DELETED);
Optional<GovernanceEvent> deleteGovernanceEvent =
watcher.createGovernanceEvent(deleteDataChangedEvent);
assertTrue(deleteGovernanceEvent.isPresent());
- assertThat(deleteGovernanceEvent.get(),
instanceOf(MutexAckLockReleasedEvent.class));
- assertThat(((MutexAckLockReleasedEvent)
deleteGovernanceEvent.get()).getLockName(), is("lockName"));
- assertThat(((MutexAckLockReleasedEvent)
deleteGovernanceEvent.get()).getLockedInstance(), is("127.0.0.1@3307"));
+ assertThat(deleteGovernanceEvent.get(),
instanceOf(DistributedAckLockReleasedEvent.class));
+ assertThat(((DistributedAckLockReleasedEvent)
deleteGovernanceEvent.get()).getLockName(), is("lockName"));
+ assertThat(((DistributedAckLockReleasedEvent)
deleteGovernanceEvent.get()).getLockedInstance(), is("127.0.0.1@3307"));
DataChangedEvent updateDataChangedEvent = new
DataChangedEvent(eventKey, "127.0.0.1@3307", DataChangedEvent.Type.UPDATED);
Optional<GovernanceEvent> updateGovernanceEvent =
watcher.createGovernanceEvent(updateDataChangedEvent);
assertFalse(updateGovernanceEvent.isPresent());
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java
index 7cbcbd428d5..a284bb2d268 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/lock/MemoryLockContext.java
@@ -18,58 +18,39 @@
package org.apache.shardingsphere.mode.manager.memory.lock;
import org.apache.shardingsphere.infra.lock.LockContext;
+import org.apache.shardingsphere.infra.lock.LockMode;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
-import java.util.Set;
-
/**
* Memory lock context.
*/
public final class MemoryLockContext implements LockContext {
- private final ShardingSphereLock mutexLock = new
ShardingSphereMemoryMutexLock();
-
- @Override
- public ShardingSphereLock getMutexLock() {
- return mutexLock;
- }
-
- @Override
- public boolean lockWrite(final String databaseName) {
- return mutexLock.tryLock(databaseName);
- }
-
- @Override
- public boolean lockWrite(final String databaseName, final Set<String>
schemaNames) {
- // TODO when the lock structure adjustment is completed
- throw new UnsupportedOperationException();
- }
+ private final ShardingSphereLock memoryLock = new
ShardingSphereMemoryMutexLock();
@Override
- public boolean tryLockWrite(final String databaseName, final long
timeoutMilliseconds) {
- return mutexLock.tryLock(databaseName, timeoutMilliseconds);
+ public ShardingSphereLock getLock() {
+ return memoryLock;
}
@Override
- public boolean tryLockWrite(final String databaseName, final Set<String>
schemaNames, final long timeoutMilliseconds) {
- // TODO when the lock structure adjustment is completed
- throw new UnsupportedOperationException();
+ public boolean tryLock(final String databaseName, final LockMode lockMode)
{
+ return memoryLock.tryLock(databaseName);
}
@Override
- public void releaseLockWrite(final String databaseName) {
- mutexLock.releaseLock(databaseName);
+ public boolean tryLock(final String databaseName, final LockMode lockMode,
final long timeoutMilliseconds) {
+ return memoryLock.tryLock(databaseName, timeoutMilliseconds);
}
@Override
- public void releaseLockWrite(final String databaseName, final String
schemaName) {
- // TODO when the lock structure adjustment is completed
- throw new UnsupportedOperationException();
+ public void releaseLock(final String databaseName) {
+ memoryLock.releaseLock(databaseName);
}
@Override
public boolean isLocked(final String databaseName) {
- return mutexLock.isLocked(databaseName);
+ return memoryLock.isLocked(databaseName);
}
@Override
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java
index 5a675f2c73b..bb3d9d1d5f3 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/lock/StandaloneLockContext.java
@@ -18,58 +18,39 @@
package org.apache.shardingsphere.mode.manager.standalone.lock;
import org.apache.shardingsphere.infra.lock.LockContext;
+import org.apache.shardingsphere.infra.lock.LockMode;
import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
-import java.util.Set;
-
/**
* Standalone lock context.
*/
public final class StandaloneLockContext implements LockContext {
- private final ShardingSphereLock mutexLock = new
ShardingSphereStandaloneMutexLock();
-
- @Override
- public ShardingSphereLock getMutexLock() {
- return mutexLock;
- }
-
- @Override
- public boolean lockWrite(final String databaseName) {
- return mutexLock.tryLock(databaseName);
- }
-
- @Override
- public boolean lockWrite(final String databaseName, final Set<String>
schemaNames) {
- // TODO when the lock structure adjustment is completed
- throw new UnsupportedOperationException();
- }
+ private final ShardingSphereLock standaloneLock = new
ShardingSphereStandaloneMutexLock();
@Override
- public boolean tryLockWrite(final String databaseName, final long
timeoutMilliseconds) {
- return mutexLock.tryLock(databaseName, timeoutMilliseconds);
+ public ShardingSphereLock getLock() {
+ return standaloneLock;
}
@Override
- public boolean tryLockWrite(final String databaseName, final Set<String>
schemaNames, final long timeoutMilliseconds) {
- // TODO when the lock structure adjustment is completed
- throw new UnsupportedOperationException();
+ public boolean tryLock(final String databaseName, final LockMode lockMode)
{
+ return standaloneLock.tryLock(databaseName);
}
@Override
- public void releaseLockWrite(final String databaseName) {
- mutexLock.releaseLock(databaseName);
+ public boolean tryLock(final String databaseName, final LockMode lockMode,
final long timeoutMilliseconds) {
+ return standaloneLock.tryLock(databaseName, timeoutMilliseconds);
}
@Override
- public void releaseLockWrite(final String databaseName, final String
schemaName) {
- // TODO when the lock structure adjustment is completed
- throw new UnsupportedOperationException();
+ public void releaseLock(final String databaseName) {
+ standaloneLock.releaseLock(databaseName);
}
@Override
public boolean isLocked(final String databaseName) {
- return mutexLock.isLocked(databaseName);
+ return standaloneLock.isLocked(databaseName);
}
@Override