private void serializeFileDiffList(INodeFile file, OutputStream out) throws IOException { FileWithSnapshotFeature sf = file.getFileWithSnapshotFeature(); if (sf != null) { DiffList<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()); if(diff.getBlocks() != null) { for(Block block : diff.getBlocks()) { fb.addBlocks(PBHelperClient.convert(block)); } } INodeFileAttributes copy = diff.snapshotINode; if (copy != null) { fb.setName(ByteString.copyFrom(copy.getLocalNameBytes())) .setSnapshotCopy(buildINodeFile(copy, parent.getSaverContext())); } fb.build().writeDelimitedTo(out); } } }
@Override FileDiff createDiff(int snapshotId, INodeFile file) { return new FileDiff(snapshotId, file); }
public void destroyAndCollectSnapshotBlocks( BlocksMapUpdateInfo collectedBlocks) { for (FileDiff d : asList()) { d.destroyAndCollectSnapshotBlocks(collectedBlocks); } }
BlockInfo[] removedBlocks = removed.getBlocks(); if (removedBlocks == null) { FileWithSnapshotFeature sf = file.getFileWithSnapshotFeature(); return; int p = getPrior(removed.getSnapshotId(), true); FileDiff earlierDiff = p == Snapshot.NO_SNAPSHOT_ID ? null : getDiffById(p); earlierDiff.setBlocks(removedBlocks); (earlierDiff == null ? new BlockInfoContiguous[]{} : earlierDiff.getBlocks()); BlockInfo[] laterBlocks = findLaterSnapshotBlocks(removed.getSnapshotId()); laterBlocks = (laterBlocks == null) ? file.getBlocks() : laterBlocks;
/** * If some blocks at the end of the block list no longer belongs to * any inode, collect them and update the block list. */ public void collectBlocksAndClear( INode.ReclaimContext reclaimContext, final INodeFile file) { // check if everything is deleted. if (isCurrentFileDeleted() && getDiffs().asList().isEmpty()) { file.clearFile(reclaimContext); return; } // find max file size. final long max; FileDiff diff = getDiffs().getLast(); if (isCurrentFileDeleted()) { max = diff == null? 0: diff.getFileSize(); } else { max = file.computeFileSize(); } // Collect blocks that should be deleted FileDiff last = diffs.getLast(); BlockInfo[] snapshotBlocks = last == null ? null : last.getBlocks(); if(snapshotBlocks == null) file.collectBlocksBeyondMax(max, reclaimContext.collectedBlocks(), null); else file.collectBlocksBeyondSnapshot(snapshotBlocks, reclaimContext.collectedBlocks()); } }
public BlockInfo[] findEarlierSnapshotBlocks(int snapshotId) { assert snapshotId != Snapshot.NO_SNAPSHOT_ID : "Wrong snapshot id"; if (snapshotId == Snapshot.CURRENT_STATE_ID) { return null; } DiffList<FileDiff> diffs = this.asList(); int i = diffs.binarySearch(snapshotId); BlockInfo[] blocks = null; for(i = i >= 0 ? i : -i-2; i >= 0; i--) { blocks = diffs.get(i).getBlocks(); if(blocks != null) { break; } } return blocks; }
/** * Compute file size of the current file if the given snapshot is null; * otherwise, get the file size from the given snapshot. */ public final long computeFileSize(int snapshotId) { FileWithSnapshotFeature sf = this.getFileWithSnapshotFeature(); if (snapshotId != CURRENT_STATE_ID && sf != null) { final FileDiff d = sf.getDiffs().getDiffById(snapshotId); if (d != null) { return d.getFileSize(); } } return computeFileSize(true, false); }
assertEquals(1, barDiffList.size()); FileDiff barDiff = barDiffList.get(0); assertEquals(s1.getId(), barDiff.getSnapshotId());
@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); } }
public void saveSelf2Snapshot(int latestSnapshotId, INodeFile iNodeFile, INodeFileAttributes snapshotCopy, boolean withBlocks) { final FileDiff diff = super.saveSelf2Snapshot(latestSnapshotId, iNodeFile, snapshotCopy); if (withBlocks) { // Store blocks if this is the first update BlockInfo[] blks = iNodeFile.getBlocks(); assert blks != null; diff.setBlocks(blks); } }
AclFeature aclFeature = removed.getSnapshotINode().getAclFeature(); if (aclFeature != null) { AclStorage.removeAclFeature(aclFeature);
BlocksMapUpdateInfo collectedBlocks, List<INode> removedINodes) { BlockInfoContiguous[] removedBlocks = removed.getBlocks(); if(removedBlocks == null) { FileWithSnapshotFeature sf = file.getFileWithSnapshotFeature(); return; int p = getPrior(removed.getSnapshotId(), true); FileDiff earlierDiff = p == Snapshot.NO_SNAPSHOT_ID ? null : getDiffById(p); earlierDiff.setBlocks(removedBlocks); BlockInfoContiguous[] earlierBlocks = (earlierDiff == null ? new BlockInfoContiguous[]{} : earlierDiff.getBlocks()); BlockInfoContiguous[] laterBlocks = findLaterSnapshotBlocks(removed.getSnapshotId()); laterBlocks = (laterBlocks==null) ? file.getBlocks() : laterBlocks;
public BlockInfo[] findLaterSnapshotBlocks(int snapshotId) { assert snapshotId != Snapshot.NO_SNAPSHOT_ID : "Wrong snapshot id"; if (snapshotId == Snapshot.CURRENT_STATE_ID) { return null; } DiffList<FileDiff> diffs = this.asList(); int i = diffs.binarySearch(snapshotId); BlockInfo[] blocks = null; for (i = i >= 0 ? i+1 : -i-1; i < diffs.size(); i++) { blocks = diffs.get(i).getBlocks(); if (blocks != null) { break; } } return blocks; }
/** * If some blocks at the end of the block list no longer belongs to * any inode, collect them and update the block list. */ public void collectBlocksAndClear(final BlockStoragePolicySuite bsps, final INodeFile file, final BlocksMapUpdateInfo info, final List<INode> removedINodes) { // check if everything is deleted. if (isCurrentFileDeleted() && getDiffs().asList().isEmpty()) { file.destroyAndCollectBlocks(bsps, info, removedINodes); return; } // find max file size. final long max; FileDiff diff = getDiffs().getLast(); if (isCurrentFileDeleted()) { max = diff == null? 0: diff.getFileSize(); } else { max = file.computeFileSize(); } // Collect blocks that should be deleted FileDiff last = diffs.getLast(); BlockInfoContiguous[] snapshotBlocks = last == null ? null : last.getBlocks(); if(snapshotBlocks == null) file.collectBlocksBeyondMax(max, info); else file.collectBlocksBeyondSnapshot(snapshotBlocks, info); } }
final long earlierLength = diffList.get(earlierDiffIndex).getFileSize(); final long laterLength = laterDiffIndex == diffList.size() ? file .computeFileSize(true, false) : diffList.get(laterDiffIndex) .getFileSize(); if (earlierLength != laterLength) { // file length has been changed return true;
List<FileDiff> bar1Diffs = bar1.getDiffs().asList(); assertEquals(3, bar1Diffs.size()); assertEquals(s333.getId(), bar1Diffs.get(2).getSnapshotId()); assertEquals(s22.getId(), bar1Diffs.get(1).getSnapshotId()); assertEquals(s1.getId(), bar1Diffs.get(0).getSnapshotId()); List<FileDiff> barDiffs = bar.getDiffs().asList(); assertEquals(4, barDiffs.size()); assertEquals(s2222.getId(), barDiffs.get(3).getSnapshotId()); assertEquals(s333.getId(), barDiffs.get(2).getSnapshotId()); assertEquals(s22.getId(), barDiffs.get(1).getSnapshotId()); assertEquals(s1.getId(), barDiffs.get(0).getSnapshotId()); bar1Diffs = bar1.getDiffs().asList(); assertEquals(3, bar1Diffs.size()); assertEquals(s333.getId(), bar1Diffs.get(2).getSnapshotId()); barDiffs = bar.getDiffs().asList(); assertEquals(4, barDiffs.size()); assertEquals(s2222.getId(), barDiffs.get(3).getSnapshotId());
@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); } }
public void saveSelf2Snapshot(int latestSnapshotId, INodeFile iNodeFile, INodeFileAttributes snapshotCopy, boolean withBlocks) { final FileDiff diff = super.saveSelf2Snapshot(latestSnapshotId, iNodeFile, snapshotCopy); if(withBlocks) // Store blocks if this is the first update diff.setBlocks(iNodeFile.getBlocks()); }