Class HintsService

  • All Implemented Interfaces:
    HintsServiceMBean

    public final class HintsService
    extends java.lang.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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void deleteAllHints()
      Deletes all hints for all destinations.
      void deleteAllHintsForEndpoint​(java.lang.String address)
      Deletes all hints for the provided destination.
      void deleteAllHintsForEndpoint​(InetAddressAndPort target)
      Deletes all hints for the provided destination.
      void excise​(java.util.UUID hostId)
      Cleans up hints-related state after a node with id = hostId left.
      long findOldestHintTimestamp​(java.util.UUID hostId)
      Find the oldest hint written for a particular node by looking into descriptors and current open writer, if any.
      void flushAndFsyncBlockingly​(java.lang.Iterable<java.util.UUID> hostIds)
      Flush the buffer pool for the selected target nodes, then fsync their writers.
      java.util.List<java.util.Map<java.lang.String,​java.lang.String>> getPendingHints()
      Returns all pending hints that this node has.
      java.util.List<PendingHintsInfo> getPendingHintsInfo()
      Returns all pending hints that this node has.
      long getTotalHintsSize​(java.util.UUID hostId)
      Get the total size in bytes of all the hints files associating with the host on disk.
      boolean isDispatchPaused()  
      boolean isShutDown()
      Returns true in case service is shut down.
      void pauseDispatch()
      Pause dispatch of all hints.
      void registerMBean()  
      void resumeDispatch()
      Resume dispatch of all hints.
      void shutdownBlocking()
      Gracefully and blockingly shut down the service.
      void startDispatch()  
      Future transferHints​(java.util.function.Supplier<java.util.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.
      void write​(java.util.Collection<java.util.UUID> hostIds, Hint hint)
      Write a hint for a iterable of nodes.
      void write​(java.util.UUID hostId, Hint hint)
      Write a hint for a single node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • registerMBean

        public void registerMBean()
      • write

        public void write​(java.util.Collection<java.util.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​(java.util.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​(java.lang.Iterable<java.util.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()
      • getTotalHintsSize

        public long getTotalHintsSize​(java.util.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 java.util.concurrent.ExecutionException,
                                     java.lang.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:
        java.util.concurrent.ExecutionException
        java.lang.InterruptedException
      • getPendingHintsInfo

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

        public java.util.List<java.util.Map<java.lang.String,​java.lang.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​(java.lang.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​(java.util.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​(java.util.function.Supplier<java.util.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​(java.util.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()