Skip to content

Commit 6da29ed

Browse files
committed
Reverting HADOOP-5901. FileSystem.fixName() has unexpected behaviour.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@890941 13f79535-47bb-0310-9956-ffa450edef68
1 parent 08adb34 commit 6da29ed

File tree

3 files changed

+19
-158
lines changed

3 files changed

+19
-158
lines changed

CHANGES.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ Trunk (unreleased changes)
9494
HADOOP-6391. Classpath should not be part of command line arguments.
9595
(Cristian Ivascu via tomwhite)
9696

97-
HADOOP-5901. FileSystem.fixName() has unexpected behaviour.
98-
(Aaron Kimball via tomwhite)
99-
10097
Release 0.21.0 - Unreleased
10198

10299
INCOMPATIBLE CHANGES

src/java/org/apache/hadoop/fs/FileSystem.java

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.FileNotFoundException;
2222
import java.io.IOException;
2323
import java.net.URI;
24-
import java.net.URISyntaxException;
2524
import java.util.ArrayList;
2625
import java.util.Arrays;
2726
import java.util.EnumSet;
@@ -109,15 +108,7 @@ public static FileSystem get(Configuration conf) throws IOException {
109108
* @return the uri of the default filesystem
110109
*/
111110
public static URI getDefaultUri(Configuration conf) {
112-
try {
113-
String uri = conf.get(FS_DEFAULT_NAME_KEY, null);
114-
checkName(uri);
115-
return new URI(uri);
116-
} catch (Exception e) {
117-
// fs.default.name not set, or set to an invalid value. Create
118-
// one based on a known-good URI
119-
return URI.create(DEFAULT_FS);
120-
}
111+
return URI.create(fixName(conf.get(FS_DEFAULT_NAME_KEY, DEFAULT_FS)));
121112
}
122113

123114
/** Set the default filesystem URI in a configuration.
@@ -131,12 +122,9 @@ public static void setDefaultUri(Configuration conf, URI uri) {
131122
/** Set the default filesystem URI in a configuration.
132123
* @param conf the configuration to alter
133124
* @param uri the new default filesystem uri
134-
* @throws IOException if the URI is invalid.
135125
*/
136-
public static void setDefaultUri(Configuration conf, String uri)
137-
throws IOException {
138-
checkName(uri);
139-
setDefaultUri(conf, URI.create(uri));
126+
public static void setDefaultUri(Configuration conf, String uri) {
127+
setDefaultUri(conf, URI.create(fixName(uri)));
140128
}
141129

142130
/** Called after a new FileSystem instance is constructed.
@@ -150,52 +138,22 @@ public void initialize(URI name, Configuration conf) throws IOException {
150138

151139
/** Returns a URI whose scheme and authority identify this FileSystem.*/
152140
public abstract URI getUri();
153-
154-
/** Checks that a FileSystem name is given in an understandable format.
155-
* The old "local" alias for "file:///" is unsupported, as are any
156-
* URIs without a scheme component.
157-
* @throws IOException if a name is in an unsupported format
158-
*/
159-
private static void checkName(String name) throws IOException {
160-
if (null == name) {
161-
throw new IOException("Null FS name provided to checkName()");
162-
} else if ("local".equals(name)) {
163-
throw new IOException ("FileSystem 'local' is not supported; use 'file:///'");
164-
} else {
165-
// Try parsing this into a URI
166-
try {
167-
URI uri = new URI(name);
168-
169-
// No scheme; don't know how to parse this.
170-
if (null == uri.getScheme()) {
171-
throw new IOException("FileSystem name '" + name
172-
+ "' is provided in an unsupported format. (Try 'hdfs://"
173-
+ name + "' instead?)");
174-
}
175-
176-
// This may have been a misparse. java.net.URI specifies that
177-
// a URI is of the form:
178-
// URI ::= [SCHEME-PART:]SCHEME-SPECIFIC-PART
179-
//
180-
// The scheme-specific-part may be parsed in numerous ways, but if
181-
// it starts with a '/' character, that makes it a "hierarchical URI",
182-
// subject to the following parsing:
183-
// SCHEME-SPECIFIC-PART ::= "//" AUTHORITY-PART
184-
// AUTHORITY-PART ::= [USER-INFO-PART] HOSTNAME [ ":" PORT ]
185-
//
186-
// In Hadoop, we require a host-based authority as well.
187-
// java.net.URI parses left-to-right, so deprecated hostnames of the
188-
// form 'foo:8020' will have 'foo' as their scheme and '8020' as their
189-
// scheme-specific-part. We don't want this behavior.
190-
if (null == uri.getAuthority()) {
191-
throw new IOException("FileSystem name '" + name
192-
+ "' is provided in an unsupported format. (Try 'hdfs://"
193-
+ name + "' instead?)");
194-
}
195-
} catch (URISyntaxException use) {
196-
throw new IOException("FileSystem name cannot be understood as a URI", use);
197-
}
198-
}
141+
142+
/** Update old-format filesystem names, for back-compatibility. This should
143+
* eventually be replaced with a checkName() method that throws an exception
144+
* for old-format names. */
145+
private static String fixName(String name) {
146+
// convert old-format name to new-format name
147+
if (name.equals("local")) { // "local" is now "file:///".
148+
LOG.warn("\"local\" is a deprecated filesystem name."
149+
+" Use \"file:///\" instead.");
150+
name = "file:///";
151+
} else if (name.indexOf('/')==-1) { // unqualified is "hdfs://"
152+
LOG.warn("\""+name+"\" is a deprecated filesystem name."
153+
+" Use \"hdfs://"+name+"/\" instead.");
154+
name = "hdfs://"+name;
155+
}
156+
return name;
199157
}
200158

201159
/**

src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818

1919
package org.apache.hadoop.fs;
2020

21-
import static junit.framework.Assert.assertEquals;
2221
import static junit.framework.Assert.assertSame;
23-
import static junit.framework.Assert.assertNotNull;
2422
import static junit.framework.Assert.assertNotSame;
25-
import static junit.framework.Assert.assertTrue;
26-
import static junit.framework.Assert.fail;
2723

2824
import java.net.URI;
2925

@@ -51,94 +47,4 @@ public void testCacheDisabled() throws Exception {
5147
assertNotSame(fs1, fs2);
5248
}
5349

54-
@Test
55-
public void testGetLocal() throws Exception {
56-
Configuration conf = new Configuration();
57-
conf.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY,
58-
CommonConfigurationKeys.FS_DEFAULT_NAME_DEFAULT);
59-
FileSystem fs1 = FileSystem.get(conf);
60-
assertTrue(fs1 instanceof LocalFileSystem);
61-
62-
FileSystem fs2 = FileSystem.get(LocalFileSystem.NAME, conf);
63-
assertTrue(fs2 instanceof LocalFileSystem);
64-
}
65-
66-
@Test
67-
public void testGetDefaultFs() throws Exception {
68-
Configuration conf = new Configuration();
69-
FileSystem fs = FileSystem.get(conf);
70-
assertNotNull(fs);
71-
}
72-
73-
private void checkDefaultFsParam(Configuration conf, String uri)
74-
throws Exception {
75-
conf.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY, uri);
76-
assertNotNull(FileSystem.get(conf));
77-
}
78-
79-
@Test
80-
public void testInvalidDefaultFsParam() throws Exception {
81-
Configuration conf = new Configuration();
82-
83-
// All of the following set the default filesystem config
84-
// to an invalid URI. Subsequent requests for a FileSystem
85-
// should return the internal default fs.
86-
87-
checkDefaultFsParam(conf, "this-is-an-/invalid_uri");
88-
checkDefaultFsParam(conf, "");
89-
checkDefaultFsParam(conf, "/foo");
90-
checkDefaultFsParam(conf, "/foo/bar");
91-
checkDefaultFsParam(conf, "foo");
92-
checkDefaultFsParam(conf, "foo:8020");
93-
checkDefaultFsParam(conf, "foo/bar");
94-
checkDefaultFsParam(conf, "foo:8020/bar");
95-
checkDefaultFsParam(conf, "hdfs://");
96-
checkDefaultFsParam(conf, "local");
97-
}
98-
99-
@Test
100-
public void testGetInvalidFs() throws Exception {
101-
Configuration conf = new Configuration();
102-
103-
// None of these are valid FileSystem URIs. The default FS
104-
// should be returned in all cases.
105-
106-
assertNotNull(FileSystem.get(URI.create("/foo"), conf));
107-
assertNotNull(FileSystem.get(URI.create("/foo/bar"), conf));
108-
assertNotNull(FileSystem.get(URI.create("foo"), conf));
109-
assertNotNull(FileSystem.get(URI.create("foo/bar"), conf));
110-
assertNotNull(FileSystem.get(URI.create("local"), conf));
111-
}
112-
113-
private void checkBadUri(Configuration conf, String uri) {
114-
try {
115-
FileSystem.setDefaultUri(conf, uri);
116-
fail("Expected invalid URI: " + uri);
117-
} catch (Exception e) {
118-
// Got expected exception; ok.
119-
}
120-
}
121-
122-
@Test
123-
public void testDefaultUri() throws Exception {
124-
Configuration conf = new Configuration();
125-
URI uri = FileSystem.getDefaultUri(conf);
126-
assertNotNull(uri.getScheme());
127-
128-
final URI exampleGoodUri = new URI("hdfs://foo.example.com:999");
129-
130-
FileSystem.setDefaultUri(conf, exampleGoodUri);
131-
URI out = FileSystem.getDefaultUri(conf);
132-
assertEquals(exampleGoodUri, out);
133-
134-
checkBadUri(conf, "bla"); // no scheme
135-
checkBadUri(conf, "local"); // deprecated syntax
136-
checkBadUri(conf, "foo:8020"); // no scheme, deprecated syntax.
137-
checkBadUri(conf, "hdfs://"); // not a valid uri; requires authority-part
138-
checkBadUri(conf, ""); // not a uri.
139-
140-
// Check that none of these actually changed the conf.
141-
out = FileSystem.getDefaultUri(conf);
142-
assertEquals(exampleGoodUri, out);
143-
}
14450
}

0 commit comments

Comments
 (0)