Java 类org.apache.hadoop.hdfs.server.namenode.FsImageProto 实例源码

项目:hadoop    文件:PBImageTextWriter.java   
/**
 * Scan the INodeDirectory section to construct the namespace.
 */
private void buildNamespace(InputStream in, List<Long> refIdList) throws IOException {
  int count = 0;
  while (true) {
    FsImageProto.INodeDirectorySection.DirEntry e =
        FsImageProto.INodeDirectorySection.DirEntry.parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    count++;
    if (LOG.isDebugEnabled() && count % 10000 == 0) {
      LOG.debug("Scanned {} directories.", count);
    }
    long parentId = e.getParent();
    for (int i = 0; i < e.getChildrenCount(); i++) {
      long childId = e.getChildren(i);
      metadataMap.putDirChild(parentId, childId);
    }
    for (int i = e.getChildrenCount();
         i < e.getChildrenCount() + e.getRefChildrenCount(); i++) {
      int refId = e.getRefChildren(i - e.getChildrenCount());
      metadataMap.putDirChild(parentId, refIdList.get(refId));
    }
  }
  LOG.info("Scanned {} INode directories to build namespace.", count);
}
项目:hadoop    文件:FSImageLoader.java   
@Override
public int compare(byte[] o1, byte[] o2) {
  try {
    final FsImageProto.INodeSection.INode l = FsImageProto.INodeSection
            .INode.parseFrom(o1);
    final FsImageProto.INodeSection.INode r = FsImageProto.INodeSection
            .INode.parseFrom(o2);
    if (l.getId() < r.getId()) {
      return -1;
    } else if (l.getId() > r.getId()) {
      return 1;
    } else {
      return 0;
    }
  } catch (InvalidProtocolBufferException e) {
    throw new RuntimeException(e);
  }
}
项目:hadoop    文件:FSImageLoader.java   
static ImmutableList<Long> loadINodeReferenceSection(InputStream in)
    throws IOException {
  LOG.info("Loading inode references");
  ImmutableList.Builder<Long> builder = ImmutableList.builder();
  long counter = 0;
  while (true) {
    FsImageProto.INodeReferenceSection.INodeReference e =
        FsImageProto.INodeReferenceSection.INodeReference
            .parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    ++counter;
    builder.add(e.getReferredId());
  }
  LOG.info("Loaded " + counter + " inode references");
  return builder.build();
}
项目:hadoop    文件:FSImageLoader.java   
private List<Map<String, Object>> getFileStatusList(String path)
        throws IOException {
  List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  if (inode.getType() == FsImageProto.INodeSection.INode.Type.DIRECTORY) {
    if (!dirmap.containsKey(id)) {
      // if the directory is empty, return empty list
      return list;
    }
    long[] children = dirmap.get(id);
    for (long cid : children) {
      list.add(getFileStatus(fromINodeId(cid), true));
    }
  } else {
    list.add(getFileStatus(inode, false));
  }
  return list;
}
项目:hadoop    文件:FSImageLoader.java   
private List<AclEntry> getAclEntryList(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          f.getAcl(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          d.getAcl(), stringTable);
    }
    default: {
      return new ArrayList<AclEntry>();
    }
  }
}
项目:hadoop    文件:FSImageLoader.java   
private PermissionStatus getPermissionStatus(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadPermission(
          f.getPermission(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadPermission(
          d.getPermission(), stringTable);
    }
    case SYMLINK: {
      FsImageProto.INodeSection.INodeSymlink s = inode.getSymlink();
      return FSImageFormatPBINode.Loader.loadPermission(
          s.getPermission(), stringTable);
    }
    default: {
      return null;
    }
  }
}
项目:hadoop    文件:FSImageLoader.java   
private FsImageProto.INodeSection.INode fromINodeId(final long id)
        throws IOException {
  int l = 0, r = inodes.length;
  while (l < r) {
    int mid = l + (r - l) / 2;
    FsImageProto.INodeSection.INode n = FsImageProto.INodeSection.INode
            .parseFrom(inodes[mid]);
    long nid = n.getId();
    if (id > nid) {
      l = mid + 1;
    } else if (id < nid) {
      r = mid;
    } else {
      return n;
    }
  }
  return null;
}
项目:aliyun-oss-hadoop-fs    文件:PBImageTextWriter.java   
/**
 * Scan the INodeDirectory section to construct the namespace.
 */
private void buildNamespace(InputStream in) throws IOException {
  int count = 0;
  while (true) {
    FsImageProto.INodeDirectorySection.DirEntry e =
        FsImageProto.INodeDirectorySection.DirEntry.parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    count++;
    if (LOG.isDebugEnabled() && count % 10000 == 0) {
      LOG.debug("Scanned {} directories.", count);
    }
    long parentId = e.getParent();
    // Referred INode is not support for now.
    for (int i = 0; i < e.getChildrenCount(); i++) {
      long childId = e.getChildren(i);
      metadataMap.putDirChild(parentId, childId);
    }
    Preconditions.checkState(e.getRefChildrenCount() == 0);
  }
  LOG.info("Scanned {} INode directories to build namespace.", count);
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
@Override
public int compare(byte[] o1, byte[] o2) {
  try {
    final FsImageProto.INodeSection.INode l = FsImageProto.INodeSection
            .INode.parseFrom(o1);
    final FsImageProto.INodeSection.INode r = FsImageProto.INodeSection
            .INode.parseFrom(o2);
    if (l.getId() < r.getId()) {
      return -1;
    } else if (l.getId() > r.getId()) {
      return 1;
    } else {
      return 0;
    }
  } catch (InvalidProtocolBufferException e) {
    throw new RuntimeException(e);
  }
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
private static ImmutableList<Long> loadINodeReferenceSection(InputStream in)
    throws IOException {
  LOG.info("Loading inode references");
  ImmutableList.Builder<Long> builder = ImmutableList.builder();
  long counter = 0;
  while (true) {
    FsImageProto.INodeReferenceSection.INodeReference e =
        FsImageProto.INodeReferenceSection.INodeReference
            .parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    ++counter;
    builder.add(e.getReferredId());
  }
  LOG.info("Loaded " + counter + " inode references");
  return builder.build();
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
private List<Map<String, Object>> getFileStatusList(String path)
        throws IOException {
  List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  if (inode.getType() == FsImageProto.INodeSection.INode.Type.DIRECTORY) {
    if (!dirmap.containsKey(id)) {
      // if the directory is empty, return empty list
      return list;
    }
    long[] children = dirmap.get(id);
    for (long cid : children) {
      list.add(getFileStatus(fromINodeId(cid), true));
    }
  } else {
    list.add(getFileStatus(inode, false));
  }
  return list;
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
private List<AclEntry> getAclEntryList(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          f.getAcl(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          d.getAcl(), stringTable);
    }
    default: {
      return new ArrayList<AclEntry>();
    }
  }
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
private PermissionStatus getPermissionStatus(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadPermission(
          f.getPermission(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadPermission(
          d.getPermission(), stringTable);
    }
    case SYMLINK: {
      FsImageProto.INodeSection.INodeSymlink s = inode.getSymlink();
      return FSImageFormatPBINode.Loader.loadPermission(
          s.getPermission(), stringTable);
    }
    default: {
      return null;
    }
  }
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
private FsImageProto.INodeSection.INode fromINodeId(final long id)
        throws IOException {
  int l = 0, r = inodes.length;
  while (l < r) {
    int mid = l + (r - l) / 2;
    FsImageProto.INodeSection.INode n = FsImageProto.INodeSection.INode
            .parseFrom(inodes[mid]);
    long nid = n.getId();
    if (id > nid) {
      l = mid + 1;
    } else if (id < nid) {
      r = mid;
    } else {
      return n;
    }
  }
  return null;
}
项目:big-c    文件:PBImageTextWriter.java   
/**
 * Scan the INodeDirectory section to construct the namespace.
 */
private void buildNamespace(InputStream in) throws IOException {
  int count = 0;
  while (true) {
    FsImageProto.INodeDirectorySection.DirEntry e =
        FsImageProto.INodeDirectorySection.DirEntry.parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    count++;
    if (LOG.isDebugEnabled() && count % 10000 == 0) {
      LOG.debug("Scanned {} directories.", count);
    }
    long parentId = e.getParent();
    // Referred INode is not support for now.
    for (int i = 0; i < e.getChildrenCount(); i++) {
      long childId = e.getChildren(i);
      metadataMap.putDirChild(parentId, childId);
    }
    Preconditions.checkState(e.getRefChildrenCount() == 0);
  }
  LOG.info("Scanned {} INode directories to build namespace.", count);
}
项目:big-c    文件:FSImageLoader.java   
@Override
public int compare(byte[] o1, byte[] o2) {
  try {
    final FsImageProto.INodeSection.INode l = FsImageProto.INodeSection
            .INode.parseFrom(o1);
    final FsImageProto.INodeSection.INode r = FsImageProto.INodeSection
            .INode.parseFrom(o2);
    if (l.getId() < r.getId()) {
      return -1;
    } else if (l.getId() > r.getId()) {
      return 1;
    } else {
      return 0;
    }
  } catch (InvalidProtocolBufferException e) {
    throw new RuntimeException(e);
  }
}
项目:big-c    文件:FSImageLoader.java   
private static ImmutableList<Long> loadINodeReferenceSection(InputStream in)
    throws IOException {
  LOG.info("Loading inode references");
  ImmutableList.Builder<Long> builder = ImmutableList.builder();
  long counter = 0;
  while (true) {
    FsImageProto.INodeReferenceSection.INodeReference e =
        FsImageProto.INodeReferenceSection.INodeReference
            .parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    ++counter;
    builder.add(e.getReferredId());
  }
  LOG.info("Loaded " + counter + " inode references");
  return builder.build();
}
项目:big-c    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:big-c    文件:FSImageLoader.java   
private List<Map<String, Object>> getFileStatusList(String path)
        throws IOException {
  List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  if (inode.getType() == FsImageProto.INodeSection.INode.Type.DIRECTORY) {
    if (!dirmap.containsKey(id)) {
      // if the directory is empty, return empty list
      return list;
    }
    long[] children = dirmap.get(id);
    for (long cid : children) {
      list.add(getFileStatus(fromINodeId(cid), true));
    }
  } else {
    list.add(getFileStatus(inode, false));
  }
  return list;
}
项目:big-c    文件:FSImageLoader.java   
private List<AclEntry> getAclEntryList(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          f.getAcl(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          d.getAcl(), stringTable);
    }
    default: {
      return new ArrayList<AclEntry>();
    }
  }
}
项目:big-c    文件:FSImageLoader.java   
private PermissionStatus getPermissionStatus(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadPermission(
          f.getPermission(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadPermission(
          d.getPermission(), stringTable);
    }
    case SYMLINK: {
      FsImageProto.INodeSection.INodeSymlink s = inode.getSymlink();
      return FSImageFormatPBINode.Loader.loadPermission(
          s.getPermission(), stringTable);
    }
    default: {
      return null;
    }
  }
}
项目:big-c    文件:FSImageLoader.java   
private FsImageProto.INodeSection.INode fromINodeId(final long id)
        throws IOException {
  int l = 0, r = inodes.length;
  while (l < r) {
    int mid = l + (r - l) / 2;
    FsImageProto.INodeSection.INode n = FsImageProto.INodeSection.INode
            .parseFrom(inodes[mid]);
    long nid = n.getId();
    if (id > nid) {
      l = mid + 1;
    } else if (id < nid) {
      r = mid;
    } else {
      return n;
    }
  }
  return null;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:PBImageTextWriter.java   
/**
 * Scan the INodeDirectory section to construct the namespace.
 */
private void buildNamespace(InputStream in) throws IOException {
  int count = 0;
  while (true) {
    FsImageProto.INodeDirectorySection.DirEntry e =
        FsImageProto.INodeDirectorySection.DirEntry.parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    count++;
    if (LOG.isDebugEnabled() && count % 10000 == 0) {
      LOG.debug("Scanned {} directories.", count);
    }
    long parentId = e.getParent();
    // Referred INode is not support for now.
    for (int i = 0; i < e.getChildrenCount(); i++) {
      long childId = e.getChildren(i);
      metadataMap.putDirChild(parentId, childId);
    }
    Preconditions.checkState(e.getRefChildrenCount() == 0);
  }
  LOG.info("Scanned {} INode directories to build namespace.", count);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
@Override
public int compare(byte[] o1, byte[] o2) {
  try {
    final FsImageProto.INodeSection.INode l = FsImageProto.INodeSection
            .INode.parseFrom(o1);
    final FsImageProto.INodeSection.INode r = FsImageProto.INodeSection
            .INode.parseFrom(o2);
    if (l.getId() < r.getId()) {
      return -1;
    } else if (l.getId() > r.getId()) {
      return 1;
    } else {
      return 0;
    }
  } catch (InvalidProtocolBufferException e) {
    throw new RuntimeException(e);
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
private static ImmutableList<Long> loadINodeReferenceSection(InputStream in)
    throws IOException {
  LOG.info("Loading inode references");
  ImmutableList.Builder<Long> builder = ImmutableList.builder();
  long counter = 0;
  while (true) {
    FsImageProto.INodeReferenceSection.INodeReference e =
        FsImageProto.INodeReferenceSection.INodeReference
            .parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    ++counter;
    builder.add(e.getReferredId());
  }
  LOG.info("Loaded " + counter + " inode references");
  return builder.build();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
private List<Map<String, Object>> getFileStatusList(String path)
        throws IOException {
  List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  if (inode.getType() == FsImageProto.INodeSection.INode.Type.DIRECTORY) {
    if (!dirmap.containsKey(id)) {
      // if the directory is empty, return empty list
      return list;
    }
    long[] children = dirmap.get(id);
    for (long cid : children) {
      list.add(getFileStatus(fromINodeId(cid), true));
    }
  } else {
    list.add(getFileStatus(inode, false));
  }
  return list;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
private List<AclEntry> getAclEntryList(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          f.getAcl(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          d.getAcl(), stringTable);
    }
    default: {
      return new ArrayList<AclEntry>();
    }
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
private PermissionStatus getPermissionStatus(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadPermission(
          f.getPermission(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadPermission(
          d.getPermission(), stringTable);
    }
    case SYMLINK: {
      FsImageProto.INodeSection.INodeSymlink s = inode.getSymlink();
      return FSImageFormatPBINode.Loader.loadPermission(
          s.getPermission(), stringTable);
    }
    default: {
      return null;
    }
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
private FsImageProto.INodeSection.INode fromINodeId(final long id)
        throws IOException {
  int l = 0, r = inodes.length;
  while (l < r) {
    int mid = l + (r - l) / 2;
    FsImageProto.INodeSection.INode n = FsImageProto.INodeSection.INode
            .parseFrom(inodes[mid]);
    long nid = n.getId();
    if (id > nid) {
      l = mid + 1;
    } else if (id < nid) {
      r = mid;
    } else {
      return n;
    }
  }
  return null;
}
项目:FlexMap    文件:FSImageLoader.java   
@Override
public int compare(byte[] o1, byte[] o2) {
  try {
    final FsImageProto.INodeSection.INode l = FsImageProto.INodeSection
            .INode.parseFrom(o1);
    final FsImageProto.INodeSection.INode r = FsImageProto.INodeSection
            .INode.parseFrom(o2);
    if (l.getId() < r.getId()) {
      return -1;
    } else if (l.getId() > r.getId()) {
      return 1;
    } else {
      return 0;
    }
  } catch (InvalidProtocolBufferException e) {
    throw new RuntimeException(e);
  }
}
项目:FlexMap    文件:FSImageLoader.java   
private static ImmutableList<Long> loadINodeReferenceSection(InputStream in)
    throws IOException {
  LOG.info("Loading inode references");
  ImmutableList.Builder<Long> builder = ImmutableList.builder();
  long counter = 0;
  while (true) {
    FsImageProto.INodeReferenceSection.INodeReference e =
        FsImageProto.INodeReferenceSection.INodeReference
            .parseDelimitedFrom(in);
    if (e == null) {
      break;
    }
    ++counter;
    builder.add(e.getReferredId());
  }
  LOG.info("Loaded " + counter + " inode references");
  return builder.build();
}
项目:FlexMap    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:FlexMap    文件:FSImageLoader.java   
private List<Map<String, Object>> getFileStatusList(String path)
        throws IOException {
  List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  if (inode.getType() == FsImageProto.INodeSection.INode.Type.DIRECTORY) {
    if (!dirmap.containsKey(id)) {
      // if the directory is empty, return empty list
      return list;
    }
    long[] children = dirmap.get(id);
    for (long cid : children) {
      list.add(getFileStatus(fromINodeId(cid), true));
    }
  } else {
    list.add(getFileStatus(inode, false));
  }
  return list;
}
项目:FlexMap    文件:FSImageLoader.java   
private List<AclEntry> getAclEntryList(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          f.getAcl(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadAclEntries(
          d.getAcl(), stringTable);
    }
    default: {
      return new ArrayList<AclEntry>();
    }
  }
}
项目:FlexMap    文件:FSImageLoader.java   
private PermissionStatus getPermissionStatus(String path) throws IOException {
  long id = lookup(path);
  FsImageProto.INodeSection.INode inode = fromINodeId(id);
  switch (inode.getType()) {
    case FILE: {
      FsImageProto.INodeSection.INodeFile f = inode.getFile();
      return FSImageFormatPBINode.Loader.loadPermission(
          f.getPermission(), stringTable);
    }
    case DIRECTORY: {
      FsImageProto.INodeSection.INodeDirectory d = inode.getDirectory();
      return FSImageFormatPBINode.Loader.loadPermission(
          d.getPermission(), stringTable);
    }
    case SYMLINK: {
      FsImageProto.INodeSection.INodeSymlink s = inode.getSymlink();
      return FSImageFormatPBINode.Loader.loadPermission(
          s.getPermission(), stringTable);
    }
    default: {
      return null;
    }
  }
}
项目:FlexMap    文件:FSImageLoader.java   
private FsImageProto.INodeSection.INode fromINodeId(final long id)
        throws IOException {
  int l = 0, r = inodes.length;
  while (l < r) {
    int mid = l + (r - l) / 2;
    FsImageProto.INodeSection.INode n = FsImageProto.INodeSection.INode
            .parseFrom(inodes[mid]);
    long nid = n.getId();
    if (id > nid) {
      l = mid + 1;
    } else if (id < nid) {
      r = mid;
    } else {
      return n;
    }
  }
  return null;
}
项目:hadoop    文件:FSImageLoader.java   
private static Map<Long, long[]> loadINodeDirectorySection
        (InputStream in, List<Long> refIdList)
    throws IOException {
  LOG.info("Loading inode directory section");
  Map<Long, long[]> dirs = Maps.newHashMap();
  long counter = 0;
  while (true) {
    FsImageProto.INodeDirectorySection.DirEntry e =
        FsImageProto.INodeDirectorySection.DirEntry.parseDelimitedFrom(in);
    // note that in is a LimitedInputStream
    if (e == null) {
      break;
    }
    ++counter;

    long[] l = new long[e.getChildrenCount() + e.getRefChildrenCount()];
    for (int i = 0; i < e.getChildrenCount(); ++i) {
      l[i] = e.getChildren(i);
    }
    for (int i = e.getChildrenCount(); i < l.length; i++) {
      int refId = e.getRefChildren(i - e.getChildrenCount());
      l[i] = refIdList.get(refId);
    }
    dirs.put(e.getParent(), l);
  }
  LOG.info("Loaded " + counter + " directories");
  return dirs;
}
项目:hadoop    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}