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

View File

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

View File

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

View File

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

View File

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

View File

@ -223,7 +223,8 @@ private StorageContainerManager(OzoneConfiguration conf) throws IOException {
conf.getTimeDuration(ScmConfigKeys.HDDS_SCM_WATCHER_TIMEOUT, conf.getTimeDuration(ScmConfigKeys.HDDS_SCM_WATCHER_TIMEOUT,
HDDS_SCM_WATCHER_TIMEOUT_DEFAULT, TimeUnit.MILLISECONDS); HDDS_SCM_WATCHER_TIMEOUT_DEFAULT, TimeUnit.MILLISECONDS);
commandWatcherLeaseManager = new LeaseManager<>(watcherTimeout); commandWatcherLeaseManager = new LeaseManager<>("CommandWatcher",
watcherTimeout);
//TODO: support configurable containerPlacement policy //TODO: support configurable containerPlacement policy
ContainerPlacementPolicy containerPlacementPolicy = ContainerPlacementPolicy containerPlacementPolicy =

View File

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