Class ShortCircuitShm

java.lang.Object
org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm
Direct Known Subclasses:
DfsClientShm

public class ShortCircuitShm extends Object
A shared memory segment used to implement short-circuit reads.
  • Field Details

  • Constructor Details

    • ShortCircuitShm

      public ShortCircuitShm(ShortCircuitShm.ShmId shmId, FileInputStream stream) throws IOException
      Create the ShortCircuitShm.
      Parameters:
      shmId - The ID to use.
      stream - The stream that we're going to use to create this shared memory segment. Although this is a FileInputStream, we are going to assume that the underlying file descriptor is writable as well as readable. It would be more appropriate to use a RandomAccessFile here, but that class does not have any public accessor which returns a FileDescriptor, unlike FileInputStream.
      Throws:
      IOException
  • Method Details

    • getShmId

      public final ShortCircuitShm.ShmId getShmId()
    • isEmpty

      public final boolean isEmpty()
      Determine if this shared memory object is empty.
      Returns:
      True if the shared memory object is empty.
    • isFull

      public final boolean isFull()
      Determine if this shared memory object is full.
      Returns:
      True if the shared memory object is full.
    • allocAndRegisterSlot

      public final ShortCircuitShm.Slot allocAndRegisterSlot(ExtendedBlockId blockId)
      Allocate a new slot and register it. This function chooses an empty slot, initializes it, and then returns the relevant Slot object.
      Returns:
      The new slot.
    • getSlot

      public final ShortCircuitShm.Slot getSlot(int slotIdx) throws org.apache.hadoop.fs.InvalidRequestException
      Throws:
      org.apache.hadoop.fs.InvalidRequestException
    • registerSlot

      public final ShortCircuitShm.Slot registerSlot(int slotIdx, ExtendedBlockId blockId) throws org.apache.hadoop.fs.InvalidRequestException
      Register a slot. This function looks at a slot which has already been initialized (by another process), and registers it with us. Then, it returns the relevant Slot object.
      Returns:
      The slot.
      Throws:
      org.apache.hadoop.fs.InvalidRequestException - If the slot index we're trying to allocate has not been initialized, or is already in use.
    • unregisterSlot

      public final void unregisterSlot(int slotIdx)
      Unregisters a slot. This doesn't alter the contents of the slot. It just means
      Parameters:
      slotIdx - Index of the slot to unregister.
    • slotIterator

      public ShortCircuitShm.SlotIterator slotIterator()
      Iterate over all allocated slots. Note that this method isn't safe if
      Returns:
      The slot iterator.
    • free

      public void free()
    • toString

      public String toString()
      Overrides:
      toString in class Object