Class BigtableClientReaper
java.lang.Object
io.github.flink.gcp.connector.bigtable.BigtableClientReaper
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
ConstructorsConstructorDescriptionBigtableClientReaper(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 TypeMethodDescriptionvoidTakes a permit for a client about to be created, waiting for a closing one to finish.intvoidWaits until every scheduled close has physically finished.voidcloseAll(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.voidcloseEventually(AutoCloseable client, String description) Closes a client on a reaper thread, releasing its permit when the close finishes.static Throwableprioritize(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.voidReturns a permit whose client creation failed, so nothing holds it.
-
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
-
-
Method Details
-
acquireSlot
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
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 anError. -
awaitIdle
Waits until every scheduled close has physically finished.- Throws:
InterruptedException
-
closeAll
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
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.
-