From 0ad27ad3e3f8de83cb4bb7330d69ea1cb6ea1663 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Thu, 18 Apr 2013 01:28:00 +0000 Subject: [PATCH] HDFS-4707. Add snapshot methods to FilterFileSystem and fix findbugs warnings. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-2802@1469119 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/hadoop/fs/FilterFileSystem.java | 18 ++++++++++++++++++ .../apache/hadoop/fs/TestFilterFileSystem.java | 2 ++ .../hadoop-hdfs/CHANGES.HDFS-2802.txt | 3 +++ .../hdfs/server/namenode/FSImageFormat.java | 8 ++++---- .../server/namenode/FSImageSerialization.java | 2 +- .../server/namenode/snapshot/Snapshot.java | 2 +- .../snapshot/SnapshotFSImageFormat.java | 2 +- 7 files changed, 30 insertions(+), 7 deletions(-) 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++) {