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

The following examples show how to use org.apache.hadoop.hdfs.protocol.QuotaExceededException. 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: FSDirMkdirOp.java    From hadoop with 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 #2
Source File: FSDirectory.java    From RDFS with 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 #3
Source File: FSDirectory.java    From hadoop with 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 #4
Source File: FSDirectory.java    From hadoop-gpu with 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 #5
Source File: FSDirectory.java    From RDFS with 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 #6
Source File: TestSymlinkHdfs.java    From big-c with 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 #7
Source File: DirectoryWithQuotaFeature.java    From big-c with 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 #8
Source File: FSDirectory.java    From RDFS with 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 #9
Source File: DirectoryWithQuotaFeature.java    From hadoop with 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 #10
Source File: TestINodeFile.java    From hadoop with 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 #11
Source File: FSDirRenameOp.java    From big-c with 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 #12
Source File: TestAbandonBlock.java    From hadoop with 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 #13
Source File: FSDirRenameOp.java    From hadoop with 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 #14
Source File: INodeDirectory.java    From big-c with 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 #15
Source File: TestSymlinkHdfs.java    From hadoop with 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 #16
Source File: FSDirRenameOp.java    From hadoop with 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 #17
Source File: FSDirRenameOp.java    From hadoop with 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 #18
Source File: TestAbandonBlock.java    From big-c with 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 #19
Source File: FSDirAttrOp.java    From hadoop with 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 #20
Source File: INodeDirectory.java    From big-c with 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 #21
Source File: FSDirAttrOp.java    From big-c with 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 #22
Source File: TestINodeFile.java    From big-c with 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 #23
Source File: INode.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Check and add namespace/storagespace/storagetype consumed to itself and the ancestors.
 * @throws QuotaExceededException if quote is violated.
 */
void addSpaceConsumed2Parent(QuotaCounts counts, boolean verify)
  throws QuotaExceededException {
  if (parent != null) {
    parent.addSpaceConsumed(counts, verify);
  }
}
 
Example #24
Source File: DirectoryWithSnapshotFeature.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Add an inode into parent's children list. The caller of this method needs
 * to make sure that parent is in the given snapshot "latest".
 */
public boolean addChild(INodeDirectory parent, INode inode,
    boolean setModTime, int latestSnapshotId) throws QuotaExceededException {
  ChildrenDiff diff = diffs.checkAndAddLatestSnapshotDiff(latestSnapshotId,
      parent).diff;
  int undoInfo = diff.create(inode);

  final boolean added = parent.addChild(inode, setModTime,
      Snapshot.CURRENT_STATE_ID);
  if (!added) {
    diff.undoCreate(inode, undoInfo);
  }
  return added;
}
 
Example #25
Source File: FSDirConcatOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static void verifyQuota(FSDirectory fsd, INodesInPath targetIIP,
    QuotaCounts deltas) throws QuotaExceededException {
  if (!fsd.getFSNamesystem().isImageLoaded() || fsd.shouldSkipQuotaChecks()) {
    // Do not check quota if editlog is still being processed
    return;
  }
  FSDirectory.verifyQuota(targetIIP, targetIIP.length() - 1, deltas, null);
}
 
Example #26
Source File: AclStorage.java    From big-c with 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 #27
Source File: FSDirectory.java    From big-c with 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 File: INodeDirectoryWithQuota.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/** Convert an existing directory inode to one with the given quota
 * 
 * @param nsQuota Namespace quota to be assigned to this inode
 * @param dsQuota Diskspace quota to be assigned to this indoe
 * @param other The other inode from which all other properties are copied
 */
INodeDirectoryWithQuota(long nsQuota, long dsQuota, INodeDirectory other)
throws QuotaExceededException {
  super(other);
  INode.DirCounts counts = new INode.DirCounts();
  other.spaceConsumedInTree(counts);
  this.nsCount= counts.getNsCount();
  this.diskspace = counts.getDsCount();
  setQuota(nsQuota, dsQuota);
}
 
Example #29
Source File: TestHDFSConcat.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcatWithQuotaIncrease() throws IOException {
  final short repl = 3;
  final int srcNum = 10;
  final Path foo = new Path("/foo");
  final Path bar = new Path(foo, "bar");
  final Path[] srcs = new Path[srcNum];
  final Path target = new Path(bar, "target");
  DFSTestUtil.createFile(dfs, target, blockSize, repl, 0L);

  final long dsQuota = blockSize * repl + blockSize * srcNum * REPL_FACTOR;
  dfs.setQuota(foo, Long.MAX_VALUE - 1, dsQuota);

  for (int i = 0; i < srcNum; i++) {
    srcs[i] = new Path(bar, "src" + i);
    DFSTestUtil.createFile(dfs, srcs[i], blockSize, REPL_FACTOR, 0L);
  }

  ContentSummary summary = dfs.getContentSummary(bar);
  Assert.assertEquals(11, summary.getFileCount());
  Assert.assertEquals(dsQuota, summary.getSpaceConsumed());

  try {
    dfs.concat(target, srcs);
    fail("QuotaExceededException expected");
  } catch (RemoteException e) {
    Assert.assertTrue(
        e.unwrapRemoteException() instanceof QuotaExceededException);
  }

  dfs.setQuota(foo, Long.MAX_VALUE - 1, Long.MAX_VALUE - 1);
  dfs.concat(target, srcs);
  summary = dfs.getContentSummary(bar);
  Assert.assertEquals(1, summary.getFileCount());
  Assert.assertEquals(blockSize * repl * (srcNum + 1),
      summary.getSpaceConsumed());
}
 
Example #30
Source File: FSDirRenameOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
void updateQuotasInSourceTree(BlockStoragePolicySuite bsps) throws QuotaExceededException {
  // update the quota usage in src tree
  if (isSrcInSnapshot) {
    // get the counts after rename
    QuotaCounts newSrcCounts = srcChild.computeQuotaUsage(bsps,
        new QuotaCounts.Builder().build(), false);
    newSrcCounts.subtract(oldSrcCounts);
    srcParent.addSpaceConsumed(newSrcCounts, false);
  }
}