Package org.apache.hadoop.io.nativeio
Class SharedFileDescriptorFactory
java.lang.Object
org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory
A factory for creating shared file descriptors inside a given directory.
Typically, the directory will be /dev/shm or /tmp.
We will hand out file descriptors that correspond to unlinked files residing
in that directory. These file descriptors are suitable for sharing across
multiple processes and are both readable and writable.
Because we unlink the temporary files right after creating them, a JVM crash
usually does not leave behind any temporary files in the directory. However,
it may happen that we crash right after creating the file and before
unlinking it. In the constructor, we attempt to clean up after any such
remnants by trying to unlink any temporary files created by previous
SharedFileDescriptorFactory instances that also used our prefix.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedFileDescriptorFactoryCreate a new SharedFileDescriptorFactory.createDescriptor(String info, int length) Create a shared file descriptor which will be both readable and writable.static StringgetPath()
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Method Details
-
getLoadingFailureReason
-
create
Create a new SharedFileDescriptorFactory.- Parameters:
prefix- The prefix to prepend to all the file names created by this factory.paths- An array of paths to use. We will try each path in succession, and return a factory using the first usable path.- Returns:
- The factory.
- Throws:
IOException- If a factory could not be created for any reason.
-
getPath
-
createDescriptor
Create a shared file descriptor which will be both readable and writable.- Parameters:
info- Information to include in the path of the generated descriptor.length- The starting file length.- Returns:
- The file descriptor, wrapped in a FileInputStream.
- Throws:
IOException- If there was an I/O or configuration error creating the descriptor.
-