From af074299c211efb750af4854e73d88515a8fca2a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 7 May 2012 16:04:16 +0000 Subject: [PATCH] Merge -r 1335084:1335085 from trunk to branch-2. Fixes: HADOOP-8328 git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1335087 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../org/apache/hadoop/fs/FilterFileSystem.java | 2 +- .../org/apache/hadoop/fs/LocalFileSystem.java | 11 +++++++++++ .../org/apache/hadoop/fs/TestLocalFileSystem.java | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 297a1d40daf..0ff45371679 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -294,6 +294,9 @@ Release 2.0.0 - UNRELEASED HADOOP-8349. ViewFS doesn't work when the root of a file system is mounted. (atm) + HADOOP-8328. Duplicate FileSystem Statistics object for 'file' scheme. + (tomwhite) + BREAKDOWN OF HADOOP-7454 SUBTASKS HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh) 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 1794c3d032f..6cbaf591e5a 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 @@ -53,7 +53,7 @@ import org.apache.hadoop.util.Progressable; public class FilterFileSystem extends FileSystem { protected FileSystem fs; - private String swapScheme; + protected String swapScheme; /* * so that extending classes can define it diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalFileSystem.java index ac9b25d972a..394c01f7054 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/LocalFileSystem.java @@ -39,6 +39,17 @@ public class LocalFileSystem extends ChecksumFileSystem { public LocalFileSystem() { this(new RawLocalFileSystem()); } + + @Override + public void initialize(URI name, Configuration conf) throws IOException { + if (fs.getConf() == null) { + fs.initialize(name, conf); + } + String scheme = name.getScheme(); + if (!scheme.equals(fs.getUri().getScheme())) { + swapScheme = scheme; + } + } /** * Return the protocol scheme for the FileSystem. diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java index 6ccc201c55a..604ea78d0fb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestLocalFileSystem.java @@ -18,11 +18,14 @@ package org.apache.hadoop.fs; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem.Statistics; + import static org.apache.hadoop.fs.FileSystemTestHelper.*; import java.io.*; import static org.junit.Assert.*; + import org.junit.Before; import org.junit.Test; @@ -233,4 +236,16 @@ public class TestLocalFileSystem { assertTrue("Did not delete file", fs.delete(file1)); assertTrue("Did not delete non-empty dir", fs.delete(dir1)); } + + @Test + public void testStatistics() throws Exception { + FileSystem.getLocal(new Configuration()); + int fileSchemeCount = 0; + for (Statistics stats : FileSystem.getAllStatistics()) { + if (stats.getScheme().equals("file")) { + fileSchemeCount++; + } + } + assertEquals(1, fileSchemeCount); + } }