this.snapshotManager = new SnapshotManager(conf, dir); this.cacheManager = new CacheManager(this, conf, blockManager);
final INodesInPath iip, String snapshotRoot, String snapshotName) throws IOException { INodeDirectory srcRoot = getSnapshottableRoot(iip); if (snapshotCounter == getMaxSnapshotID()) {
@Metric({ "Snapshots", "The number of snapshots" }) public int getNumSnapshots() { return this.snapshotManager.getNumSnapshots(); }
@Override // SnapshotStatsMXBean public SnapshottableDirectoryStatus.Bean[] getSnapshottableDirectories() { List<SnapshottableDirectoryStatus.Bean> beans = new ArrayList<SnapshottableDirectoryStatus.Bean>(); for (INodeDirectory d : getSnapshottableDirs()) { beans.add(toBean(d)); } return beans.toArray(new SnapshottableDirectoryStatus.Bean[beans.size()]); }
/** * Compute the difference between two snapshots of a directory, or between a * snapshot of the directory and its current tree. */ public SnapshotDiffReport diff(final INodesInPath iip, final String snapshotPath, final String from, final String to) throws IOException { // Find the source root directory path where the snapshots were taken. // All the check for path has been included in the valueOf method. INodeDirectory snapshotRootDir; if (this.snapshotDiffAllowSnapRootDescendant) { snapshotRootDir = getSnapshottableAncestorDir(iip); } else { snapshotRootDir = getSnapshottableRoot(iip); } Preconditions.checkNotNull(snapshotRootDir); INodeDirectory snapshotDescendantDir = INodeDirectory.valueOf( iip.getLastINode(), snapshotPath); if ((from == null || from.isEmpty()) && (to == null || to.isEmpty())) { // both fromSnapshot and toSnapshot indicate the current tree return new SnapshotDiffReport(snapshotPath, from, to, Collections.<DiffReportEntry> emptyList()); } final SnapshotDiffInfo diffs = snapshotRootDir .getDirectorySnapshottableFeature().computeDiff( snapshotRootDir, snapshotDescendantDir, from, to); return diffs != null ? diffs.generateReport() : new SnapshotDiffReport( snapshotPath, from, to, Collections.<DiffReportEntry> emptyList()); }
logVersion); INodesInPath iip = fsDir.getINodesInPath(snapshotRoot, DirOp.WRITE); String path = fsNamesys.getSnapshotManager().createSnapshot( fsDir.getFSNamesystem().getLeaseManager(), iip, snapshotRoot, createSnapshotOp.snapshotName); logVersion); INodesInPath iip = fsDir.getINodesInPath(snapshotRoot, DirOp.WRITE); fsNamesys.getSnapshotManager().deleteSnapshot(iip, deleteSnapshotOp.snapshotName, new INode.ReclaimContext(fsNamesys.dir.getBlockStoragePolicySuite(), logVersion); INodesInPath iip = fsDir.getINodesInPath(snapshotRoot, DirOp.WRITE); fsNamesys.getSnapshotManager().renameSnapshot(iip, snapshotRoot, renameSnapshotOp.snapshotOldName, renameSnapshotOp.snapshotNewName); final String snapshotRoot = renameReservedPathsOnUpgrade(allowSnapshotOp.snapshotRoot, logVersion); fsNamesys.getSnapshotManager().setSnapshottable( snapshotRoot, false); break; renameReservedPathsOnUpgrade(disallowSnapshotOp.snapshotRoot, logVersion); fsNamesys.getSnapshotManager().resetSnapshottable( snapshotRoot); break;
INodesInPath iip = mock(INodesInPath.class); SnapshotManager sm = spy(new SnapshotManager(fsdir)); doReturn(ids).when(sm).getSnapshottableRoot((INodesInPath) anyObject()); doReturn(testMaxSnapshotLimit).when(sm).getMaxSnapshotID(); sm.createSnapshot(iip, "dummy", i.toString()); sm.createSnapshot(iip, "dummy", "shouldFailSnapshot"); Assert.fail("Expected SnapshotException not thrown"); } catch (SnapshotException se) { sm.deleteSnapshot(iip, "", mock(INode.BlocksMapUpdateInfo.class), new ArrayList<INode>()); sm.createSnapshot(iip, "dummy", "shouldFailSnapshot2"); Assert.fail("Expected SnapshotException not thrown"); } catch (SnapshotException se) {
SnapshotManager sm = fsn.getSnapshotManager(); SnapshotSection.Builder b = SnapshotSection.newBuilder() .setSnapshotCounter(sm.getSnapshotCounter()) .setNumSnapshots(sm.getNumSnapshots()); INodeDirectory[] snapshottables = sm.getSnapshottableDirs(); for (INodeDirectory sdir : snapshottables) { b.addSnapshottableDir(sdir.getId()); Preconditions.checkState(i == sm.getNumSnapshots()); parent.commitSection(headers, FSImageFormatProtobuf.SectionName.SNAPSHOT);
/** * Load the snapshots section from fsimage. Also add snapshottable feature * to snapshottable directories. */ public void loadSnapshotSection(InputStream in) throws IOException { SnapshotManager sm = fsn.getSnapshotManager(); SnapshotSection section = SnapshotSection.parseDelimitedFrom(in); int snum = section.getNumSnapshots(); sm.setNumSnapshots(snum); sm.setSnapshotCounter(section.getSnapshotCounter()); for (long sdirId : section.getSnapshottableDirList()) { INodeDirectory dir = fsDir.getInode(sdirId).asDirectory(); if (!dir.isSnapshottable()) { dir.addSnapshottableFeature(); } else { // dir is root, and admin set root to snapshottable before dir.setSnapshotQuota( DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT); } sm.addSnapshottable(dir); } loadSnapshots(in, snum); }
/** * Delete a snapshot for a snapshottable directory * @param snapshotName Name of the snapshot to be deleted * @param reclaimContext Used to collect information to reclaim blocks * and inodes */ public void deleteSnapshot(final INodesInPath iip, final String snapshotName, INode.ReclaimContext reclaimContext) throws IOException { INodeDirectory srcRoot = getSnapshottableRoot(iip); srcRoot.removeSnapshot(reclaimContext, snapshotName); numSnapshots.getAndDecrement(); }
mxbeanName, "SnapshottableDirectories"); int numDirectories = Array.getLength(directories); assertEquals(sm.getNumSnapshottableDirs(), numDirectories); CompositeData[] snapshots = (CompositeData[]) mbs.getAttribute(mxbeanName, "Snapshots"); int numSnapshots = Array.getLength(snapshots); assertEquals(sm.getNumSnapshots(), numSnapshots);
/** * Set the given directory as a snapshottable directory. * If the path is already a snapshottable directory, update the quota. */ public void setSnapshottable(final String path, boolean checkNestedSnapshottable) throws IOException { final INodesInPath iip = fsdir.getINodesInPath(path, DirOp.WRITE); final INodeDirectory d = INodeDirectory.valueOf(iip.getLastINode(), path); if (checkNestedSnapshottable) { checkNestedSnapshottable(d, path); } if (d.isSnapshottable()) { //The directory is already a snapshottable directory. d.setSnapshotQuota(DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT); } else { d.addSnapshottableFeature(); } addSnapshottable(d); }
hdfs.allowSnapshot(bar2); assertEquals(2, cluster.getNamesystem().getSnapshotManager() .getNumSnapshottableDirs()); assertEquals(2, cluster.getNamesystem().getSnapshotManager() .getSnapshottableDirs().length); .getNumSnapshottableDirs()); assertEquals(0, cluster.getNamesystem().getSnapshotManager() .getSnapshottableDirs().length); hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); hdfs.saveNamespace();
@Override // NameNodeMXBean public long getNumberOfSnapshottableDirs() { return snapshotManager.getNumSnapshottableDirs(); }
assertEquals(1, fsn.getSnapshotManager().getNumSnapshottableDirs()); SnapshottableDirectoryStatus[] sdirs = fsn.getSnapshotManager() .getSnapshottableDirListing(null); assertEquals(root, sdirs[0].getFullPath());
static SnapshottableDirectoryStatus[] getSnapshottableDirListing( FSDirectory fsd, FSPermissionChecker pc, SnapshotManager snapshotManager) throws IOException { fsd.readLock(); try { final String user = pc.isSuperUser()? null : pc.getUser(); return snapshotManager.getSnapshottableDirListing(user); } finally { fsd.readUnlock(); } }
fsd.writeLock(); try { snapshotPath = snapshotManager.createSnapshot( fsd.getFSNamesystem().getLeaseManager(), iip, snapshotRoot, snapshotName);
fsd.writeLock(); try { snapshotManager.deleteSnapshot(iip, snapshotName, context); fsd.updateCount(iip, context.quotaDelta(), false); fsd.removeFromInodeMap(removedINodes);
this.namesystem.getSnapshotManager().addSnapshottable(parent);
logVersion); INodesInPath iip = fsDir.getINodesInPath4Write(snapshotRoot); String path = fsNamesys.getSnapshotManager().createSnapshot(iip, snapshotRoot, createSnapshotOp.snapshotName); if (toAddRetryCache) { logVersion); INodesInPath iip = fsDir.getINodesInPath4Write(snapshotRoot); fsNamesys.getSnapshotManager().deleteSnapshot( iip, deleteSnapshotOp.snapshotName, collectedBlocks, removedINodes); logVersion); INodesInPath iip = fsDir.getINodesInPath4Write(snapshotRoot); fsNamesys.getSnapshotManager().renameSnapshot(iip, snapshotRoot, renameSnapshotOp.snapshotOldName, renameSnapshotOp.snapshotNewName); final String snapshotRoot = renameReservedPathsOnUpgrade(allowSnapshotOp.snapshotRoot, logVersion); fsNamesys.getSnapshotManager().setSnapshottable( snapshotRoot, false); break; renameReservedPathsOnUpgrade(disallowSnapshotOp.snapshotRoot, logVersion); fsNamesys.getSnapshotManager().resetSnapshottable( snapshotRoot); break;