@Override protected void acquire(TransactionLocks locks) throws IOException { Set<String> hldrs = new HashSet<>(); if (leaseHolder != null) { hldrs.add(leaseHolder); } if (locks.containsLock(Type.INode)) { BaseINodeLock inodeLock = (BaseINodeLock) locks.getLock(Type.INode); for (INode f : inodeLock.getAllResolvedINodes()) { if (f instanceof INodeFileUnderConstruction) { hldrs.add(((INodeFileUnderConstruction) f).getClientName()); } } } setLockMode(lockType); List<String> holders = new ArrayList<>(hldrs); Collections.sort(holders); for (String h : holders) { Lease lease = acquireLock(lockType, Lease.Finder.ByHolder, h, Lease.getHolderId(h)); if (lease != null) { leases.add(lease); } } }
@Override boolean checkNamenodeBeforeReturn() throws Exception { INodeFileUnderConstruction fileNode = (INodeFileUnderConstruction) cluster .getNamesystem(0).getFSDirectory().getINode4Write(file).asFile(); BlockInfoUnderConstruction blkUC = (BlockInfoUnderConstruction) (fileNode.getBlocks())[1]; int datanodeNum = blkUC.getExpectedLocations().length; for (int i = 0; i < CHECKTIMES && datanodeNum != 2; i++) { Thread.sleep(1000); datanodeNum = blkUC.getExpectedLocations().length; } return datanodeNum == 2; }
@Override public INode convertHDFStoDAL( org.apache.hadoop.hdfs.server.namenode.INode inode) throws StorageException { INode hopINode = null; if (inode != null) { hopINode = new INode(); hopINode.setModificationTime(inode.getModificationTime()); hopINode.setAccessTime(inode.getAccessTime()); hopINode.setName(inode.getLocalName()); hopINode.setUserID(inode.getUserID()); hopINode.setGroupID(inode.getGroupID()); hopINode.setPermission(inode.getFsPermission().toShort()); hopINode.setParentId(inode.getParentId()); hopINode.setId(inode.getId()); hopINode.setIsDir(inode.isDirectory()); hopINode.setPartitionId(inode.getPartitionId()); hopINode.setLogicalTime(inode.getLogicalTime()); if (inode.isDirectory()) { hopINode.setUnderConstruction(false); hopINode.setDirWithQuota(inode instanceof INodeDirectoryWithQuota ? true : false); hopINode.setMetaEnabled(((INodeDirectory) inode).isMetaEnabled()); } if (inode instanceof INodeFile) { hopINode .setUnderConstruction(inode.isUnderConstruction() ? true : false); hopINode.setDirWithQuota(false); if (inode instanceof INodeFileUnderConstruction) { hopINode.setClientName( ((INodeFileUnderConstruction) inode).getClientName()); hopINode.setClientMachine( ((INodeFileUnderConstruction) inode).getClientMachine()); hopINode.setClientNode( ((INodeFileUnderConstruction) inode).getClientNode() == null ? null : ((INodeFileUnderConstruction) inode).getClientNode() .getXferAddr()); } hopINode.setGenerationStamp(((INodeFile) inode).getGenerationStamp()); hopINode.setFileSize(((INodeFile) inode).getSize()); hopINode.setFileStoredInDB(((INodeFile)inode).isFileStoredInDB()); } if (inode instanceof INodeSymlink) { hopINode.setUnderConstruction(false); hopINode.setDirWithQuota(false); String linkValue = DFSUtil.bytes2String(((INodeSymlink) inode).getSymlink()); hopINode.setSymlink(linkValue); } hopINode.setSubtreeLocked(inode.isSubtreeLocked()); hopINode.setSubtreeLockOwner(inode.getSubtreeLockOwner()); } hopINode.setHeader(inode.getHeader()); return hopINode; }
/** * Construct an {@link INodeFileUnderConstructionWithSnapshot} based on an * {@link INodeFileUnderConstruction}. * * @param f The given {@link INodeFileUnderConstruction} instance */ public INodeFileUnderConstructionWithSnapshot(INodeFileUnderConstruction f, final FileDiffList diffs) { this(f, f.getClientName(), f.getClientMachine(), f.getClientNode(), diffs); }