Class FlowControl
java.lang.Object
io.camunda.zeebe.logstreams.impl.flowcontrol.FlowControl
- All Implemented Interfaces:
LogStorage.AppendListener
Maintains a view of in-flight entries as they are being appended, written, committed and finally
processed.
If enabled, a write rate limiter is used to limit the rate of appends to the log storage. Additionally, a request limiter is used to limit the amount of unprocessed user commands to ensure fast response times.
Thread safety
Access patterns:- Calls to
tryAcquire(WriteContext, List)from the sequencer, serialized through the sequencers write lock. - Calls to
onAppend(InFlightEntry, long)from the sequencer, serialized through the sequencers write lock. - Calls to
onWrite(long, long)from the log storage, serialized through the single raft thread. - Calls to
onCommit(long, long)from the log storage, serialized through the single raft thread. - Calls to
onProcessed(long)from the stream processor, serialized through the stream processor actor.
tryAcquire(WriteContext, List)andonAppend(InFlightEntry, long)are always called in that order and before any other methods.onWrite(long, long)andonCommit(long, long)andonProcessed(long)can be called in any order.
The inFlight map is only modified in the onAppend(InFlightEntry, long)
method. All other methods only read from it.
A volatile field lastProcessedPosition is only modified in onProcessed(long)
and used in onAppend(InFlightEntry, long) to clean up old entries.
The RateMeasurement#observe method only returns true when a new observation value is available. This way we prevent updating the metrics too often with repeated values. We use the RateMeasurements to update the cluster load and the exporting rate metrics.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionFlowControl(LogStreamMetrics metrics) FlowControl(LogStreamMetrics metrics, com.netflix.concurrency.limits.Limit requestLimit, RateLimit writeRateLimit) -
Method Summary
Modifier and TypeMethodDescriptioncom.netflix.concurrency.limits.LimitvoidonAppend(InFlightEntry entry, long highestPosition) voidonCommit(long index, long highestPosition) Called when the entry has been successfully committed.voidonExported(long position) voidonProcessed(long position) voidonWrite(long index, long highestPosition) Called when the entry has been successfully written to the local storage.voidsetRequestLimit(com.netflix.concurrency.limits.Limit requestLimit) voidsetWriteRateLimit(RateLimit writeRateLimit) tryAcquire(WriteContext context, List<LogAppendEntryMetadata> batchMetadata) Tries to acquire a free in-flight spot, applying backpressure as needed.
-
Constructor Details
-
FlowControl
-
FlowControl
public FlowControl(LogStreamMetrics metrics, com.netflix.concurrency.limits.Limit requestLimit, RateLimit writeRateLimit)
-
-
Method Details
-
tryAcquire
public Either<FlowControl.Rejection,InFlightEntry> tryAcquire(WriteContext context, List<LogAppendEntryMetadata> batchMetadata) Tries to acquire a free in-flight spot, applying backpressure as needed.- Returns:
- An Optional containing a
InFlightEntryif append was accepted, an empty Optional otherwise.
-
onAppend
-
onWrite
public void onWrite(long index, long highestPosition) Description copied from interface:LogStorage.AppendListenerCalled when the entry has been successfully written to the local storage.- Specified by:
onWritein interfaceLogStorage.AppendListener- Parameters:
index- the index of the written entry
-
onCommit
public void onCommit(long index, long highestPosition) Description copied from interface:LogStorage.AppendListenerCalled when the entry has been successfully committed.- Specified by:
onCommitin interfaceLogStorage.AppendListener- Parameters:
index- the index of the committed entryhighestPosition- the highest position (i.e. last position) of the records within the entry that was committed.
-
onProcessed
public void onProcessed(long position) -
onExported
public void onExported(long position) -
getRequestLimit
public com.netflix.concurrency.limits.Limit getRequestLimit() -
setRequestLimit
public void setRequestLimit(com.netflix.concurrency.limits.Limit requestLimit) -
getWriteRateLimit
-
setWriteRateLimit
-