@VisibleForTesting public void runLeaseChecks() { checkLeases(); }
/** Check leases periodically. */ @Override public void run() { for(; shouldRunMonitor && fsnamesystem.isRunning(); ) { boolean needSync = false; try { fsnamesystem.writeLockInterruptibly(); try { if (!fsnamesystem.isInSafeMode()) { needSync = checkLeases(); } } finally { fsnamesystem.writeUnlock("leaseManager"); // lease reassignments should to be sync'ed. if (needSync) { fsnamesystem.getEditLog().logSync(); } } Thread.sleep(fsnamesystem.getLeaseRecheckIntervalMs()); } catch(InterruptedException ie) { LOG.debug("{} is interrupted", name, ie); } catch(Throwable e) { LOG.warn("Unexpected throwable: ", e); } } } }
/** Check leases periodically. */ public void run() { for(; fsnamesystem.isRunning(); ) { fsnamesystem.writeLock(); try { if (!fsnamesystem.isInSafeMode()) { checkLeases(); } } finally { fsnamesystem.writeUnlock(); } try { Thread.sleep(2000); } catch(InterruptedException ie) { if (LOG.isDebugEnabled()) { LOG.debug(name + " is interrupted", ie); } } } } }
/** Check leases periodically. */ @Override public void run() { for(; shouldRunMonitor && fsnamesystem.isRunning(); ) { boolean needSync = false; try { fsnamesystem.writeLockInterruptibly(); try { if (!fsnamesystem.isInSafeMode()) { needSync = checkLeases(); } } finally { fsnamesystem.writeUnlock("leaseManager"); // lease reassignments should to be sync'ed. if (needSync) { fsnamesystem.getEditLog().logSync(); } } Thread.sleep(HdfsServerConstants.NAMENODE_LEASE_RECHECK_INTERVAL); } catch(InterruptedException ie) { if (LOG.isDebugEnabled()) { LOG.debug(name + " is interrupted", ie); } } } } }
/** Check leases periodically. */ @Override public void run() { for(; shouldRunMonitor && fsnamesystem.isRunning(); ) { boolean needSync = false; try { fsnamesystem.writeLockInterruptibly(); try { if (!fsnamesystem.isInSafeMode()) { needSync = checkLeases(); } } finally { fsnamesystem.writeUnlock("leaseManager"); // lease reassignments should to be sync'ed. if (needSync) { fsnamesystem.getEditLog().logSync(); } } Thread.sleep(HdfsServerConstants.NAMENODE_LEASE_RECHECK_INTERVAL); } catch(InterruptedException ie) { if (LOG.isDebugEnabled()) { LOG.debug(name + " is interrupted", ie); } } } } }
/** Check that even if LeaseManager.checkLease is not able to relinquish * leases, the Namenode does't enter an infinite loop while holding the FSN * write lock and thus become unresponsive */ @Test (timeout=1000) public void testCheckLeaseNotInfiniteLoop() { FSDirectory dir = Mockito.mock(FSDirectory.class); FSNamesystem fsn = Mockito.mock(FSNamesystem.class); Mockito.when(fsn.isRunning()).thenReturn(true); Mockito.when(fsn.hasWriteLock()).thenReturn(true); Mockito.when(fsn.getFSDirectory()).thenReturn(dir); LeaseManager lm = new LeaseManager(fsn); //Make sure the leases we are going to add exceed the hard limit lm.setLeasePeriod(0,0); //Add some leases to the LeaseManager lm.addLease("holder1", "src1"); lm.addLease("holder2", "src2"); lm.addLease("holder3", "src3"); assertEquals(lm.getNumSortedLeases(), 3); //Initiate a call to checkLease. This should exit within the test timeout lm.checkLeases(); }