Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless generic type of LockContext #34119

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -19,10 +19,8 @@

/**
* Lock context.
*
* @param <T> type of lock definition
*/
public interface LockContext<T extends LockDefinition> {
public interface LockContext {

/**
* Try Lock.
Expand All @@ -31,12 +29,12 @@ public interface LockContext<T extends LockDefinition> {
* @param timeoutMillis timeout milliseconds
* @return is locked or not
*/
boolean tryLock(T lockDefinition, long timeoutMillis);
boolean tryLock(LockDefinition lockDefinition, long timeoutMillis);

/**
* Unlock.
*
* @param lockDefinition lock definition
*/
void unlock(T lockDefinition);
void unlock(LockDefinition lockDefinition);
}
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 @@ -27,7 +27,7 @@
* Cluster lock context.
*/
@RequiredArgsConstructor
public final class ClusterLockContext implements LockContext<LockDefinition> {
public final class ClusterLockContext implements LockContext {

private final LockPersistService<GlobalLockDefinition> globalLockPersistService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Standalone lock context.
*/
public final class StandaloneLockContext implements LockContext<LockDefinition> {
public final class StandaloneLockContext implements LockContext {

@Override
public boolean tryLock(final LockDefinition lockDefinition, final long timeoutMillis) {
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
Loading