diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/lease/LeaseManager.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/lease/LeaseManager.java index b8390ddd3d..756a41af08 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/lease/LeaseManager.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/lease/LeaseManager.java @@ -42,6 +42,7 @@ public class LeaseManager { private static final Logger LOG = LoggerFactory.getLogger(LeaseManager.class); + private final String name; private final long defaultTimeout; private Map> activeLeases; private LeaseMonitor leaseMonitor; @@ -51,10 +52,13 @@ public class LeaseManager { /** * 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 LeaseManager(long defaultTimeout) { * 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 void start() { 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 @@ private LeaseMonitor() { @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()) { diff --git a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/lease/TestLeaseManager.java b/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/lease/TestLeaseManager.java index 517c1a7c47..bdc70fc983 100644 --- a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/lease/TestLeaseManager.java +++ b/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/lease/TestLeaseManager.java @@ -67,7 +67,7 @@ public boolean equals(Object obj) { 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 manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); DummyResource resourceTwo = new DummyResource("two"); @@ -93,7 +93,7 @@ public void testLeaseAcquireAndRelease() throws LeaseException { @Test public void testLeaseAlreadyExist() throws LeaseException { - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); DummyResource resourceTwo = new DummyResource("two"); @@ -113,7 +113,7 @@ public void testLeaseAlreadyExist() throws LeaseException { @Test public void testLeaseNotFound() throws LeaseException, InterruptedException { - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); DummyResource resourceTwo = new DummyResource("two"); @@ -154,7 +154,7 @@ public void testLeaseNotFound() throws LeaseException, InterruptedException { @Test public void testCustomLeaseTimeout() throws LeaseException { - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); DummyResource resourceTwo = new DummyResource("two"); @@ -179,7 +179,7 @@ public void testCustomLeaseTimeout() throws LeaseException { @Test public void testLeaseCallback() throws LeaseException, InterruptedException { Map leaseStatus = new HashMap<>(); - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); Lease leaseOne = manager.acquire(resourceOne); @@ -209,7 +209,7 @@ public void testCallbackExecutionInCaseOfLeaseRelease() throws LeaseException, InterruptedException { // Callbacks should not be executed in case of lease release Map leaseStatus = new HashMap<>(); - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); Lease leaseOne = manager.acquire(resourceOne); @@ -231,7 +231,7 @@ public void testCallbackExecutionInCaseOfLeaseRelease() public void testLeaseCallbackWithMultipleLeases() throws LeaseException, InterruptedException { Map leaseStatus = new HashMap<>(); - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); DummyResource resourceTwo = new DummyResource("two"); @@ -302,7 +302,7 @@ public void testLeaseCallbackWithMultipleLeases() @Test public void testReuseReleasedLease() throws LeaseException { - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); Lease leaseOne = manager.acquire(resourceOne); @@ -324,13 +324,12 @@ public void testReuseReleasedLease() throws LeaseException { @Test public void testReuseTimedOutLease() throws LeaseException, InterruptedException { - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); Lease 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 void testReuseTimedOutLease() @Test public void testRenewLease() throws LeaseException, InterruptedException { - LeaseManager manager = new LeaseManager<>(5000); + LeaseManager manager = new LeaseManager<>("Test", 5000); manager.start(); DummyResource resourceOne = new DummyResource("one"); Lease leaseOne = manager.acquire(resourceOne); diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/events/TestEventWatcher.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/events/TestEventWatcher.java index 786b7b8a5a..b72d2ae768 100644 --- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/events/TestEventWatcher.java +++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/events/TestEventWatcher.java @@ -46,7 +46,7 @@ public class TestEventWatcher { @Before public void startLeaseManager() { DefaultMetricsSystem.instance(); - leaseManager = new LeaseManager<>(2000l); + leaseManager = new LeaseManager<>("Test", 2000L); leaseManager.start(); } diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java index f07d22baaf..e17fe3d699 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java @@ -139,8 +139,8 @@ public ContainerMapping( 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(); } diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipelines/PipelineSelector.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipelines/PipelineSelector.java index 08710e7937..b1e1dd02a3 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipelines/PipelineSelector.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipelines/PipelineSelector.java @@ -99,8 +99,8 @@ public PipelineSelector(NodeManager nodeManager, Configuration conf) { 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. diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java index f4cd448f16..165805f155 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java @@ -223,7 +223,8 @@ private StorageContainerManager(OzoneConfiguration conf) throws IOException { 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 = diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java index 99ec59f89f..9aa4b64543 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/replication/TestReplicationManager.java @@ -112,7 +112,7 @@ public void testEventSending() throws InterruptedException, IOException { //GIVEN - LeaseManager leaseManager = new LeaseManager<>(100000L); + LeaseManager leaseManager = new LeaseManager<>("Test", 100000L); try { leaseManager.start(); @@ -152,7 +152,7 @@ protected List getCurrentReplicas( public void testCommandWatcher() throws InterruptedException, IOException { Logger.getRootLogger().setLevel(Level.DEBUG); - LeaseManager leaseManager = new LeaseManager<>(1000L); + LeaseManager leaseManager = new LeaseManager<>("Test", 1000L); try { leaseManager.start();