if (prior != Snapshot.NO_SNAPSHOT_ID) { // there is still snapshot before diffs.get(snapshotIndex).setSnapshotId(prior); } else { // there is no snapshot before removed = diffs.remove(0); diffs = null; removed.destroyDiffAndCollectBlocks(reclaimContext, currentINode); if (previous.getSnapshotId() != prior) { diffs.get(snapshotIndex).setSnapshotId(prior); } else { previous.combinePosteriorAndCollectBlocks(reclaimContext, currentINode, removed); previous.setPosterior(removed.getPosterior()); removed.setPosterior(null);
/** * @return the inode corresponding to the given snapshot. * Note that the current inode is returned if there is no change * between the given snapshot and the current state. */ public A getSnapshotINode(final int snapshotId, final A currentINode) { final D diff = getDiffById(snapshotId); final A inode = diff == null? null: diff.getSnapshotINode(); return inode == null? currentINode: inode; }
/** Save the snapshot copy to the latest snapshot. */ public D saveSelf2Snapshot(int latestSnapshotId, N currentINode, A snapshotCopy) { D diff = null; if (latestSnapshotId != Snapshot.CURRENT_STATE_ID) { diff = checkAndAddLatestSnapshotDiff(latestSnapshotId, currentINode); if (diff.snapshotINode == null) { if (snapshotCopy == null) { snapshotCopy = createSnapshotCopy(currentINode); } diff.saveSnapshotCopy(snapshotCopy); } } return diff; }
@Override public String toString() { return getClass().getSimpleName() + ": " + this.getSnapshotId() + " (post=" + (posteriorDiff == null? null: posteriorDiff.getSnapshotId()) + ")"; }
@Override public String toString() { return super.toString() + " childrenSize=" + childrenSize + ", " + diff; }
/** Append the diff at the end of the list. */ private D addLast(D diff) { createDiffsIfNeeded(); final D last = getLast(); diffs.addLast(diff); if (last != null) { last.setPosterior(diff); } return diff; }
/** * Save SnapshotDiff list for an INodeDirectoryWithSnapshot. * @param sNode The directory that the SnapshotDiff list belongs to. * @param out The {@link DataOutput} to write. */ private static <N extends INode, A extends INodeAttributes, D extends AbstractINodeDiff<N, A, D>> void saveINodeDiffs(final AbstractINodeDiffList<N, A, D> diffs, final DataOutput out, ReferenceMap referenceMap) throws IOException { // Record the diffs in reversed order, so that we can find the correct // reference for INodes in the created list when loading the FSImage if (diffs == null) { out.writeInt(-1); // no diffs } else { final DiffList<D> list = diffs.asList(); final int size = list.size(); out.writeInt(size); for (int i = size - 1; i >= 0; i--) { list.get(i).write(out, referenceMap); } } }
/** * Search for the snapshot whose id is 1) no less than the given id, * and 2) most close to the given id. */ public final int getSnapshotById(final int snapshotId) { D diff = getDiffById(snapshotId); return diff == null ? Snapshot.CURRENT_STATE_ID : diff.getSnapshotId(); }
@Override public String toString() { return super.toString() + " fileSize=" + fileSize + ", rep=" + (snapshotINode == null? "?": snapshotINode.getFileReplication()); }
/** Add the diff to the beginning of the list. */ final void addFirst(D diff) { createDiffsIfNeeded(); final D first = diffs.isEmpty()? null : diffs.get(0); diffs.addFirst(diff); diff.setPosterior(first); }
/** * Save SnapshotDiff list for an INodeDirectoryWithSnapshot. * @param sNode The directory that the SnapshotDiff list belongs to. * @param out The {@link DataOutput} to write. */ private static <N extends INode, A extends INodeAttributes, D extends AbstractINodeDiff<N, A, D>> void saveINodeDiffs(final AbstractINodeDiffList<N, A, D> diffs, final DataOutput out, ReferenceMap referenceMap) throws IOException { // Record the diffs in reversed order, so that we can find the correct // reference for INodes in the created list when loading the FSImage if (diffs == null) { out.writeInt(-1); // no diffs } else { final List<D> list = diffs.asList(); final int size = list.size(); out.writeInt(size); for (int i = size - 1; i >= 0; i--) { list.get(i).write(out, referenceMap); } } }
if (prior != Snapshot.NO_SNAPSHOT_ID) { // there is still snapshot before diffs.get(snapshotIndex).setSnapshotId(prior); } else { // there is no snapshot before removed = diffs.remove(0); counts.add(removed.destroyDiffAndCollectBlocks(bsps, currentINode, collectedBlocks, removedINodes)); if (previous.getSnapshotId() != prior) { diffs.get(snapshotIndex).setSnapshotId(prior); } else { counts.add(previous.combinePosteriorAndCollectBlocks( bsps, currentINode, removed, collectedBlocks, removedINodes)); previous.setPosterior(removed.getPosterior()); removed.setPosterior(null);
/** @return the id of the last snapshot. */ public final int getLastSnapshotId() { final AbstractINodeDiff<N, A, D> last = getLast(); return last == null ? Snapshot.CURRENT_STATE_ID : last.getSnapshotId(); }
@Override public String toString() { return super.toString() + " childrenSize=" + childrenSize + ", " + diff; }
/** Add the diff to the beginning of the list. */ final void addFirst(D diff) { final D first = diffs.isEmpty()? null: diffs.get(0); diffs.add(0, diff); diff.setPosterior(first); }
/** * @return the inode corresponding to the given snapshot. * Note that the current inode is returned if there is no change * between the given snapshot and the current state. */ public A getSnapshotINode(final int snapshotId, final A currentINode) { final D diff = getDiffById(snapshotId); final A inode = diff == null? null: diff.getSnapshotINode(); return inode == null? currentINode: inode; }
/** Save the snapshot copy to the latest snapshot. */ public D saveSelf2Snapshot(int latestSnapshotId, N currentINode, A snapshotCopy) { D diff = null; if (latestSnapshotId != Snapshot.CURRENT_STATE_ID) { diff = checkAndAddLatestSnapshotDiff(latestSnapshotId, currentINode); if (diff.snapshotINode == null) { if (snapshotCopy == null) { snapshotCopy = createSnapshotCopy(currentINode); } diff.saveSnapshotCopy(snapshotCopy); } } return diff; }
/** * Save SnapshotDiff list for an INodeDirectoryWithSnapshot. * @param sNode The directory that the SnapshotDiff list belongs to. * @param out The {@link DataOutput} to write. */ private static <N extends INode, A extends INodeAttributes, D extends AbstractINodeDiff<N, A, D>> void saveINodeDiffs(final AbstractINodeDiffList<N, A, D> diffs, final DataOutput out, ReferenceMap referenceMap) throws IOException { // Record the diffs in reversed order, so that we can find the correct // reference for INodes in the created list when loading the FSImage if (diffs == null) { out.writeInt(-1); // no diffs } else { final List<D> list = diffs.asList(); final int size = list.size(); out.writeInt(size); for (int i = size - 1; i >= 0; i--) { list.get(i).write(out, referenceMap); } } }
if (prior != Snapshot.NO_SNAPSHOT_ID) { // there is still snapshot before diffs.get(snapshotIndex).setSnapshotId(prior); } else { // there is no snapshot before removed = diffs.remove(0); counts.add(removed.destroyDiffAndCollectBlocks(bsps, currentINode, collectedBlocks, removedINodes)); if (previous.getSnapshotId() != prior) { diffs.get(snapshotIndex).setSnapshotId(prior); } else { counts.add(previous.combinePosteriorAndCollectBlocks( bsps, currentINode, removed, collectedBlocks, removedINodes)); previous.setPosterior(removed.getPosterior()); removed.setPosterior(null);
/** * Check if the latest snapshot diff exists. If not, add it. * @return the latest snapshot diff, which is never null. */ final D checkAndAddLatestSnapshotDiff(int latestSnapshotId, N currentINode) { final D last = getLast(); return (last != null && Snapshot.ID_INTEGER_COMPARATOR .compare(last.getSnapshotId(), latestSnapshotId) >= 0) ? last : addDiff(latestSnapshotId, currentINode); }