Class PartitionStripedExecutor

java.lang.Object
com.linkedin.venice.utils.concurrent.PartitionStripedExecutor

public final class PartitionStripedExecutor extends Object
A minimal, producer-agnostic, bounded partition-striped executor. Each stripe is one FIFO worker thread with a bounded queue; a partition is mapped by stripeFor(int) and always lands on the same stripe, so same-stripe tasks run in submission order while different stripes run in parallel and never stall one another. Admission is bounded and blocking (never caller-runs, never drops); it carries no producer concepts (writers, callbacks, futures, flush, retries), only opaque Runnables.
  • Constructor Details

    • PartitionStripedExecutor

      public PartitionStripedExecutor(int stripeCount, int queueCapacity, String threadNamePrefix)
    • PartitionStripedExecutor

      public PartitionStripedExecutor(int stripeCount, int queueCapacity, String threadNamePrefix, ObjIntConsumer<ThreadPoolExecutor> stripeObserver)
      Parameters:
      threadNamePrefix - per-stripe thread names are <threadNamePrefix>-<stripe>-t<n>
      stripeObserver - optional construction-time observer invoked once per stripe with its ThreadPoolExecutor and index (e.g. to register metrics); may be null
  • Method Details

    • getStripeCount

      public int getStripeCount()
    • stripeFor

      public int stripeFor(int partition)
      Maps a partition to a stripe in [0, stripeCount); masks the sign bit so Integer.MIN_VALUE stays in range.
    • submit

      public void submit(int partition, Runnable task)
      Routes a task to the stripe owning partition, blocking if that stripe's queue is full.
      Throws:
      RejectedExecutionException - if the executor is shut down or the caller is interrupted while waiting
    • executeOnStripe

      public void executeOnStripe(int stripe, Runnable task)
      Routes a task to an exact stripe (used for per-stripe fence markers), blocking if its queue is full.
    • getStripeQueueSize

      public int getStripeQueueSize(int stripe)
    • getTotalQueueSize

      public int getTotalQueueSize()
    • shutdown

      public void shutdown()
    • shutdownNow

      public List<Runnable> shutdownNow()
    • awaitTermination

      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
      Awaits termination of every stripe against a single shared deadline derived from timeout.
      Throws:
      InterruptedException