/** * When destroying a reference node (WithName or DstReference), we call this * method to identify the snapshot which is the latest snapshot before the * reference node's creation. */ static Snapshot getPriorSnapshot(INodeReference ref) { WithCount wc = (WithCount) ref.getReferredINode(); WithName wn = null; if (ref instanceof DstReference) { wn = wc.getLastWithName(); } else if (ref instanceof WithName) { wn = wc.getPriorWithName((WithName) ref); } if (wn != null) { INode referred = wc.getReferredINode(); if (referred instanceof FileWithSnapshot) { return ((FileWithSnapshot) referred).getDiffs().getPrior( wn.lastSnapshotId); } else if (referred instanceof INodeDirectoryWithSnapshot) { return ((INodeDirectoryWithSnapshot) referred).getDiffs().getPrior( wn.lastSnapshotId); } } return null; }
private Snapshot getSelfSnapshot(final Snapshot prior) { WithCount wc = (WithCount) getReferredINode().asReference(); INode referred = wc.getReferredINode(); Snapshot lastSnapshot = null; if (referred instanceof FileWithSnapshot) { lastSnapshot = ((FileWithSnapshot) referred).getDiffs() .getLastSnapshot(); } else if (referred instanceof INodeDirectoryWithSnapshot) { lastSnapshot = ((INodeDirectoryWithSnapshot) referred) .getLastSnapshot(); } if (lastSnapshot != null && !lastSnapshot.equals(prior)) { return lastSnapshot; } else { return null; } }
@Override public void destroyAndCollectBlocks(BlocksMapUpdateInfo collectedBlocks, final List<INode> removedINodes) { if (blocks != null && collectedBlocks != null) { for (BlockInfo blk : blocks) { collectedBlocks.addDeleteBlock(blk); blk.setBlockCollection(null); } } setBlocks(null); clear(); removedINodes.add(this); if (this instanceof FileWithSnapshot) { ((FileWithSnapshot) this).getDiffs().clear(); } }
@Override public final Quota.Counts computeQuotaUsage(Quota.Counts counts, boolean useCache, int lastSnapshotId) { long nsDelta = 1; final long dsDelta; if (this instanceof FileWithSnapshot) { FileDiffList fileDiffList = ((FileWithSnapshot) this).getDiffs(); Snapshot last = fileDiffList.getLastSnapshot(); List<FileDiff> diffs = fileDiffList.asList(); if (lastSnapshotId == Snapshot.INVALID_ID || last == null) { nsDelta += diffs.size(); dsDelta = diskspaceConsumed(); } else if (last.getId() < lastSnapshotId) { dsDelta = computeFileSize(true, false) * getFileReplication(); } else { Snapshot s = fileDiffList.getSnapshotById(lastSnapshotId); dsDelta = diskspaceConsumed(s); } } else { dsDelta = diskspaceConsumed(); } counts.add(Quota.NAMESPACE, nsDelta); counts.add(Quota.DISKSPACE, dsDelta); return counts; }
private void computeContentSummary4Snapshot(final Content.Counts counts) { // file length and diskspace only counted for the latest state of the file // i.e. either the current state or the last snapshot if (this instanceof FileWithSnapshot) { final FileWithSnapshot withSnapshot = (FileWithSnapshot)this; final FileDiffList diffs = withSnapshot.getDiffs(); final int n = diffs.asList().size(); counts.add(Content.FILE, n); if (n > 0 && withSnapshot.isCurrentFileDeleted()) { counts.add(Content.LENGTH, diffs.getLast().getFileSize()); } if (withSnapshot.isCurrentFileDeleted()) { final long lastFileSize = diffs.getLast().getFileSize(); counts.add(Content.DISKSPACE, lastFileSize * getBlockReplication()); } } }
private Snapshot getSelfSnapshot() { INode referred = getReferredINode().asReference().getReferredINode(); Snapshot snapshot = null; if (referred instanceof FileWithSnapshot) { snapshot = ((FileWithSnapshot) referred).getDiffs().getPrior( lastSnapshotId); } else if (referred instanceof INodeDirectoryWithSnapshot) { snapshot = ((INodeDirectoryWithSnapshot) referred).getDiffs().getPrior( lastSnapshotId); } return snapshot; }
private void computeContentSummary4Current(final Content.Counts counts) { if (this instanceof FileWithSnapshot && ((FileWithSnapshot)this).isCurrentFileDeleted()) { return; } counts.add(Content.LENGTH, computeFileSize()); counts.add(Content.FILE, 1); counts.add(Content.DISKSPACE, diskspaceConsumed()); }
/** * 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(Snapshot snapshot) { if (snapshot != null && this instanceof FileWithSnapshot) { final FileDiff d = ((FileWithSnapshot)this).getDiffs().getDiff(snapshot); if (d != null) { return d.getFileSize(); } } return computeFileSize(true, false); }
@Override public final short getBlockReplication() { return this instanceof FileWithSnapshot? Util.getBlockReplication((FileWithSnapshot)this) : getFileReplication(null); }