org.apache.hadoop.hdfs.server.namenode.FSImageSerialization Java Examples

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.FSImageSerialization. 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: SnapshotFSImageFormat.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void writeINodeReferenceWithCount(
    INodeReference.WithCount withCount, DataOutput out,
    boolean writeUnderConstruction) throws IOException {
  final INode referred = withCount.getReferredINode();
  final long id = withCount.getId();
  final boolean firstReferred = !referenceMap.containsKey(id);
  out.writeBoolean(firstReferred);

  if (firstReferred) {
    FSImageSerialization.saveINode2Image(referred, out,
        writeUnderConstruction, this);
    referenceMap.put(id, withCount);
  } else {
    out.writeLong(id);
  }
}
 
Example #2
Source File: DirectoryWithSnapshotFeature.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
void write(DataOutput out, ReferenceMap referenceMap) throws IOException {
  writeSnapshot(out);
  out.writeInt(childrenSize);

  // Write snapshotINode
  out.writeBoolean(isSnapshotRoot);
  if (!isSnapshotRoot) {
    if (snapshotINode != null) {
      out.writeBoolean(true);
      FSImageSerialization.writeINodeDirectoryAttributes(snapshotINode, out);
    } else {
      out.writeBoolean(false);
    }
  }
  // Write diff. Node need to write poseriorDiff, since diffs is a list.
  diff.write(out, referenceMap);
}
 
Example #3
Source File: DirectoryWithSnapshotFeature.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
void write(DataOutput out, ReferenceMap referenceMap) throws IOException {
  writeSnapshot(out);
  out.writeInt(childrenSize);

  // Write snapshotINode
  out.writeBoolean(isSnapshotRoot);
  if (!isSnapshotRoot) {
    if (snapshotINode != null) {
      out.writeBoolean(true);
      FSImageSerialization.writeINodeDirectoryAttributes(snapshotINode, out);
    } else {
      out.writeBoolean(false);
    }
  }
  // Write diff. Node need to write poseriorDiff, since diffs is a list.
  diff.write(out, referenceMap);
}
 
Example #4
Source File: SnapshotFSImageFormat.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void writeINodeReferenceWithCount(
    INodeReference.WithCount withCount, DataOutput out,
    boolean writeUnderConstruction) throws IOException {
  final INode referred = withCount.getReferredINode();
  final long id = withCount.getId();
  final boolean firstReferred = !referenceMap.containsKey(id);
  out.writeBoolean(firstReferred);

  if (firstReferred) {
    FSImageSerialization.saveINode2Image(referred, out,
        writeUnderConstruction, this);
    referenceMap.put(id, withCount);
  } else {
    out.writeLong(id);
  }
}
 
Example #5
Source File: SnapshotFSImageFormat.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Load the created list from fsimage.
 * @param parent The directory that the created list belongs to.
 * @param in The {@link DataInput} to read.
 * @return The created list.
 */
private static List<INode> loadCreatedList(INodeDirectory parent,
    DataInput in) throws IOException {
  // read the size of the created list
  int createdSize = in.readInt();
  List<INode> createdList = new ArrayList<INode>(createdSize);
  for (int i = 0; i < createdSize; i++) {
    byte[] createdNodeName = FSImageSerialization.readLocalName(in);
    INode created = loadCreated(createdNodeName, parent);
    createdList.add(created);
  }
  return createdList;
}
 
Example #6
Source File: ImageLoaderCurrent.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
  * Process an INode
  * 
  * @param in image stream
  * @param v visitor
  * @param skipBlocks skip blocks or not
  * @param parentName the name of its parent node
  * @throws IOException
  */
private void processINode(DataInputStream in, ImageVisitor v,
    boolean skipBlocks, String parentName) throws IOException {
  v.visitEnclosingElement(ImageElement.INODE);
  String pathName = FSImageSerialization.readString(in);
  if (parentName != null) {  // local name
    pathName = "/" + pathName;
    if (!"/".equals(parentName)) { // children of non-root directory
      pathName = parentName + pathName;
    }
  }

  v.visit(ImageElement.INODE_PATH, pathName);
  v.visit(ImageElement.REPLICATION, in.readShort());
  v.visit(ImageElement.MODIFICATION_TIME, formatDate(in.readLong()));
  if(LayoutVersion.supports(Feature.FILE_ACCESS_TIME, imageVersion))
    v.visit(ImageElement.ACCESS_TIME, formatDate(in.readLong()));
  v.visit(ImageElement.BLOCK_SIZE, in.readLong());
  int numBlocks = in.readInt();

  processBlocks(in, v, numBlocks, skipBlocks);

  // File or directory
  if (numBlocks > 0 || numBlocks == -1) {
    v.visit(ImageElement.NS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
    if (LayoutVersion.supports(Feature.DISKSPACE_QUOTA, imageVersion))
      v.visit(ImageElement.DS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
  }
  if (numBlocks == -2) {
    v.visit(ImageElement.SYMLINK, Text.readString(in));
  }

  processPermission(in, v);
  v.leaveEnclosingElement(); // INode
}
 
Example #7
Source File: ImageLoaderCurrent.java    From RDFS with Apache License 2.0 5 votes vote down vote up
private int processDirectory(DataInputStream in, ImageVisitor v,
   boolean skipBlocks) throws IOException {
  String parentName = FSImageSerialization.readString(in);
  int numChildren = in.readInt();
  for (int i=0; i<numChildren; i++) {
    processINode(in, v, skipBlocks, parentName);
  }
  return numChildren;
}
 
Example #8
Source File: ImageLoaderCurrent.java    From big-c with Apache License 2.0 5 votes vote down vote up
private String readINodePath(DataInputStream in, String parentName)
    throws IOException {
  String pathName = FSImageSerialization.readString(in);
  if (parentName != null) {  // local name
    pathName = "/" + pathName;
    if (!"/".equals(parentName)) { // children of non-root directory
      pathName = parentName + pathName;
    }
  }
  return pathName;
}
 
Example #9
Source File: DirectoryWithSnapshotFeature.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Serialize {@link #deleted} */
private void writeDeleted(DataOutput out,
    ReferenceMap referenceMap) throws IOException {
  final List<INode> deleted = getList(ListType.DELETED);
  out.writeInt(deleted.size());
  for (INode node : deleted) {
    FSImageSerialization.saveINode2Image(node, out, true, referenceMap);
  }
}
 
Example #10
Source File: FileDiff.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
void write(DataOutput out, ReferenceMap referenceMap) throws IOException {
  writeSnapshot(out);
  out.writeLong(fileSize);

  // write snapshotINode
  if (snapshotINode != null) {
    out.writeBoolean(true);
    FSImageSerialization.writeINodeFileAttributes(snapshotINode, out);
  } else {
    out.writeBoolean(false);
  }
}
 
Example #11
Source File: ImageLoaderCurrent.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private String readINodePath(DataInputStream in, String parentName)
    throws IOException {
  String pathName = FSImageSerialization.readString(in);
  if (parentName != null) {  // local name
    pathName = "/" + pathName;
    if (!"/".equals(parentName)) { // children of non-root directory
      pathName = parentName + pathName;
    }
  }
  return pathName;
}
 
Example #12
Source File: DirectoryWithSnapshotFeature.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Serialize {@link #deleted} */
private void writeDeleted(DataOutput out,
    ReferenceMap referenceMap) throws IOException {
  final List<INode> deleted = getList(ListType.DELETED);
  out.writeInt(deleted.size());
  for (INode node : deleted) {
    FSImageSerialization.saveINode2Image(node, out, true, referenceMap);
  }
}
 
Example #13
Source File: FileDiff.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
void write(DataOutput out, ReferenceMap referenceMap) throws IOException {
  writeSnapshot(out);
  out.writeLong(fileSize);

  // write snapshotINode
  if (snapshotINode != null) {
    out.writeBoolean(true);
    FSImageSerialization.writeINodeFileAttributes(snapshotINode, out);
  } else {
    out.writeBoolean(false);
  }
}
 
Example #14
Source File: SnapshotFSImageFormat.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Load the created list from fsimage.
 * @param parent The directory that the created list belongs to.
 * @param in The {@link DataInput} to read.
 * @return The created list.
 */
private static List<INode> loadCreatedList(INodeDirectory parent,
    DataInput in) throws IOException {
  // read the size of the created list
  int createdSize = in.readInt();
  List<INode> createdList = new ArrayList<INode>(createdSize);
  for (int i = 0; i < createdSize; i++) {
    byte[] createdNodeName = FSImageSerialization.readLocalName(in);
    INode created = loadCreated(createdNodeName, parent);
    createdList.add(created);
  }
  return createdList;
}
 
Example #15
Source File: ImageLoaderCurrent.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Process an INode
 * 
 * @param in image stream
 * @param v visitor
 * @param skipBlocks skip blocks or not
 * @param parentName the name of its parent node
 * @param isSnapshotCopy whether or not the inode is a snapshot copy
 * @throws IOException
 */
private void processINode(DataInputStream in, ImageVisitor v,
    boolean skipBlocks, String parentName, boolean isSnapshotCopy)
    throws IOException {
  boolean supportSnapshot = 
      NameNodeLayoutVersion.supports(Feature.SNAPSHOT, imageVersion);
  boolean supportInodeId = 
      NameNodeLayoutVersion.supports(Feature.ADD_INODE_ID, imageVersion);
  
  v.visitEnclosingElement(ImageElement.INODE);
  final String pathName = readINodePath(in, parentName);
  v.visit(ImageElement.INODE_PATH, pathName);

  long inodeId = INodeId.GRANDFATHER_INODE_ID;
  if (supportInodeId) {
    inodeId = in.readLong();
    v.visit(ImageElement.INODE_ID, inodeId);
  }
  v.visit(ImageElement.REPLICATION, in.readShort());
  v.visit(ImageElement.MODIFICATION_TIME, formatDate(in.readLong()));
  if(NameNodeLayoutVersion.supports(Feature.FILE_ACCESS_TIME, imageVersion))
    v.visit(ImageElement.ACCESS_TIME, formatDate(in.readLong()));
  v.visit(ImageElement.BLOCK_SIZE, in.readLong());
  int numBlocks = in.readInt();

  processBlocks(in, v, numBlocks, skipBlocks);
  
  if (numBlocks >= 0) { // File
    if (supportSnapshot) {
      // make sure subtreeMap only contains entry for directory
      subtreeMap.remove(inodeId);
      // process file diffs
      processFileDiffList(in, v, parentName);
      if (isSnapshotCopy) {
        boolean underConstruction = in.readBoolean();
        if (underConstruction) {
          v.visit(ImageElement.CLIENT_NAME,
              FSImageSerialization.readString(in));
          v.visit(ImageElement.CLIENT_MACHINE,
              FSImageSerialization.readString(in));
        }
      }
    }
    processPermission(in, v);
  } else if (numBlocks == -1) { // Directory
    if (supportSnapshot && supportInodeId) {
      dirNodeMap.put(inodeId, pathName);
    }
    v.visit(ImageElement.NS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
    if (NameNodeLayoutVersion.supports(Feature.DISKSPACE_QUOTA, imageVersion))
      v.visit(ImageElement.DS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
    if (supportSnapshot) {
      boolean snapshottable = in.readBoolean();
      if (!snapshottable) {
        boolean withSnapshot = in.readBoolean();
        v.visit(ImageElement.IS_WITHSNAPSHOT_DIR, Boolean.toString(withSnapshot));
      } else {
        v.visit(ImageElement.IS_SNAPSHOTTABLE_DIR, Boolean.toString(snapshottable));
      }
    }
    processPermission(in, v);
  } else if (numBlocks == -2) {
    v.visit(ImageElement.SYMLINK, Text.readString(in));
    processPermission(in, v);
  } else if (numBlocks == -3) { // reference node
    final boolean isWithName = in.readBoolean();
    int snapshotId = in.readInt();
    if (isWithName) {
      v.visit(ImageElement.SNAPSHOT_LAST_SNAPSHOT_ID, snapshotId);
    } else {
      v.visit(ImageElement.SNAPSHOT_DST_SNAPSHOT_ID, snapshotId);
    }
    
    final boolean firstReferred = in.readBoolean();
    if (firstReferred) {
      // if a subtree is linked by multiple "parents", the corresponding dir
      // must be referred by a reference node. we put the reference node into
      // the subtreeMap here and let its value be false. when we later visit
      // the subtree for the first time, we change the value to true.
      subtreeMap.put(inodeId, false);
      v.visitEnclosingElement(ImageElement.SNAPSHOT_REF_INODE);
      processINode(in, v, skipBlocks, parentName, isSnapshotCopy);
      v.leaveEnclosingElement();  // referred inode    
    } else {
      v.visit(ImageElement.SNAPSHOT_REF_INODE_ID, in.readLong());
    }
  }

  v.leaveEnclosingElement(); // INode
}
 
Example #16
Source File: Snapshot.java    From big-c with Apache License 2.0 4 votes vote down vote up
/** Serialize the fields to out */
void write(DataOutput out) throws IOException {
  out.writeInt(id);
  // write root
  FSImageSerialization.writeINodeDirectory(root, out);
}
 
Example #17
Source File: Snapshot.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/** Serialize the fields to out */
void write(DataOutput out) throws IOException {
  out.writeInt(id);
  // write root
  FSImageSerialization.writeINodeDirectory(root, out);
}
 
Example #18
Source File: ImageLoaderCurrent.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void processDirectoryDiff(DataInputStream in, ImageVisitor v,
    String currentINodeName) throws IOException {
  v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF);
  int snapshotId = in.readInt();
  v.visit(ImageElement.SNAPSHOT_DIFF_SNAPSHOTID, snapshotId);
  v.visit(ImageElement.SNAPSHOT_DIR_DIFF_CHILDREN_SIZE, in.readInt());
  
  // process snapshotINode
  boolean useRoot = in.readBoolean();
  if (!useRoot) {
    if (in.readBoolean()) {
      v.visitEnclosingElement(ImageElement.SNAPSHOT_INODE_DIRECTORY_ATTRIBUTES);
      if (NameNodeLayoutVersion.supports(Feature.OPTIMIZE_SNAPSHOT_INODES, imageVersion)) {
        processINodeDirectoryAttributes(in, v, currentINodeName);
      } else {
        processINode(in, v, true, currentINodeName, true);
      }
      v.leaveEnclosingElement();
    }
  }
  
  // process createdList
  int createdSize = in.readInt();
  v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF_CREATEDLIST,
      ImageElement.SNAPSHOT_DIR_DIFF_CREATEDLIST_SIZE, createdSize);
  for (int i = 0; i < createdSize; i++) {
    String createdNode = FSImageSerialization.readString(in);
    v.visit(ImageElement.SNAPSHOT_DIR_DIFF_CREATED_INODE, createdNode);
  }
  v.leaveEnclosingElement();
  
  // process deletedList
  int deletedSize = in.readInt();
  v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF_DELETEDLIST,
      ImageElement.SNAPSHOT_DIR_DIFF_DELETEDLIST_SIZE, deletedSize);
  for (int i = 0; i < deletedSize; i++) {
    v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF_DELETED_INODE);
    processINode(in, v, false, currentINodeName, true);
    v.leaveEnclosingElement();
  }
  v.leaveEnclosingElement();
  v.leaveEnclosingElement();
}
 
Example #19
Source File: ImageLoaderCurrent.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private int processDirectory(DataInputStream in, ImageVisitor v,
   boolean skipBlocks) throws IOException {
  String parentName = FSImageSerialization.readString(in);
  return processChildren(in, v, skipBlocks, parentName);
}
 
Example #20
Source File: ImageLoaderCurrent.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Process the INodes under construction section of the fsimage.
 *
 * @param in DataInputStream to process
 * @param v Visitor to walk over inodes
 * @param skipBlocks Walk over each block?
 */
private void processINodesUC(DataInputStream in, ImageVisitor v,
    boolean skipBlocks) throws IOException {
  int numINUC = in.readInt();

  v.visitEnclosingElement(ImageElement.INODES_UNDER_CONSTRUCTION,
                         ImageElement.NUM_INODES_UNDER_CONSTRUCTION, numINUC);

  for(int i = 0; i < numINUC; i++) {
    v.visitEnclosingElement(ImageElement.INODE_UNDER_CONSTRUCTION);
    byte [] name = FSImageSerialization.readBytes(in);
    String n = new String(name, "UTF8");
    v.visit(ImageElement.INODE_PATH, n);
    
    if (NameNodeLayoutVersion.supports(Feature.ADD_INODE_ID, imageVersion)) {
      long inodeId = in.readLong();
      v.visit(ImageElement.INODE_ID, inodeId);
    }
    
    v.visit(ImageElement.REPLICATION, in.readShort());
    v.visit(ImageElement.MODIFICATION_TIME, formatDate(in.readLong()));

    v.visit(ImageElement.PREFERRED_BLOCK_SIZE, in.readLong());
    int numBlocks = in.readInt();
    processBlocks(in, v, numBlocks, skipBlocks);

    processPermission(in, v);
    v.visit(ImageElement.CLIENT_NAME, FSImageSerialization.readString(in));
    v.visit(ImageElement.CLIENT_MACHINE, FSImageSerialization.readString(in));

    // Skip over the datanode descriptors, which are still stored in the
    // file but are not used by the datanode or loaded into memory
    int numLocs = in.readInt();
    for(int j = 0; j < numLocs; j++) {
      in.readShort();
      in.readLong();
      in.readLong();
      in.readLong();
      in.readInt();
      FSImageSerialization.readString(in);
      FSImageSerialization.readString(in);
      WritableUtils.readEnum(in, AdminStates.class);
    }

    v.leaveEnclosingElement(); // INodeUnderConstruction
  }

  v.leaveEnclosingElement(); // INodesUnderConstruction
}
 
Example #21
Source File: ImageLoaderCurrent.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Process the INodes under construction section of the fsimage.
 *
 * @param in DataInputStream to process
 * @param v Visitor to walk over inodes
 * @param skipBlocks Walk over each block?
 */
private void processINodesUC(DataInputStream in, ImageVisitor v,
    boolean skipBlocks) throws IOException {
  int numINUC = in.readInt();

  v.visitEnclosingElement(ImageElement.INODES_UNDER_CONSTRUCTION,
                         ImageElement.NUM_INODES_UNDER_CONSTRUCTION, numINUC);

  for(int i = 0; i < numINUC; i++) {
    v.visitEnclosingElement(ImageElement.INODE_UNDER_CONSTRUCTION);
    byte [] name = FSImageSerialization.readBytes(in);
    String n = new String(name, "UTF8");
    v.visit(ImageElement.INODE_PATH, n);
    
    if (NameNodeLayoutVersion.supports(Feature.ADD_INODE_ID, imageVersion)) {
      long inodeId = in.readLong();
      v.visit(ImageElement.INODE_ID, inodeId);
    }
    
    v.visit(ImageElement.REPLICATION, in.readShort());
    v.visit(ImageElement.MODIFICATION_TIME, formatDate(in.readLong()));

    v.visit(ImageElement.PREFERRED_BLOCK_SIZE, in.readLong());
    int numBlocks = in.readInt();
    processBlocks(in, v, numBlocks, skipBlocks);

    processPermission(in, v);
    v.visit(ImageElement.CLIENT_NAME, FSImageSerialization.readString(in));
    v.visit(ImageElement.CLIENT_MACHINE, FSImageSerialization.readString(in));

    // Skip over the datanode descriptors, which are still stored in the
    // file but are not used by the datanode or loaded into memory
    int numLocs = in.readInt();
    for(int j = 0; j < numLocs; j++) {
      in.readShort();
      in.readLong();
      in.readLong();
      in.readLong();
      in.readInt();
      FSImageSerialization.readString(in);
      FSImageSerialization.readString(in);
      WritableUtils.readEnum(in, AdminStates.class);
    }

    v.leaveEnclosingElement(); // INodeUnderConstruction
  }

  v.leaveEnclosingElement(); // INodesUnderConstruction
}
 
Example #22
Source File: ImageLoaderCurrent.java    From big-c with Apache License 2.0 4 votes vote down vote up
private int processDirectory(DataInputStream in, ImageVisitor v,
   boolean skipBlocks) throws IOException {
  String parentName = FSImageSerialization.readString(in);
  return processChildren(in, v, skipBlocks, parentName);
}
 
Example #23
Source File: ImageLoaderCurrent.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void processDirectoryDiff(DataInputStream in, ImageVisitor v,
    String currentINodeName) throws IOException {
  v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF);
  int snapshotId = in.readInt();
  v.visit(ImageElement.SNAPSHOT_DIFF_SNAPSHOTID, snapshotId);
  v.visit(ImageElement.SNAPSHOT_DIR_DIFF_CHILDREN_SIZE, in.readInt());
  
  // process snapshotINode
  boolean useRoot = in.readBoolean();
  if (!useRoot) {
    if (in.readBoolean()) {
      v.visitEnclosingElement(ImageElement.SNAPSHOT_INODE_DIRECTORY_ATTRIBUTES);
      if (NameNodeLayoutVersion.supports(Feature.OPTIMIZE_SNAPSHOT_INODES, imageVersion)) {
        processINodeDirectoryAttributes(in, v, currentINodeName);
      } else {
        processINode(in, v, true, currentINodeName, true);
      }
      v.leaveEnclosingElement();
    }
  }
  
  // process createdList
  int createdSize = in.readInt();
  v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF_CREATEDLIST,
      ImageElement.SNAPSHOT_DIR_DIFF_CREATEDLIST_SIZE, createdSize);
  for (int i = 0; i < createdSize; i++) {
    String createdNode = FSImageSerialization.readString(in);
    v.visit(ImageElement.SNAPSHOT_DIR_DIFF_CREATED_INODE, createdNode);
  }
  v.leaveEnclosingElement();
  
  // process deletedList
  int deletedSize = in.readInt();
  v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF_DELETEDLIST,
      ImageElement.SNAPSHOT_DIR_DIFF_DELETEDLIST_SIZE, deletedSize);
  for (int i = 0; i < deletedSize; i++) {
    v.visitEnclosingElement(ImageElement.SNAPSHOT_DIR_DIFF_DELETED_INODE);
    processINode(in, v, false, currentINodeName, true);
    v.leaveEnclosingElement();
  }
  v.leaveEnclosingElement();
  v.leaveEnclosingElement();
}
 
Example #24
Source File: ImageLoaderCurrent.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Process an INode
 * 
 * @param in image stream
 * @param v visitor
 * @param skipBlocks skip blocks or not
 * @param parentName the name of its parent node
 * @param isSnapshotCopy whether or not the inode is a snapshot copy
 * @throws IOException
 */
private void processINode(DataInputStream in, ImageVisitor v,
    boolean skipBlocks, String parentName, boolean isSnapshotCopy)
    throws IOException {
  boolean supportSnapshot = 
      NameNodeLayoutVersion.supports(Feature.SNAPSHOT, imageVersion);
  boolean supportInodeId = 
      NameNodeLayoutVersion.supports(Feature.ADD_INODE_ID, imageVersion);
  
  v.visitEnclosingElement(ImageElement.INODE);
  final String pathName = readINodePath(in, parentName);
  v.visit(ImageElement.INODE_PATH, pathName);

  long inodeId = INodeId.GRANDFATHER_INODE_ID;
  if (supportInodeId) {
    inodeId = in.readLong();
    v.visit(ImageElement.INODE_ID, inodeId);
  }
  v.visit(ImageElement.REPLICATION, in.readShort());
  v.visit(ImageElement.MODIFICATION_TIME, formatDate(in.readLong()));
  if(NameNodeLayoutVersion.supports(Feature.FILE_ACCESS_TIME, imageVersion))
    v.visit(ImageElement.ACCESS_TIME, formatDate(in.readLong()));
  v.visit(ImageElement.BLOCK_SIZE, in.readLong());
  int numBlocks = in.readInt();

  processBlocks(in, v, numBlocks, skipBlocks);
  
  if (numBlocks >= 0) { // File
    if (supportSnapshot) {
      // make sure subtreeMap only contains entry for directory
      subtreeMap.remove(inodeId);
      // process file diffs
      processFileDiffList(in, v, parentName);
      if (isSnapshotCopy) {
        boolean underConstruction = in.readBoolean();
        if (underConstruction) {
          v.visit(ImageElement.CLIENT_NAME,
              FSImageSerialization.readString(in));
          v.visit(ImageElement.CLIENT_MACHINE,
              FSImageSerialization.readString(in));
        }
      }
    }
    processPermission(in, v);
  } else if (numBlocks == -1) { // Directory
    if (supportSnapshot && supportInodeId) {
      dirNodeMap.put(inodeId, pathName);
    }
    v.visit(ImageElement.NS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
    if (NameNodeLayoutVersion.supports(Feature.DISKSPACE_QUOTA, imageVersion))
      v.visit(ImageElement.DS_QUOTA, numBlocks == -1 ? in.readLong() : -1);
    if (supportSnapshot) {
      boolean snapshottable = in.readBoolean();
      if (!snapshottable) {
        boolean withSnapshot = in.readBoolean();
        v.visit(ImageElement.IS_WITHSNAPSHOT_DIR, Boolean.toString(withSnapshot));
      } else {
        v.visit(ImageElement.IS_SNAPSHOTTABLE_DIR, Boolean.toString(snapshottable));
      }
    }
    processPermission(in, v);
  } else if (numBlocks == -2) {
    v.visit(ImageElement.SYMLINK, Text.readString(in));
    processPermission(in, v);
  } else if (numBlocks == -3) { // reference node
    final boolean isWithName = in.readBoolean();
    int snapshotId = in.readInt();
    if (isWithName) {
      v.visit(ImageElement.SNAPSHOT_LAST_SNAPSHOT_ID, snapshotId);
    } else {
      v.visit(ImageElement.SNAPSHOT_DST_SNAPSHOT_ID, snapshotId);
    }
    
    final boolean firstReferred = in.readBoolean();
    if (firstReferred) {
      // if a subtree is linked by multiple "parents", the corresponding dir
      // must be referred by a reference node. we put the reference node into
      // the subtreeMap here and let its value be false. when we later visit
      // the subtree for the first time, we change the value to true.
      subtreeMap.put(inodeId, false);
      v.visitEnclosingElement(ImageElement.SNAPSHOT_REF_INODE);
      processINode(in, v, skipBlocks, parentName, isSnapshotCopy);
      v.leaveEnclosingElement();  // referred inode    
    } else {
      v.visit(ImageElement.SNAPSHOT_REF_INODE_ID, in.readLong());
    }
  }

  v.leaveEnclosingElement(); // INode
}
 
Example #25
Source File: ImageLoaderCurrent.java    From RDFS with Apache License 2.0 4 votes vote down vote up
/**
 * Process the INodes under construction section of the fsimage.
 *
 * @param in DataInputStream to process
 * @param v Visitor to walk over inodes
 * @param skipBlocks Walk over each block?
 */
private void processINodesUC(DataInputStream in, ImageVisitor v,
    boolean skipBlocks) throws IOException {
  int numINUC = in.readInt();

  v.visitEnclosingElement(ImageElement.INODES_UNDER_CONSTRUCTION,
                         ImageElement.NUM_INODES_UNDER_CONSTRUCTION, numINUC);

  for(int i = 0; i < numINUC; i++) {
    v.visitEnclosingElement(ImageElement.INODE_UNDER_CONSTRUCTION);
    byte [] name = FSImageSerialization.readBytes(in);
    String n = new String(name, "UTF8");
    v.visit(ImageElement.INODE_PATH, n);
    v.visit(ImageElement.REPLICATION, in.readShort());
    v.visit(ImageElement.MODIFICATION_TIME, formatDate(in.readLong()));

    v.visit(ImageElement.PREFERRED_BLOCK_SIZE, in.readLong());
    int numBlocks = in.readInt();
    processBlocks(in, v, numBlocks, skipBlocks);

    processPermission(in, v);
    v.visit(ImageElement.CLIENT_NAME, FSImageSerialization.readString(in));
    v.visit(ImageElement.CLIENT_MACHINE, FSImageSerialization.readString(in));

    // Skip over the datanode descriptors, which are still stored in the
    // file but are not used by the datanode or loaded into memory
    int numLocs = in.readInt();
    for(int j = 0; j < numLocs; j++) {
      in.readShort();
      in.readLong();
      in.readLong();
      in.readLong();
      in.readInt();
      FSImageSerialization.readString(in);
      FSImageSerialization.readString(in);
      WritableUtils.readEnum(in, AdminStates.class);
    }

    v.leaveEnclosingElement(); // INodeUnderConstruction
  }

  v.leaveEnclosingElement(); // INodesUnderConstruction
}