/** 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); }
/** Remove the given child from the deleted list, if there is any. */ public boolean removeDeletedChild(final INode child) { final DiffList<DirectoryDiff> diffList = asList(); for(int i = diffList.size() - 1; i >= 0; i--) { final ChildrenDiff diff = diffList.get(i).diff; if (diff.removeDeleted(child)) { return true; } } return 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(); }
/** * Find the corresponding snapshot whose deleted list contains the given * inode. * @return the id of the snapshot. {@link Snapshot#NO_SNAPSHOT_ID} if the * given inode is not in any of the snapshot. */ public int findSnapshotDeleted(final INode child) { final DiffList<DirectoryDiff> diffList = asList(); for(int i = diffList.size() - 1; i >= 0; i--) { final DirectoryDiff diff = diffList.get(i); if (diff.getChildrenDiff().containsDeleted(child)) { return diff.getSnapshotId(); } } return NO_SNAPSHOT_ID; }
/** * Get the name of the given snapshot. * @param s The given snapshot. * @return The name of the snapshot, or an empty string if {@code s} is null */ static String getSnapshotName(Snapshot s) { return s != null ? s.getRoot().getLocalName() : ""; }
/** 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; }
public void destroyAndCollectSnapshotBlocks( BlocksMapUpdateInfo collectedBlocks) { for (FileDiff d : asList()) { d.destroyAndCollectSnapshotBlocks(collectedBlocks); } }
/** * @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; }
public void clear( INode.ReclaimContext reclaimContext, INodeDirectory currentINode) { // destroy its diff list for (DirectoryDiff diff : diffs) { diff.destroyDiffAndCollectBlocks(reclaimContext, currentINode); } diffs.clear(); }
/** Replace the given child in the created/deleted list, if there is any. */ public boolean replaceCreatedChild(final INode oldChild, final INode newChild) { final DiffList<DirectoryDiff> diffList = asList(); for(int i = diffList.size() - 1; i >= 0; i--) { final ChildrenDiff diff = diffList.get(i).diff; if (diff.replaceCreated(oldChild, newChild)) { return true; } } return false; }
/** @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(); }
public ChildrenDiff getChildrenDiff(int level) { if (level == 0) { return diff != null? diff.getChildrenDiff(): null; } else { return skips[level - 1].getDiff(); } }
/** * Returns the list of diffs between two indexes corresponding to two * snapshots. * @param fromIndex Index of the diff corresponding to the earlier snapshot * @param toIndex Index of the diff corresponding to the later snapshot * @param dir The Directory to which the diffList belongs * @return list of directory diffs */ List<DirectoryDiff> getDiffListBetweenSnapshots(int fromIndex, int toIndex, INodeDirectory dir) { return asList().getMinListForRange(fromIndex, toIndex, dir); } }
/** * Remove a list of INodeDirectorySnapshottable from the SnapshotManager * @param toRemove the list of INodeDirectorySnapshottable to be removed */ void removeSnapshottableDirs(List<INodeDirectory> toRemove) { if (snapshotManager != null) { snapshotManager.removeSnapshottable(toRemove); } }
/** @return this list as a unmodifiable {@link List}. */ public final DiffList<D> asList() { return diffs != null ? DiffList.unmodifiableList(diffs) : DiffList.emptyList(); }
SkipListNode getSkipNode(int level) { return level == 0? next : level <= skips.length? skips[level - 1].getSkipTo() : null; }
@Override DiffList<DirectoryDiff> newDiffs() { return DirectoryDiffListFactory .createDiffList(INodeDirectory.DEFAULT_FILES_PER_DIRECTORY); }
private void createDiffsIfNeeded() { if (diffs == null) { diffs = newDiffs(); } }