Class OrderedGracefulLeaveHandler

java.lang.Object
org.infinispan.topology.OrderedGracefulLeaveHandler

public class OrderedGracefulLeaveHandler extends Object
Serializes graceful leave operations on the coordinator to prevent data loss during concurrent scale-down.

When multiple nodes leave simultaneously (e.g., Kubernetes scaling down a StatefulSet), each leave triggers a rebalance that redistributes data to surviving nodes. Without serializing the operations, all leaves execute before any rebalance completes, causing segments to lose all owners.

This handler maintains a per-cache chain of CompletableFutures. Each leave waits for the previous leave's rebalance to finish before proceeding:

  Leave B --(doLeave + wait rebalance)--> Leave C --(doLeave + wait rebalance)--> ...

Only used when the leaving node requests a graceful stop with a positive timeout (via CacheLeaveCommand). Abrupt leaves (view change, kill) bypass this handler entirely.

Since:
16.2
See Also:
  • Field Details

    • blockingManager

      protected BlockingManager blockingManager
    • timeService

      protected TimeService timeService
    • tracker

      protected org.infinispan.statetransfer.StateTransferTracker tracker
  • Constructor Details

    • OrderedGracefulLeaveHandler

      public OrderedGracefulLeaveHandler()
  • Method Details

    • enqueue

      public CompletionStage<Void> enqueue(String cacheName, Address leaver, long timeout, TimeUnit unit, ClusterCacheStatus status)
      Enqueues a graceful leave for the given cache, serialized behind any pending leaves.
      Parameters:
      cacheName - the cache the node is leaving
      leaver - the address of the leaving node
      timeout - maximum time to wait for the rebalance triggered by this leave
      unit - time unit for the timeout
      status - the coordinator-side cache status, used to execute the leave and read topology state
      Returns:
      a stage that completes when this leave's rebalance finishes (or the timeout expires)
    • remove

      public void remove(String cacheName)
      Removes the leave chain for a cache. Called when the last member leaves and the cache status is removed.
      Parameters:
      cacheName - the cache to clean up
    • drainAll

      public boolean drainAll(long timeout, TimeUnit unit) throws InterruptedException
      Waits for all in-flight graceful leave chains to complete.

      The method ensures that all currently pending leave requests are consumed before returning. Concurrent leave requests included while draining are also included in the consuming list. The method waits until all the requests and associated state transfer complete, or a timeout elapses.

      Parameters:
      timeout - maximum time to wait for all chains to complete
      unit - time unit for the timeout
      Returns:
      true if all chains completed before the deadline; false if the timeout expired
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting