Browse Source

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
Tsz-wo Sze 12 years ago
parent
commit
0ad27ad3e3

+ 18 - 0
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);
+  }
 }

+ 2 - 0
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());

+ 3 - 0
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)

+ 4 - 4
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<INodeDirectory> snapshotSubDirs = snapshotDirMap.get(ss);
-          for (INodeDirectory subDir : snapshotSubDirs) {
+        for (Entry<Snapshot, List<INodeDirectory>> 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);
           }
         }

+ 1 - 1
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);

+ 1 - 1
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<byte[]> {
   }
 
   /** The root directory of the snapshot. */
-  public class Root extends INodeDirectory {
+  static public class Root extends INodeDirectory {
     Root(INodeDirectory other) {
       super(other, false);
     }

+ 1 - 1
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++) {