Class HintsService

java.lang.Object
org.apache.cassandra.hints.HintsService
All Implemented Interfaces:
HintsServiceMBean

public final class HintsService extends Object implements HintsServiceMBean
A singleton-ish wrapper over various hints components: - a catalog of all hints stores - a single-threaded write executor - a multi-threaded dispatch executor - the buffer pool for writing hints into - an optional scheduled task to clean up the applicable hints files The front-end for everything hints related.
  • Field Details

  • Method Details

    • registerMBean

      public void registerMBean()
    • write

      public void write(Collection<UUID> hostIds, Hint hint)
      Write a hint for a iterable of nodes.
      Parameters:
      hostIds - host ids of the hint's target nodes
      hint - the hint to store
    • write

      public void write(UUID hostId, Hint hint)
      Write a hint for a single node.
      Parameters:
      hostId - host id of the hint's target node
      hint - the hint to store
    • flushAndFsyncBlockingly

      public void flushAndFsyncBlockingly(Iterable<UUID> hostIds)
      Flush the buffer pool for the selected target nodes, then fsync their writers.
      Parameters:
      hostIds - host ids of the nodes to flush and fsync hints for
    • startDispatch

      public void startDispatch()
    • pauseDispatch

      public void pauseDispatch()
      Description copied from interface: HintsServiceMBean
      Pause dispatch of all hints. Does not affect the creation of hints.
      Specified by:
      pauseDispatch in interface HintsServiceMBean
    • resumeDispatch

      public void resumeDispatch()
      Description copied from interface: HintsServiceMBean
      Resume dispatch of all hints. Does not affect the creation of hints.
      Specified by:
      resumeDispatch in interface HintsServiceMBean
    • getTotalHintsSize

      public long getTotalHintsSize(UUID hostId)
      Get the total size in bytes of all the hints files associating with the host on disk.
      Parameters:
      hostId - belonging host
      Returns:
      total file size, in bytes
    • shutdownBlocking

      public void shutdownBlocking() throws ExecutionException, InterruptedException
      Gracefully and blockingly shut down the service. Will abort dispatch sessions that are currently in progress (which is okay, it's idempotent), and make sure the buffers are flushed, hints files written and fsynced.
      Throws:
      ExecutionException
      InterruptedException
    • getPendingHintsInfo

      public List<PendingHintsInfo> getPendingHintsInfo()
      Returns all pending hints that this node has.
      Returns:
      a list of PendingHintsInfo
    • getPendingHints

      public List<Map<String,String>> getPendingHints()
      Returns all pending hints that this node has.
      Specified by:
      getPendingHints in interface HintsServiceMBean
      Returns:
      a list of maps with endpoints' ids, total number of hint files, their oldest and newest timestamps.
    • deleteAllHints

      public void deleteAllHints()
      Deletes all hints for all destinations. Doesn't make snapshots - should be used with care.
      Specified by:
      deleteAllHints in interface HintsServiceMBean
    • deleteAllHintsForEndpoint

      public void deleteAllHintsForEndpoint(String address)
      Deletes all hints for the provided destination. Doesn't make snapshots - should be used with care.
      Specified by:
      deleteAllHintsForEndpoint in interface HintsServiceMBean
      Parameters:
      address - inet address of the target node - encoded as a string for easier JMX consumption
    • deleteAllHintsForEndpoint

      public void deleteAllHintsForEndpoint(InetAddressAndPort target)
      Deletes all hints for the provided destination. Doesn't make snapshots - should be used with care.
      Parameters:
      target - inet address of the target node
    • excise

      public void excise(UUID hostId)
      Cleans up hints-related state after a node with id = hostId left. Dispatcher can not stop itself (isHostAlive() can not start returning false for the leaving host because this method is called by the same thread as gossip, which blocks gossip), so we can't simply wait for completion. We should also flush the buffer if there are any hints for the node there, and close the writer (if any), so that we don't leave any hint files lying around. Once that is done, we can simply delete all hint files and remove the host id from the catalog. The worst that can happen if we don't get everything right is a hints file (or two) remaining undeleted.
      Parameters:
      hostId - id of the node being excised
    • transferHints

      public Future transferHints(Supplier<UUID> hostIdSupplier)
      Transfer all local hints to the hostId supplied by hostIdSupplier Flushes the buffer to make sure all hints are on disk and closes the hint writers so we don't leave any hint files around. After that, we serially dispatch all the hints in the HintsCatalog. If we fail delivering all hints, we will ask the hostIdSupplier for a new target host and retry delivering any remaining hints there, once, with a delay of 10 seconds before retrying.
      Parameters:
      hostIdSupplier - supplier of stream target host ids. This is generally the closest one according to the DynamicSnitch
      Returns:
      When this future is done, it either has streamed all hints to remote nodes or has failed with a proper log message
    • findOldestHintTimestamp

      public long findOldestHintTimestamp(UUID hostId)
      Find the oldest hint written for a particular node by looking into descriptors and current open writer, if any.
      Parameters:
      hostId - UUID of the node to check its hints.
      Returns:
      the oldest hint of the given host id or Long.MAX_VALUE when not found
    • isShutDown

      public boolean isShutDown()
      Returns true in case service is shut down.
    • isDispatchPaused

      public boolean isDispatchPaused()