@Private
@Unstable
public class FileIoProvider
extends java.lang.Object
DFSConfigKeys.DFS_DATANODE_FILEIO_PROFILING_SAMPLING_PERCENTAGE_KEY
and DFSConfigKeys.DFS_DATANODE_ENABLE_FILEIO_FAULT_INJECTION_KEY.
These event hooks are disabled by default.
Most functions accept an optional FsVolumeSpi parameter for
instrumentation/logging.
Some methods may look redundant, especially the multiple variations of
move/rename/list. They exist to retain behavior compatibility for existing
code.| Modifier and Type | Class | Description |
|---|---|---|
static class |
FileIoProvider.OPERATION |
Lists the types of file system operations.
|
| Modifier and Type | Field | Description |
|---|---|---|
static org.slf4j.Logger |
LOG |
| Constructor | Description |
|---|---|
FileIoProvider(org.apache.hadoop.conf.Configuration conf,
DataNode datanode) |
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
createFile(FsVolumeSpi volume,
java.io.File f) |
Create a file.
|
boolean |
delete(FsVolumeSpi volume,
java.io.File f) |
Delete a file.
|
boolean |
deleteWithExistsCheck(FsVolumeSpi volume,
java.io.File f) |
Delete a file, first checking to see if it exists.
|
void |
dirSync(FsVolumeSpi volume,
java.io.File dir) |
Sync the given directory changes to durable device.
|
boolean |
exists(FsVolumeSpi volume,
java.io.File f) |
Check for file existence using
File.exists(). |
void |
flush(FsVolumeSpi volume,
java.io.Flushable f) |
See
Flushable.flush(). |
boolean |
fullyDelete(FsVolumeSpi volume,
java.io.File dir) |
Delete the given directory using
FileUtil.fullyDelete(File). |
java.io.FileInputStream |
getFileInputStream(FsVolumeSpi volume,
java.io.File f) |
Create a FileInputStream using
FileInputStream(File). |
java.io.FileOutputStream |
getFileOutputStream(FsVolumeSpi volume,
java.io.File f) |
Create a FileOutputStream using
FileOutputStream(File, boolean). |
java.io.FileOutputStream |
getFileOutputStream(FsVolumeSpi volume,
java.io.FileDescriptor fd) |
Create a FileOutputStream using
FileOutputStream(FileDescriptor). |
java.io.FileOutputStream |
getFileOutputStream(FsVolumeSpi volume,
java.io.File f,
boolean append) |
Create a FileOutputStream using
FileOutputStream(File, boolean). |
int |
getHardLinkCount(FsVolumeSpi volume,
java.io.File f) |
Retrieves the number of links to the specified file.
|
org.apache.hadoop.hdfs.server.datanode.ProfilingFileIoEvents |
getProfilingEventHook() |
|
java.io.RandomAccessFile |
getRandomAccessFile(FsVolumeSpi volume,
java.io.File f,
java.lang.String mode) |
Create a RandomAccessFile using
RandomAccessFile(File, String). |
java.io.FileInputStream |
getShareDeleteFileInputStream(FsVolumeSpi volume,
java.io.File f,
long offset) |
Create a FileInputStream using
NativeIO.getShareDeleteFileDescriptor(java.io.File, long). |
java.lang.String[] |
list(FsVolumeSpi volume,
java.io.File dir) |
Get a listing of the given directory using
FileUtil.listFiles(File). |
java.util.List<java.lang.String> |
listDirectory(FsVolumeSpi volume,
java.io.File dir,
java.io.FilenameFilter filter) |
Get a listing of the given directory using
IOUtils.listDirectory(File, FilenameFilter). |
java.io.File[] |
listFiles(FsVolumeSpi volume,
java.io.File dir) |
Get a listing of the given directory using
FileUtil.listFiles(File). |
boolean |
mkdirs(FsVolumeSpi volume,
java.io.File dir) |
See
File.mkdirs(). |
void |
mkdirsWithExistsCheck(FsVolumeSpi volume,
java.io.File dir) |
Create the target directory using
File.mkdirs() only if
it doesn't exist already. |
void |
move(FsVolumeSpi volume,
java.nio.file.Path src,
java.nio.file.Path target,
java.nio.file.CopyOption... options) |
Move the src file to the target using
Files.move(Path, Path, CopyOption...). |
void |
moveFile(FsVolumeSpi volume,
java.io.File src,
java.io.File target) |
Move the src file to the target using
FileUtils.moveFile(File, File). |
void |
nativeCopyFileUnbuffered(FsVolumeSpi volume,
java.io.File src,
java.io.File target,
boolean preserveFileDate) |
|
java.io.FileInputStream |
openAndSeek(FsVolumeSpi volume,
java.io.File f,
long offset) |
Create a FileInputStream using
FileInputStream(File) and position
it at the given offset. |
void |
posixFadvise(FsVolumeSpi volume,
java.lang.String identifier,
java.io.FileDescriptor outFd,
long offset,
long length,
int flags) |
Call posix_fadvise on the given file descriptor.
|
void |
rename(FsVolumeSpi volume,
java.io.File src,
java.io.File target) |
Move the src file to the target using
Storage.rename(File, File). |
void |
replaceFile(FsVolumeSpi volume,
java.io.File src,
java.io.File target) |
Move the src file to the target using
FileUtil.replaceFile(File, File). |
void |
sync(FsVolumeSpi volume,
java.io.FileOutputStream fos) |
Sync the given
FileOutputStream. |
void |
syncFileRange(FsVolumeSpi volume,
java.io.FileDescriptor outFd,
long offset,
long numBytes,
int flags) |
Call sync_file_range on the given file descriptor.
|
void |
transferToSocketFully(FsVolumeSpi volume,
org.apache.hadoop.net.SocketOutputStream sockOut,
java.nio.channels.FileChannel fileCh,
long position,
int count,
org.apache.hadoop.io.LongWritable waitTime,
org.apache.hadoop.io.LongWritable transferTime) |
Transfer data from a FileChannel to a SocketOutputStream.
|
public FileIoProvider(@Nullable
org.apache.hadoop.conf.Configuration conf,
DataNode datanode)
conf - Configuration object. May be null. When null,
the event handlers are no-ops.datanode - datanode that owns this FileIoProvider. Used for
IO error based volume checker callbackpublic void flush(@Nullable
FsVolumeSpi volume,
java.io.Flushable f)
throws java.io.IOException
Flushable.flush().volume - target volume. null if unavailable.java.io.IOExceptionpublic void sync(@Nullable
FsVolumeSpi volume,
java.io.FileOutputStream fos)
throws java.io.IOException
FileOutputStream.volume - target volume. null if unavailable.java.io.IOExceptionpublic void dirSync(@Nullable
FsVolumeSpi volume,
java.io.File dir)
throws java.io.IOException
java.io.IOExceptionpublic void syncFileRange(@Nullable
FsVolumeSpi volume,
java.io.FileDescriptor outFd,
long offset,
long numBytes,
int flags)
throws org.apache.hadoop.io.nativeio.NativeIOException
volume - target volume. null if unavailable.org.apache.hadoop.io.nativeio.NativeIOExceptionpublic void posixFadvise(@Nullable
FsVolumeSpi volume,
java.lang.String identifier,
java.io.FileDescriptor outFd,
long offset,
long length,
int flags)
throws org.apache.hadoop.io.nativeio.NativeIOException
volume - target volume. null if unavailable.org.apache.hadoop.io.nativeio.NativeIOExceptionpublic boolean delete(@Nullable
FsVolumeSpi volume,
java.io.File f)
volume - target volume. null if unavailable.f - File to delete.public boolean deleteWithExistsCheck(@Nullable
FsVolumeSpi volume,
java.io.File f)
volume - target volume. null if unavailable.f - File to deletepublic void transferToSocketFully(@Nullable
FsVolumeSpi volume,
org.apache.hadoop.net.SocketOutputStream sockOut,
java.nio.channels.FileChannel fileCh,
long position,
int count,
org.apache.hadoop.io.LongWritable waitTime,
org.apache.hadoop.io.LongWritable transferTime)
throws java.io.IOException
volume - target volume. null if unavailable.sockOut - SocketOutputStream to write the data.fileCh - FileChannel from which to read data.position - position within the channel where the transfer begins.count - number of bytes to transfer.waitTime - returns the nanoseconds spent waiting for the socket
to become writable.transferTime - returns the nanoseconds spent transferring data.java.io.IOExceptionpublic boolean createFile(@Nullable
FsVolumeSpi volume,
java.io.File f)
throws java.io.IOException
volume - target volume. null if unavailable.f - File to be created.java.io.IOExceptionpublic java.io.FileInputStream getFileInputStream(@Nullable
FsVolumeSpi volume,
java.io.File f)
throws java.io.FileNotFoundException
FileInputStream(File).
Wraps the created input stream to intercept read calls
before delegating to the wrapped stream.volume - target volume. null if unavailable.f - File object.java.io.FileNotFoundExceptionpublic java.io.FileOutputStream getFileOutputStream(@Nullable
FsVolumeSpi volume,
java.io.File f,
boolean append)
throws java.io.FileNotFoundException
FileOutputStream(File, boolean).
Wraps the created output stream to intercept write calls
before delegating to the wrapped stream.volume - target volume. null if unavailable.f - File object.append - if true, then bytes will be written to the end of the
file rather than the beginning.java.io.FileNotFoundExceptionpublic java.io.FileOutputStream getFileOutputStream(@Nullable
FsVolumeSpi volume,
java.io.File f)
throws java.io.FileNotFoundException
FileOutputStream(File, boolean).
Wraps the created output stream to intercept write calls
before delegating to the wrapped stream.volume - target volume. null if unavailable.f - File object.java.io.FileNotFoundExceptionpublic java.io.FileOutputStream getFileOutputStream(@Nullable
FsVolumeSpi volume,
java.io.FileDescriptor fd)
FileOutputStream(FileDescriptor).
Wraps the created output stream to intercept write calls
before delegating to the wrapped stream.volume - target volume. null if unavailable.fd - File descriptor object.public java.io.FileInputStream getShareDeleteFileInputStream(@Nullable
FsVolumeSpi volume,
java.io.File f,
long offset)
throws java.io.IOException
NativeIO.getShareDeleteFileDescriptor(java.io.File, long).
Wraps the created input stream to intercept input calls
before delegating to the wrapped stream.volume - target volume. null if unavailable.f - File object.offset - the offset position, measured in bytes from the
beginning of the file, at which to set the file
pointer.java.io.FileNotFoundExceptionjava.io.IOExceptionpublic java.io.FileInputStream openAndSeek(@Nullable
FsVolumeSpi volume,
java.io.File f,
long offset)
throws java.io.IOException
FileInputStream(File) and position
it at the given offset.
Wraps the created input stream to intercept read calls
before delegating to the wrapped stream.volume - target volume. null if unavailable.f - File object.offset - the offset position, measured in bytes from the
beginning of the file, at which to set the file
pointer.java.io.FileNotFoundExceptionjava.io.IOExceptionpublic java.io.RandomAccessFile getRandomAccessFile(@Nullable
FsVolumeSpi volume,
java.io.File f,
java.lang.String mode)
throws java.io.FileNotFoundException
RandomAccessFile(File, String).
Wraps the created input stream to intercept IO calls
before delegating to the wrapped RandomAccessFile.volume - target volume. null if unavailable.f - File object.mode - See RandomAccessFile for a description
of the mode string.java.io.FileNotFoundExceptionpublic boolean fullyDelete(@Nullable
FsVolumeSpi volume,
java.io.File dir)
FileUtil.fullyDelete(File).volume - target volume. null if unavailable.dir - directory to be deleted.public void replaceFile(@Nullable
FsVolumeSpi volume,
java.io.File src,
java.io.File target)
throws java.io.IOException
FileUtil.replaceFile(File, File).volume - target volume. null if unavailable.src - source path.target - target path.java.io.IOExceptionpublic void rename(@Nullable
FsVolumeSpi volume,
java.io.File src,
java.io.File target)
throws java.io.IOException
Storage.rename(File, File).volume - target volume. null if unavailable.src - source path.target - target path.java.io.IOExceptionpublic void moveFile(@Nullable
FsVolumeSpi volume,
java.io.File src,
java.io.File target)
throws java.io.IOException
FileUtils.moveFile(File, File).volume - target volume. null if unavailable.src - source path.target - target path.java.io.IOExceptionpublic void move(@Nullable
FsVolumeSpi volume,
java.nio.file.Path src,
java.nio.file.Path target,
java.nio.file.CopyOption... options)
throws java.io.IOException
Files.move(Path, Path, CopyOption...).volume - target volume. null if unavailable.src - source path.target - target path.options - See Files.move(java.nio.file.Path, java.nio.file.Path, java.nio.file.CopyOption...) for a description
of the options.java.io.IOExceptionpublic void nativeCopyFileUnbuffered(@Nullable
FsVolumeSpi volume,
java.io.File src,
java.io.File target,
boolean preserveFileDate)
throws java.io.IOException
volume - target volume. null if unavailable.src - an existing file to copy, must not be nulltarget - the new file, must not be nullpreserveFileDate - true if the file date of the copy
should be the same as the originaljava.io.IOExceptionpublic boolean mkdirs(@Nullable
FsVolumeSpi volume,
java.io.File dir)
throws java.io.IOException
File.mkdirs().volume - target volume. null if unavailable.dir - directory to be created.java.io.IOException - if a directory with the given name does
not exist and could not be created.public void mkdirsWithExistsCheck(@Nullable
FsVolumeSpi volume,
java.io.File dir)
throws java.io.IOException
File.mkdirs() only if
it doesn't exist already.volume - target volume. null if unavailable.dir - directory to be created.java.io.IOException - if the directory could not createdpublic java.io.File[] listFiles(@Nullable
FsVolumeSpi volume,
java.io.File dir)
throws java.io.IOException
FileUtil.listFiles(File).volume - target volume. null if unavailable.dir - Directory to be listed.java.io.IOExceptionpublic java.lang.String[] list(@Nullable
FsVolumeSpi volume,
java.io.File dir)
throws java.io.IOException
FileUtil.listFiles(File).volume - target volume. null if unavailable.dir - directory to be listed.java.io.IOExceptionpublic java.util.List<java.lang.String> listDirectory(@Nullable
FsVolumeSpi volume,
java.io.File dir,
java.io.FilenameFilter filter)
throws java.io.IOException
IOUtils.listDirectory(File, FilenameFilter).volume - target volume. null if unavailable.dir - Directory to list.filter - FilenameFilter to filter the directory entries.java.io.IOExceptionpublic int getHardLinkCount(@Nullable
FsVolumeSpi volume,
java.io.File f)
throws java.io.IOException
volume - target volume. null if unavailable.f - file whose link count is being queried.java.io.IOExceptionpublic boolean exists(@Nullable
FsVolumeSpi volume,
java.io.File f)
File.exists().volume - target volume. null if unavailable.f - file object.public org.apache.hadoop.hdfs.server.datanode.ProfilingFileIoEvents getProfilingEventHook()
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.