Browse Source

HADOOP-2565. Remove DFSPath cache of FileStatus. Contributed by Tse Wo (Nicholas), SZE.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@663732 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang 17 years ago
parent
commit
dbcbdaf9da

+ 3 - 0
CHANGES.txt

@@ -463,6 +463,9 @@ Trunk (unreleased changes)
     HADOOP-2427. Ensure that the cwd of completed tasks is cleaned-up
     correctly on task-completion. (Amareshwari Sri Ramadasu via acmurthy) 
 
+    HADOOP-2565. Remove DFSPath cache of FileStatus. 
+    (Tsz Wo (Nicholas), SZE via hairong)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

+ 0 - 61
src/java/org/apache/hadoop/dfs/DfsPath.java

@@ -1,61 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.dfs;
-
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.FileSystem;
-
-/** 
- * DfsPath is a Path that's been annotated with some extra information.
- * The point of this class is to pass back the "common" metadata about 
- * a file with the names in a directory listing to make accesses faster.
- */
-class DfsPath extends Path {
-  DFSFileInfo info;
-
-  /**
-   * DfsPaths are fully qualified with scheme and authority.
-   */
-  public DfsPath(DFSFileInfo info, FileSystem fs) {
-    super((new Path(info.getPath().toString())).makeQualified(fs).toString());
-    this.info = info;
-  }
-
-  public boolean isDirectory() {
-    return info.isDir();
-  }
-  public boolean isFile() {
-    return ! isDirectory();
-  }
-  public long length() {
-    return info.getLen();
-  }
-  public long getContentsLength() {
-    assert !isDirectory();
-    return info.getLen();
-  }
-  public short getReplication() {
-    return info.getReplication();
-  }
-  public long getBlockSize() {
-    return info.getBlockSize();
-  }
-  public long getModificationTime() {
-    return info.getModificationTime();
-  }
-}

+ 9 - 13
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -200,16 +200,19 @@ public class DistributedFileSystem extends FileSystem {
     dfs.setQuota(getPathName(src), quota);
   }
   
+  private FileStatus makeQualified(FileStatus f) {
+    return new FileStatus(f.getLen(), f.isDir(), f.getReplication(),
+        f.getBlockSize(), f.getModificationTime(),
+        f.getPermission(), f.getOwner(), f.getGroup(),
+        f.getPath().makeQualified(this)); // fully-qualify path
+  }
+
   public FileStatus[] listStatus(Path p) throws IOException {
     DFSFileInfo[] infos = dfs.listPaths(getPathName(p));
     if (infos == null) return null;
     FileStatus[] stats = new FileStatus[infos.length];
     for (int i = 0; i < infos.length; i++) {
-      DFSFileInfo f = (DFSFileInfo)infos[i];
-      stats[i] = new FileStatus(f.getLen(), f.isDir(), f.getReplication(),
-                                f.getBlockSize(), f.getModificationTime(),
-                                f.getPermission(), f.getOwner(), f.getGroup(),
-                                new DfsPath(f, this)); // fully-qualify path
+      stats[i] = makeQualified(infos[i]);
     }
     return stats;
   }
@@ -369,16 +372,9 @@ public class DistributedFileSystem extends FileSystem {
    * @throws FileNotFoundException if the file does not exist.
    */
   public FileStatus getFileStatus(Path f) throws IOException {
-    if (f instanceof DfsPath) {
-      DfsPath p = (DfsPath) f;
-      return p.info;
-    }
     DFSFileInfo fi = dfs.getFileInfo(getPathName(f));
     if (fi != null) {
-      return new FileStatus(fi.getLen(), fi.isDir(), fi.getReplication(),
-          fi.getBlockSize(), fi.getModificationTime(),
-          fi.getPermission(), fi.getOwner(), fi.getGroup(),
-          new DfsPath(fi, this)); // fully-qualify path;
+      return makeQualified(fi);
     } else {
       throw new FileNotFoundException("File does not exist: " + f);
     }