@Internal public class LimitedConnectionsFileSystem extends FileSystem
This file system can wrap another existing file system in cases where the target file system cannot handle certain connection spikes and connections would fail in that case. This happens, for example, for very small HDFS clusters with few RPC handlers, when a large Flink job tries to build up many connections during a checkpoint.
The filesystem may track the progress of streams and close streams that have been inactive for too long, to avoid locked streams of taking up the complete pool. Rather than having a dedicated reaper thread, the calls that try to open a new stream periodically check the currently open streams once the limit of open streams is reached.
Modifier and Type | Class and Description |
---|---|
static class |
LimitedConnectionsFileSystem.ConnectionLimitingSettings
A simple configuration data object capturing the settings for limited connections.
|
static class |
LimitedConnectionsFileSystem.StreamTimeoutException
A special IOException, indicating a timeout in the data output stream.
|
FileSystem.WriteMode
Constructor and Description |
---|
LimitedConnectionsFileSystem(FileSystem originalFs,
int maxNumOpenStreamsTotal)
Creates a new output connection limiting file system.
|
LimitedConnectionsFileSystem(FileSystem originalFs,
int maxNumOpenStreamsTotal,
int maxNumOpenOutputStreams,
int maxNumOpenInputStreams,
long streamOpenTimeout,
long streamInactivityTimeout)
Creates a new output connection limiting file system, limiting input and output streams with
potentially different quotas.
|
LimitedConnectionsFileSystem(FileSystem originalFs,
int maxNumOpenStreamsTotal,
long streamOpenTimeout,
long streamInactivityTimeout)
Creates a new output connection limiting file system.
|
Modifier and Type | Method and Description |
---|---|
FSDataOutputStream |
create(Path f,
boolean overwrite,
int bufferSize,
short replication,
long blockSize)
Deprecated.
|
FSDataOutputStream |
create(Path f,
FileSystem.WriteMode overwriteMode)
Opens an FSDataOutputStream to a new file at the given path.
|
boolean |
delete(Path f,
boolean recursive)
Delete a file.
|
boolean |
exists(Path f)
Check if exists.
|
long |
getDefaultBlockSize()
Deprecated.
|
BlockLocation[] |
getFileBlockLocations(FileStatus file,
long start,
long len)
Return an array containing hostnames, offset and size of portions of the given file.
|
FileStatus |
getFileStatus(Path f)
Return a file status object that represents the path.
|
Path |
getHomeDirectory()
Returns the path of the user's home directory in this file system.
|
FileSystemKind |
getKind()
Gets a description of the characteristics of this file system.
|
int |
getMaxNumOpenInputStreams()
Gets the maximum number of concurrently open input streams.
|
int |
getMaxNumOpenOutputStreams()
Gets the maximum number of concurrently open output streams.
|
int |
getMaxNumOpenStreamsTotal()
Gets the maximum number of concurrently open streams (input + output).
|
int |
getNumberOfOpenInputStreams()
Gets the number of currently open input streams.
|
int |
getNumberOfOpenOutputStreams()
Gets the number of currently open output streams.
|
long |
getStreamInactivityTimeout()
Gets the milliseconds that a stream may spend not writing any bytes before it is closed as
inactive.
|
long |
getStreamOpenTimeout()
Gets the number of milliseconds that a opening a stream may wait for availability in the
connection pool.
|
int |
getTotalNumberOfOpenStreams()
Gets the total number of open streams (input plus output).
|
URI |
getUri()
Returns a URI whose scheme and authority identify this file system.
|
Path |
getWorkingDirectory()
Returns the path of the file system's current working directory.
|
boolean |
isDistributedFS()
Returns true if this is a distributed file system.
|
FileStatus[] |
listStatus(Path f)
List the statuses of the files/directories in the given path if the path is a directory.
|
boolean |
mkdirs(Path f)
Make the given file and all non-existent parents into directories.
|
FSDataInputStream |
open(Path f)
Opens an FSDataInputStream at the indicated Path.
|
FSDataInputStream |
open(Path f,
int bufferSize)
Opens an FSDataInputStream at the indicated Path.
|
boolean |
rename(Path src,
Path dst)
Renames the file/directory src to dst.
|
create, createRecoverableWriter, get, getDefaultFsUri, getLocalFileSystem, getUnguardedFileSystem, initialize, initialize, initOutPathDistFS, initOutPathLocalFS
public LimitedConnectionsFileSystem(FileSystem originalFs, int maxNumOpenStreamsTotal)
If streams are inactive (meaning not writing bytes) for longer than the given timeout, then they are terminated as "inactive", to prevent that the limited number of connections gets stuck on only blocked threads.
originalFs
- The original file system to which connections are limited.maxNumOpenStreamsTotal
- The maximum number of concurrent open streams (0 means no
limit).public LimitedConnectionsFileSystem(FileSystem originalFs, int maxNumOpenStreamsTotal, long streamOpenTimeout, long streamInactivityTimeout)
If streams are inactive (meaning not writing bytes) for longer than the given timeout, then they are terminated as "inactive", to prevent that the limited number of connections gets stuck on only blocked threads.
originalFs
- The original file system to which connections are limited.maxNumOpenStreamsTotal
- The maximum number of concurrent open streams (0 means no
limit).streamOpenTimeout
- The maximum number of milliseconds that the file system will wait
when no more connections are currently permitted.streamInactivityTimeout
- The milliseconds that a stream may spend not writing any bytes
before it is closed as inactive.public LimitedConnectionsFileSystem(FileSystem originalFs, int maxNumOpenStreamsTotal, int maxNumOpenOutputStreams, int maxNumOpenInputStreams, long streamOpenTimeout, long streamInactivityTimeout)
If streams are inactive (meaning not writing bytes) for longer than the given timeout, then they are terminated as "inactive", to prevent that the limited number of connections gets stuck on only blocked threads.
originalFs
- The original file system to which connections are limited.maxNumOpenStreamsTotal
- The maximum number of concurrent open streams (0 means no
limit).maxNumOpenOutputStreams
- The maximum number of concurrent open output streams (0 means
no limit).maxNumOpenInputStreams
- The maximum number of concurrent open input streams (0 means no
limit).streamOpenTimeout
- The maximum number of milliseconds that the file system will wait
when no more connections are currently permitted.streamInactivityTimeout
- The milliseconds that a stream may spend not writing any bytes
before it is closed as inactive.public int getMaxNumOpenOutputStreams()
public int getMaxNumOpenInputStreams()
public int getMaxNumOpenStreamsTotal()
public long getStreamOpenTimeout()
public long getStreamInactivityTimeout()
public int getTotalNumberOfOpenStreams()
public int getNumberOfOpenOutputStreams()
public int getNumberOfOpenInputStreams()
public FSDataOutputStream create(Path f, FileSystem.WriteMode overwriteMode) throws IOException
FileSystem
If the file already exists, the behavior depends on the given WriteMode
. If the
mode is set to FileSystem.WriteMode.NO_OVERWRITE
, then this method fails with an exception.
create
in class FileSystem
f
- The file path to write tooverwriteMode
- The action to take if a file or directory already exists at the given
path.IOException
- Thrown, if the stream could not be opened because of an I/O, or because a
file already exists at that path and the write mode indicates to not overwrite the file.@Deprecated public FSDataOutputStream create(Path f, boolean overwrite, int bufferSize, short replication, long blockSize) throws IOException
FileSystem
This method is deprecated, because most of its parameters are ignored by most file systems. To control for example the replication factor and block size in the Hadoop Distributed File system, make sure that the respective Hadoop configuration file is either linked from the Flink configuration, or in the classpath of either Flink or the user code.
create
in class FileSystem
f
- the file name to openoverwrite
- if a file with this name already exists, then if true, the file will be
overwritten, and if false an error will be thrown.bufferSize
- the size of the buffer to be used.replication
- required block replication for the file.blockSize
- the size of the file blocksIOException
- Thrown, if the stream could not be opened because of an I/O, or because a
file already exists at that path and the write mode indicates to not overwrite the file.public FSDataInputStream open(Path f, int bufferSize) throws IOException
FileSystem
open
in class FileSystem
f
- the file name to openbufferSize
- the size of the buffer to be used.IOException
public FSDataInputStream open(Path f) throws IOException
FileSystem
open
in class FileSystem
f
- the file to openIOException
public FileSystemKind getKind()
FileSystem
getKind
in class FileSystem
public boolean isDistributedFS()
FileSystem
isDistributedFS
in class FileSystem
public Path getWorkingDirectory()
FileSystem
getWorkingDirectory
in class FileSystem
public Path getHomeDirectory()
FileSystem
getHomeDirectory
in class FileSystem
public URI getUri()
FileSystem
getUri
in class FileSystem
public FileStatus getFileStatus(Path f) throws IOException
FileSystem
getFileStatus
in class FileSystem
f
- The path we want information fromFileNotFoundException
- when the path does not exist; IOException see specific
implementationIOException
public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException
FileSystem
getFileBlockLocations
in class FileSystem
IOException
public FileStatus[] listStatus(Path f) throws IOException
FileSystem
listStatus
in class FileSystem
f
- given pathIOException
public boolean delete(Path f, boolean recursive) throws IOException
FileSystem
delete
in class FileSystem
f
- the path to deleterecursive
- if path is a directory and set to true
, the directory is
deleted else throws an exception. In case of a file the recursive can be set to either
true
or false
true
if delete is successful, false
otherwiseIOException
public boolean mkdirs(Path f) throws IOException
FileSystem
mkdirs
in class FileSystem
f
- the directory/directories to be createdtrue
if at least one new directory has been created, false
otherwiseIOException
- thrown if an I/O error occurs while creating the directorypublic boolean rename(Path src, Path dst) throws IOException
FileSystem
rename
in class FileSystem
src
- the file/directory to renamedst
- the new name of the file/directorytrue
if the renaming was successful, false
otherwiseIOException
public boolean exists(Path f) throws IOException
FileSystem
exists
in class FileSystem
f
- source fileIOException
@Deprecated public long getDefaultBlockSize()
FileSystem
getDefaultBlockSize
in class FileSystem
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.