Fix shutdown sequence

Fix a few issues in shutdown sequence and make sure
scheduler shutdown without invoking run works

Inorder for the main thread to shutdown, the scheduler's
final shutdown still needs to be invoked, which only
happens via the run method.
This commit is contained in:
Aravinda Kidambi Srinivasan 2024-11-08 12:10:15 -08:00
parent 037dd7f6c8
commit 6acb51d66e
4 changed files with 13 additions and 2 deletions

View file

@ -120,6 +120,11 @@
<artifactId>http-client-spi</artifactId>
<version>${awssdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb-enhanced</artifactId>
<version>${awssdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.glue</groupId>

View file

@ -223,6 +223,9 @@ public final class DynamicMigrationComponentsInitializer {
workerMetricsThreadPool.shutdown();
try {
if (!lamThreadPool.awaitTermination(SCHEDULER_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
log.info(
"LamThreadPool did not shutdown in {}s, forcefully shutting down",
SCHEDULER_SHUTDOWN_TIMEOUT_SECONDS);
lamThreadPool.shutdownNow();
}
} catch (final InterruptedException e) {
@ -232,6 +235,9 @@ public final class DynamicMigrationComponentsInitializer {
try {
if (!workerMetricsThreadPool.awaitTermination(SCHEDULER_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
log.info(
"WorkerMetricsThreadPool did not shutdown in {}s, forcefully shutting down",
SCHEDULER_SHUTDOWN_TIMEOUT_SECONDS);
workerMetricsThreadPool.shutdownNow();
}
} catch (final InterruptedException e) {

View file

@ -87,7 +87,7 @@ public class MigrationClientVersion3xWithRollbackState implements MigrationClien
}
@Override
public void leave() {
public synchronized void leave() {
if (entered && !left) {
log.info("Leaving {}", this);
cancelRollbackMonitor();

View file

@ -126,7 +126,7 @@ public class MigrationStateMachineImpl implements MigrationStateMachine {
if (!stateMachineThreadPool.isShutdown()) {
stateMachineThreadPool.shutdown();
try {
if (stateMachineThreadPool.awaitTermination(THREAD_POOL_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
if (!stateMachineThreadPool.awaitTermination(THREAD_POOL_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
log.info(
"StateMachineThreadPool did not shutdown within {} seconds, forcefully shutting down",
THREAD_POOL_SHUTDOWN_TIMEOUT_SECONDS);