/** * 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); }
/** Add an {@link AbstractINodeDiff} for the given snapshot. */ final D addDiff(int latestSnapshotId, N currentINode) { return addLast(createDiff(latestSnapshotId, currentINode)); }
/** * 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); } } }
/** 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; }
public final int getPrior(int snapshotId) { return getPrior(snapshotId, false); }
/** * 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(); }
/** @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(); }
/** 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; }
int last = getLastSnapshotId(); if (exclusive && last == anchorId) { return Snapshot.NO_SNAPSHOT_ID;
/** 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; }
/** * Update the prior snapshot. */ final int updatePrior(int snapshot, int prior) { int p = getPrior(snapshot, true); if (p != Snapshot.CURRENT_STATE_ID && Snapshot.ID_INTEGER_COMPARATOR.compare(p, prior) > 0) { return p; } return prior; }
/** * @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; }
/** Append the diff at the end of the list. */ private final D addLast(D diff) { final D last = getLast(); diffs.add(diff); if (last != null) { last.setPosterior(diff); } return diff; }
int last = getLastSnapshotId(); if(exclusive && last == anchorId) return Snapshot.NO_SNAPSHOT_ID;
/** * 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); }
/** Add an {@link AbstractINodeDiff} for the given snapshot. */ final D addDiff(int latestSnapshotId, N currentINode) { return addLast(createDiff(latestSnapshotId, currentINode)); }
/** 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; }
public final int getPrior(int snapshotId) { return getPrior(snapshotId, false); }
/** * 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(); }
/** @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(); }