Class SharedFileDescriptorFactory

java.lang.Object
org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory

@Private @Unstable public class SharedFileDescriptorFactory extends Object
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 Details

    • LOG

      public static final org.slf4j.Logger LOG
  • Method Details

    • getLoadingFailureReason

      public static String getLoadingFailureReason()
    • create

      public static SharedFileDescriptorFactory create(String prefix, String[] paths) throws IOException
      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

      public String getPath()
    • createDescriptor

      public FileInputStream createDescriptor(String info, int length) throws IOException
      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.