/** * Reassign lease for file src to the new holder. */ synchronized Lease reassignLease(Lease lease, INodeFile src, String newHolder) { assert newHolder != null : "new lease holder is null"; if (lease != null) { removeLease(lease, src.getId()); } return addLease(newHolder, src.getId()); }
throw new IOException("Unable to add " + src + " to namespace"); fsn.leaseManager.addLease( newNode.getFileUnderConstructionFeature().getClientName(), newNode.getId());
/** * Reassign lease for file src to the new holder. */ synchronized Lease reassignLease(Lease lease, String src, String newHolder) { assert newHolder != null : "new lease holder is null"; if (lease != null) { removeLease(lease, src); } return addLease(newHolder, src); }
/** * Reassign lease for file src to the new holder. */ synchronized Lease reassignLease(Lease lease, String src, String newHolder) { assert newHolder != null : "new lease holder is null"; if (lease != null) { removeLease(lease, src); } return addLease(newHolder, src); }
/** * Reassign lease for file src to the new holder. */ synchronized Lease reassignLease(Lease lease, String src, String newHolder) { assert newHolder != null : "new lease holder is null"; LeaseOpenTime leaseOpenTime = null; if (lease != null) { leaseOpenTime = removeLease(lease, src); } return addLease(newHolder, src, leaseOpenTime != null ? leaseOpenTime.openTime : System.currentTimeMillis()); }
namesystem.leaseManager.addLease(uc.getClientName(), oldnode.getId());
file.toUnderConstruction(uc.getClientName(), uc.getClientMachine()); fsn.leaseManager.addLease(uc.getClientName(), file.getId()); if (blocks.length > 0) { BlockInfo lastBlk = file.getLastBlock();
file.toUnderConstruction(leaseHolder, clientMachine); fsn.getLeaseManager().addLease( file.getFileUnderConstructionFeature().getClientName(), file.getId());
file.toUnderConstruction(leaseHolder, clientMachine); assert file.isUnderConstruction() : "inode should be under construction."; fsn.getLeaseManager().addLease( file.getFileUnderConstructionFeature().getClientName(), file.getId()); boolean shouldRecoverNow = (newBlock == null);
private void loadFilesUnderConstruction(int version, DataInputStream in, FSNamesystem fs) throws IOException { FSDirectory fsDir = fs.dir; if (version > -13) // pre lease image version return; int size = in.readInt(); LOG.info("Number of files under construction = " + size); for (int i = 0; i < size; i++) { INodeFileUnderConstruction cons = readINodeUnderConstruction(in); // verify that file exists in namespace String path = cons.getLocalName(); INode old = fsDir.getFileINode(path); if (old == null) { throw new IOException("Found lease for non-existent file " + path); } if (old.isDirectory()) { throw new IOException("Found lease for directory " + path); } INodeFile oldnode = (INodeFile) old; fsDir.replaceNode(path, oldnode, cons); fs.leaseManager.addLease(cons.clientName, path); } }
/** * Load the under-construction files section, and update the lease map */ void loadFilesUnderConstructionSection(InputStream in) throws IOException { // This section is consumed, but not actually used for restoring leases. while (true) { FileUnderConstructionEntry entry = FileUnderConstructionEntry .parseDelimitedFrom(in); if (entry == null) { break; } } // Add a lease for each and every file under construction. for (INodeFile file : ucFiles) { FileUnderConstructionFeature uc = file.getFileUnderConstructionFeature(); Preconditions.checkState(uc != null); // file must be under-construction String path = file.getFullPathName(); // Skip the deleted files in snapshot. This leaks UC inodes that are // deleted from the current view. if (path.startsWith("/")) { fsn.leaseManager.addLease(uc.getClientName(), path); } } }
private void loadFilesUnderConstruction(DataInputStream in) throws IOException { FSDirectory fsDir = namesystem.dir; int imgVersion = getLayoutVersion(); if (imgVersion > -13) // pre lease image version return; int size = in.readInt(); LOG.info("Number of files under construction = " + size); for (int i = 0; i < size; i++) { INodeFileUnderConstruction cons = FSImageSerialization.readINodeUnderConstruction(in); // verify that file exists in namespace String path = cons.getLocalName(); INode old = fsDir.getFileINode(path); if (old == null) { throw new IOException("Found lease for non-existent file " + path); } if (old.isDirectory()) { throw new IOException("Found lease for directory " + path); } INodeFile oldnode = (INodeFile) old; fsDir.replaceNode(path, oldnode, cons); namesystem.leaseManager.addLease(cons.getClientName(), path, cons.getModificationTime()); } }
/** * Load the under-construction files section, and update the lease map */ void loadFilesUnderConstructionSection(InputStream in) throws IOException { // This section is consumed, but not actually used for restoring leases. while (true) { FileUnderConstructionEntry entry = FileUnderConstructionEntry .parseDelimitedFrom(in); if (entry == null) { break; } } // Add a lease for each and every file under construction. for (INodeFile file : ucFiles) { FileUnderConstructionFeature uc = file.getFileUnderConstructionFeature(); Preconditions.checkState(uc != null); // file must be under-construction String path = file.getFullPathName(); // Skip the deleted files in snapshot. This leaks UC inodes that are // deleted from the current view. if (path.startsWith("/")) { fsn.leaseManager.addLease(uc.getClientName(), path); } } }
assert newFile != null; iip = INodesInPath.replace(iip, iip.length() - 1, newFile); fsNamesys.leaseManager.addLease(addCloseOp.clientName, newFile.getId());
/** 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(); }
@Test public void testRemoveLeaseWithPrefixPath() throws Exception { MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); cluster.waitActive(); LeaseManager lm = NameNodeAdapter.getLeaseManager(cluster.getNamesystem()); lm.addLease("holder1", "/a/b"); lm.addLease("holder2", "/a/c"); assertNotNull(lm.getLeaseByPath("/a/b")); assertNotNull(lm.getLeaseByPath("/a/c")); lm.removeLeaseWithPrefixPath("/a"); assertNull(lm.getLeaseByPath("/a/b")); assertNull(lm.getLeaseByPath("/a/c")); lm.addLease("holder1", "/a/b"); lm.addLease("holder2", "/a/c"); lm.removeLeaseWithPrefixPath("/a/"); assertNull(lm.getLeaseByPath("/a/b")); assertNull(lm.getLeaseByPath("/a/c")); }
/** * Test that FSNamesystem#clear clears all leases. */ @Test public void testFSNamespaceClearLeases() throws Exception { Configuration conf = new HdfsConfiguration(); File nameDir = new File(MiniDFSCluster.getBaseDirectory(), "name"); conf.set(DFS_NAMENODE_NAME_DIR_KEY, nameDir.getAbsolutePath()); NameNode.initMetrics(conf, NamenodeRole.NAMENODE); DFSTestUtil.formatNameNode(conf); FSNamesystem fsn = FSNamesystem.loadFromDisk(conf); LeaseManager leaseMan = fsn.getLeaseManager(); leaseMan.addLease("client1", "importantFile"); assertEquals(1, leaseMan.countLease()); fsn.clear(); leaseMan = fsn.getLeaseManager(); assertEquals(0, leaseMan.countLease()); }
@Test (timeout=30000) public void testSaveNamespaceWithDanglingLease() throws Exception { MiniDFSCluster cluster = new MiniDFSCluster.Builder(new Configuration()) .numDataNodes(1).build(); cluster.waitActive(); DistributedFileSystem fs = cluster.getFileSystem(); try { cluster.getNamesystem().leaseManager.addLease("me", "/non-existent"); fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); cluster.getNameNodeRpc().saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } finally { if (cluster != null) { cluster.shutdown(); } } }
namesystem.leaseManager.addLease(cons .getFileUnderConstructionFeature().getClientName(), path);
namesystem.leaseManager.addLease(cons .getFileUnderConstructionFeature().getClientName(), path);