private void serializeFileDiffList(INodeFile file, OutputStream out) throws IOException {
   FileWithSnapshotFeature sf = file.getFileWithSnapshotFeature();
   if (sf != null) {
     List<FileDiff> diffList = sf.getDiffs().asList();
     SnapshotDiffSection.DiffEntry entry =
         SnapshotDiffSection.DiffEntry.newBuilder()
             .setInodeId(file.getId())
             .setType(Type.FILEDIFF)
             .setNumOfDiff(diffList.size())
             .build();
     entry.writeDelimitedTo(out);
     for (int i = diffList.size() - 1; i >= 0; i--) {
       FileDiff diff = diffList.get(i);
       SnapshotDiffSection.FileDiff.Builder fb =
           SnapshotDiffSection.FileDiff.newBuilder()
               .setSnapshotId(diff.getSnapshotId())
               .setFileSize(diff.getFileSize());
       INodeFileAttributes copy = diff.snapshotINode;
       if (copy != null) {
         fb.setName(ByteString.copyFrom(copy.getLocalNameBytes()))
             .setSnapshotCopy(buildINodeFile(copy, parent.getSaverContext()));
       }
       fb.build().writeDelimitedTo(out);
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * If some blocks at the end of the block list no longer belongs to any inode, collect them and
   * update the block list.
   */
  private void collectBlocksAndClear(
      final INodeFile file, final BlocksMapUpdateInfo info, final List<INode> removedINodes) {
    // check if everything is deleted.
    if (isCurrentFileDeleted() && getDiffs().asList().isEmpty()) {
      file.destroyAndCollectBlocks(info, removedINodes);
      return;
    }
    // find max file size.
    final long max;
    if (isCurrentFileDeleted()) {
      final FileDiff last = getDiffs().getLast();
      max = last == null ? 0 : last.getFileSize();
    } else {
      max = file.computeFileSize();
    }

    collectBlocksBeyondMax(file, max, info);
  }