org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease Java Examples
The following examples show how to use
org.apache.hadoop.hdfs.server.namenode.LeaseManager.Lease.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FSDirectory.java From RDFS with Apache License 2.0 | 6 votes |
/** * Retrieves a list of random files with some information. * * @param maxFiles * the maximum number of files to return * @return the list of files */ public List<FileStatusExtended> getRandomFileStats(int maxFiles) { readLock(); try { List<FileStatusExtended> stats = new LinkedList<FileStatusExtended>(); for (INodeFile file : getRandomFiles(maxFiles)) { String path = file.getFullPathName(); FileStatus stat = createFileStatus(path, file); Lease lease = this.getFSNamesystem().leaseManager.getLeaseByPath(path); String holder = (lease == null) ? null : lease.getHolder(); stats.add(new FileStatusExtended(stat, file.getBlocks(), holder)); } return stats; } finally { readUnlock(); } }
Example #2
Source File: FSNamesystem.java From hadoop-gpu with Apache License 2.0 | 6 votes |
/** * Serializes leases. */ void saveFilesUnderConstruction(DataOutputStream out) throws IOException { synchronized (leaseManager) { out.writeInt(leaseManager.countPath()); // write the size for (Lease lease : leaseManager.getSortedLeases()) { for(String path : lease.getPaths()) { // verify that path exists in namespace INode node = dir.getFileINode(path); if (node == null) { throw new IOException("saveLeases found path " + path + " but no matching entry in namespace."); } if (!node.isUnderConstruction()) { throw new IOException("saveLeases found path " + path + " but is not under construction."); } INodeFileUnderConstruction cons = (INodeFileUnderConstruction) node; FSImage.writeINodeUnderConstruction(out, cons, path); } } } }
Example #3
Source File: NameNodeAdapter.java From hadoop with Apache License 2.0 | 5 votes |
/** * @return the timestamp of the last renewal of the given lease, * or -1 in the case that the lease doesn't exist. */ public static long getLeaseRenewalTime(NameNode nn, String path) { LeaseManager lm = nn.getNamesystem().leaseManager; Lease l = lm.getLeaseByPath(path); if (l == null) { return -1; } return l.getLastUpdate(); }
Example #4
Source File: NameNodeAdapter.java From big-c with Apache License 2.0 | 5 votes |
/** * @return the timestamp of the last renewal of the given lease, * or -1 in the case that the lease doesn't exist. */ public static long getLeaseRenewalTime(NameNode nn, String path) { LeaseManager lm = nn.getNamesystem().leaseManager; Lease l = lm.getLeaseByPath(path); if (l == null) { return -1; } return l.getLastUpdate(); }
Example #5
Source File: NameNodeAdapter.java From hadoop with Apache License 2.0 | 4 votes |
public static String getLeaseHolderForPath(NameNode namenode, String path) { Lease l = namenode.getNamesystem().leaseManager.getLeaseByPath(path); return l == null? null: l.getHolder(); }
Example #6
Source File: TestFSImage.java From hadoop with Apache License 2.0 | 4 votes |
private void testPersistHelper(Configuration conf) throws IOException { MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNamesystem(); DistributedFileSystem fs = cluster.getFileSystem(); final Path dir = new Path("/abc/def"); final Path file1 = new Path(dir, "f1"); final Path file2 = new Path(dir, "f2"); // create an empty file f1 fs.create(file1).close(); // create an under-construction file f2 FSDataOutputStream out = fs.create(file2); out.writeBytes("hello"); ((DFSOutputStream) out.getWrappedStream()).hsync(EnumSet .of(SyncFlag.UPDATE_LENGTH)); // checkpoint fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); cluster.restartNameNode(); cluster.waitActive(); fs = cluster.getFileSystem(); assertTrue(fs.isDirectory(dir)); assertTrue(fs.exists(file1)); assertTrue(fs.exists(file2)); // check internals of file2 INodeFile file2Node = fsn.dir.getINode4Write(file2.toString()).asFile(); assertEquals("hello".length(), file2Node.computeFileSize()); assertTrue(file2Node.isUnderConstruction()); BlockInfoContiguous[] blks = file2Node.getBlocks(); assertEquals(1, blks.length); assertEquals(BlockUCState.UNDER_CONSTRUCTION, blks[0].getBlockUCState()); // check lease manager Lease lease = fsn.leaseManager.getLeaseByPath(file2.toString()); Assert.assertNotNull(lease); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example #7
Source File: NameNodeAdapter.java From big-c with Apache License 2.0 | 4 votes |
public static String getLeaseHolderForPath(NameNode namenode, String path) { Lease l = namenode.getNamesystem().leaseManager.getLeaseByPath(path); return l == null? null: l.getHolder(); }
Example #8
Source File: TestFSImage.java From big-c with Apache License 2.0 | 4 votes |
private void testPersistHelper(Configuration conf) throws IOException { MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNamesystem(); DistributedFileSystem fs = cluster.getFileSystem(); final Path dir = new Path("/abc/def"); final Path file1 = new Path(dir, "f1"); final Path file2 = new Path(dir, "f2"); // create an empty file f1 fs.create(file1).close(); // create an under-construction file f2 FSDataOutputStream out = fs.create(file2); out.writeBytes("hello"); ((DFSOutputStream) out.getWrappedStream()).hsync(EnumSet .of(SyncFlag.UPDATE_LENGTH)); // checkpoint fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); cluster.restartNameNode(); cluster.waitActive(); fs = cluster.getFileSystem(); assertTrue(fs.isDirectory(dir)); assertTrue(fs.exists(file1)); assertTrue(fs.exists(file2)); // check internals of file2 INodeFile file2Node = fsn.dir.getINode4Write(file2.toString()).asFile(); assertEquals("hello".length(), file2Node.computeFileSize()); assertTrue(file2Node.isUnderConstruction()); BlockInfoContiguous[] blks = file2Node.getBlocks(); assertEquals(1, blks.length); assertEquals(BlockUCState.UNDER_CONSTRUCTION, blks[0].getBlockUCState()); // check lease manager Lease lease = fsn.leaseManager.getLeaseByPath(file2.toString()); Assert.assertNotNull(lease); } finally { if (cluster != null) { cluster.shutdown(); } } }