Update the Worker shutdown logic to make sure that the LeaseCleanupManager also terminates all the threads that it has started (#816)

* Update the Worker shutdown logic to make sure that the LeaseCleanupManager also terminates all the threads that it has started

* Minor javadoc fixes
This commit is contained in:
catalinclapon 2021-05-13 12:53:52 -07:00 committed by GitHub
parent b314d56308
commit cf71e4e4e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View file

@ -1045,6 +1045,10 @@ public class Worker implements Runnable {
// Lost leases will force Worker to begin shutdown process for all shard consumers in
// Worker.run().
leaseCoordinator.stop();
// Stop the lease cleanup manager
leaseCleanupManager.shutdown();
// Stop the periodicShardSyncManager for the worker
if (shardSyncStrategy != null) {
shardSyncStrategy.onWorkerShutDown();

View file

@ -121,6 +121,23 @@ public class LeaseCleanupManager {
}
}
/**
* Stops the lease cleanup thread, which is scheduled periodically as specified by
* {@link LeaseCleanupManager#leaseCleanupIntervalMillis}
*/
public void shutdown() {
if (isRunning) {
LOG.info("Stopping the lease cleanup thread.");
completedLeaseStopwatch.stop();
garbageLeaseStopwatch.stop();
deletionThreadPool.shutdown();
isRunning = false;
} else {
LOG.info("Lease cleanup thread already stopped.");
}
}
/**
* Enqueues a lease for deletion without check for duplicate entry. Use {@link #isEnqueuedForDeletion}
* for checking the duplicate entries.

View file

@ -93,6 +93,18 @@ public class LeaseCleanupManagerTest {
leaseCleanupManager.start();
}
/**
* Tests subsequent calls to shutdown {@link LeaseCleanupManager}.
*/
@Test
public final void testSubsequentShutdowns() {
leaseCleanupManager.start();
Assert.assertTrue(leaseCleanupManager.isRunning());
leaseCleanupManager.shutdown();
Assert.assertFalse(leaseCleanupManager.isRunning());
leaseCleanupManager.shutdown();
}
/**
* Tests that when both child shard leases are present, we are able to delete the parent shard for the completed
* shard case.