Java Code Examples for org.apache.hadoop.hdfs.server.namenode.INodeDirectory#setSnapshotQuota()

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.INodeDirectory#setSnapshotQuota() . 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: SnapshotManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Set the given directory as a snapshottable directory.
 * If the path is already a snapshottable directory, update the quota.
 */
public void setSnapshottable(final String path, boolean checkNestedSnapshottable)
    throws IOException {
  final INodesInPath iip = fsdir.getINodesInPath4Write(path);
  final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path);
  if (checkNestedSnapshottable) {
    checkNestedSnapshottable(d, path);
  }

  if (d.isSnapshottable()) {
    //The directory is already a snapshottable directory.
    d.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_LIMIT);
  } else {
    d.addSnapshottableFeature();
  }
  addSnapshottable(d);
}
 
Example 2
Source File: SnapshotManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Set the given snapshottable directory to non-snapshottable.
 * 
 * @throws SnapshotException if there are snapshots in the directory.
 */
public void resetSnapshottable(final String path) throws IOException {
  final INodesInPath iip = fsdir.getINodesInPath4Write(path);
  final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path);
  DirectorySnapshottableFeature sf = d.getDirectorySnapshottableFeature();
  if (sf == null) {
    // the directory is already non-snapshottable
    return;
  }
  if (sf.getNumSnapshots() > 0) {
    throw new SnapshotException("The directory " + path + " has snapshot(s). "
        + "Please redo the operation after removing all the snapshots.");
  }

  if (d == fsdir.getRoot()) {
    d.setSnapshotQuota(0);
  } else {
    d.removeSnapshottableFeature();
  }
  removeSnapshottable(d);
}
 
Example 3
Source File: SnapshotFSImageFormat.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Load snapshots and snapshotQuota for a Snapshottable directory.
 *
 * @param snapshottableParent
 *          The snapshottable directory for loading.
 * @param numSnapshots
 *          The number of snapshots that the directory has.
 * @param loader
 *          The loader
 */
public static void loadSnapshotList(INodeDirectory snapshottableParent,
    int numSnapshots, DataInput in, FSImageFormat.Loader loader)
    throws IOException {
  DirectorySnapshottableFeature sf = snapshottableParent
      .getDirectorySnapshottableFeature();
  Preconditions.checkArgument(sf != null);
  for (int i = 0; i < numSnapshots; i++) {
    // read snapshots
    final Snapshot s = loader.getSnapshot(in);
    s.getRoot().setParent(snapshottableParent);
    sf.addSnapshot(s);
  }
  int snapshotQuota = in.readInt();
  snapshottableParent.setSnapshotQuota(snapshotQuota);
}
 
Example 4
Source File: FSImageFormatPBSnapshot.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Load the snapshots section from fsimage. Also add snapshottable feature
 * to snapshottable directories.
 */
public void loadSnapshotSection(InputStream in) throws IOException {
  SnapshotManager sm = fsn.getSnapshotManager();
  SnapshotSection section = SnapshotSection.parseDelimitedFrom(in);
  int snum = section.getNumSnapshots();
  sm.setNumSnapshots(snum);
  sm.setSnapshotCounter(section.getSnapshotCounter());
  for (long sdirId : section.getSnapshottableDirList()) {
    INodeDirectory dir = fsDir.getInode(sdirId).asDirectory();
    if (!dir.isSnapshottable()) {
      dir.addSnapshottableFeature();
    } else {
      // dir is root, and admin set root to snapshottable before
      dir.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_LIMIT);
    }
    sm.addSnapshottable(dir);
  }
  loadSnapshots(in, snum);
}
 
Example 5
Source File: SnapshotManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Set the given directory as a snapshottable directory.
 * If the path is already a snapshottable directory, update the quota.
 */
public void setSnapshottable(final String path, boolean checkNestedSnapshottable)
    throws IOException {
  final INodesInPath iip = fsdir.getINodesInPath4Write(path);
  final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path);
  if (checkNestedSnapshottable) {
    checkNestedSnapshottable(d, path);
  }

  if (d.isSnapshottable()) {
    //The directory is already a snapshottable directory.
    d.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_LIMIT);
  } else {
    d.addSnapshottableFeature();
  }
  addSnapshottable(d);
}
 
Example 6
Source File: SnapshotManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Set the given snapshottable directory to non-snapshottable.
 * 
 * @throws SnapshotException if there are snapshots in the directory.
 */
public void resetSnapshottable(final String path) throws IOException {
  final INodesInPath iip = fsdir.getINodesInPath4Write(path);
  final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path);
  DirectorySnapshottableFeature sf = d.getDirectorySnapshottableFeature();
  if (sf == null) {
    // the directory is already non-snapshottable
    return;
  }
  if (sf.getNumSnapshots() > 0) {
    throw new SnapshotException("The directory " + path + " has snapshot(s). "
        + "Please redo the operation after removing all the snapshots.");
  }

  if (d == fsdir.getRoot()) {
    d.setSnapshotQuota(0);
  } else {
    d.removeSnapshottableFeature();
  }
  removeSnapshottable(d);
}
 
Example 7
Source File: SnapshotFSImageFormat.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Load snapshots and snapshotQuota for a Snapshottable directory.
 *
 * @param snapshottableParent
 *          The snapshottable directory for loading.
 * @param numSnapshots
 *          The number of snapshots that the directory has.
 * @param loader
 *          The loader
 */
public static void loadSnapshotList(INodeDirectory snapshottableParent,
    int numSnapshots, DataInput in, FSImageFormat.Loader loader)
    throws IOException {
  DirectorySnapshottableFeature sf = snapshottableParent
      .getDirectorySnapshottableFeature();
  Preconditions.checkArgument(sf != null);
  for (int i = 0; i < numSnapshots; i++) {
    // read snapshots
    final Snapshot s = loader.getSnapshot(in);
    s.getRoot().setParent(snapshottableParent);
    sf.addSnapshot(s);
  }
  int snapshotQuota = in.readInt();
  snapshottableParent.setSnapshotQuota(snapshotQuota);
}
 
Example 8
Source File: FSImageFormatPBSnapshot.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Load the snapshots section from fsimage. Also add snapshottable feature
 * to snapshottable directories.
 */
public void loadSnapshotSection(InputStream in) throws IOException {
  SnapshotManager sm = fsn.getSnapshotManager();
  SnapshotSection section = SnapshotSection.parseDelimitedFrom(in);
  int snum = section.getNumSnapshots();
  sm.setNumSnapshots(snum);
  sm.setSnapshotCounter(section.getSnapshotCounter());
  for (long sdirId : section.getSnapshottableDirList()) {
    INodeDirectory dir = fsDir.getInode(sdirId).asDirectory();
    if (!dir.isSnapshottable()) {
      dir.addSnapshottableFeature();
    } else {
      // dir is root, and admin set root to snapshottable before
      dir.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_LIMIT);
    }
    sm.addSnapshottable(dir);
  }
  loadSnapshots(in, snum);
}