HDDS-201. Add name for LeaseManager. Contributed by Sandeep Nemuri.

This commit is contained in:
Nanda kumar 2018-07-26 19:00:23 +05:30
parent 9089790cab
commit a19229594e
7 changed files with 28 additions and 24 deletions

View File

@ -42,6 +42,7 @@ public class LeaseManager<T> {
private static final Logger LOG =
LoggerFactory.getLogger(LeaseManager.class);
private final String name;
private final long defaultTimeout;
private Map<T, Lease<T>> activeLeases;
private LeaseMonitor leaseMonitor;
@ -51,10 +52,13 @@ public class LeaseManager<T> {
/**
* Creates an instance of lease manager.
*
* @param name
* Name for the LeaseManager instance.
* @param defaultTimeout
* Default timeout in milliseconds to be used for lease creation.
*/
public LeaseManager(long defaultTimeout) {
public LeaseManager(String name, long defaultTimeout) {
this.name = name;
this.defaultTimeout = defaultTimeout;
}
@ -62,11 +66,11 @@ public class LeaseManager<T> {
* Starts the lease manager service.
*/
public void start() {
LOG.debug("Starting LeaseManager service");
LOG.debug("Starting {} LeaseManager service", name);
activeLeases = new ConcurrentHashMap<>();
leaseMonitor = new LeaseMonitor();
leaseMonitorThread = new Thread(leaseMonitor);
leaseMonitorThread.setName("LeaseManager#LeaseMonitor");
leaseMonitorThread.setName(name + "-LeaseManager#LeaseMonitor");
leaseMonitorThread.setDaemon(true);
leaseMonitorThread.setUncaughtExceptionHandler((thread, throwable) -> {
// Let us just restart this thread after logging an error.
@ -75,7 +79,7 @@ public class LeaseManager<T> {
thread.toString(), throwable);
leaseMonitorThread.start();
});
LOG.debug("Starting LeaseManager#LeaseMonitor Thread");
LOG.debug("Starting {}-LeaseManager#LeaseMonitor Thread", name);
leaseMonitorThread.start();
isRunning = true;
}
@ -203,7 +207,7 @@ public class LeaseManager<T> {
@Override
public void run() {
while(monitor) {
LOG.debug("LeaseMonitor: checking for lease expiry");
LOG.debug("{}-LeaseMonitor: checking for lease expiry", name);
long sleepTime = Long.MAX_VALUE;
for (T resource : activeLeases.keySet()) {

View File

@ -67,7 +67,7 @@ public class TestLeaseManager {
public void testLeaseAcquireAndRelease() throws LeaseException {
//It is assumed that the test case execution won't take more than 5 seconds,
//if it takes more time increase the defaultTimeout value of LeaseManager.
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
DummyResource resourceTwo = new DummyResource("two");
@ -93,7 +93,7 @@ public class TestLeaseManager {
@Test
public void testLeaseAlreadyExist() throws LeaseException {
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
DummyResource resourceTwo = new DummyResource("two");
@ -113,7 +113,7 @@ public class TestLeaseManager {
@Test
public void testLeaseNotFound() throws LeaseException, InterruptedException {
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
DummyResource resourceTwo = new DummyResource("two");
@ -154,7 +154,7 @@ public class TestLeaseManager {
@Test
public void testCustomLeaseTimeout() throws LeaseException {
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
DummyResource resourceTwo = new DummyResource("two");
@ -179,7 +179,7 @@ public class TestLeaseManager {
@Test
public void testLeaseCallback() throws LeaseException, InterruptedException {
Map<DummyResource, String> leaseStatus = new HashMap<>();
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
Lease<DummyResource> leaseOne = manager.acquire(resourceOne);
@ -209,7 +209,7 @@ public class TestLeaseManager {
throws LeaseException, InterruptedException {
// Callbacks should not be executed in case of lease release
Map<DummyResource, String> leaseStatus = new HashMap<>();
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
Lease<DummyResource> leaseOne = manager.acquire(resourceOne);
@ -231,7 +231,7 @@ public class TestLeaseManager {
public void testLeaseCallbackWithMultipleLeases()
throws LeaseException, InterruptedException {
Map<DummyResource, String> leaseStatus = new HashMap<>();
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
DummyResource resourceTwo = new DummyResource("two");
@ -302,7 +302,7 @@ public class TestLeaseManager {
@Test
public void testReuseReleasedLease() throws LeaseException {
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
Lease<DummyResource> leaseOne = manager.acquire(resourceOne);
@ -324,13 +324,12 @@ public class TestLeaseManager {
@Test
public void testReuseTimedOutLease()
throws LeaseException, InterruptedException {
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
Lease<DummyResource> leaseOne = manager.acquire(resourceOne);
Assert.assertEquals(leaseOne, manager.get(resourceOne));
Assert.assertFalse(leaseOne.hasExpired());
// wait for lease to expire
long sleepTime = leaseOne.getRemainingTime() + 1000;
try {
@ -352,7 +351,7 @@ public class TestLeaseManager {
@Test
public void testRenewLease() throws LeaseException, InterruptedException {
LeaseManager<DummyResource> manager = new LeaseManager<>(5000);
LeaseManager<DummyResource> manager = new LeaseManager<>("Test", 5000);
manager.start();
DummyResource resourceOne = new DummyResource("one");
Lease<DummyResource> leaseOne = manager.acquire(resourceOne);

View File

@ -46,7 +46,7 @@ public class TestEventWatcher {
@Before
public void startLeaseManager() {
DefaultMetricsSystem.instance();
leaseManager = new LeaseManager<>(2000l);
leaseManager = new LeaseManager<>("Test", 2000L);
leaseManager.start();
}

View File

@ -139,8 +139,8 @@ public class ContainerMapping implements Mapping {
ScmConfigKeys.OZONE_SCM_CONTAINER_CREATION_LEASE_TIMEOUT,
ScmConfigKeys.OZONE_SCM_CONTAINER_CREATION_LEASE_TIMEOUT_DEFAULT,
TimeUnit.MILLISECONDS);
LOG.trace("Starting Container Lease Manager.");
containerLeaseManager = new LeaseManager<>(containerCreationLeaseTimeout);
containerLeaseManager = new LeaseManager<>("ContainerCreation",
containerCreationLeaseTimeout);
containerLeaseManager.start();
}

View File

@ -99,8 +99,8 @@ public class PipelineSelector {
ScmConfigKeys.OZONE_SCM_PIPELINE_CREATION_LEASE_TIMEOUT,
ScmConfigKeys.OZONE_SCM_PIPELINE_CREATION_LEASE_TIMEOUT_DEFAULT,
TimeUnit.MILLISECONDS);
LOG.trace("Starting Pipeline Lease Manager.");
pipelineLeaseManager = new LeaseManager<>(pipelineCreationLeaseTimeout);
pipelineLeaseManager = new LeaseManager<>("PipelineCreation",
pipelineCreationLeaseTimeout);
pipelineLeaseManager.start();
// These are the steady states of a container.

View File

@ -223,7 +223,8 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
conf.getTimeDuration(ScmConfigKeys.HDDS_SCM_WATCHER_TIMEOUT,
HDDS_SCM_WATCHER_TIMEOUT_DEFAULT, TimeUnit.MILLISECONDS);
commandWatcherLeaseManager = new LeaseManager<>(watcherTimeout);
commandWatcherLeaseManager = new LeaseManager<>("CommandWatcher",
watcherTimeout);
//TODO: support configurable containerPlacement policy
ContainerPlacementPolicy containerPlacementPolicy =

View File

@ -112,7 +112,7 @@ public class TestReplicationManager {
//GIVEN
LeaseManager<Long> leaseManager = new LeaseManager<>(100000L);
LeaseManager<Long> leaseManager = new LeaseManager<>("Test", 100000L);
try {
leaseManager.start();
@ -152,7 +152,7 @@ public class TestReplicationManager {
public void testCommandWatcher() throws InterruptedException, IOException {
Logger.getRootLogger().setLevel(Level.DEBUG);
LeaseManager<Long> leaseManager = new LeaseManager<>(1000L);
LeaseManager<Long> leaseManager = new LeaseManager<>("Test", 1000L);
try {
leaseManager.start();