HADOOP-13140. FileSystem#initialize must not attempt to create StorageStatistics objects with null or empty schemes (Mingliang Liu via cmccabe)
(cherry picked from commit f2c1d9181f80e53890b50309b15c9ea37cb24987)
This commit is contained in:
parent
e9dd0d84e5
commit
feabfe9cda
@ -75,6 +75,7 @@
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.*;
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.*;
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
@ -211,7 +212,13 @@ public static void setDefaultUri(Configuration conf, String uri) {
|
|||||||
* @param conf the configuration
|
* @param conf the configuration
|
||||||
*/
|
*/
|
||||||
public void initialize(URI name, Configuration conf) throws IOException {
|
public void initialize(URI name, Configuration conf) throws IOException {
|
||||||
statistics = getStatistics(name.getScheme(), getClass());
|
final String scheme;
|
||||||
|
if (name.getScheme() == null || name.getScheme().isEmpty()) {
|
||||||
|
scheme = getDefaultUri(conf).getScheme();
|
||||||
|
} else {
|
||||||
|
scheme = name.getScheme();
|
||||||
|
}
|
||||||
|
statistics = getStatistics(scheme, getClass());
|
||||||
resolveSymlinks = conf.getBoolean(
|
resolveSymlinks = conf.getBoolean(
|
||||||
CommonConfigurationKeys.FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_KEY,
|
CommonConfigurationKeys.FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_KEY,
|
||||||
CommonConfigurationKeys.FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_DEFAULT);
|
CommonConfigurationKeys.FS_CLIENT_RESOLVE_REMOTE_SYMLINKS_DEFAULT);
|
||||||
@ -3576,6 +3583,8 @@ public static synchronized List<Statistics> getAllStatistics() {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public static synchronized Statistics getStatistics(final String scheme,
|
public static synchronized Statistics getStatistics(final String scheme,
|
||||||
Class<? extends FileSystem> cls) {
|
Class<? extends FileSystem> cls) {
|
||||||
|
checkArgument(scheme != null,
|
||||||
|
"No statistics is allowed for a file system with null scheme!");
|
||||||
Statistics result = statisticsTable.get(cls);
|
Statistics result = statisticsTable.get(cls);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
final Statistics newStats = new Statistics(scheme);
|
final Statistics newStats = new Statistics(scheme);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +56,7 @@ public interface StorageStatisticsProvider {
|
|||||||
* null if there is none.
|
* null if there is none.
|
||||||
*/
|
*/
|
||||||
public synchronized StorageStatistics get(String name) {
|
public synchronized StorageStatistics get(String name) {
|
||||||
return map.get(name);
|
return name == null ? null : map.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,6 +71,8 @@ public synchronized StorageStatistics get(String name) {
|
|||||||
*/
|
*/
|
||||||
public synchronized StorageStatistics put(String name,
|
public synchronized StorageStatistics put(String name,
|
||||||
StorageStatisticsProvider provider) {
|
StorageStatisticsProvider provider) {
|
||||||
|
Preconditions.checkNotNull(name,
|
||||||
|
"Storage statistics can not have a null name!");
|
||||||
StorageStatistics stats = map.get(name);
|
StorageStatistics stats = map.get(name);
|
||||||
if (stats != null) {
|
if (stats != null) {
|
||||||
return stats;
|
return stats;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user