Class BigtableClientReaper

java.lang.Object
io.github.flink.gcp.connector.bigtable.BigtableClientReaper

@Internal public final class BigtableClientReaper extends Object
Closes Bigtable data clients away from the task thread while keeping their physical lifetime bounded. Scheduling failure falls back to synchronous close so the attempted handoff cannot leak the client.

The semaphore counts open and closing clients. The executor can run at most that many closes, and receives at most that many tasks because every one still owns a permit. A synchronous queue is unnecessary: the permit is the stronger bound, while a fixed pool lets releases submit without depending on whether a worker has started yet.

Shared by the module's client factories — the MutateRows batcher factory and the single-row request client factory — so that one bounded pool holds every client a subtask opens, whichever family opened it (ADR-0145, ADR-0148). A factory owns exactly one reaper, created lazily with its first client and never serialized into the job graph.

  • Constructor Summary

    Constructors
    Constructor
    Description
    BigtableClientReaper(int maxClients)
    Creates a reaper whose daemon threads inherit the calling thread's uncaught-exception handler, so a fatal close error reaches the task's handler rather than vanishing.
    BigtableClientReaper(int maxClients, ThreadFactory threadFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Takes a permit for a client about to be created, waiting for a closing one to finish.
    int
     
    void
    Waits until every scheduled close has physically finished.
    void
    closeAll(List<AutoCloseable> activeClients)
    Closes every remaining client and then the reaper itself, starting every close before waiting for any so the SDK's bounded final metric exports overlap.
    void
    closeEventually(AutoCloseable client, String description)
    Closes a client on a reaper thread, releasing its permit when the close finishes.
    static Throwable
    prioritize(Throwable next, Throwable previous)
    Chooses which of two failures to report, suppressing the other into it: a JVM-fatal or out-of-memory error anywhere in a chain wins, then an interruption, then any other error, then everything else, with the earlier failure winning a tie.
    void
    Returns a permit whose client creation failed, so nothing holds it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BigtableClientReaper

      public BigtableClientReaper(int maxClients)
      Creates a reaper whose daemon threads inherit the calling thread's uncaught-exception handler, so a fatal close error reaches the task's handler rather than vanishing.
      Parameters:
      maxClients - the number of clients that may be open or closing at once
    • BigtableClientReaper

      @VisibleForTesting public BigtableClientReaper(int maxClients, ThreadFactory threadFactory)
  • Method Details

    • acquireSlot

      public void acquireSlot() throws InterruptedException
      Takes a permit for a client about to be created, waiting for a closing one to finish.
      Throws:
      InterruptedException
    • releaseUnusedSlot

      public void releaseUnusedSlot()
      Returns a permit whose client creation failed, so nothing holds it.
    • availableSlots

      @VisibleForTesting public int availableSlots()
    • closeEventually

      public void closeEventually(AutoCloseable client, String description)
      Closes a client on a reaper thread, releasing its permit when the close finishes. A close failure is hygiene: it is logged, never thrown, unless it is an Error.
    • awaitIdle

      public void awaitIdle() throws InterruptedException
      Waits until every scheduled close has physically finished.
      Throws:
      InterruptedException
    • closeAll

      public void closeAll(List<AutoCloseable> activeClients) throws Exception
      Closes every remaining client and then the reaper itself, starting every close before waiting for any so the SDK's bounded final metric exports overlap. A refused handoff closes that client synchronously before the next is attempted. Reports the highest-priority failure with the others suppressed; an interruption is restored after the teardown completes.
      Throws:
      Exception
    • prioritize

      public static Throwable prioritize(Throwable next, @Nullable Throwable previous)
      Chooses which of two failures to report, suppressing the other into it: a JVM-fatal or out-of-memory error anywhere in a chain wins, then an interruption, then any other error, then everything else, with the earlier failure winning a tie.