/** @return the snapshot with the given name. */ public Snapshot getSnapshot(byte[] snapshotName) { final int i = searchSnapshot(snapshotName); return i < 0? null: snapshotsByNames.get(i); }
/** * Find the snapshot matching the given name. * * @param snapshotRoot The directory where snapshots were taken. * @param snapshotName The name of the snapshot. * @return The corresponding snapshot. Null if snapshotName is null or empty. * @throws SnapshotException If snapshotName is not null or empty, but there * is no snapshot matching the name. */ private Snapshot getSnapshotByName(INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException { Snapshot s = null; if (snapshotName != null && !snapshotName.isEmpty()) { final int index = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (index < 0) { throw new SnapshotException("Cannot find the snapshot of directory " + snapshotRoot.getFullPathName() + " with name " + snapshotName); } s = snapshotsByNames.get(index); } return s; }
final int indexOfOld = searchSnapshot(DFSUtil.string2Bytes(oldName)); if (indexOfOld < 0) { throw new SnapshotException("The snapshot " + oldName int indexOfNew = searchSnapshot(newNameBytes); if (indexOfNew >= 0) { throw new SnapshotException("The snapshot " + newName
/** * Remove the snapshot with the given name from {@link #snapshotsByNames}, * and delete all the corresponding DirectoryDiff. * * @param reclaimContext records blocks and inodes that need to be reclaimed * @param snapshotRoot The directory where we take snapshots * @param snapshotName The name of the snapshot to be removed * @return The removed snapshot. Null if no snapshot with the given name * exists. */ public Snapshot removeSnapshot( INode.ReclaimContext reclaimContext, INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException { final int i = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (i < 0) { throw new SnapshotException("Cannot delete snapshot " + snapshotName + " from path " + snapshotRoot.getFullPathName() + ": the snapshot does not exist."); } else { final Snapshot snapshot = snapshotsByNames.get(i); int prior = Snapshot.findLatestSnapshot(snapshotRoot, snapshot.getId()); snapshotRoot.cleanSubtree(reclaimContext, snapshot.getId(), prior); // remove from snapshotsByNames after successfully cleaning the subtree snapshotsByNames.remove(i); return snapshot; } }
/** @return the snapshot with the given name. */ public Snapshot getSnapshot(byte[] snapshotName) { final int i = searchSnapshot(snapshotName); return i < 0? null: snapshotsByNames.get(i); }
/** @return the snapshot with the given name. */ public Snapshot getSnapshot(byte[] snapshotName) { final int i = searchSnapshot(snapshotName); return i < 0? null: snapshotsByNames.get(i); }
final int i = searchSnapshot(nameBytes); if (i >= 0) { throw new SnapshotException("Failed to add snapshot: there is already a "
/** * Find the snapshot matching the given name. * * @param snapshotRoot The directory where snapshots were taken. * @param snapshotName The name of the snapshot. * @return The corresponding snapshot. Null if snapshotName is null or empty. * @throws SnapshotException If snapshotName is not null or empty, but there * is no snapshot matching the name. */ private Snapshot getSnapshotByName(INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException { Snapshot s = null; if (snapshotName != null && !snapshotName.isEmpty()) { final int index = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (index < 0) { throw new SnapshotException("Cannot find the snapshot of directory " + snapshotRoot.getFullPathName() + " with name " + snapshotName); } s = snapshotsByNames.get(index); } return s; }
/** * Find the snapshot matching the given name. * * @param snapshotRoot The directory where snapshots were taken. * @param snapshotName The name of the snapshot. * @return The corresponding snapshot. Null if snapshotName is null or empty. * @throws SnapshotException If snapshotName is not null or empty, but there * is no snapshot matching the name. */ private Snapshot getSnapshotByName(INodeDirectory snapshotRoot, String snapshotName) throws SnapshotException { Snapshot s = null; if (snapshotName != null && !snapshotName.isEmpty()) { final int index = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (index < 0) { throw new SnapshotException("Cannot find the snapshot of directory " + snapshotRoot.getFullPathName() + " with name " + snapshotName); } s = snapshotsByNames.get(index); } return s; }
return; final int indexOfOld = searchSnapshot(DFSUtil.string2Bytes(oldName)); if (indexOfOld < 0) { throw new SnapshotException("The snapshot " + oldName } else { final byte[] newNameBytes = DFSUtil.string2Bytes(newName); int indexOfNew = searchSnapshot(newNameBytes); if (indexOfNew >= 0) { throw new SnapshotException("The snapshot " + newName
return; final int indexOfOld = searchSnapshot(DFSUtil.string2Bytes(oldName)); if (indexOfOld < 0) { throw new SnapshotException("The snapshot " + oldName } else { final byte[] newNameBytes = DFSUtil.string2Bytes(newName); int indexOfNew = searchSnapshot(newNameBytes); if (indexOfNew >= 0) { throw new SnapshotException("The snapshot " + newName
String snapshotName, BlocksMapUpdateInfo collectedBlocks, final List<INode> removedINodes) throws SnapshotException { final int i = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (i < 0) { throw new SnapshotException("Cannot delete snapshot " + snapshotName
String snapshotName, BlocksMapUpdateInfo collectedBlocks, final List<INode> removedINodes) throws SnapshotException { final int i = searchSnapshot(DFSUtil.string2Bytes(snapshotName)); if (i < 0) { throw new SnapshotException("Cannot delete snapshot " + snapshotName
/** Add a snapshot. */ public Snapshot addSnapshot(INodeDirectory snapshotRoot, int id, String name) throws SnapshotException, QuotaExceededException { //check snapshot quota final int n = getNumSnapshots(); if (n + 1 > snapshotQuota) { throw new SnapshotException("Failed to add snapshot: there are already " + n + " snapshot(s) and the snapshot quota is " + snapshotQuota); } final Snapshot s = new Snapshot(id, name, snapshotRoot); final byte[] nameBytes = s.getRoot().getLocalNameBytes(); final int i = searchSnapshot(nameBytes); if (i >= 0) { throw new SnapshotException("Failed to add snapshot: there is already a " + "snapshot with the same name \"" + Snapshot.getSnapshotName(s) + "\"."); } final DirectoryDiff d = getDiffs().addDiff(id, snapshotRoot); d.setSnapshotRoot(s.getRoot()); snapshotsByNames.add(-i - 1, s); // set modification time final long now = Time.now(); snapshotRoot.updateModificationTime(now, Snapshot.CURRENT_STATE_ID); s.getRoot().setModificationTime(now, Snapshot.CURRENT_STATE_ID); return s; }
/** Add a snapshot. */ public Snapshot addSnapshot(INodeDirectory snapshotRoot, int id, String name) throws SnapshotException, QuotaExceededException { //check snapshot quota final int n = getNumSnapshots(); if (n + 1 > snapshotQuota) { throw new SnapshotException("Failed to add snapshot: there are already " + n + " snapshot(s) and the snapshot quota is " + snapshotQuota); } final Snapshot s = new Snapshot(id, name, snapshotRoot); final byte[] nameBytes = s.getRoot().getLocalNameBytes(); final int i = searchSnapshot(nameBytes); if (i >= 0) { throw new SnapshotException("Failed to add snapshot: there is already a " + "snapshot with the same name \"" + Snapshot.getSnapshotName(s) + "\"."); } final DirectoryDiff d = getDiffs().addDiff(id, snapshotRoot); d.setSnapshotRoot(s.getRoot()); snapshotsByNames.add(-i - 1, s); // set modification time final long now = Time.now(); snapshotRoot.updateModificationTime(now, Snapshot.CURRENT_STATE_ID); s.getRoot().setModificationTime(now, Snapshot.CURRENT_STATE_ID); return s; }