diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java index 9fc8bb2d97..d526a78e39 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FilterFileSystem.java @@ -462,4 +462,22 @@ protected boolean primitiveMkdir(Path f, FsPermission abdolutePermission) public FileSystem[] getChildFileSystems() { return new FileSystem[]{fs}; } + + @Override // FileSystem + public Path createSnapshot(Path path, String snapshotName) + throws IOException { + return fs.createSnapshot(path, snapshotName); + } + + @Override // FileSystem + public void renameSnapshot(Path path, String snapshotOldName, + String snapshotNewName) throws IOException { + fs.renameSnapshot(path, snapshotOldName, snapshotNewName); + } + + @Override // FileSystem + public void deleteSnapshot(Path path, String snapshotName) + throws IOException { + fs.deleteSnapshot(path, snapshotName); + } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java index 3d029ff5fd..b70f6be53d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFilterFileSystem.java @@ -218,6 +218,8 @@ public void testFilterFileSystem() throws Exception { continue; if (Modifier.isPrivate(m.getModifiers())) continue; + if (Modifier.isFinal(m.getModifiers())) + continue; try { DontCheck.class.getMethod(m.getName(), m.getParameterTypes()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt index b065651598..32a33f08eb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-2802.txt @@ -250,3 +250,6 @@ Branch-2802 Snapshot (Unreleased) HDFS-4550. Refactor INodeDirectory.INodesInPath to a standalone class. (szetszwo) + + HDFS-4707. Add snapshot methods to FilterFileSystem and fix findbugs warnings. + (szetszwo) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java index 1f1822fa3c..7677c02c56 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageFormat.java @@ -35,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.apache.commons.logging.Log; import org.apache.hadoop.classification.InterfaceAudience; @@ -1001,14 +1002,13 @@ private void saveImage(ByteBuffer currentDirName, INodeDirectory current, currentDirName.position(prefixLen); } if (snapshotDirMap != null) { - for (Snapshot ss : snapshotDirMap.keySet()) { - List snapshotSubDirs = snapshotDirMap.get(ss); - for (INodeDirectory subDir : snapshotSubDirs) { + for (Entry> e : snapshotDirMap.entrySet()) { + for (INodeDirectory subDir : e.getValue()) { // make sure we only save the subtree under a reference node once boolean toSave = subDir.getParentReference() != null ? referenceMap.toProcessSubtree(subDir.getId()) : true; currentDirName.put(PATH_SEPARATOR).put(subDir.getLocalNameBytes()); - saveImage(currentDirName, subDir, out, ss, toSave); + saveImage(currentDirName, subDir, out, e.getKey(), toSave); currentDirName.position(prefixLen); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageSerialization.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageSerialization.java index eaa7e7665b..48aa9c6bbc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageSerialization.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSImageSerialization.java @@ -192,7 +192,7 @@ public static void writeINodeFile(INodeFile file, DataOutput out, SnapshotFSImageFormat.saveFileDiffList(file, out); if (writeUnderConstruction) { - if (file.isUnderConstruction()) { + if (file instanceof INodeFileUnderConstruction) { out.writeBoolean(true); final INodeFileUnderConstruction uc = (INodeFileUnderConstruction)file; writeString(uc.getClientName(), out); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java index 7c194107a9..2404615963 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/Snapshot.java @@ -113,7 +113,7 @@ public static Snapshot findLatestSnapshot(INode inode, Snapshot anchor) { } /** The root directory of the snapshot. */ - public class Root extends INodeDirectory { + static public class Root extends INodeDirectory { Root(INodeDirectory other) { super(other, false); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java index caf0c92189..96bded784f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/SnapshotFSImageFormat.java @@ -238,7 +238,7 @@ public static void loadSnapshotList( public static void loadDirectoryDiffList(INodeDirectory dir, DataInput in, FSImageFormat.Loader loader) throws IOException { final int size = in.readInt(); - if (size != -1) { + if (dir instanceof INodeDirectoryWithSnapshot) { INodeDirectoryWithSnapshot withSnapshot = (INodeDirectoryWithSnapshot)dir; DirectoryDiffList diffs = withSnapshot.getDiffs(); for (int i = 0; i < size; i++) {