Class ShortCircuitRegistry

java.lang.Object
org.apache.hadoop.hdfs.server.datanode.ShortCircuitRegistry

public class ShortCircuitRegistry extends Object
Manages client short-circuit memory segments on the DataNode. DFSClients request shared memory segments from the DataNode. The ShortCircuitRegistry generates and manages these segments. Each segment has a randomly generated 128-bit ID which uniquely identifies it. The segments each contain several "slots." Before performing a short-circuit read, DFSClients must request a pair of file descriptors from the DataNode via the REQUEST_SHORT_CIRCUIT_FDS operation. As part of this operation, DFSClients pass the ID of the shared memory segment they would like to use to communicate information about this replica, as well as the slot number within that segment they would like to use. Slot allocation is always done by the client. Slots are used to track the state of the block on the both the client and datanode. When this DataNode mlocks a block, the corresponding slots for the replicas are marked as "anchorable". Anchorable blocks can be safely read without verifying the checksum. This means that BlockReaderLocal objects using these replicas can skip checksumming. It also means that we can do zero-copy reads on these replicas (the ZCR interface has no way of verifying checksums.) When a DN needs to munlock a block, it needs to first wait for the block to be unanchored by clients doing a no-checksum read or a zero-copy read. The DN also marks the block's slots as "unanchorable" to prevent additional clients from initiating these operations in the future. The counterpart of this class on the client is DfsClientShmManager.
  • Field Details

    • LOG

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

    • ShortCircuitRegistry

      public ShortCircuitRegistry(org.apache.hadoop.conf.Configuration conf) throws IOException
      Throws:
      IOException
  • Method Details

    • removeShm

      public void removeShm(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm shm)
    • processBlockMlockEvent

      public void processBlockMlockEvent(org.apache.hadoop.hdfs.ExtendedBlockId blockId)
      Process a block mlock event from the FsDatasetCache.
      Parameters:
      blockId - The block that was mlocked.
    • processBlockMunlockRequest

      public boolean processBlockMunlockRequest(org.apache.hadoop.hdfs.ExtendedBlockId blockId)
      Mark any slots associated with this blockId as unanchorable.
      Parameters:
      blockId - The block ID.
      Returns:
      True if we should allow the munlock request.
    • processBlockInvalidation

      public void processBlockInvalidation(org.apache.hadoop.hdfs.ExtendedBlockId blockId)
      Invalidate any slot associated with a blockId that we are invalidating (deleting) from this DataNode. When a slot is invalid, the DFSClient will not use the corresponding replica for new read or mmap operations (although existing, ongoing read or mmap operations will complete.)
      Parameters:
      blockId - The block ID.
    • getClientNames

      public String getClientNames(org.apache.hadoop.hdfs.ExtendedBlockId blockId)
    • createNewMemorySegment

      public ShortCircuitRegistry.NewShmInfo createNewMemorySegment(String clientName, org.apache.hadoop.net.unix.DomainSocket sock) throws IOException
      Handle a DFSClient request to create a new memory segment.
      Parameters:
      clientName - Client name as reported by the client.
      sock - The DomainSocket to associate with this memory segment. When this socket is closed, or the other side writes anything to the socket, the segment will be closed. This can happen at any time, including right after this function returns.
      Returns:
      A NewShmInfo object. The caller must close the NewShmInfo object once they are done with it.
      Throws:
      IOException - If the new memory segment could not be created.
    • registerSlot

      public void registerSlot(org.apache.hadoop.hdfs.ExtendedBlockId blockId, org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.SlotId slotId, boolean isCached) throws org.apache.hadoop.fs.InvalidRequestException
      Throws:
      org.apache.hadoop.fs.InvalidRequestException
    • unregisterSlot

      public void unregisterSlot(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.SlotId slotId) throws org.apache.hadoop.fs.InvalidRequestException
      Throws:
      org.apache.hadoop.fs.InvalidRequestException
    • shutdown

      public void shutdown()
    • visit

      @VisibleForTesting public boolean visit(ShortCircuitRegistry.Visitor visitor)
    • getShmNum

      @VisibleForTesting public int getShmNum()