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

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.INodeDirectory#getId() . 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 5 votes vote down vote up
/**
 * List all the snapshottable directories that are owned by the current user.
 * @param userName Current user name.
 * @return Snapshottable directories that are owned by the current user,
 *         represented as an array of {@link SnapshottableDirectoryStatus}. If
 *         {@code userName} is null, return all the snapshottable dirs.
 */
public SnapshottableDirectoryStatus[] getSnapshottableDirListing(
    String userName) {
  if (snapshottables.isEmpty()) {
    return null;
  }
  
  List<SnapshottableDirectoryStatus> statusList = 
      new ArrayList<SnapshottableDirectoryStatus>();
  for (INodeDirectory dir : snapshottables.values()) {
    if (userName == null || userName.equals(dir.getUserName())) {
      SnapshottableDirectoryStatus status = new SnapshottableDirectoryStatus(
          dir.getModificationTime(), dir.getAccessTime(),
          dir.getFsPermission(), dir.getUserName(), dir.getGroupName(),
          dir.getLocalNameBytes(), dir.getId(), 
          dir.getChildrenNum(Snapshot.CURRENT_STATE_ID),
          dir.getDirectorySnapshottableFeature().getNumSnapshots(),
          dir.getDirectorySnapshottableFeature().getSnapshotQuota(),
          dir.getParent() == null ? DFSUtil.EMPTY_BYTES :
              DFSUtil.string2Bytes(dir.getParent().getFullPathName()));
      statusList.add(status);
    }
  }
  Collections.sort(statusList, SnapshottableDirectoryStatus.COMPARATOR);
  return statusList.toArray(
      new SnapshottableDirectoryStatus[statusList.size()]);
}
 
Example 2
Source File: TestRenameWithSnapshots.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Test rename where the src/dst directories are both snapshottable 
 * directories without snapshots. In such case we need to update the 
 * snapshottable dir list in SnapshotManager.
 */
@Test (timeout=60000)
public void testRenameAndUpdateSnapshottableDirs() throws Exception {
  final Path sdir1 = new Path("/dir1");
  final Path sdir2 = new Path("/dir2");
  final Path foo = new Path(sdir1, "foo");
  final Path bar = new Path(sdir2, "bar");
  hdfs.mkdirs(foo);
  hdfs.mkdirs(bar);
  
  hdfs.allowSnapshot(foo);
  SnapshotTestHelper.createSnapshot(hdfs, bar, snap1);
  assertEquals(2, fsn.getSnapshottableDirListing().length);
  
  INodeDirectory fooNode = fsdir.getINode4Write(foo.toString()).asDirectory();
  long fooId = fooNode.getId();
  
  try {
    hdfs.rename(foo, bar, Rename.OVERWRITE);
    fail("Expect exception since " + bar
        + " is snapshottable and already has snapshots");
  } catch (IOException e) {
    GenericTestUtils.assertExceptionContains(bar.toString()
        + " is snapshottable and already has snapshots", e);
  }
  
  hdfs.deleteSnapshot(bar, snap1);
  hdfs.rename(foo, bar, Rename.OVERWRITE);
  SnapshottableDirectoryStatus[] dirs = fsn.getSnapshottableDirListing();
  assertEquals(1, dirs.length);
  assertEquals(bar, dirs[0].getFullPath());
  assertEquals(fooId, dirs[0].getDirStatus().getFileId());
}
 
Example 3
Source File: SnapshotManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * List all the snapshottable directories that are owned by the current user.
 * @param userName Current user name.
 * @return Snapshottable directories that are owned by the current user,
 *         represented as an array of {@link SnapshottableDirectoryStatus}. If
 *         {@code userName} is null, return all the snapshottable dirs.
 */
public SnapshottableDirectoryStatus[] getSnapshottableDirListing(
    String userName) {
  if (snapshottables.isEmpty()) {
    return null;
  }
  
  List<SnapshottableDirectoryStatus> statusList = 
      new ArrayList<SnapshottableDirectoryStatus>();
  for (INodeDirectory dir : snapshottables.values()) {
    if (userName == null || userName.equals(dir.getUserName())) {
      SnapshottableDirectoryStatus status = new SnapshottableDirectoryStatus(
          dir.getModificationTime(), dir.getAccessTime(),
          dir.getFsPermission(), dir.getUserName(), dir.getGroupName(),
          dir.getLocalNameBytes(), dir.getId(), 
          dir.getChildrenNum(Snapshot.CURRENT_STATE_ID),
          dir.getDirectorySnapshottableFeature().getNumSnapshots(),
          dir.getDirectorySnapshottableFeature().getSnapshotQuota(),
          dir.getParent() == null ? DFSUtil.EMPTY_BYTES :
              DFSUtil.string2Bytes(dir.getParent().getFullPathName()));
      statusList.add(status);
    }
  }
  Collections.sort(statusList, SnapshottableDirectoryStatus.COMPARATOR);
  return statusList.toArray(
      new SnapshottableDirectoryStatus[statusList.size()]);
}
 
Example 4
Source File: TestRenameWithSnapshots.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test rename where the src/dst directories are both snapshottable 
 * directories without snapshots. In such case we need to update the 
 * snapshottable dir list in SnapshotManager.
 */
@Test (timeout=60000)
public void testRenameAndUpdateSnapshottableDirs() throws Exception {
  final Path sdir1 = new Path("/dir1");
  final Path sdir2 = new Path("/dir2");
  final Path foo = new Path(sdir1, "foo");
  final Path bar = new Path(sdir2, "bar");
  hdfs.mkdirs(foo);
  hdfs.mkdirs(bar);
  
  hdfs.allowSnapshot(foo);
  SnapshotTestHelper.createSnapshot(hdfs, bar, snap1);
  assertEquals(2, fsn.getSnapshottableDirListing().length);
  
  INodeDirectory fooNode = fsdir.getINode4Write(foo.toString()).asDirectory();
  long fooId = fooNode.getId();
  
  try {
    hdfs.rename(foo, bar, Rename.OVERWRITE);
    fail("Expect exception since " + bar
        + " is snapshottable and already has snapshots");
  } catch (IOException e) {
    GenericTestUtils.assertExceptionContains(bar.toString()
        + " is snapshottable and already has snapshots", e);
  }
  
  hdfs.deleteSnapshot(bar, snap1);
  hdfs.rename(foo, bar, Rename.OVERWRITE);
  SnapshottableDirectoryStatus[] dirs = fsn.getSnapshottableDirListing();
  assertEquals(1, dirs.length);
  assertEquals(bar, dirs[0].getFullPath());
  assertEquals(fooId, dirs[0].getDirStatus().getFileId());
}