/** * Add block b belonging to the specified file inode to the map. */ BlockInfo addINode(Block b, INodeFile iNode) { BlockInfo info = checkBlockInfo(b, iNode.getReplication()); info.inode = iNode; return info; }
/** * Add block b belonging to the specified file inode to the map. */ BlockInfo addINode(Block b, INodeFile iNode) { BlockInfo info = checkBlockInfo(b, iNode.getReplication()); info.inode = iNode; return info; }
private int getReplication(Block block) { INodeFile fileINode = blocksMap.getINode(block); if (fileINode == null) { // block does not belong to any file return 0; } assert !fileINode.isDirectory() : "Block cannot belong to a directory."; return fileINode.getReplication(); }
private int getReplication(Block block) { INodeFile fileINode = blocksMap.getINode(block); if (fileINode == null) { // block does not belong to any file return 0; } assert !fileINode.isDirectory() : "Block cannot belong to a directory."; return fileINode.getReplication(); }
protected INodeFile(INodeFile inodeFile) { super(inodeFile); this.setReplication(inodeFile.getReplication()); this.setPreferredBlockSize(inodeFile.getPreferredBlockSize()); blocks = inodeFile.getBlocks(); }
if (!node.isDirectory()) { // write file inode INodeFile fileINode = (INodeFile)node; out.writeShort(fileINode.getReplication()); out.writeLong(fileINode.getModificationTime()); out.writeLong(fileINode.getAccessTime());
if (!node.isDirectory()) { // write file inode INodeFile fileINode = (INodeFile)node; out.writeShort(fileINode.getReplication()); out.writeLong(fileINode.getModificationTime()); out.writeLong(fileINode.getAccessTime());
long diskspaceConsumed(Block[] blkArr) { long size = 0; if(blkArr == null) { return 0; } for (Block blk : blkArr) { if (blk != null) { size += blk.getNumBytes(); } } /* If the last block is being written to, use prefferedBlockSize * rather than the actual block size. */ if (blkArr.length > 0 && blkArr[blkArr.length-1] != null && isUnderConstruction()) { size += getPreferredBlockSize() - blocks[blocks.length-1].getNumBytes(); } return size * getReplication(); }
/** * Add a block to the file. Returns a reference to the added block. */ Block addBlock(String path, INode[] inodes, Block block) throws IOException { waitForReady(); synchronized (rootDir) { INodeFile fileNode = (INodeFile) inodes[inodes.length-1]; // check quota limits and updated space consumed updateCount(inodes, inodes.length-1, 0, fileNode.getPreferredBlockSize()*fileNode.getReplication()); // associate the new list of blocks with this file namesystem.blocksMap.addINode(block, fileNode); BlockInfo blockInfo = namesystem.blocksMap.getStoredBlock(block); fileNode.addBlock(blockInfo); NameNode.stateChangeLog.debug("DIR* FSDirectory.addFile: " + path + " with " + block + " block is added to the in-memory " + "file system"); } return block; }
/** * Test for the Replication value. Sets a value and checks if it was set * correct. */ @Test public void testReplication () { replication = 3; preferredBlockSize = 128*1024*1024; INodeFile inf = new INodeFile(new PermissionStatus(userName, null, FsPermission.getDefault()), null, replication, 0L, 0L, preferredBlockSize); assertEquals("True has to be returned in this case", replication, inf.getReplication()); }
/** * Check all blocks of a file. If any blocks are lower than their intended * replication factor, then insert them into neededReplication */ private void checkReplicationFactor(INodeFile file) { int numExpectedReplicas = file.getReplication(); Block[] pendingBlocks = file.getBlocks(); int nrBlocks = pendingBlocks.length; for (int i = 0; i < nrBlocks; i++) { // filter out containingNodes that are marked for decommission. NumberReplicas number = countNodes(pendingBlocks[i]); if (number.liveReplicas() < numExpectedReplicas) { neededReplications.add(pendingBlocks[i], number.liveReplicas(), number.decommissionedReplicas, numExpectedReplicas); } } }
/** * Add a block to the file. Returns a reference to the added block. */ Block addBlock(String path, INode[] inodes, Block block) throws IOException { waitForReady(); writeLock(); try { INodeFile fileNode = (INodeFile) inodes[inodes.length-1]; // check quota limits and updated space consumed updateCount(inodes, inodes.length-1, 0, fileNode.getPreferredBlockSize()*fileNode.getReplication(), true); // associate the new list of blocks with this file BlockInfo blockInfo = getFSNamesystem().blocksMap.addINode(block, fileNode); fileNode.addBlock(blockInfo); if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("DIR* FSDirectory.addFile: " + path + " with " + block + " block is added to the in-memory " + "file system"); } } finally { writeUnlock(); } return block; }
/** * Create HdfsFileStatus by file INode */ static FileStatus createFileStatus(String path, INode node) { // length is zero for directories return new FileStatus(node.isDirectory() ? 0 : node.computeContentSummary().getLength(), node.isDirectory(), node.isDirectory() ? 0 : ((INodeFile)node).getReplication(), node.isDirectory() ? 0 : ((INodeFile)node).getPreferredBlockSize(), node.getModificationTime(), node.getAccessTime(), node.getFsPermission(), node.getUserName(), node.getGroupName(), new Path(path)); }
/** * Add block b belonging to the specified file inode to the map, this * overwrites the map with the new block information. */ BlockInfo updateINode(BlockInfo oldBlock, Block newBlock, INodeFile iNode) throws IOException { // If the old block is not same as the new block, probably the GS was // bumped up, hence remove the old block and replace it with the new one. if (oldBlock != null && !oldBlock.equals(newBlock)) { if (oldBlock.getBlockId() != newBlock.getBlockId()) { throw new IOException("block ids don't match : " + oldBlock + ", " + newBlock); } removeBlock(oldBlock); } BlockInfo info = checkBlockInfo(newBlock, iNode.getReplication()); info.set(newBlock.getBlockId(), newBlock.getNumBytes(), newBlock.getGenerationStamp()); info.inode = iNode; return info; }
Block[] unprotectedSetReplication( String src, short replication, int[] oldReplication ) throws IOException { if (oldReplication == null) oldReplication = new int[1]; oldReplication[0] = -1; Block[] fileBlocks = null; synchronized(rootDir) { INode[] inodes = rootDir.getExistingPathINodes(src); INode inode = inodes[inodes.length - 1]; if (inode == null) return null; if (inode.isDirectory()) return null; INodeFile fileNode = (INodeFile)inode; oldReplication[0] = fileNode.getReplication(); // check disk quota long dsDelta = (replication - oldReplication[0]) * (fileNode.diskspaceConsumed()/oldReplication[0]); updateCount(inodes, inodes.length-1, 0, dsDelta); fileNode.setReplication(replication); fileBlocks = fileNode.getBlocks(); } return fileBlocks; }
/** * Add close lease record to edit log. */ public void logCloseFile(String path, INodeFile newNode) { CloseOp op = CloseOp.getInstance(); op.set(path, newNode.getReplication(), newNode.getModificationTime(), newNode.getAccessTime(), newNode.getPreferredBlockSize(), newNode.getBlocks(), newNode.getPermissionStatus(), null, null); logEdit(op); }
INodeFile fileNode = (INodeFile)node; size = fileNode.computeContentSummary().getLength(); replication = fileNode.getReplication(); blocksize = fileNode.getPreferredBlockSize();
Block[] unprotectedSetReplication( String src, short replication, int[] oldReplication ) throws IOException { if (oldReplication == null) oldReplication = new int[1]; oldReplication[0] = -1; Block[] fileBlocks = null; writeLock(); try { INode[] inodes = rootDir.getExistingPathINodes(src); INode inode = inodes[inodes.length - 1]; if (inode == null) return null; if (inode.isDirectory()) return null; INodeFile fileNode = (INodeFile)inode; oldReplication[0] = fileNode.getReplication(); // check disk quota long dsDelta = (replication - oldReplication[0]) * (fileNode.diskspaceConsumed()/oldReplication[0]); updateCount(inodes, inodes.length-1, 0, dsDelta, true); fileNode.setReplication(replication); fileBlocks = fileNode.getBlocks(); } finally { writeUnlock(); } return fileBlocks; }
/** * Add close lease record to edit log. */ public void logCloseFile(String path, INodeFile newNode) { UTF8 nameReplicationPair[] = new UTF8[] { new UTF8(path), FSEditLog.toLogReplication(newNode.getReplication()), FSEditLog.toLogLong(newNode.getModificationTime()), FSEditLog.toLogLong(newNode.getAccessTime()), FSEditLog.toLogLong(newNode.getPreferredBlockSize())}; logEdit(OP_CLOSE, new ArrayWritable(UTF8.class, nameReplicationPair), new ArrayWritable(Block.class, newNode.getBlocks()), newNode.getPermissionStatus()); }
/** * Create FileStatus by file INode */ private static FileStatus createFileStatus(String path, INode node) { // length is zero for directories return new FileStatus(node.isDirectory() ? 0 : node.computeContentSummary().getLength(), node.isDirectory(), node.isDirectory() ? 0 : ((INodeFile)node).getReplication(), node.isDirectory() ? 0 : ((INodeFile)node).getPreferredBlockSize(), node.getModificationTime(), node.getAccessTime(), node.getFsPermission(), node.getUserName(), node.getGroupName(), new Path(path)); } }