LeaseManager { void removeLeaseWithPrefixPath(String prefix) throws StorageException, TransactionContextException { for (Map.Entry<LeasePath, Lease> entry : findLeaseWithPrefixPath(prefix) .entrySet()) { if (LOG.isDebugEnabled()) { LOG.debug(LeaseManager.class.getSimpleName() + ".removeLeaseWithPrefixPath: entry=" + entry); } removeLease(entry.getValue(), entry.getKey()); } } 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 testRemoveLeaseWithPrefixPath() throws Exception { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); cluster.waitActive(); int leaseCreationLockRows = conf.getInt(DFSConfigKeys.DFS_LEASE_CREATION_LOCKS_COUNT_KEY, DFSConfigKeys.DFS_LEASE_CREATION_LOCKS_COUNT_DEFAULT); LeaseManager lm = NameNodeAdapter.getLeaseManager(cluster.getNamesystem()); addLease(lm, "holder1", "/a/b", leaseCreationLockRows); addLease(lm, "holder2", "/a/c", leaseCreationLockRows); assertNotNull(getLeaseByPath(lm, "/a/b")); assertNotNull(getLeaseByPath(lm, "/a/c")); removeLeaseWithPrefixPath(lm, "/a", leaseCreationLockRows); assertNull(getLeaseByPath(lm, "/a/b")); assertNull(getLeaseByPath(lm, "/a/c")); addLease(lm, "holder1", "/a/b", leaseCreationLockRows); addLease(lm, "holder2", "/a/c", leaseCreationLockRows); removeLeaseWithPrefixPath(lm, "/a/", leaseCreationLockRows); assertNull(getLeaseByPath(lm, "/a/b")); assertNull(getLeaseByPath(lm, "/a/c")); }