LeaseManager { void removeLease(Lease lease, LeasePath src) throws StorageException, TransactionContextException { if(lease == null){ LOG.warn("Lease not found. Removing lease path"); src.deletePersistent(); return; } if (!lease.removePath(src)) { LOG.error(src + " not found in lease.paths (=" + lease.getPaths() + ")"); } src.deletePersistent(); if (!lease.hasPath()) { lease.deletePersistent(); } } LeaseManager(FSNamesystem fsnamesystem); Lease getLeaseByPath(String src); int countLease(); void setLeasePeriod(long softLimit, long hardLimit); boolean expiredSoftLimit(Lease lease); static final Log LOG; }
@Test public void testRemoveLease() throws Exception { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); int leaseCreationLockRows = conf.getInt(DFSConfigKeys.DFS_LEASE_CREATION_LOCKS_COUNT_KEY, DFSConfigKeys.DFS_LEASE_CREATION_LOCKS_COUNT_DEFAULT); cluster.waitActive(); cluster.setLeasePeriod(3*1000, 1000); LeaseManager lm = NameNodeAdapter.getLeaseManager(cluster.getNamesystem()); addLease(lm, "holder1", null, leaseCreationLockRows); addLease(lm, "holder2", null, leaseCreationLockRows); addLease(lm, "holder3", null, leaseCreationLockRows); assertEquals(lm.getNumSortedLeases() , 3); Thread.sleep(10000); assertEquals(lm.getNumSortedLeases() , 0); }