diff --git a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java index 7c505dd06942d..0bed58cbd4cfe 100644 --- a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java +++ b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/preparer/MigrationJobPreparer.java @@ -70,7 +70,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.parser.SQLParserEngine; import org.apache.shardingsphere.mode.lock.global.GlobalLockDefinition; -import org.apache.shardingsphere.mode.lock.global.GlobalLockNames; +import org.apache.shardingsphere.mode.lock.global.GlobalLockName; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.parser.rule.SQLParserRule; @@ -118,7 +118,7 @@ private void prepareAndCheckTargetWithLock(final MigrationJobItemContext jobItem if (!jobItemManager.getProgress(jobId, jobItemContext.getShardingItem()).isPresent()) { jobItemManager.persistProgress(jobItemContext); } - LockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockNames.PREPARE, jobConfig.getJobId()); + LockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockName.PREPARE, jobConfig.getJobId()); long startTimeMillis = System.currentTimeMillis(); if (lockContext.tryLock(lockDefinition, 600 * 1000L)) { log.info("Lock success, jobId={}, shardingItem={}, cost {} ms.", jobId, jobItemContext.getShardingItem(), System.currentTimeMillis() - startTimeMillis); diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHook.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHook.java index 16e01e9c3eef1..6f9f8cc23f309 100644 --- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHook.java +++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHook.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.globalclock.rule.constant.GlobalClockOrder; import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.mode.lock.global.GlobalLockNames; +import org.apache.shardingsphere.mode.lock.global.GlobalLockName; import org.apache.shardingsphere.infra.lock.LockContext; import org.apache.shardingsphere.infra.lock.LockDefinition; import org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext; @@ -41,7 +41,7 @@ */ public final class GlobalClockTransactionHook implements TransactionHook { - private final LockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockNames.GLOBAL_LOCK); + private final LockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockName.GLOBAL_LOCK); @Override public void beforeBegin(final GlobalClockRule rule, final DatabaseType databaseType, final TransactionConnectionContext transactionContext) { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinition.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinition.java index 9988d61cb9765..bee425df49d7b 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinition.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinition.java @@ -30,11 +30,7 @@ public final class GlobalLockDefinition implements LockDefinition { private final String lockKey; - public GlobalLockDefinition(final String lockName) { - lockKey = String.format(KEY_PATTERN, lockName); - } - - public GlobalLockDefinition(final GlobalLockNames lockName, final Object... lockParams) { + public GlobalLockDefinition(final GlobalLockName lockName, final Object... lockParams) { lockKey = String.format(KEY_PATTERN, String.format(lockName.getLockName(), lockParams)); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockNames.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockName.java similarity index 95% rename from mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockNames.java rename to mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockName.java index 1656c137889e3..03a92419e45a6 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockNames.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/lock/global/GlobalLockName.java @@ -21,11 +21,11 @@ import lombok.RequiredArgsConstructor; /** - * Global lock names. + * Global lock name. */ @RequiredArgsConstructor @Getter -public enum GlobalLockNames { +public enum GlobalLockName { CLUSTER_LOCK("cluster_lock"), diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngine.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngine.java index 59aab09ab855f..d3add96827bf4 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngine.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/ShardingSphereStatisticsRefreshEngine.java @@ -36,7 +36,7 @@ import org.apache.shardingsphere.infra.yaml.data.swapper.YamlShardingSphereRowDataSwapper; import org.apache.shardingsphere.metadata.persist.data.AlteredShardingSphereDatabaseData; import org.apache.shardingsphere.mode.lock.global.GlobalLockDefinition; -import org.apache.shardingsphere.mode.lock.global.GlobalLockNames; +import org.apache.shardingsphere.mode.lock.global.GlobalLockName; import org.apache.shardingsphere.mode.manager.ContextManager; import java.util.ArrayList; @@ -84,7 +84,7 @@ public void refresh() { } private void collectAndRefresh() { - GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockNames.STATISTICS); + GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockName.STATISTICS); if (lockContext.tryLock(lockDefinition, 5000L)) { try { ShardingSphereStatistics statistics = contextManager.getMetaDataContexts().getStatistics(); diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinitionTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinitionTest.java index 8e273682d8a85..19732c7a989f3 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinitionTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/lock/global/GlobalLockDefinitionTest.java @@ -26,6 +26,6 @@ class GlobalLockDefinitionTest { @Test void assertGetLockKey() { - assertThat(new GlobalLockDefinition(GlobalLockNames.CLUSTER_LOCK).getLockKey(), is("/lock/exclusive/locks/cluster_lock")); + assertThat(new GlobalLockDefinition(GlobalLockName.CLUSTER_LOCK).getLockKey(), is("/lock/exclusive/locks/cluster_lock")); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/lock/ClusterLockContextTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/lock/ClusterLockContextTest.java index 711d7335a00fe..08d857be142c3 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/lock/ClusterLockContextTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/lock/ClusterLockContextTest.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.mode.lock.LockPersistService; import org.apache.shardingsphere.mode.lock.global.GlobalLockDefinition; -import org.apache.shardingsphere.mode.lock.global.GlobalLockNames; +import org.apache.shardingsphere.mode.lock.global.GlobalLockName; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -33,7 +33,7 @@ @ExtendWith(MockitoExtension.class) class ClusterLockContextTest { - private final GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockNames.CLUSTER_LOCK); + private final GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockName.CLUSTER_LOCK); @Mock private LockPersistService lockPersistService; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistServiceTest.java index 164a4402b5780..77ea847d5e003 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistServiceTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistServiceTest.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.mode.manager.cluster.persist.service; import org.apache.shardingsphere.mode.lock.global.GlobalLockDefinition; -import org.apache.shardingsphere.mode.lock.global.GlobalLockNames; +import org.apache.shardingsphere.mode.lock.global.GlobalLockName; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -39,13 +39,13 @@ class GlobalLockPersistServiceTest { @Test void assertTryLock() { when(repository.getDistributedLockHolder().getDistributedLock("/lock/exclusive/locks/cluster_lock").tryLock(1000L)).thenReturn(true); - GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockNames.CLUSTER_LOCK); + GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockName.CLUSTER_LOCK); assertTrue(new GlobalLockPersistService(repository).tryLock(lockDefinition, 1000L)); } @Test void assertUnlock() { - GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockNames.CLUSTER_LOCK); + GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockName.CLUSTER_LOCK); new GlobalLockPersistService(repository).unlock(lockDefinition); verify(repository.getDistributedLockHolder().getDistributedLock("/lock/exclusive/locks/cluster_lock")).unlock(); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java index a35bf9bf1288d..ebaf98e816db9 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.algorithm.core.exception.MissingRequiredAlgorithmException; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.sql.identifier.SQLExceptionIdentifier; -import org.apache.shardingsphere.mode.lock.global.GlobalLockNames; +import org.apache.shardingsphere.mode.lock.global.GlobalLockName; import org.apache.shardingsphere.infra.lock.LockContext; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.state.cluster.ClusterState; @@ -43,7 +43,7 @@ public void executeUpdate(final LockClusterStatement sqlStatement, final Context checkState(contextManager); checkAlgorithm(sqlStatement); LockContext lockContext = contextManager.getComputeNodeInstanceContext().getLockContext(); - GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockNames.CLUSTER_LOCK); + GlobalLockDefinition lockDefinition = new GlobalLockDefinition(GlobalLockName.CLUSTER_LOCK); if (lockContext.tryLock(lockDefinition, 3000L)) { try { checkState(contextManager); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java index 6c24fdc623a0a..701e1c0eee3f0 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorClusterModeRequired; import org.apache.shardingsphere.distsql.statement.ral.updatable.UnlockClusterStatement; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; -import org.apache.shardingsphere.mode.lock.global.GlobalLockNames; +import org.apache.shardingsphere.mode.lock.global.GlobalLockName; import org.apache.shardingsphere.infra.lock.LockContext; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.mode.exception.NotLockedClusterException; @@ -38,7 +38,7 @@ public final class UnlockClusterExecutor implements DistSQLUpdateExecutor