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 9fc8bb2d974..d526a78e39f 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 @@ public class FilterFileSystem extends FileSystem { 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 3d029ff5fdc..b70f6be53d1 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 class TestFilterFileSystem { 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 b0656515985..32a33f08eba 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 1f1822fa3c8..7677c02c56f 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.Arrays; 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 @@ public class FSImageFormat { 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 eaa7e7665bc..48aa9c6bbc0 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 class FSImageSerialization { 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 7c194107a97..24046159638 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 class Snapshot implements Comparable { } /** 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 caf0c921895..96bded784ff 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 class SnapshotFSImageFormat { 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++) {