Class PerKeyWriteSequencer<K,W>
java.lang.Object
io.github.flink.gcp.connector.base.sink.PerKeyWriteSequencer<K,W>
- Type Parameters:
K- the key a write is ordered byW- the write
Admits one write per key at a time and holds the rest of that key's writes in arrival order.
A key is active from the admission of a write until the caller releases it with nothing held. A write for an active key is held behind the earlier ones, and a release hands back the oldest held write, which then occupies the key in its turn. Writes for other keys are not affected.
Nothing here knows what a write is or when it is answered; the writer decides both and calls
this sequencer from its task thread only, so the sequencer is not thread-safe. The Firestore and
Bigtable sinks share it (#1618); a key's toString appears in the invariant failures
below, so a sink whose keys are user data supplies a key type that does not render them.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Forgets every key and held write.voidHolds a write behind its active key's earlier writes.Ends the turn of the key's current write.booleanAdmits a write if its key is not active, making the key active.
-
Constructor Details
-
PerKeyWriteSequencer
public PerKeyWriteSequencer()
-
-
Method Details
-
tryAdmit
Admits a write if its key is not active, making the key active.- Returns:
trueif the write may be sent now;falseif its key is active, when the caller musthold(Object, Object)it instead
-
hold
Holds a write behind its active key's earlier writes.- Throws:
IllegalStateException- if the key is not active
-
release
Ends the turn of the key's current write.- Returns:
- the key's oldest held write, which now occupies the key and may be sent, or
nullif none is held, which makes the key inactive - Throws:
IllegalStateException- if the key is not active: a write was released twice, or one never admitted was released
-
clear
public void clear()Forgets every key and held write.
-