Java Code Examples for org.apache.hadoop.hdfs.protocol.QuotaExceededException

The following examples show how to use org.apache.hadoop.hdfs.protocol.QuotaExceededException. These examples are extracted from open source projects. 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 Project: hadoop   Source File: DirectoryWithQuotaFeature.java    License: Apache License 2.0 6 votes vote down vote up
void addSpaceConsumed(final INodeDirectory dir, final QuotaCounts counts,
    boolean verify) throws QuotaExceededException {
  if (dir.isQuotaSet()) {
    // The following steps are important:
    // check quotas in this inode and all ancestors before changing counts
    // so that no change is made if there is any quota violation.
    // (1) verify quota in this inode
    if (verify) {
      verifyQuota(counts);
    }
    // (2) verify quota and then add count in ancestors
    dir.addSpaceConsumed2Parent(counts, verify);
    // (3) add count in this inode
    addSpaceConsumed2Cache(counts);
  } else {
    dir.addSpaceConsumed2Parent(counts, verify);
  }
}
 
Example 2
Source Project: hadoop-gpu   Source File: FSDirectory.java    License: Apache License 2.0 6 votes vote down vote up
/** Add a node child to the inodes at index pos. 
 * Its ancestors are stored at [0, pos-1]. 
 * QuotaExceededException is thrown if it violates quota limit */
private <T extends INode> T addChild(INode[] pathComponents, int pos, T child,
     long childDiskspace, boolean inheritPermission) throws QuotaExceededException {
  INode.DirCounts counts = new INode.DirCounts();
  child.spaceConsumedInTree(counts);
  if (childDiskspace < 0) {
    childDiskspace = counts.getDsCount();
  }
  updateCount(pathComponents, pos, counts.getNsCount(), childDiskspace);
  T addedNode = ((INodeDirectory)pathComponents[pos-1]).addChild(
      child, inheritPermission);
  if (addedNode == null) {
    updateCount(pathComponents, pos, 
                -counts.getNsCount(), -childDiskspace);
  }
  return addedNode;
}
 
Example 3
Source Project: RDFS   Source File: FSDirectory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify quota for rename operation where srcInodes[srcInodes.length-1] moves
 * dstInodes[dstInodes.length-1]
 * 
 * @param srcInodes directory from where node is being moved.
 * @param dstInodes directory to where node is moved to.
 * @throws QuotaExceededException if quota limit is exceeded.
 */
private void verifyQuotaForRename(INode[] srcInodes, INode[]dstInodes)
    throws QuotaExceededException {
  if (!ready) {
    // Do not check quota if edits log is still being processed
    return;
  }
  INode srcInode = srcInodes[srcInodes.length - 1];
  INode commonAncestor = null;
  for(int i =0;srcInodes[i] == dstInodes[i]; i++) {
    commonAncestor = srcInodes[i];
  }
  INode.DirCounts counts = new INode.DirCounts();
  srcInode.spaceConsumedInTree(counts);
  verifyQuota(dstInodes, dstInodes.length - 1, counts.getNsCount(),
          counts.getDsCount(), commonAncestor);
}
 
Example 4
Source Project: big-c   Source File: TestSymlinkHdfs.java    License: Apache License 2.0 6 votes vote down vote up
@Test(timeout=10000)
/** Test craeteSymlink(..) with quota. */
public void testQuota() throws IOException {
  final Path dir = new Path(testBaseDir1());
  dfs.setQuota(dir, 3, HdfsConstants.QUOTA_DONT_SET);

  final Path file = new Path(dir, "file");
  createAndWriteFile(file);

  //creating the first link should succeed
  final Path link1 = new Path(dir, "link1");
  wrapper.createSymlink(file, link1, false);

  try {
    //creating the second link should fail with QuotaExceededException.
    final Path link2 = new Path(dir, "link2");
    wrapper.createSymlink(file, link2, false);
    fail("Created symlink despite quota violation");
  } catch(QuotaExceededException qee) {
    //expected
  }
}
 
Example 5
Source Project: RDFS   Source File: FSDirectory.java    License: Apache License 2.0 6 votes vote down vote up
/** Add a node child to the namespace. The full path name of the node is src.
 * childDiskspace should be -1, if unknown. 
 * QuotaExceededException is thrown if it violates quota limit */
private <T extends INode> T addNode(String src, T child, 
      long childDiskspace, boolean inheritPermission) 
throws QuotaExceededException {
  byte[][] components = INode.getPathComponents(src);
  byte[] path = components[components.length - 1];
  child.setLocalName(path);
  cacheName(child);
  INode[] inodes = new INode[components.length];
  writeLock();
  try {
    rootDir.getExistingPathINodes(components, inodes);
    return addChild(inodes, inodes.length-1, child, childDiskspace,
                    inheritPermission);
  } finally {
    writeUnlock();
  }
}
 
Example 6
Source Project: hadoop   Source File: FSDirectory.java    License: Apache License 2.0 6 votes vote down vote up
/** update count of each inode with quota
 * 
 * @param iip inodes in a path
 * @param numOfINodes the number of inodes to update starting from index 0
 * @param counts the count of space/namespace/type usage to be update
 * @param checkQuota if true then check if quota is exceeded
 * @throws QuotaExceededException if the new count violates any quota limit
 */
void updateCount(INodesInPath iip, int numOfINodes,
                  QuotaCounts counts, boolean checkQuota)
                  throws QuotaExceededException {
  assert hasWriteLock();
  if (!namesystem.isImageLoaded()) {
    //still initializing. do not check or update quotas.
    return;
  }
  if (numOfINodes > iip.length()) {
    numOfINodes = iip.length();
  }
  if (checkQuota && !skipQuotaCheck) {
    verifyQuota(iip, numOfINodes, counts, null);
  }
  unprotectedUpdateCount(iip, numOfINodes, counts);
}
 
Example 7
Source Project: hadoop   Source File: FSDirRenameOp.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify quota for rename operation where srcInodes[srcInodes.length-1] moves
 * dstInodes[dstInodes.length-1]
 */
private static void verifyQuotaForRename(FSDirectory fsd, INodesInPath src,
    INodesInPath dst) throws QuotaExceededException {
  if (!fsd.getFSNamesystem().isImageLoaded() || fsd.shouldSkipQuotaChecks()) {
    // Do not check quota if edits log is still being processed
    return;
  }
  int i = 0;
  while(src.getINode(i) == dst.getINode(i)) { i++; }
  // src[i - 1] is the last common ancestor.
  BlockStoragePolicySuite bsps = fsd.getBlockStoragePolicySuite();
  final QuotaCounts delta = src.getLastINode().computeQuotaUsage(bsps);

  // Reduce the required quota by dst that is being removed
  final INode dstINode = dst.getLastINode();
  if (dstINode != null) {
    delta.subtract(dstINode.computeQuotaUsage(bsps));
  }
  FSDirectory.verifyQuota(dst, dst.length() - 1, delta, src.getINode(i - 1));
}
 
Example 8
Source Project: hadoop   Source File: FSDirRenameOp.java    License: Apache License 2.0 6 votes vote down vote up
void restoreSource() throws QuotaExceededException {
  // Rename failed - restore src
  final INode oldSrcChild = srcChild;
  // put it back
  if (withCount == null) {
    srcChild.setLocalName(srcChildName);
  } else if (!srcChildIsReference) { // src must be in snapshot
    // the withCount node will no longer be used thus no need to update
    // its reference number here
    srcChild = withCount.getReferredINode();
    srcChild.setLocalName(srcChildName);
  } else {
    withCount.removeReference(oldSrcChild.asReference());
    srcChild = new INodeReference.DstReference(srcParent, withCount,
        srcRefDstSnapshot);
    withCount.getReferredINode().setLocalName(srcChildName);
  }

  if (isSrcInSnapshot) {
    srcParent.undoRename4ScrParent(oldSrcChild.asReference(), srcChild);
  } else {
    // srcParent is not an INodeDirectoryWithSnapshot, we only need to add
    // the srcChild back
    fsd.addLastINodeNoQuotaCheck(srcParentIIP, srcChild);
  }
}
 
Example 9
Source Project: hadoop   Source File: FSDirRenameOp.java    License: Apache License 2.0 6 votes vote down vote up
boolean cleanDst(BlockStoragePolicySuite bsps, BlocksMapUpdateInfo collectedBlocks)
    throws QuotaExceededException {
  Preconditions.checkState(oldDstChild != null);
  List<INode> removedINodes = new ChunkedArrayList<>();
  final boolean filesDeleted;
  if (!oldDstChild.isInLatestSnapshot(dstIIP.getLatestSnapshotId())) {
    oldDstChild.destroyAndCollectBlocks(bsps, collectedBlocks, removedINodes);
    filesDeleted = true;
  } else {
    filesDeleted = oldDstChild.cleanSubtree(bsps, Snapshot.CURRENT_STATE_ID,
        dstIIP.getLatestSnapshotId(), collectedBlocks, removedINodes)
        .getNameSpace() >= 0;
  }
  fsd.getFSNamesystem().removeLeasesAndINodes(src, removedINodes, false);
  return filesDeleted;
}
 
Example 10
Source Project: big-c   Source File: TestAbandonBlock.java    License: Apache License 2.0 6 votes vote down vote up
@Test
/** Make sure that the quota is decremented correctly when a block is abandoned */
public void testQuotaUpdatedWhenBlockAbandoned() throws IOException {
  // Setting diskspace quota to 3MB
  fs.setQuota(new Path("/"), HdfsConstants.QUOTA_DONT_SET, 3 * 1024 * 1024);

  // Start writing a file with 2 replicas to ensure each datanode has one.
  // Block Size is 1MB.
  String src = FILE_NAME_PREFIX + "test_quota1";
  FSDataOutputStream fout = fs.create(new Path(src), true, 4096, (short)2, 1024 * 1024);
  for (int i = 0; i < 1024; i++) {
    fout.writeByte(123);
  }

  // Shutdown one datanode, causing the block abandonment.
  cluster.getDataNodes().get(0).shutdown();

  // Close the file, new block will be allocated with 2MB pending size.
  try {
    fout.close();
  } catch (QuotaExceededException e) {
    fail("Unexpected quota exception when closing fout");
  }
}
 
Example 11
Source Project: hadoop   Source File: FSDirAttrOp.java    License: Apache License 2.0 6 votes vote down vote up
static void unprotectedSetOwner(
    FSDirectory fsd, String src, String username, String groupname)
    throws FileNotFoundException, UnresolvedLinkException,
    QuotaExceededException, SnapshotAccessControlException {
  assert fsd.hasWriteLock();
  final INodesInPath inodesInPath = fsd.getINodesInPath4Write(src, true);
  INode inode = inodesInPath.getLastINode();
  if (inode == null) {
    throw new FileNotFoundException("File does not exist: " + src);
  }
  if (username != null) {
    inode = inode.setUser(username, inodesInPath.getLatestSnapshotId());
  }
  if (groupname != null) {
    inode.setGroup(groupname, inodesInPath.getLatestSnapshotId());
  }
}
 
Example 12
Source Project: big-c   Source File: FSDirAttrOp.java    License: Apache License 2.0 6 votes vote down vote up
static void unprotectedSetOwner(
    FSDirectory fsd, String src, String username, String groupname)
    throws FileNotFoundException, UnresolvedLinkException,
    QuotaExceededException, SnapshotAccessControlException {
  assert fsd.hasWriteLock();
  final INodesInPath inodesInPath = fsd.getINodesInPath4Write(src, true);
  INode inode = inodesInPath.getLastINode();
  if (inode == null) {
    throw new FileNotFoundException("File does not exist: " + src);
  }
  if (username != null) {
    inode = inode.setUser(username, inodesInPath.getLatestSnapshotId());
  }
  if (groupname != null) {
    inode.setGroup(groupname, inodesInPath.getLatestSnapshotId());
  }
}
 
Example 13
Source Project: hadoop   Source File: FSDirMkdirOp.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * create a directory at path specified by parent
 */
private static INodesInPath unprotectedMkdir(FSDirectory fsd, long inodeId,
    INodesInPath parent, byte[] name, PermissionStatus permission,
    List<AclEntry> aclEntries, long timestamp)
    throws QuotaExceededException, AclException, FileAlreadyExistsException {
  assert fsd.hasWriteLock();
  assert parent.getLastINode() != null;
  if (!parent.getLastINode().isDirectory()) {
    throw new FileAlreadyExistsException("Parent path is not a directory: " +
        parent.getPath() + " " + DFSUtil.bytes2String(name));
  }
  final INodeDirectory dir = new INodeDirectory(inodeId, name, permission,
      timestamp);

  INodesInPath iip = fsd.addLastINode(parent, dir, true);
  if (iip != null && aclEntries != null) {
    AclStorage.updateINodeAcl(dir, aclEntries, Snapshot.CURRENT_STATE_ID);
  }
  return iip;
}
 
Example 14
Source Project: hadoop   Source File: TestSymlinkHdfs.java    License: Apache License 2.0 6 votes vote down vote up
@Test(timeout=10000)
/** Test craeteSymlink(..) with quota. */
public void testQuota() throws IOException {
  final Path dir = new Path(testBaseDir1());
  dfs.setQuota(dir, 3, HdfsConstants.QUOTA_DONT_SET);

  final Path file = new Path(dir, "file");
  createAndWriteFile(file);

  //creating the first link should succeed
  final Path link1 = new Path(dir, "link1");
  wrapper.createSymlink(file, link1, false);

  try {
    //creating the second link should fail with QuotaExceededException.
    final Path link2 = new Path(dir, "link2");
    wrapper.createSymlink(file, link2, false);
    fail("Created symlink despite quota violation");
  } catch(QuotaExceededException qee) {
    //expected
  }
}
 
Example 15
Source Project: hadoop   Source File: TestAbandonBlock.java    License: Apache License 2.0 6 votes vote down vote up
@Test
/** Make sure that the quota is decremented correctly when a block is abandoned */
public void testQuotaUpdatedWhenBlockAbandoned() throws IOException {
  // Setting diskspace quota to 3MB
  fs.setQuota(new Path("/"), HdfsConstants.QUOTA_DONT_SET, 3 * 1024 * 1024);

  // Start writing a file with 2 replicas to ensure each datanode has one.
  // Block Size is 1MB.
  String src = FILE_NAME_PREFIX + "test_quota1";
  FSDataOutputStream fout = fs.create(new Path(src), true, 4096, (short)2, 1024 * 1024);
  for (int i = 0; i < 1024; i++) {
    fout.writeByte(123);
  }

  // Shutdown one datanode, causing the block abandonment.
  cluster.getDataNodes().get(0).shutdown();

  // Close the file, new block will be allocated with 2MB pending size.
  try {
    fout.close();
  } catch (QuotaExceededException e) {
    fail("Unexpected quota exception when closing fout");
  }
}
 
Example 16
Source Project: hadoop   Source File: TestINodeFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * For a given path, build a tree of INodes and return the leaf node.
 */
private INode createTreeOfInodes(String path) throws QuotaExceededException {
  byte[][] components = INode.getPathComponents(path);
  FsPermission perm = FsPermission.createImmutable((short)0755);
  PermissionStatus permstatus = PermissionStatus.createImmutable("", "", perm);
  
  long id = 0;
  INodeDirectory prev = new INodeDirectory(++id, new byte[0], permstatus, 0);
  INodeDirectory dir = null;
  for (byte[] component : components) {
    if (component.length == 0) {
      continue;
    }
    System.out.println("Adding component " + DFSUtil.bytes2String(component));
    dir = new INodeDirectory(++id, component, permstatus, 0);
    prev.addChild(dir, false, Snapshot.CURRENT_STATE_ID);
    prev = dir;
  }
  return dir; // Last Inode in the chain
}
 
Example 17
Source Project: big-c   Source File: DirectoryWithQuotaFeature.java    License: Apache License 2.0 6 votes vote down vote up
void addSpaceConsumed(final INodeDirectory dir, final QuotaCounts counts,
    boolean verify) throws QuotaExceededException {
  if (dir.isQuotaSet()) {
    // The following steps are important:
    // check quotas in this inode and all ancestors before changing counts
    // so that no change is made if there is any quota violation.
    // (1) verify quota in this inode
    if (verify) {
      verifyQuota(counts);
    }
    // (2) verify quota and then add count in ancestors
    dir.addSpaceConsumed2Parent(counts, verify);
    // (3) add count in this inode
    addSpaceConsumed2Cache(counts);
  } else {
    dir.addSpaceConsumed2Parent(counts, verify);
  }
}
 
Example 18
Source Project: RDFS   Source File: FSDirectory.java    License: Apache License 2.0 6 votes vote down vote up
/** Add a node child to the inodes at index pos. 
 * Its ancestors are stored at [0, pos-1]. 
 * QuotaExceededException is thrown if it violates quota limit */
private <T extends INode> T addChild(INode[] pathComponents, int pos,
    T child, long childDiskspace, boolean inheritPermission,
    boolean checkQuota) throws QuotaExceededException {
  INode.DirCounts counts = new INode.DirCounts();
  child.spaceConsumedInTree(counts);
  if (childDiskspace < 0) {
    childDiskspace = counts.getDsCount();
  }
  updateCount(pathComponents, pos, counts.getNsCount(), childDiskspace,
      checkQuota);
  T addedNode = ((INodeDirectory)pathComponents[pos-1]).addChild(
      child, inheritPermission);
  if (addedNode == null) {
    updateCount(pathComponents, pos, -counts.getNsCount(), 
        -childDiskspace, true);
  }
  return addedNode;
}
 
Example 19
Source Project: big-c   Source File: INodeDirectory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Undo the rename operation for the dst tree, i.e., if the rename operation
 * (with OVERWRITE option) removes a file/dir from the dst tree, add it back
 * and delete possible record in the deleted list.  
 */
public void undoRename4DstParent(final BlockStoragePolicySuite bsps,
    final INode deletedChild,
    int latestSnapshotId) throws QuotaExceededException {
  DirectoryWithSnapshotFeature sf = getDirectoryWithSnapshotFeature();
  Preconditions.checkState(sf != null,
      "Directory does not have snapshot feature");
  boolean removeDeletedChild = sf.getDiffs().removeChild(ListType.DELETED,
      deletedChild);
  int sid = removeDeletedChild ? Snapshot.CURRENT_STATE_ID : latestSnapshotId;
  final boolean added = addChild(deletedChild, true, sid);
  // update quota usage if adding is successfully and the old child has not
  // been stored in deleted list before
  if (added && !removeDeletedChild) {
    final QuotaCounts counts = deletedChild.computeQuotaUsage(bsps);
    addSpaceConsumed(counts, false);

  }
}
 
Example 20
Source Project: big-c   Source File: TestINodeFile.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * For a given path, build a tree of INodes and return the leaf node.
 */
private INode createTreeOfInodes(String path) throws QuotaExceededException {
  byte[][] components = INode.getPathComponents(path);
  FsPermission perm = FsPermission.createImmutable((short)0755);
  PermissionStatus permstatus = PermissionStatus.createImmutable("", "", perm);
  
  long id = 0;
  INodeDirectory prev = new INodeDirectory(++id, new byte[0], permstatus, 0);
  INodeDirectory dir = null;
  for (byte[] component : components) {
    if (component.length == 0) {
      continue;
    }
    System.out.println("Adding component " + DFSUtil.bytes2String(component));
    dir = new INodeDirectory(++id, component, permstatus, 0);
    prev.addChild(dir, false, Snapshot.CURRENT_STATE_ID);
    prev = dir;
  }
  return dir; // Last Inode in the chain
}
 
Example 21
Source Project: big-c   Source File: INodeDirectory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add a child inode to the directory.
 * 
 * @param node INode to insert
 * @param setModTime set modification time for the parent node
 *                   not needed when replaying the addition and 
 *                   the parent already has the proper mod time
 * @return false if the child with this name already exists; 
 *         otherwise, return true;
 */
public boolean addChild(INode node, final boolean setModTime,
    final int latestSnapshotId) throws QuotaExceededException {
  final int low = searchChildren(node.getLocalNameBytes());
  if (low >= 0) {
    return false;
  }

  if (isInLatestSnapshot(latestSnapshotId)) {
    // create snapshot feature if necessary
    DirectoryWithSnapshotFeature sf = this.getDirectoryWithSnapshotFeature();
    if (sf == null) {
      sf = this.addSnapshotFeature(null);
    }
    return sf.addChild(this, node, setModTime, latestSnapshotId);
  }
  addChild(node, low);
  if (setModTime) {
    // update modification time of the parent directory
    updateModificationTime(node.getModificationTime(), latestSnapshotId);
  }
  return true;
}
 
Example 22
Source Project: big-c   Source File: FSDirRenameOp.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Verify quota for rename operation where srcInodes[srcInodes.length-1] moves
 * dstInodes[dstInodes.length-1]
 */
private static void verifyQuotaForRename(FSDirectory fsd, INodesInPath src,
    INodesInPath dst) throws QuotaExceededException {
  if (!fsd.getFSNamesystem().isImageLoaded() || fsd.shouldSkipQuotaChecks()) {
    // Do not check quota if edits log is still being processed
    return;
  }
  int i = 0;
  while(src.getINode(i) == dst.getINode(i)) { i++; }
  // src[i - 1] is the last common ancestor.
  BlockStoragePolicySuite bsps = fsd.getBlockStoragePolicySuite();
  final QuotaCounts delta = src.getLastINode().computeQuotaUsage(bsps);

  // Reduce the required quota by dst that is being removed
  final INode dstINode = dst.getLastINode();
  if (dstINode != null) {
    delta.subtract(dstINode.computeQuotaUsage(bsps));
  }
  FSDirectory.verifyQuota(dst, dst.length() - 1, delta, src.getINode(i - 1));
}
 
Example 23
Source Project: hadoop   Source File: AclStorage.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Updates an inode with a new ACL.  This method takes a full logical ACL and
 * stores the entries to the inode's {@link FsPermission} and
 * {@link AclFeature}.
 *
 * @param inode INode to update
 * @param newAcl List<AclEntry> containing new ACL entries
 * @param snapshotId int latest snapshot ID of inode
 * @throws AclException if the ACL is invalid for the given inode
 * @throws QuotaExceededException if quota limit is exceeded
 */
public static void updateINodeAcl(INode inode, List<AclEntry> newAcl,
    int snapshotId) throws AclException, QuotaExceededException {
  assert newAcl.size() >= 3;
  FsPermission perm = inode.getFsPermission();
  final FsPermission newPerm;
  if (!AclUtil.isMinimalAcl(newAcl)) {
    // This is an extended ACL.  Split entries into access vs. default.
    ScopedAclEntries scoped = new ScopedAclEntries(newAcl);
    List<AclEntry> accessEntries = scoped.getAccessEntries();
    List<AclEntry> defaultEntries = scoped.getDefaultEntries();

    // Only directories may have a default ACL.
    if (!defaultEntries.isEmpty() && !inode.isDirectory()) {
      throw new AclException(
        "Invalid ACL: only directories may have a default ACL.");
    }

    // Attach entries to the feature.
    if (inode.getAclFeature() != null) {
      inode.removeAclFeature(snapshotId);
    }
    inode.addAclFeature(createAclFeature(accessEntries, defaultEntries),
      snapshotId);
    newPerm = createFsPermissionForExtendedAcl(accessEntries, perm);
  } else {
    // This is a minimal ACL.  Remove the ACL feature if it previously had one.
    if (inode.getAclFeature() != null) {
      inode.removeAclFeature(snapshotId);
    }
    newPerm = createFsPermissionForMinimalAcl(newAcl, perm);
  }

  inode.setPermission(newPerm, snapshotId);
}
 
Example 24
Source Project: hadoop-gpu   Source File: FSDirectory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 */
INode unprotectedMkdir(String src, PermissionStatus permissions,
                        long timestamp) throws QuotaExceededException {
  byte[][] components = INode.getPathComponents(src);
  INode[] inodes = new INode[components.length];
  synchronized (rootDir) {
    rootDir.getExistingPathINodes(components, inodes);
    unprotectedMkdir(inodes, inodes.length-1, components[inodes.length-1],
        permissions, false, timestamp);
    return inodes[inodes.length-1];
  }
}
 
Example 25
Source Project: hadoop   Source File: FSDirectory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add the given filename to the fs.
 * @return the new INodesInPath instance that contains the new INode
 */
INodesInPath addFile(INodesInPath existing, String localName, PermissionStatus
    permissions, short replication, long preferredBlockSize,
    String clientName, String clientMachine)
  throws FileAlreadyExistsException, QuotaExceededException,
    UnresolvedLinkException, SnapshotAccessControlException, AclException {

  long modTime = now();
  INodeFile newNode = newINodeFile(allocateNewInodeId(), permissions, modTime,
      modTime, replication, preferredBlockSize);
  newNode.setLocalName(localName.getBytes(Charsets.UTF_8));
  newNode.toUnderConstruction(clientName, clientMachine);

  INodesInPath newiip;
  writeLock();
  try {
    newiip = addINode(existing, newNode);
  } finally {
    writeUnlock();
  }
  if (newiip == null) {
    NameNode.stateChangeLog.info("DIR* addFile: failed to add " +
        existing.getPath() + "/" + localName);
    return null;
  }

  if(NameNode.stateChangeLog.isDebugEnabled()) {
    NameNode.stateChangeLog.debug("DIR* addFile: " + localName + " is added");
  }
  return newiip;
}
 
Example 26
Source Project: hadoop   Source File: FSDirectory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Update usage count without replication factor change
 */
void updateCount(INodesInPath iip, long nsDelta, long ssDelta, short replication,
    boolean checkQuota) throws QuotaExceededException {
  final INodeFile fileINode = iip.getLastINode().asFile();
  EnumCounters<StorageType> typeSpaceDeltas =
    getStorageTypeDeltas(fileINode.getStoragePolicyID(), ssDelta,
        replication, replication);;
  updateCount(iip, iip.length() - 1,
    new QuotaCounts.Builder().nameSpace(nsDelta).storageSpace(ssDelta * replication).
        typeSpaces(typeSpaceDeltas).build(),
      checkQuota);
}
 
Example 27
Source Project: hadoop   Source File: FSDirectory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add the given child to the namespace.
 * @param existing the INodesInPath containing all the ancestral INodes
 * @param child the new INode to add
 * @return a new INodesInPath instance containing the new child INode. Null
 * if the adding fails.
 * @throws QuotaExceededException is thrown if it violates quota limit
 */
INodesInPath addINode(INodesInPath existing, INode child)
    throws QuotaExceededException, UnresolvedLinkException {
  cacheName(child);
  writeLock();
  try {
    return addLastINode(existing, child, true);
  } finally {
    writeUnlock();
  }
}
 
Example 28
Source Project: RDFS   Source File: INodeDirectoryWithQuota.java    License: Apache License 2.0 5 votes vote down vote up
/** Verify if the namespace count disk space satisfies the quota restriction 
 * @throws QuotaExceededException if the given quota is less than the count
 */
void verifyQuota(long nsDelta, long dsDelta) throws QuotaExceededException {
  long newCount = nsCount + nsDelta;
  long newDiskspace = diskspace + dsDelta;
  if (nsDelta>0 || dsDelta>0) {
    if (nsQuota >= 0 && nsQuota < newCount) {
      throw new NSQuotaExceededException(nsQuota, newCount);
    }
    if (dsQuota >= 0 && dsQuota < newDiskspace) {
      throw new DSQuotaExceededException(dsQuota, newDiskspace);
  }
  }
}
 
Example 29
Source Project: hadoop   Source File: FSDirectory.java    License: Apache License 2.0 5 votes vote down vote up
INodesInPath addLastINodeNoQuotaCheck(INodesInPath existing, INode i) {
  try {
    return addLastINode(existing, i, false);
  } catch (QuotaExceededException e) {
    NameNode.LOG.warn("FSDirectory.addChildNoQuotaCheck - unexpected", e);
  }
  return null;
}
 
Example 30
Source Project: big-c   Source File: DirectorySnapshottableFeature.java    License: Apache License 2.0 5 votes vote down vote up
/** Add a snapshot. */
public Snapshot addSnapshot(INodeDirectory snapshotRoot, int id, String name)
    throws SnapshotException, QuotaExceededException {
  //check snapshot quota
  final int n = getNumSnapshots();
  if (n + 1 > snapshotQuota) {
    throw new SnapshotException("Failed to add snapshot: there are already "
        + n + " snapshot(s) and the snapshot quota is "
        + snapshotQuota);
  }
  final Snapshot s = new Snapshot(id, name, snapshotRoot);
  final byte[] nameBytes = s.getRoot().getLocalNameBytes();
  final int i = searchSnapshot(nameBytes);
  if (i >= 0) {
    throw new SnapshotException("Failed to add snapshot: there is already a "
        + "snapshot with the same name \"" + Snapshot.getSnapshotName(s) + "\".");
  }

  final DirectoryDiff d = getDiffs().addDiff(id, snapshotRoot);
  d.setSnapshotRoot(s.getRoot());
  snapshotsByNames.add(-i - 1, s);

  // set modification time
  final long now = Time.now();
  snapshotRoot.updateModificationTime(now, Snapshot.CURRENT_STATE_ID);
  s.getRoot().setModificationTime(now, Snapshot.CURRENT_STATE_ID);
  return s;
}