From 2f1d413468939c4c0618095f890ebe07d653ac95 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Sun, 22 Dec 2024 12:22:06 +0800 Subject: [PATCH] Remove useless generic type of LockContext --- .../infra/instance/ComputeNodeInstanceContext.java | 6 +++--- .../infra/instance/ComputeNodeInstanceContextTest.java | 2 +- .../scenario/migration/preparer/MigrationJobPreparer.java | 1 - .../globalclock/executor/GlobalClockTransactionHook.java | 2 -- .../executor/GlobalClockTransactionHookTest.java | 4 ---- .../shardingsphere/transaction/spi/TransactionHook.java | 2 -- .../mode/manager/cluster/ClusterContextManagerBuilder.java | 2 +- .../handler/distsql/ral/updatable/LockClusterExecutor.java | 1 - .../distsql/ral/updatable/UnlockClusterExecutor.java | 1 - 9 files changed, 5 insertions(+), 16 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContext.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContext.java index c1cbcd2d87737..a3d8cb81b6eaa 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContext.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContext.java @@ -49,7 +49,7 @@ public final class ComputeNodeInstanceContext { private final AtomicReference workerIdGenerator; @Getter(AccessLevel.NONE) - private final AtomicReference> lockContext; + private final AtomicReference lockContext; private final ClusterInstanceRegistry clusterInstanceRegistry; @@ -68,7 +68,7 @@ public ComputeNodeInstanceContext(final ComputeNodeInstance instance, final Mode * @param workerIdGenerator worker id generator * @param lockContext lock context */ - public void init(final WorkerIdGenerator workerIdGenerator, final LockContext lockContext) { + public void init(final WorkerIdGenerator workerIdGenerator, final LockContext lockContext) { this.workerIdGenerator.set(workerIdGenerator); this.lockContext.set(lockContext); } @@ -148,7 +148,7 @@ public int generateWorkerId(final Properties props) { * * @return lock context */ - public LockContext getLockContext() { + public LockContext getLockContext() { return Optional.ofNullable(lockContext.get()).orElseThrow(() -> new IllegalStateException("Lock context is not initialized.")); } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContextTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContextTest.java index 9d757c3e2207a..e0c39e3b0b51c 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContextTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstanceContextTest.java @@ -42,7 +42,7 @@ class ComputeNodeInstanceContextTest { void assertInit() { ComputeNodeInstanceContext context = new ComputeNodeInstanceContext(new ComputeNodeInstance(mock(InstanceMetaData.class)), mock(ModeConfiguration.class), new EventBusContext()); WorkerIdGenerator workerIdGenerator = mock(WorkerIdGenerator.class); - LockContext lockContext = mock(LockContext.class); + LockContext lockContext = mock(LockContext.class); context.init(workerIdGenerator, lockContext); context.generateWorkerId(new Properties()); verify(workerIdGenerator).generate(new Properties()); 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 3f07a53380f02..e8d29bf89e2ce 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 @@ -110,7 +110,6 @@ public void prepare(final MigrationJobItemContext jobItemContext) throws SQLExce jobItemContext.getJobId(), jobItemContext.getShardingItem(), jobItemContext.getInventoryTasks(), jobItemContext.getIncrementalTasks()); } - @SuppressWarnings({"unchecked", "rawtypes"}) private void prepareAndCheckTargetWithLock(final MigrationJobItemContext jobItemContext) throws SQLException { MigrationJobConfiguration jobConfig = jobItemContext.getJobConfig(); String jobId = jobConfig.getJobId(); 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 295d2f1beb8df..abe1f6436c5a1 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 @@ -80,7 +80,6 @@ public void beforeExecuteSQL(final GlobalClockRule rule, final DatabaseType data } @Override - @SuppressWarnings({"unchecked", "rawtypes"}) public void beforeCommit(final GlobalClockRule rule, final DatabaseType databaseType, final Collection connections, final TransactionConnectionContext transactionContext, final LockContext lockContext) throws SQLException { if (!rule.getConfiguration().isEnabled()) { @@ -98,7 +97,6 @@ public void beforeCommit(final GlobalClockRule rule, final DatabaseType database } @Override - @SuppressWarnings({"unchecked", "rawtypes"}) public void afterCommit(final GlobalClockRule rule, final DatabaseType databaseType, final Collection connections, final TransactionConnectionContext transactionContext, final LockContext lockContext) { Optional globalClockProvider = rule.getGlobalClockProvider(); diff --git a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java index 1a5a16c0486f1..6e092cfd2bfbb 100644 --- a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java +++ b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/executor/GlobalClockTransactionHookTest.java @@ -145,7 +145,6 @@ void assertBeforeExecuteSQLWhenNullTransactionIsolationLevel() throws SQLExcepti verify(globalClockTransactionExecutor).sendSnapshotTimestamp(Collections.emptyList(), 10L); } - @SuppressWarnings({"rawtypes", "unchecked"}) @Test void assertBeforeCommitWhenDisabledGlobalClockRule() throws SQLException { LockContext lockContext = mock(LockContext.class); @@ -153,7 +152,6 @@ void assertBeforeCommitWhenDisabledGlobalClockRule() throws SQLException { verify(lockContext, times(0)).tryLock(any(), anyLong()); } - @SuppressWarnings("rawtypes") @Test void assertBeforeCommitWhenTryLockFailed() throws SQLException { when(rule.getConfiguration().isEnabled()).thenReturn(true); @@ -162,7 +160,6 @@ void assertBeforeCommitWhenTryLockFailed() throws SQLException { verify(globalClockTransactionExecutor, times(0)).sendCommitTimestamp(any(), anyLong()); } - @SuppressWarnings({"rawtypes", "unchecked"}) @Test void assertBeforeCommitWhenGlobalClockTransactionExecutorAbsent() throws SQLException { when(rule.getConfiguration().isEnabled()).thenReturn(true); @@ -173,7 +170,6 @@ void assertBeforeCommitWhenGlobalClockTransactionExecutorAbsent() throws SQLExce verify(globalClockTransactionExecutor, times(0)).sendCommitTimestamp(any(), anyLong()); } - @SuppressWarnings({"rawtypes", "unchecked"}) @Test void assertBeforeCommit() throws SQLException { when(rule.getConfiguration().isEnabled()).thenReturn(true); diff --git a/kernel/transaction/api/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionHook.java b/kernel/transaction/api/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionHook.java index 656a4821397a0..a02673b8d2767 100644 --- a/kernel/transaction/api/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionHook.java +++ b/kernel/transaction/api/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionHook.java @@ -89,7 +89,6 @@ void beforeExecuteSQL(T rule, DatabaseType databaseType, Collection * @param lockContext lock context * @throws SQLException SQL exception */ - @SuppressWarnings("rawtypes") void beforeCommit(T rule, DatabaseType databaseType, Collection connections, TransactionConnectionContext transactionContext, LockContext lockContext) throws SQLException; /** @@ -102,7 +101,6 @@ void beforeExecuteSQL(T rule, DatabaseType databaseType, Collection * @param lockContext lock context * @throws SQLException SQL exception */ - @SuppressWarnings("rawtypes") void afterCommit(T rule, DatabaseType databaseType, Collection connections, TransactionConnectionContext transactionContext, LockContext lockContext) throws SQLException; /** diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index becc43ad29f63..cdca1a7fdab09 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -59,7 +59,7 @@ public ContextManager build(final ContextManagerBuilderParameter param, final Ev ClusterPersistRepositoryConfiguration config = (ClusterPersistRepositoryConfiguration) modeConfig.getRepository(); ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext(new ComputeNodeInstance(param.getInstanceMetaData(), param.getLabels()), modeConfig, eventBusContext); ClusterPersistRepository repository = getClusterPersistRepository(config, computeNodeInstanceContext); - LockContext lockContext = new ClusterLockContext(new GlobalLockPersistService(repository)); + LockContext lockContext = new ClusterLockContext(new GlobalLockPersistService(repository)); computeNodeInstanceContext.init(new ClusterWorkerIdGenerator(repository, param.getInstanceMetaData().getId()), lockContext); MetaDataPersistService metaDataPersistService = new MetaDataPersistService(repository); MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, param, computeNodeInstanceContext); 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 075b9ada22656..7316f5405c5c4 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 @@ -39,7 +39,6 @@ public final class LockClusterExecutor implements DistSQLUpdateExecutor { @Override - @SuppressWarnings({"unchecked", "rawtypes"}) public void executeUpdate(final LockClusterStatement sqlStatement, final ContextManager contextManager) { checkState(contextManager); checkAlgorithm(sqlStatement); 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 318311e4dc2fa..a32b2e650fd2d 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 @@ -35,7 +35,6 @@ public final class UnlockClusterExecutor implements DistSQLUpdateExecutor { @Override - @SuppressWarnings({"unchecked", "rawtypes"}) public void executeUpdate(final UnlockClusterStatement sqlStatement, final ContextManager contextManager) { checkState(contextManager); LockContext lockContext = contextManager.getComputeNodeInstanceContext().getLockContext();