/** * @return the parent as a reference if this is a referred inode; * otherwise, return null. */ public INodeReference getParentReference() { return parent == null || !parent.isReference()? null: (INodeReference)parent; }
public WithCount(INodeReference parent, INode referred) { super(parent, referred); Preconditions.checkArgument(!referred.isReference()); referred.setParentReference(this); }
/** * Try to remove the given reference and then return the reference count. * If the given inode is not a reference, return -1; */ public static int tryRemoveReference(INode inode) { if (!inode.isReference()) { return -1; } return removeReference(inode.asReference()); }
/** @return the parent directory */ public final INodeDirectory getParent() { return parent == null? null : parent.isReference()? getParentReference().getParent(): parent.asDirectory(); }
/** * When {@link #recordModification} is called on a referred node, * this method tells which snapshot the modification should be * associated with: the snapshot that belongs to the SRC tree of the rename * operation, or the snapshot belonging to the DST tree. * * @param latestInDst * id of the latest snapshot in the DST tree above the reference node * @return True: the modification should be recorded in the snapshot that * belongs to the SRC tree. False: the modification should be * recorded in the snapshot that belongs to the DST tree. */ public final boolean shouldRecordInSrcSnapshot(final int latestInDst) { Preconditions.checkState(!isReference()); if (latestInDst == Snapshot.CURRENT_STATE_ID) { return true; } INodeReference withCount = getParentReference(); if (withCount != null) { int dstSnapshotId = withCount.getParentReference().getDstSnapshotId(); if (dstSnapshotId != Snapshot.CURRENT_STATE_ID && dstSnapshotId >= latestInDst) { return true; } } return false; }
/** Is this inode in the latest snapshot? */ public final boolean isInLatestSnapshot(final int latestSnapshotId) { if (latestSnapshotId == Snapshot.CURRENT_STATE_ID || latestSnapshotId == Snapshot.NO_SNAPSHOT_ID) { return false; } // if parent is a reference node, parent must be a renamed node. We can // stop the check at the reference node. if (parent != null && parent.isReference()) { return true; } final INodeDirectory parentDir = getParent(); if (parentDir == null) { // root return true; } if (!parentDir.isInLatestSnapshot(latestSnapshotId)) { return false; } final INode child = parentDir.getChild(getLocalNameBytes(), latestSnapshotId); if (this == child) { return true; } return child != null && child.isReference() && this == child.asReference().getReferredINode(); }
INodeReference.WithName replaceChild4ReferenceWithName(INode oldChild, int latestSnapshotId) { Preconditions.checkArgument(latestSnapshotId != Snapshot.CURRENT_STATE_ID); if (oldChild instanceof INodeReference.WithName) { return (INodeReference.WithName)oldChild; } final INodeReference.WithCount withCount; if (oldChild.isReference()) { Preconditions.checkState(oldChild instanceof INodeReference.DstReference); withCount = (INodeReference.WithCount) oldChild.asReference() .getReferredINode(); } else { withCount = new INodeReference.WithCount(null, oldChild); } final INodeReference.WithName ref = new INodeReference.WithName(this, withCount, oldChild.getLocalNameBytes(), latestSnapshotId); replaceChild(oldChild, ref, null); return ref; }
oldChild = children.get(i); if (oldChild.isReference() && newChild.isReference()) {
/** Add a dir-diff pair */ void addDirDiff(INodeDirectory dir, byte[][] relativePath, ChildrenDiff diff) { dirDiffMap.put(dir, diff); diffMap.put(dir, relativePath); // detect rename for (INode created : diff.getCreatedUnmodifiable()) { if (created.isReference()) { RenameEntry entry = getEntry(created.getId()); if (entry.getTargetPath() == null) { entry.setTarget(created, relativePath); } } } for (INode deleted : diff.getDeletedUnmodifiable()) { if (deleted instanceof INodeReference.WithName) { RenameEntry entry = getEntry(deleted.getId()); entry.setSource(deleted, relativePath); } } }
byte[][] path = newPath(parent, created.getLocalNameBytes()); createdList.add(new DiffReportListingEntry(dirId, created.getId(), path, created.isReference(), null)); } else { setLastPath(parent);
void restoreDst(BlockStoragePolicySuite bsps) { Preconditions.checkState(oldDstChild != null); final INodeDirectory dstParent = dstParentIIP.getLastINode().asDirectory(); if (dstParent.isWithSnapshot()) { dstParent.undoRename4DstParent(bsps, oldDstChild, dstIIP.getLatestSnapshotId()); } else { fsd.addLastINodeNoQuotaCheck(dstParentIIP, oldDstChild); } if (oldDstChild != null && oldDstChild.isReference()) { final INodeReference removedDstRef = oldDstChild.asReference(); final INodeReference.WithCount wc = (INodeReference.WithCount) removedDstRef.getReferredINode().asReference(); wc.addReference(removedDstRef); } }
boolean toSave = child.isReference() ? referenceMap.toProcessSubtree(child.getId()) : true; saveImage(child.asDirectory(), out, toSave, inSnapshot, counter);
/** * Save one inode's attributes to the image. */ public static void saveINode2Image(INode node, DataOutput out, boolean writeUnderConstruction, ReferenceMap referenceMap) throws IOException { if (node.isReference()) { writeINodeReference(node.asReference(), out, writeUnderConstruction, referenceMap); } else if (node.isDirectory()) { writeINodeDirectory(node.asDirectory(), out); } else if (node.isSymlink()) { writeINodeSymlink(node.asSymlink(), out); } else if (node.isFile()) { writeINodeFile(node.asFile(), out, writeUnderConstruction); } }
++numImageErrors; if (!inode.isReference()) { b.addChildren(inode.getId()); } else {
final boolean lastComp = (count == components.length - 1); inodes[inodeNum++] = curNode; final boolean isRef = curNode.isReference(); final boolean isDir = curNode.isDirectory(); final INodeDirectory dir = isDir? curNode.asDirectory(): null;
INode inode, final int snapshot, final int prior) { Preconditions.checkArgument(prior != NO_SNAPSHOT_ID); if (inode.isReference()) { if (inode instanceof INodeReference.WithName && snapshot != Snapshot.CURRENT_STATE_ID) {
if (d.isReference()) { refList.add(d.asReference()); db.addDeletedINodeRef(refList.size() - 1);
if (srcINode.isReference() && ((INodeReference.WithCount) srcINode.asReference().getReferredINode()).getReferenceCount() > 1) { throw new SnapshotException("Concat: the source file " + src
final int srcLatestSnapshotId = srcIIP.getLatestSnapshotId(); isSrcInSnapshot = srcChild.isInLatestSnapshot(srcLatestSnapshotId); srcChildIsReference = srcChild.isReference(); srcParent = this.srcIIP.getINode(-2).asDirectory();
/** @return the parent directory */ public final INodeDirectory getParent() { return parent == null? null : parent.isReference()? getParentReference().getParent(): parent.asDirectory(); }