Created
October 19, 2015 20:02
-
-
Save RussellSpitzer/e26742e8682370ee3732 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Source code recreated from a .class file by IntelliJ IDEA | |
// (powered by Fernflower decompiler) | |
// | |
package org.apache.hadoop.fs; | |
import com.google.common.annotations.VisibleForTesting; | |
import java.io.Closeable; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.lang.ref.WeakReference; | |
import java.net.URI; | |
import java.net.URISyntaxException; | |
import java.security.PrivilegedExceptionAction; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.EnumSet; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.IdentityHashMap; | |
import java.util.Iterator; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.NoSuchElementException; | |
import java.util.ServiceLoader; | |
import java.util.Set; | |
import java.util.Stack; | |
import java.util.TreeSet; | |
import java.util.Map.Entry; | |
import java.util.concurrent.atomic.AtomicLong; | |
import org.apache.commons.logging.Log; | |
import org.apache.commons.logging.LogFactory; | |
import org.apache.hadoop.classification.InterfaceAudience.LimitedPrivate; | |
import org.apache.hadoop.classification.InterfaceAudience.Private; | |
import org.apache.hadoop.classification.InterfaceAudience.Public; | |
import org.apache.hadoop.classification.InterfaceStability.Stable; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.conf.Configured; | |
import org.apache.hadoop.fs.BlockLocation; | |
import org.apache.hadoop.fs.ContentSummary; | |
import org.apache.hadoop.fs.CreateFlag; | |
import org.apache.hadoop.fs.FSDataInputStream; | |
import org.apache.hadoop.fs.FSDataOutputStream; | |
import org.apache.hadoop.fs.FileAlreadyExistsException; | |
import org.apache.hadoop.fs.FileChecksum; | |
import org.apache.hadoop.fs.FileStatus; | |
import org.apache.hadoop.fs.FileUtil; | |
import org.apache.hadoop.fs.FsServerDefaults; | |
import org.apache.hadoop.fs.FsStatus; | |
import org.apache.hadoop.fs.Globber; | |
import org.apache.hadoop.fs.LocalFileSystem; | |
import org.apache.hadoop.fs.LocatedFileStatus; | |
import org.apache.hadoop.fs.ParentNotDirectoryException; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.fs.PathFilter; | |
import org.apache.hadoop.fs.RemoteIterator; | |
import org.apache.hadoop.fs.UnsupportedFileSystemException; | |
import org.apache.hadoop.fs.XAttrSetFlag; | |
import org.apache.hadoop.fs.ContentSummary.Builder; | |
import org.apache.hadoop.fs.Options.ChecksumOpt; | |
import org.apache.hadoop.fs.Options.Rename; | |
import org.apache.hadoop.fs.permission.AclEntry; | |
import org.apache.hadoop.fs.permission.AclStatus; | |
import org.apache.hadoop.fs.permission.FsAction; | |
import org.apache.hadoop.fs.permission.FsPermission; | |
import org.apache.hadoop.io.MultipleIOException; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.security.AccessControlException; | |
import org.apache.hadoop.security.Credentials; | |
import org.apache.hadoop.security.SecurityUtil; | |
import org.apache.hadoop.security.UserGroupInformation; | |
import org.apache.hadoop.security.token.Token; | |
import org.apache.hadoop.util.Progressable; | |
import org.apache.hadoop.util.ReflectionUtils; | |
import org.apache.hadoop.util.ShutdownHookManager; | |
import org.apache.hadoop.util.StringUtils; | |
import org.apache.hadoop.util.DataChecksum.Type; | |
@Public | |
@Stable | |
public abstract class FileSystem extends Configured implements Closeable { | |
public static final String FS_DEFAULT_NAME_KEY = "fs.defaultFS"; | |
public static final String DEFAULT_FS = "file:///"; | |
public static final Log LOG = LogFactory.getLog(FileSystem.class); | |
public static final int SHUTDOWN_HOOK_PRIORITY = 10; | |
static final FileSystem.Cache CACHE = new FileSystem.Cache(); | |
private FileSystem.Cache.Key key; | |
private static final Map<Class<? extends FileSystem>, FileSystem.Statistics> statisticsTable = new IdentityHashMap(); | |
protected FileSystem.Statistics statistics; | |
private Set<Path> deleteOnExit = new TreeSet(); | |
boolean resolveSymlinks; | |
private static final PathFilter DEFAULT_FILTER = new PathFilter() { | |
public boolean accept(Path file) { | |
return true; | |
} | |
}; | |
private static volatile boolean FILE_SYSTEMS_LOADED = false; | |
private static final Map<String, Class<? extends FileSystem>> SERVICE_FILE_SYSTEMS = new HashMap(); | |
private static boolean symlinksEnabled = false; | |
private static Configuration conf = null; | |
static void addFileSystemForTesting(URI uri, Configuration conf, FileSystem fs) throws IOException { | |
CACHE.map.put(new FileSystem.Cache.Key(uri, conf), fs); | |
} | |
public static FileSystem get(final URI uri, final Configuration conf, String user) throws IOException, InterruptedException { | |
String ticketCachePath = conf.get("hadoop.security.kerberos.ticket.cache.path"); | |
UserGroupInformation ugi = UserGroupInformation.getBestUGI(ticketCachePath, user); | |
return (FileSystem)ugi.doAs(new PrivilegedExceptionAction() { | |
public FileSystem run() throws IOException { | |
return FileSystem.get(uri, conf); | |
} | |
}); | |
} | |
public static FileSystem get(Configuration conf) throws IOException { | |
return get(getDefaultUri(conf), conf); | |
} | |
public static URI getDefaultUri(Configuration conf) { | |
return URI.create(fixName(conf.get("fs.defaultFS", "file:///"))); | |
} | |
public static void setDefaultUri(Configuration conf, URI uri) { | |
conf.set("fs.defaultFS", uri.toString()); | |
} | |
public static void setDefaultUri(Configuration conf, String uri) { | |
setDefaultUri(conf, URI.create(fixName(uri))); | |
} | |
public void initialize(URI name, Configuration conf) throws IOException { | |
this.statistics = getStatistics(name.getScheme(), this.getClass()); | |
this.resolveSymlinks = conf.getBoolean("fs.client.resolve.remote.symlinks", true); | |
} | |
public String getScheme() { | |
throw new UnsupportedOperationException("Not implemented by the " + this.getClass().getSimpleName() + " FileSystem implementation"); | |
} | |
public abstract URI getUri(); | |
protected URI getCanonicalUri() { | |
return this.canonicalizeUri(this.getUri()); | |
} | |
protected URI canonicalizeUri(URI uri) { | |
if(uri.getPort() == -1 && this.getDefaultPort() > 0) { | |
try { | |
uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), this.getDefaultPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); | |
} catch (URISyntaxException var3) { | |
throw new AssertionError("Valid URI became unparseable: " + uri); | |
} | |
} | |
return uri; | |
} | |
protected int getDefaultPort() { | |
return 0; | |
} | |
protected static FileSystem getFSofPath(Path absOrFqPath, Configuration conf) throws UnsupportedFileSystemException, IOException { | |
absOrFqPath.checkNotSchemeWithRelative(); | |
absOrFqPath.checkNotRelative(); | |
return get(absOrFqPath.toUri(), conf); | |
} | |
@LimitedPrivate({"HDFS", "MapReduce"}) | |
public String getCanonicalServiceName() { | |
return this.getChildFileSystems() == null?SecurityUtil.buildDTServiceName(this.getUri(), this.getDefaultPort()):null; | |
} | |
/** @deprecated */ | |
@Deprecated | |
public String getName() { | |
return this.getUri().toString(); | |
} | |
/** @deprecated */ | |
@Deprecated | |
public static FileSystem getNamed(String name, Configuration conf) throws IOException { | |
return get(URI.create(fixName(name)), conf); | |
} | |
private static String fixName(String name) { | |
if(name.equals("local")) { | |
LOG.warn("\"local\" is a deprecated filesystem name. Use \"file:///\" instead."); | |
name = "file:///"; | |
} else if(name.indexOf(47) == -1) { | |
LOG.warn("\"" + name + "\" is a deprecated filesystem name." + " Use \"hdfs://" + name + "/\" instead."); | |
name = "hdfs://" + name; | |
} | |
return name; | |
} | |
public static LocalFileSystem getLocal(Configuration conf) throws IOException { | |
return (LocalFileSystem)get(LocalFileSystem.NAME, conf); | |
} | |
public static FileSystem get(URI uri, Configuration conf) throws IOException { | |
String scheme = uri.getScheme(); | |
String authority = uri.getAuthority(); | |
if(scheme == null && authority == null) { | |
return get(conf); | |
} else { | |
if(scheme != null && authority == null) { | |
URI disableCacheName = getDefaultUri(conf); | |
if(scheme.equals(disableCacheName.getScheme()) && disableCacheName.getAuthority() != null) { | |
return get(disableCacheName, conf); | |
} | |
} | |
String disableCacheName1 = String.format("fs.%s.impl.disable.cache", new Object[]{scheme}); | |
return conf.getBoolean(disableCacheName1, false)?createFileSystem(uri, conf):CACHE.get(uri, conf); | |
} | |
} | |
public static FileSystem newInstance(final URI uri, final Configuration conf, String user) throws IOException, InterruptedException { | |
String ticketCachePath = conf.get("hadoop.security.kerberos.ticket.cache.path"); | |
UserGroupInformation ugi = UserGroupInformation.getBestUGI(ticketCachePath, user); | |
return (FileSystem)ugi.doAs(new PrivilegedExceptionAction() { | |
public FileSystem run() throws IOException { | |
return FileSystem.newInstance(uri, conf); | |
} | |
}); | |
} | |
public static FileSystem newInstance(URI uri, Configuration conf) throws IOException { | |
String scheme = uri.getScheme(); | |
String authority = uri.getAuthority(); | |
if(scheme == null) { | |
return newInstance(conf); | |
} else { | |
if(authority == null) { | |
URI defaultUri = getDefaultUri(conf); | |
if(scheme.equals(defaultUri.getScheme()) && defaultUri.getAuthority() != null) { | |
return newInstance(defaultUri, conf); | |
} | |
} | |
return CACHE.getUnique(uri, conf); | |
} | |
} | |
public static FileSystem newInstance(Configuration conf) throws IOException { | |
return newInstance(getDefaultUri(conf), conf); | |
} | |
public static LocalFileSystem newInstanceLocal(Configuration conf) throws IOException { | |
return (LocalFileSystem)newInstance(LocalFileSystem.NAME, conf); | |
} | |
public static void closeAll() throws IOException { | |
CACHE.closeAll(); | |
} | |
public static void closeAllForUGI(UserGroupInformation ugi) throws IOException { | |
CACHE.closeAll(ugi); | |
} | |
public Path makeQualified(Path path) { | |
this.checkPath(path); | |
return path.makeQualified(this.getUri(), this.getWorkingDirectory()); | |
} | |
@Private | |
public Token<?> getDelegationToken(String renewer) throws IOException { | |
return null; | |
} | |
@LimitedPrivate({"HDFS", "MapReduce"}) | |
public Token<?>[] addDelegationTokens(String renewer, Credentials credentials) throws IOException { | |
if(credentials == null) { | |
credentials = new Credentials(); | |
} | |
ArrayList tokens = new ArrayList(); | |
this.collectDelegationTokens(renewer, credentials, tokens); | |
return (Token[])tokens.toArray(new Token[tokens.size()]); | |
} | |
private void collectDelegationTokens(String renewer, Credentials credentials, List<Token<?>> tokens) throws IOException { | |
String serviceName = this.getCanonicalServiceName(); | |
if(serviceName != null) { | |
Text children = new Text(serviceName); | |
Token token = credentials.getToken(children); | |
if(token == null) { | |
token = this.getDelegationToken(renewer); | |
if(token != null) { | |
tokens.add(token); | |
credentials.addToken(children, token); | |
} | |
} | |
} | |
FileSystem[] var10 = this.getChildFileSystems(); | |
if(var10 != null) { | |
FileSystem[] var11 = var10; | |
int var7 = var10.length; | |
for(int var8 = 0; var8 < var7; ++var8) { | |
FileSystem fs = var11[var8]; | |
fs.collectDelegationTokens(renewer, credentials, tokens); | |
} | |
} | |
} | |
@LimitedPrivate({"HDFS"}) | |
@VisibleForTesting | |
public FileSystem[] getChildFileSystems() { | |
return null; | |
} | |
public static FSDataOutputStream create(FileSystem fs, Path file, FsPermission permission) throws IOException { | |
FSDataOutputStream out = fs.create(file); | |
fs.setPermission(file, permission); | |
return out; | |
} | |
public static boolean mkdirs(FileSystem fs, Path dir, FsPermission permission) throws IOException { | |
boolean result = fs.mkdirs(dir); | |
fs.setPermission(dir, permission); | |
return result; | |
} | |
protected FileSystem() { | |
super((Configuration)null); | |
} | |
protected void checkPath(Path path) { | |
URI uri = path.toUri(); | |
String thatScheme = uri.getScheme(); | |
if(thatScheme != null) { | |
URI thisUri = this.getCanonicalUri(); | |
String thisScheme = thisUri.getScheme(); | |
if(thisScheme.equalsIgnoreCase(thatScheme)) { | |
String thisAuthority = thisUri.getAuthority(); | |
String thatAuthority = uri.getAuthority(); | |
if(thatAuthority == null && thisAuthority != null) { | |
URI defaultUri = getDefaultUri(this.getConf()); | |
if(thisScheme.equalsIgnoreCase(defaultUri.getScheme())) { | |
uri = defaultUri; | |
} else { | |
uri = null; | |
} | |
} | |
if(uri != null) { | |
uri = this.canonicalizeUri(uri); | |
thatAuthority = uri.getAuthority(); | |
if(thisAuthority == thatAuthority || thisAuthority != null && thisAuthority.equalsIgnoreCase(thatAuthority)) { | |
return; | |
} | |
} | |
} | |
throw new IllegalArgumentException("Wrong FS: " + path + ", expected: " + this.getUri()); | |
} | |
} | |
public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { | |
if(file == null) { | |
return null; | |
} else if(start >= 0L && len >= 0L) { | |
if(file.getLen() <= start) { | |
return new BlockLocation[0]; | |
} else { | |
String[] name = new String[]{"localhost:50010"}; | |
String[] host = new String[]{"localhost"}; | |
return new BlockLocation[]{new BlockLocation(name, host, 0L, file.getLen())}; | |
} | |
} else { | |
throw new IllegalArgumentException("Invalid start or len parameter"); | |
} | |
} | |
public BlockLocation[] getFileBlockLocations(Path p, long start, long len) throws IOException { | |
if(p == null) { | |
throw new NullPointerException(); | |
} else { | |
FileStatus file = this.getFileStatus(p); | |
return this.getFileBlockLocations(file, start, len); | |
} | |
} | |
/** @deprecated */ | |
@Deprecated | |
public FsServerDefaults getServerDefaults() throws IOException { | |
Configuration conf = this.getConf(); | |
return new FsServerDefaults(this.getDefaultBlockSize(), conf.getInt("io.bytes.per.checksum", 512), 65536, this.getDefaultReplication(), conf.getInt("io.file.buffer.size", 4096), false, 0L, Type.CRC32); | |
} | |
public FsServerDefaults getServerDefaults(Path p) throws IOException { | |
return this.getServerDefaults(); | |
} | |
public Path resolvePath(Path p) throws IOException { | |
this.checkPath(p); | |
return this.getFileStatus(p).getPath(); | |
} | |
public abstract FSDataInputStream open(Path var1, int var2) throws IOException; | |
public FSDataInputStream open(Path f) throws IOException { | |
return this.open(f, this.getConf().getInt("io.file.buffer.size", 4096)); | |
} | |
public FSDataOutputStream create(Path f) throws IOException { | |
return this.create(f, true); | |
} | |
public FSDataOutputStream create(Path f, boolean overwrite) throws IOException { | |
return this.create(f, overwrite, this.getConf().getInt("io.file.buffer.size", 4096), this.getDefaultReplication(f), this.getDefaultBlockSize(f)); | |
} | |
public FSDataOutputStream create(Path f, Progressable progress) throws IOException { | |
return this.create(f, true, this.getConf().getInt("io.file.buffer.size", 4096), this.getDefaultReplication(f), this.getDefaultBlockSize(f), progress); | |
} | |
public FSDataOutputStream create(Path f, short replication) throws IOException { | |
return this.create(f, true, this.getConf().getInt("io.file.buffer.size", 4096), replication, this.getDefaultBlockSize(f)); | |
} | |
public FSDataOutputStream create(Path f, short replication, Progressable progress) throws IOException { | |
return this.create(f, true, this.getConf().getInt("io.file.buffer.size", 4096), replication, this.getDefaultBlockSize(f), progress); | |
} | |
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize) throws IOException { | |
return this.create(f, overwrite, bufferSize, this.getDefaultReplication(f), this.getDefaultBlockSize(f)); | |
} | |
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, Progressable progress) throws IOException { | |
return this.create(f, overwrite, bufferSize, this.getDefaultReplication(f), this.getDefaultBlockSize(f), progress); | |
} | |
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, short replication, long blockSize) throws IOException { | |
return this.create(f, overwrite, bufferSize, replication, blockSize, (Progressable)null); | |
} | |
public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { | |
return this.create(f, FsPermission.getFileDefault().applyUMask(FsPermission.getUMask(this.getConf())), overwrite, bufferSize, replication, blockSize, progress); | |
} | |
public abstract FSDataOutputStream create(Path var1, FsPermission var2, boolean var3, int var4, short var5, long var6, Progressable var8) throws IOException; | |
public FSDataOutputStream create(Path f, FsPermission permission, EnumSet<CreateFlag> flags, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { | |
return this.create(f, permission, flags, bufferSize, replication, blockSize, progress, (ChecksumOpt)null); | |
} | |
public FSDataOutputStream create(Path f, FsPermission permission, EnumSet<CreateFlag> flags, int bufferSize, short replication, long blockSize, Progressable progress, ChecksumOpt checksumOpt) throws IOException { | |
return this.create(f, permission, flags.contains(CreateFlag.OVERWRITE), bufferSize, replication, blockSize, progress); | |
} | |
/** @deprecated */ | |
@Deprecated | |
protected FSDataOutputStream primitiveCreate(Path f, FsPermission absolutePermission, EnumSet<CreateFlag> flag, int bufferSize, short replication, long blockSize, Progressable progress, ChecksumOpt checksumOpt) throws IOException { | |
boolean pathExists = this.exists(f); | |
CreateFlag.validate(f, pathExists, flag); | |
return pathExists && flag.contains(CreateFlag.APPEND)?this.append(f, bufferSize, progress):this.create(f, absolutePermission, flag.contains(CreateFlag.OVERWRITE), bufferSize, replication, blockSize, progress); | |
} | |
/** @deprecated */ | |
@Deprecated | |
protected boolean primitiveMkdir(Path f, FsPermission absolutePermission) throws IOException { | |
return this.mkdirs(f, absolutePermission); | |
} | |
/** @deprecated */ | |
@Deprecated | |
protected void primitiveMkdir(Path f, FsPermission absolutePermission, boolean createParent) throws IOException { | |
if(!createParent) { | |
FileStatus stat = this.getFileStatus(f.getParent()); | |
if(stat == null) { | |
throw new FileNotFoundException("Missing parent:" + f); | |
} | |
if(!stat.isDirectory()) { | |
throw new ParentNotDirectoryException("parent is not a dir"); | |
} | |
} | |
if(!this.mkdirs(f, absolutePermission)) { | |
throw new IOException("mkdir of " + f + " failed"); | |
} | |
} | |
/** @deprecated */ | |
@Deprecated | |
public FSDataOutputStream createNonRecursive(Path f, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { | |
return this.createNonRecursive(f, FsPermission.getFileDefault(), overwrite, bufferSize, replication, blockSize, progress); | |
} | |
/** @deprecated */ | |
@Deprecated | |
public FSDataOutputStream createNonRecursive(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { | |
return this.createNonRecursive(f, permission, overwrite?EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE):EnumSet.of(CreateFlag.CREATE), bufferSize, replication, blockSize, progress); | |
} | |
/** @deprecated */ | |
@Deprecated | |
public FSDataOutputStream createNonRecursive(Path f, FsPermission permission, EnumSet<CreateFlag> flags, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { | |
throw new IOException("createNonRecursive unsupported for this filesystem " + this.getClass()); | |
} | |
public boolean createNewFile(Path f) throws IOException { | |
if(this.exists(f)) { | |
return false; | |
} else { | |
this.create(f, false, this.getConf().getInt("io.file.buffer.size", 4096)).close(); | |
return true; | |
} | |
} | |
public FSDataOutputStream append(Path f) throws IOException { | |
return this.append(f, this.getConf().getInt("io.file.buffer.size", 4096), (Progressable)null); | |
} | |
public FSDataOutputStream append(Path f, int bufferSize) throws IOException { | |
return this.append(f, bufferSize, (Progressable)null); | |
} | |
public abstract FSDataOutputStream append(Path var1, int var2, Progressable var3) throws IOException; | |
public void concat(Path trg, Path[] psrcs) throws IOException { | |
throw new UnsupportedOperationException("Not implemented by the " + this.getClass().getSimpleName() + " FileSystem implementation"); | |
} | |
/** @deprecated */ | |
@Deprecated | |
public short getReplication(Path src) throws IOException { | |
return this.getFileStatus(src).getReplication(); | |
} | |
public boolean setReplication(Path src, short replication) throws IOException { | |
return true; | |
} | |
public abstract boolean rename(Path var1, Path var2) throws IOException; | |
/** @deprecated */ | |
@Deprecated | |
protected void rename(Path src, Path dst, Rename... options) throws IOException { | |
FileStatus srcStatus = this.getFileLinkStatus(src); | |
if(srcStatus == null) { | |
throw new FileNotFoundException("rename source " + src + " not found."); | |
} else { | |
boolean overwrite = false; | |
if(null != options) { | |
Rename[] dstStatus = options; | |
int parent = options.length; | |
for(int parentStatus = 0; parentStatus < parent; ++parentStatus) { | |
Rename option = dstStatus[parentStatus]; | |
if(option == Rename.OVERWRITE) { | |
overwrite = true; | |
} | |
} | |
} | |
FileStatus var11; | |
try { | |
var11 = this.getFileLinkStatus(dst); | |
} catch (IOException var10) { | |
var11 = null; | |
} | |
if(var11 != null) { | |
if(srcStatus.isDirectory() != var11.isDirectory()) { | |
throw new IOException("Source " + src + " Destination " + dst + " both should be either file or directory"); | |
} | |
if(!overwrite) { | |
throw new FileAlreadyExistsException("rename destination " + dst + " already exists."); | |
} | |
if(var11.isDirectory()) { | |
FileStatus[] var12 = this.listStatus(dst); | |
if(var12 != null && var12.length != 0) { | |
throw new IOException("rename cannot overwrite non empty destination directory " + dst); | |
} | |
} | |
this.delete(dst, false); | |
} else { | |
Path var13 = dst.getParent(); | |
FileStatus var14 = this.getFileStatus(var13); | |
if(var14 == null) { | |
throw new FileNotFoundException("rename destination parent " + var13 + " not found."); | |
} | |
if(!var14.isDirectory()) { | |
throw new ParentNotDirectoryException("rename destination parent " + var13 + " is a file."); | |
} | |
} | |
if(!this.rename(src, dst)) { | |
throw new IOException("rename from " + src + " to " + dst + " failed."); | |
} | |
} | |
} | |
public boolean truncate(Path f, long newLength) throws IOException { | |
throw new UnsupportedOperationException("Not implemented by the " + this.getClass().getSimpleName() + " FileSystem implementation"); | |
} | |
/** @deprecated */ | |
@Deprecated | |
public boolean delete(Path f) throws IOException { | |
return this.delete(f, true); | |
} | |
public abstract boolean delete(Path var1, boolean var2) throws IOException; | |
public boolean deleteOnExit(Path f) throws IOException { | |
if(!this.exists(f)) { | |
return false; | |
} else { | |
Set var2 = this.deleteOnExit; | |
synchronized(this.deleteOnExit) { | |
this.deleteOnExit.add(f); | |
return true; | |
} | |
} | |
} | |
public boolean cancelDeleteOnExit(Path f) { | |
Set var2 = this.deleteOnExit; | |
synchronized(this.deleteOnExit) { | |
return this.deleteOnExit.remove(f); | |
} | |
} | |
protected void processDeleteOnExit() { | |
Set var1 = this.deleteOnExit; | |
synchronized(this.deleteOnExit) { | |
for(Iterator iter = this.deleteOnExit.iterator(); iter.hasNext(); iter.remove()) { | |
Path path = (Path)iter.next(); | |
try { | |
if(this.exists(path)) { | |
this.delete(path, true); | |
} | |
} catch (IOException var6) { | |
LOG.info("Ignoring failure to deleteOnExit for path " + path); | |
} | |
} | |
} | |
} | |
public boolean exists(Path f) throws IOException { | |
try { | |
return this.getFileStatus(f) != null; | |
} catch (FileNotFoundException var3) { | |
return false; | |
} | |
} | |
public boolean isDirectory(Path f) throws IOException { | |
try { | |
return this.getFileStatus(f).isDirectory(); | |
} catch (FileNotFoundException var3) { | |
return false; | |
} | |
} | |
public boolean isFile(Path f) throws IOException { | |
try { | |
return this.getFileStatus(f).isFile(); | |
} catch (FileNotFoundException var3) { | |
return false; | |
} | |
} | |
/** @deprecated */ | |
@Deprecated | |
public long getLength(Path f) throws IOException { | |
return this.getFileStatus(f).getLen(); | |
} | |
public ContentSummary getContentSummary(Path f) throws IOException { | |
FileStatus status = this.getFileStatus(f); | |
if(status.isFile()) { | |
long var11 = status.getLen(); | |
return (new Builder()).length(var11).fileCount(1L).directoryCount(0L).spaceConsumed(var11).build(); | |
} else { | |
long[] summary = new long[]{0L, 0L, 1L}; | |
FileStatus[] var4 = this.listStatus(f); | |
int var5 = var4.length; | |
for(int var6 = 0; var6 < var5; ++var6) { | |
FileStatus s = var4[var6]; | |
long length = s.getLen(); | |
ContentSummary c = s.isDirectory()?this.getContentSummary(s.getPath()):(new Builder()).length(length).fileCount(1L).directoryCount(0L).spaceConsumed(length).build(); | |
summary[0] += c.getLength(); | |
summary[1] += c.getFileCount(); | |
summary[2] += c.getDirectoryCount(); | |
} | |
return (new Builder()).length(summary[0]).fileCount(summary[1]).directoryCount(summary[2]).spaceConsumed(summary[0]).build(); | |
} | |
} | |
public abstract FileStatus[] listStatus(Path var1) throws FileNotFoundException, IOException; | |
private void listStatus(ArrayList<FileStatus> results, Path f, PathFilter filter) throws FileNotFoundException, IOException { | |
FileStatus[] listing = this.listStatus(f); | |
if(listing == null) { | |
throw new IOException("Error accessing " + f); | |
} else { | |
for(int i = 0; i < listing.length; ++i) { | |
if(filter.accept(listing[i].getPath())) { | |
results.add(listing[i]); | |
} | |
} | |
} | |
} | |
public RemoteIterator<Path> listCorruptFileBlocks(Path path) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getCanonicalName() + " does not support" + " listCorruptFileBlocks"); | |
} | |
public FileStatus[] listStatus(Path f, PathFilter filter) throws FileNotFoundException, IOException { | |
ArrayList results = new ArrayList(); | |
this.listStatus(results, f, filter); | |
return (FileStatus[])results.toArray(new FileStatus[results.size()]); | |
} | |
public FileStatus[] listStatus(Path[] files) throws FileNotFoundException, IOException { | |
return this.listStatus(files, DEFAULT_FILTER); | |
} | |
public FileStatus[] listStatus(Path[] files, PathFilter filter) throws FileNotFoundException, IOException { | |
ArrayList results = new ArrayList(); | |
for(int i = 0; i < files.length; ++i) { | |
this.listStatus(results, files[i], filter); | |
} | |
return (FileStatus[])results.toArray(new FileStatus[results.size()]); | |
} | |
public FileStatus[] globStatus(Path pathPattern) throws IOException { | |
return (new Globber(this, pathPattern, DEFAULT_FILTER)).glob(); | |
} | |
public FileStatus[] globStatus(Path pathPattern, PathFilter filter) throws IOException { | |
return (new Globber(this, pathPattern, filter)).glob(); | |
} | |
public RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f) throws FileNotFoundException, IOException { | |
return this.listLocatedStatus(f, DEFAULT_FILTER); | |
} | |
protected RemoteIterator<LocatedFileStatus> listLocatedStatus(final Path f, final PathFilter filter) throws FileNotFoundException, IOException { | |
return new RemoteIterator() { | |
private final FileStatus[] stats = FileSystem.this.listStatus(f, filter); | |
private int i = 0; | |
public boolean hasNext() { | |
return this.i < this.stats.length; | |
} | |
public LocatedFileStatus next() throws IOException { | |
if(!this.hasNext()) { | |
throw new NoSuchElementException("No more entry in " + f); | |
} else { | |
FileStatus result = this.stats[this.i++]; | |
BlockLocation[] locs = result.isFile()?FileSystem.this.getFileBlockLocations(result.getPath(), 0L, result.getLen()):null; | |
return new LocatedFileStatus(result, locs); | |
} | |
} | |
}; | |
} | |
public RemoteIterator<FileStatus> listStatusIterator(final Path p) throws FileNotFoundException, IOException { | |
return new RemoteIterator() { | |
private final FileStatus[] stats = FileSystem.this.listStatus(p); | |
private int i = 0; | |
public boolean hasNext() { | |
return this.i < this.stats.length; | |
} | |
public FileStatus next() throws IOException { | |
if(!this.hasNext()) { | |
throw new NoSuchElementException("No more entry in " + p); | |
} else { | |
return this.stats[this.i++]; | |
} | |
} | |
}; | |
} | |
public RemoteIterator<LocatedFileStatus> listFiles(final Path f, final boolean recursive) throws FileNotFoundException, IOException { | |
return new RemoteIterator() { | |
private Stack<RemoteIterator<LocatedFileStatus>> itors = new Stack(); | |
private RemoteIterator<LocatedFileStatus> curItor = FileSystem.this.listLocatedStatus(f); | |
private LocatedFileStatus curFile; | |
public boolean hasNext() throws IOException { | |
while(true) { | |
if(this.curFile == null) { | |
if(this.curItor.hasNext()) { | |
this.handleFileStat((LocatedFileStatus)this.curItor.next()); | |
continue; | |
} | |
if(!this.itors.empty()) { | |
this.curItor = (RemoteIterator)this.itors.pop(); | |
continue; | |
} | |
return false; | |
} | |
return true; | |
} | |
} | |
private void handleFileStat(LocatedFileStatus stat) throws IOException { | |
if(stat.isFile()) { | |
this.curFile = stat; | |
} else if(recursive) { | |
this.itors.push(this.curItor); | |
this.curItor = FileSystem.this.listLocatedStatus(stat.getPath()); | |
} | |
} | |
public LocatedFileStatus next() throws IOException { | |
if(this.hasNext()) { | |
LocatedFileStatus result = this.curFile; | |
this.curFile = null; | |
return result; | |
} else { | |
throw new NoSuchElementException("No more entry in " + f); | |
} | |
} | |
}; | |
} | |
public Path getHomeDirectory() { | |
return this.makeQualified(new Path("/user/" + System.getProperty("user.name"))); | |
} | |
public abstract void setWorkingDirectory(Path var1); | |
public abstract Path getWorkingDirectory(); | |
protected Path getInitialWorkingDirectory() { | |
return null; | |
} | |
public boolean mkdirs(Path f) throws IOException { | |
return this.mkdirs(f, FsPermission.getDirDefault()); | |
} | |
public abstract boolean mkdirs(Path var1, FsPermission var2) throws IOException; | |
public void copyFromLocalFile(Path src, Path dst) throws IOException { | |
this.copyFromLocalFile(false, src, dst); | |
} | |
public void moveFromLocalFile(Path[] srcs, Path dst) throws IOException { | |
this.copyFromLocalFile(true, true, srcs, dst); | |
} | |
public void moveFromLocalFile(Path src, Path dst) throws IOException { | |
this.copyFromLocalFile(true, src, dst); | |
} | |
public void copyFromLocalFile(boolean delSrc, Path src, Path dst) throws IOException { | |
this.copyFromLocalFile(delSrc, true, src, dst); | |
} | |
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path[] srcs, Path dst) throws IOException { | |
Configuration conf = this.getConf(); | |
FileUtil.copy(getLocal(conf), srcs, this, dst, delSrc, overwrite, conf); | |
} | |
public void copyFromLocalFile(boolean delSrc, boolean overwrite, Path src, Path dst) throws IOException { | |
Configuration conf = this.getConf(); | |
FileUtil.copy(getLocal(conf), src, this, dst, delSrc, overwrite, conf); | |
} | |
public void copyToLocalFile(Path src, Path dst) throws IOException { | |
this.copyToLocalFile(false, src, dst); | |
} | |
public void moveToLocalFile(Path src, Path dst) throws IOException { | |
this.copyToLocalFile(true, src, dst); | |
} | |
public void copyToLocalFile(boolean delSrc, Path src, Path dst) throws IOException { | |
this.copyToLocalFile(delSrc, src, dst, false); | |
} | |
public void copyToLocalFile(boolean delSrc, Path src, Path dst, boolean useRawLocalFileSystem) throws IOException { | |
Configuration conf = this.getConf(); | |
Object local = null; | |
if(useRawLocalFileSystem) { | |
local = getLocal(conf).getRawFileSystem(); | |
} else { | |
local = getLocal(conf); | |
} | |
FileUtil.copy(this, src, (FileSystem)local, dst, delSrc, conf); | |
} | |
public Path startLocalOutput(Path fsOutputFile, Path tmpLocalFile) throws IOException { | |
return tmpLocalFile; | |
} | |
public void completeLocalOutput(Path fsOutputFile, Path tmpLocalFile) throws IOException { | |
this.moveFromLocalFile(tmpLocalFile, fsOutputFile); | |
} | |
public void close() throws IOException { | |
this.processDeleteOnExit(); | |
CACHE.remove(this.key, this); | |
} | |
public long getUsed() throws IOException { | |
long used = 0L; | |
FileStatus[] files = this.listStatus(new Path("/")); | |
FileStatus[] var4 = files; | |
int var5 = files.length; | |
for(int var6 = 0; var6 < var5; ++var6) { | |
FileStatus file = var4[var6]; | |
used += file.getLen(); | |
} | |
return used; | |
} | |
/** @deprecated */ | |
@Deprecated | |
public long getBlockSize(Path f) throws IOException { | |
return this.getFileStatus(f).getBlockSize(); | |
} | |
/** @deprecated */ | |
@Deprecated | |
public long getDefaultBlockSize() { | |
return this.getConf().getLong("fs.local.block.size", 33554432L); | |
} | |
public long getDefaultBlockSize(Path f) { | |
return this.getDefaultBlockSize(); | |
} | |
/** @deprecated */ | |
@Deprecated | |
public short getDefaultReplication() { | |
return (short)1; | |
} | |
public short getDefaultReplication(Path path) { | |
return this.getDefaultReplication(); | |
} | |
public abstract FileStatus getFileStatus(Path var1) throws IOException; | |
@LimitedPrivate({"HDFS", "Hive"}) | |
public void access(Path path, FsAction mode) throws AccessControlException, FileNotFoundException, IOException { | |
checkAccessPermissions(this.getFileStatus(path), mode); | |
} | |
@Private | |
static void checkAccessPermissions(FileStatus stat, FsAction mode) throws IOException { | |
FsPermission perm = stat.getPermission(); | |
UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); | |
String user = ugi.getShortUserName(); | |
List groups = Arrays.asList(ugi.getGroupNames()); | |
if(user.equals(stat.getOwner())) { | |
if(perm.getUserAction().implies(mode)) { | |
return; | |
} | |
} else if(groups.contains(stat.getGroup())) { | |
if(perm.getGroupAction().implies(mode)) { | |
return; | |
} | |
} else if(perm.getOtherAction().implies(mode)) { | |
return; | |
} | |
throw new AccessControlException(String.format("Permission denied: user=%s, path=\"%s\":%s:%s:%s%s", new Object[]{user, stat.getPath(), stat.getOwner(), stat.getGroup(), stat.isDirectory()?"d":"-", perm})); | |
} | |
protected Path fixRelativePart(Path p) { | |
return p.isUriPathAbsolute()?p:new Path(this.getWorkingDirectory(), p); | |
} | |
public void createSymlink(Path target, Path link, boolean createParent) throws AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, UnsupportedFileSystemException, IOException { | |
throw new UnsupportedOperationException("Filesystem does not support symlinks!"); | |
} | |
public FileStatus getFileLinkStatus(Path f) throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException { | |
return this.getFileStatus(f); | |
} | |
public boolean supportsSymlinks() { | |
return false; | |
} | |
public Path getLinkTarget(Path f) throws IOException { | |
throw new UnsupportedOperationException("Filesystem does not support symlinks!"); | |
} | |
protected Path resolveLink(Path f) throws IOException { | |
throw new UnsupportedOperationException("Filesystem does not support symlinks!"); | |
} | |
public FileChecksum getFileChecksum(Path f) throws IOException { | |
return this.getFileChecksum(f, 9223372036854775807L); | |
} | |
public FileChecksum getFileChecksum(Path f, long length) throws IOException { | |
return null; | |
} | |
public void setVerifyChecksum(boolean verifyChecksum) { | |
} | |
public void setWriteChecksum(boolean writeChecksum) { | |
} | |
public FsStatus getStatus() throws IOException { | |
return this.getStatus((Path)null); | |
} | |
public FsStatus getStatus(Path p) throws IOException { | |
return new FsStatus(9223372036854775807L, 0L, 9223372036854775807L); | |
} | |
public void setPermission(Path p, FsPermission permission) throws IOException { | |
} | |
public void setOwner(Path p, String username, String groupname) throws IOException { | |
} | |
public void setTimes(Path p, long mtime, long atime) throws IOException { | |
} | |
public final Path createSnapshot(Path path) throws IOException { | |
return this.createSnapshot(path, (String)null); | |
} | |
public Path createSnapshot(Path path, String snapshotName) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support createSnapshot"); | |
} | |
public void renameSnapshot(Path path, String snapshotOldName, String snapshotNewName) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support renameSnapshot"); | |
} | |
public void deleteSnapshot(Path path, String snapshotName) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support deleteSnapshot"); | |
} | |
public void modifyAclEntries(Path path, List<AclEntry> aclSpec) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support modifyAclEntries"); | |
} | |
public void removeAclEntries(Path path, List<AclEntry> aclSpec) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support removeAclEntries"); | |
} | |
public void removeDefaultAcl(Path path) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support removeDefaultAcl"); | |
} | |
public void removeAcl(Path path) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support removeAcl"); | |
} | |
public void setAcl(Path path, List<AclEntry> aclSpec) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support setAcl"); | |
} | |
public AclStatus getAclStatus(Path path) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support getAclStatus"); | |
} | |
public void setXAttr(Path path, String name, byte[] value) throws IOException { | |
this.setXAttr(path, name, value, EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE)); | |
} | |
public void setXAttr(Path path, String name, byte[] value, EnumSet<XAttrSetFlag> flag) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support setXAttr"); | |
} | |
public byte[] getXAttr(Path path, String name) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support getXAttr"); | |
} | |
public Map<String, byte[]> getXAttrs(Path path) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support getXAttrs"); | |
} | |
public Map<String, byte[]> getXAttrs(Path path, List<String> names) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support getXAttrs"); | |
} | |
public List<String> listXAttrs(Path path) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support listXAttrs"); | |
} | |
public void removeXAttr(Path path, String name) throws IOException { | |
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " doesn\'t support removeXAttr"); | |
} | |
private static void loadFileSystems() { | |
Class var0 = FileSystem.class; | |
synchronized(FileSystem.class) { | |
if(!FILE_SYSTEMS_LOADED) { | |
ServiceLoader serviceLoader = ServiceLoader.load(FileSystem.class); | |
Iterator var2 = serviceLoader.iterator(); | |
while(var2.hasNext()) { | |
FileSystem fs = (FileSystem)var2.next(); | |
SERVICE_FILE_SYSTEMS.put(fs.getScheme(), fs.getClass()); | |
} | |
FILE_SYSTEMS_LOADED = true; | |
} | |
} | |
} | |
public static Class<? extends FileSystem> getFileSystemClass(String scheme, Configuration conf) throws IOException { | |
if(!FILE_SYSTEMS_LOADED) { | |
loadFileSystems(); | |
} | |
Class clazz = null; | |
if(conf != null) { | |
clazz = conf.getClass("fs." + scheme + ".impl", (Class)null); | |
} | |
if(clazz == null) { | |
clazz = (Class)SERVICE_FILE_SYSTEMS.get(scheme); | |
} | |
if(clazz == null) { | |
throw new IOException("No FileSystem for scheme: " + scheme); | |
} else { | |
return clazz; | |
} | |
} | |
private static FileSystem createFileSystem(URI uri, Configuration conf) throws IOException { | |
Class clazz = getFileSystemClass(uri.getScheme(), conf); | |
FileSystem fs = (FileSystem)ReflectionUtils.newInstance(clazz, conf); | |
fs.initialize(uri, conf); | |
return fs; | |
} | |
/** @deprecated */ | |
@Deprecated | |
public static synchronized Map<String, FileSystem.Statistics> getStatistics() { | |
HashMap result = new HashMap(); | |
Iterator var1 = statisticsTable.values().iterator(); | |
while(var1.hasNext()) { | |
FileSystem.Statistics stat = (FileSystem.Statistics)var1.next(); | |
result.put(stat.getScheme(), stat); | |
} | |
return result; | |
} | |
public static synchronized List<FileSystem.Statistics> getAllStatistics() { | |
return new ArrayList(statisticsTable.values()); | |
} | |
public static synchronized FileSystem.Statistics getStatistics(String scheme, Class<? extends FileSystem> cls) { | |
FileSystem.Statistics result = (FileSystem.Statistics)statisticsTable.get(cls); | |
if(result == null) { | |
result = new FileSystem.Statistics(scheme); | |
statisticsTable.put(cls, result); | |
} | |
return result; | |
} | |
public static synchronized void clearStatistics() { | |
Iterator var0 = statisticsTable.values().iterator(); | |
while(var0.hasNext()) { | |
FileSystem.Statistics stat = (FileSystem.Statistics)var0.next(); | |
stat.reset(); | |
} | |
} | |
public static synchronized void printStatistics() throws IOException { | |
Iterator var0 = statisticsTable.entrySet().iterator(); | |
while(var0.hasNext()) { | |
Entry pair = (Entry)var0.next(); | |
System.out.println(" FileSystem " + ((Class)pair.getKey()).getName() + ": " + pair.getValue()); | |
} | |
} | |
@VisibleForTesting | |
public static boolean areSymlinksEnabled() { | |
return symlinksEnabled; | |
} | |
@VisibleForTesting | |
public static void enableSymlinks() { | |
symlinksEnabled = true; | |
} | |
public static final class Statistics { | |
private final String scheme; | |
private final FileSystem.Statistics.StatisticsData rootData; | |
private final ThreadLocal<FileSystem.Statistics.StatisticsData> threadData; | |
private LinkedList<FileSystem.Statistics.StatisticsData> allData; | |
public Statistics(String scheme) { | |
this.scheme = scheme; | |
this.rootData = new FileSystem.Statistics.StatisticsData((WeakReference)null); | |
this.threadData = new ThreadLocal(); | |
this.allData = null; | |
} | |
public Statistics(FileSystem.Statistics other) { | |
this.scheme = other.scheme; | |
this.rootData = new FileSystem.Statistics.StatisticsData((WeakReference)null); | |
other.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
Statistics.this.rootData.add(data); | |
} | |
public Void aggregate() { | |
return null; | |
} | |
}); | |
this.threadData = new ThreadLocal(); | |
} | |
public FileSystem.Statistics.StatisticsData getThreadStatistics() { | |
FileSystem.Statistics.StatisticsData data = (FileSystem.Statistics.StatisticsData)this.threadData.get(); | |
if(data == null) { | |
data = new FileSystem.Statistics.StatisticsData(new WeakReference(Thread.currentThread())); | |
this.threadData.set(data); | |
synchronized(this) { | |
if(this.allData == null) { | |
this.allData = new LinkedList(); | |
} | |
this.allData.add(data); | |
} | |
} | |
return data; | |
} | |
public void incrementBytesRead(long newBytes) { | |
FileSystem.Statistics.StatisticsData var10000 = this.getThreadStatistics(); | |
var10000.bytesRead += newBytes; | |
} | |
public void incrementBytesWritten(long newBytes) { | |
FileSystem.Statistics.StatisticsData var10000 = this.getThreadStatistics(); | |
var10000.bytesWritten += newBytes; | |
} | |
public void incrementReadOps(int count) { | |
FileSystem.Statistics.StatisticsData var10000 = this.getThreadStatistics(); | |
var10000.readOps += count; | |
} | |
public void incrementLargeReadOps(int count) { | |
FileSystem.Statistics.StatisticsData var10000 = this.getThreadStatistics(); | |
var10000.largeReadOps += count; | |
} | |
public void incrementWriteOps(int count) { | |
FileSystem.Statistics.StatisticsData var10000 = this.getThreadStatistics(); | |
var10000.writeOps += count; | |
} | |
private synchronized <T> T visitAll(FileSystem.Statistics.StatisticsAggregator<T> visitor) { | |
visitor.accept(this.rootData); | |
if(this.allData != null) { | |
Iterator iter = this.allData.iterator(); | |
while(iter.hasNext()) { | |
FileSystem.Statistics.StatisticsData data = (FileSystem.Statistics.StatisticsData)iter.next(); | |
visitor.accept(data); | |
if(data.owner.get() == null) { | |
this.rootData.add(data); | |
iter.remove(); | |
} | |
} | |
} | |
return visitor.aggregate(); | |
} | |
public long getBytesRead() { | |
return ((Long)this.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
private long bytesRead = 0L; | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
this.bytesRead += data.bytesRead; | |
} | |
public Long aggregate() { | |
return Long.valueOf(this.bytesRead); | |
} | |
})).longValue(); | |
} | |
public long getBytesWritten() { | |
return ((Long)this.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
private long bytesWritten = 0L; | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
this.bytesWritten += data.bytesWritten; | |
} | |
public Long aggregate() { | |
return Long.valueOf(this.bytesWritten); | |
} | |
})).longValue(); | |
} | |
public int getReadOps() { | |
return ((Integer)this.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
private int readOps = 0; | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
this.readOps += data.readOps; | |
this.readOps += data.largeReadOps; | |
} | |
public Integer aggregate() { | |
return Integer.valueOf(this.readOps); | |
} | |
})).intValue(); | |
} | |
public int getLargeReadOps() { | |
return ((Integer)this.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
private int largeReadOps = 0; | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
this.largeReadOps += data.largeReadOps; | |
} | |
public Integer aggregate() { | |
return Integer.valueOf(this.largeReadOps); | |
} | |
})).intValue(); | |
} | |
public int getWriteOps() { | |
return ((Integer)this.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
private int writeOps = 0; | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
this.writeOps += data.writeOps; | |
} | |
public Integer aggregate() { | |
return Integer.valueOf(this.writeOps); | |
} | |
})).intValue(); | |
} | |
public String toString() { | |
return (String)this.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
private FileSystem.Statistics.StatisticsData total = new FileSystem.Statistics.StatisticsData((WeakReference)null); | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
this.total.add(data); | |
} | |
public String aggregate() { | |
return this.total.toString(); | |
} | |
}); | |
} | |
public void reset() { | |
this.visitAll(new FileSystem.Statistics.StatisticsAggregator() { | |
private FileSystem.Statistics.StatisticsData total = new FileSystem.Statistics.StatisticsData((WeakReference)null); | |
public void accept(FileSystem.Statistics.StatisticsData data) { | |
this.total.add(data); | |
} | |
public Void aggregate() { | |
this.total.negate(); | |
Statistics.this.rootData.add(this.total); | |
return null; | |
} | |
}); | |
} | |
public String getScheme() { | |
return this.scheme; | |
} | |
private interface StatisticsAggregator<T> { | |
void accept(FileSystem.Statistics.StatisticsData var1); | |
T aggregate(); | |
} | |
public static class StatisticsData { | |
volatile long bytesRead; | |
volatile long bytesWritten; | |
volatile int readOps; | |
volatile int largeReadOps; | |
volatile int writeOps; | |
final WeakReference<Thread> owner; | |
StatisticsData(WeakReference<Thread> owner) { | |
this.owner = owner; | |
} | |
void add(FileSystem.Statistics.StatisticsData other) { | |
this.bytesRead += other.bytesRead; | |
this.bytesWritten += other.bytesWritten; | |
this.readOps += other.readOps; | |
this.largeReadOps += other.largeReadOps; | |
this.writeOps += other.writeOps; | |
} | |
void negate() { | |
this.bytesRead = -this.bytesRead; | |
this.bytesWritten = -this.bytesWritten; | |
this.readOps = -this.readOps; | |
this.largeReadOps = -this.largeReadOps; | |
this.writeOps = -this.writeOps; | |
} | |
public String toString() { | |
return this.bytesRead + " bytes read, " + this.bytesWritten + " bytes written, " + this.readOps + " read ops, " + this.largeReadOps + " large read ops, " + this.writeOps + " write ops"; | |
} | |
public long getBytesRead() { | |
return this.bytesRead; | |
} | |
public long getBytesWritten() { | |
return this.bytesWritten; | |
} | |
public int getReadOps() { | |
return this.readOps; | |
} | |
public int getLargeReadOps() { | |
return this.largeReadOps; | |
} | |
public int getWriteOps() { | |
return this.writeOps; | |
} | |
} | |
} | |
static class Cache { | |
private final FileSystem.Cache.ClientFinalizer clientFinalizer = new FileSystem.Cache.ClientFinalizer(null); | |
private final Map<FileSystem.Cache.Key, FileSystem> map = new HashMap(); | |
private final Set<FileSystem.Cache.Key> toAutoClose = new HashSet(); | |
private static AtomicLong unique = new AtomicLong(1L); | |
Cache() { | |
} | |
FileSystem get(URI uri, Configuration conf) throws IOException { | |
FileSystem.Cache.Key key = new FileSystem.Cache.Key(uri, conf); | |
return this.getInternal(uri, conf, key); | |
} | |
FileSystem getUnique(URI uri, Configuration conf) throws IOException { | |
FileSystem.Cache.Key key = new FileSystem.Cache.Key(uri, conf, unique.getAndIncrement()); | |
return this.getInternal(uri, conf, key); | |
} | |
private FileSystem getInternal(URI uri, Configuration conf, FileSystem.Cache.Key key) throws IOException { | |
FileSystem fs; | |
synchronized(this) { | |
fs = (FileSystem)this.map.get(key); | |
} | |
if(fs != null) { | |
return fs; | |
} else { | |
fs = FileSystem.createFileSystem(uri, conf); | |
synchronized(this) { | |
FileSystem oldfs = (FileSystem)this.map.get(key); | |
if(oldfs != null) { | |
fs.close(); | |
return oldfs; | |
} else { | |
if(this.map.isEmpty() && !ShutdownHookManager.get().isShutdownInProgress()) { | |
ShutdownHookManager.get().addShutdownHook(this.clientFinalizer, 10); | |
} | |
fs.key = key; | |
this.map.put(key, fs); | |
if(conf.getBoolean("fs.automatic.close", true)) { | |
this.toAutoClose.add(key); | |
} | |
return fs; | |
} | |
} | |
} | |
} | |
synchronized void remove(FileSystem.Cache.Key key, FileSystem fs) { | |
if(this.map.containsKey(key) && fs == this.map.get(key)) { | |
this.map.remove(key); | |
this.toAutoClose.remove(key); | |
} | |
} | |
synchronized void closeAll() throws IOException { | |
this.closeAll(false); | |
} | |
synchronized void closeAll(boolean onlyAutomatic) throws IOException { | |
ArrayList exceptions = new ArrayList(); | |
ArrayList keys = new ArrayList(); | |
keys.addAll(this.map.keySet()); | |
Iterator var4 = keys.iterator(); | |
while(true) { | |
FileSystem.Cache.Key key; | |
FileSystem fs; | |
do { | |
if(!var4.hasNext()) { | |
if(!exceptions.isEmpty()) { | |
throw MultipleIOException.createIOException(exceptions); | |
} | |
return; | |
} | |
key = (FileSystem.Cache.Key)var4.next(); | |
fs = (FileSystem)this.map.get(key); | |
} while(onlyAutomatic && !this.toAutoClose.contains(key)); | |
this.remove(key, fs); | |
if(fs != null) { | |
try { | |
fs.close(); | |
} catch (IOException var8) { | |
exceptions.add(var8); | |
} | |
} | |
} | |
} | |
synchronized void closeAll(UserGroupInformation ugi) throws IOException { | |
ArrayList targetFSList = new ArrayList(); | |
Iterator exceptions = this.map.entrySet().iterator(); | |
while(exceptions.hasNext()) { | |
Entry entry = (Entry)exceptions.next(); | |
FileSystem.Cache.Key fs = (FileSystem.Cache.Key)entry.getKey(); | |
FileSystem ioe = (FileSystem)entry.getValue(); | |
if(ugi.equals(fs.ugi) && ioe != null) { | |
targetFSList.add(ioe); | |
} | |
} | |
ArrayList exceptions1 = new ArrayList(); | |
Iterator entry1 = targetFSList.iterator(); | |
while(entry1.hasNext()) { | |
FileSystem fs1 = (FileSystem)entry1.next(); | |
try { | |
fs1.close(); | |
} catch (IOException var7) { | |
exceptions1.add(var7); | |
} | |
} | |
if(!exceptions1.isEmpty()) { | |
throw MultipleIOException.createIOException(exceptions1); | |
} | |
} | |
static class Key { | |
final String scheme; | |
final String authority; | |
final UserGroupInformation ugi; | |
final long unique; | |
Key(URI uri, Configuration conf) throws IOException { | |
this(uri, conf, 0L); | |
} | |
Key(URI uri, Configuration conf, long unique) throws IOException { | |
this.scheme = uri.getScheme() == null?"":StringUtils.toLowerCase(uri.getScheme()); | |
this.authority = uri.getAuthority() == null?"":StringUtils.toLowerCase(uri.getAuthority()); | |
this.unique = unique; | |
this.ugi = UserGroupInformation.getCurrentUser(); | |
} | |
public int hashCode() { | |
return (this.scheme + this.authority).hashCode() + this.ugi.hashCode() + (int)this.unique; | |
} | |
static boolean isEqual(Object a, Object b) { | |
return a == b || a != null && a.equals(b); | |
} | |
public boolean equals(Object obj) { | |
if(obj == this) { | |
return true; | |
} else if(obj != null && obj instanceof FileSystem.Cache.Key) { | |
FileSystem.Cache.Key that = (FileSystem.Cache.Key)obj; | |
return isEqual(this.scheme, that.scheme) && isEqual(this.authority, that.authority) && isEqual(this.ugi, that.ugi) && this.unique == that.unique; | |
} else { | |
return false; | |
} | |
} | |
public String toString() { | |
return "(" + this.ugi.toString() + ")@" + this.scheme + "://" + this.authority; | |
} | |
} | |
private class ClientFinalizer implements Runnable { | |
private ClientFinalizer() { | |
} | |
public synchronized void run() { | |
try { | |
Cache.this.closeAll(true); | |
} catch (IOException var2) { | |
FileSystem.LOG.info("FileSystem.Cache.closeAll() threw an exception:\n" + var2); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment