Skip to content

Commit

Permalink
Remove useless generic type of LockContext
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Dec 22, 2024
1 parent 265f69a commit 2f1d413
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class ComputeNodeInstanceContext {
private final AtomicReference<WorkerIdGenerator> workerIdGenerator;

@Getter(AccessLevel.NONE)
private final AtomicReference<LockContext<?>> lockContext;
private final AtomicReference<LockContext> lockContext;

private final ClusterInstanceRegistry clusterInstanceRegistry;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection> connections, final TransactionConnectionContext transactionContext,
final LockContext lockContext) throws SQLException {
if (!rule.getConfiguration().isEnabled()) {
Expand All @@ -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<Connection> connections, final TransactionConnectionContext transactionContext,
final LockContext lockContext) {
Optional<GlobalClockProvider> globalClockProvider = rule.getGlobalClockProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,13 @@ void assertBeforeExecuteSQLWhenNullTransactionIsolationLevel() throws SQLExcepti
verify(globalClockTransactionExecutor).sendSnapshotTimestamp(Collections.emptyList(), 10L);
}

@SuppressWarnings({"rawtypes", "unchecked"})
@Test
void assertBeforeCommitWhenDisabledGlobalClockRule() throws SQLException {
LockContext lockContext = mock(LockContext.class);
transactionHook.beforeCommit(rule, databaseType, Collections.emptyList(), transactionContext, lockContext);
verify(lockContext, times(0)).tryLock(any(), anyLong());
}

@SuppressWarnings("rawtypes")
@Test
void assertBeforeCommitWhenTryLockFailed() throws SQLException {
when(rule.getConfiguration().isEnabled()).thenReturn(true);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void beforeExecuteSQL(T rule, DatabaseType databaseType, Collection<Connection>
* @param lockContext lock context
* @throws SQLException SQL exception
*/
@SuppressWarnings("rawtypes")
void beforeCommit(T rule, DatabaseType databaseType, Collection<Connection> connections, TransactionConnectionContext transactionContext, LockContext lockContext) throws SQLException;

/**
Expand All @@ -102,7 +101,6 @@ void beforeExecuteSQL(T rule, DatabaseType databaseType, Collection<Connection>
* @param lockContext lock context
* @throws SQLException SQL exception
*/
@SuppressWarnings("rawtypes")
void afterCommit(T rule, DatabaseType databaseType, Collection<Connection> connections, TransactionConnectionContext transactionContext, LockContext lockContext) throws SQLException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
public final class LockClusterExecutor implements DistSQLUpdateExecutor<LockClusterStatement> {

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public void executeUpdate(final LockClusterStatement sqlStatement, final ContextManager contextManager) {
checkState(contextManager);
checkAlgorithm(sqlStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
public final class UnlockClusterExecutor implements DistSQLUpdateExecutor<UnlockClusterStatement> {

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public void executeUpdate(final UnlockClusterStatement sqlStatement, final ContextManager contextManager) {
checkState(contextManager);
LockContext lockContext = contextManager.getComputeNodeInstanceContext().getLockContext();
Expand Down

0 comments on commit 2f1d413

Please sign in to comment.