[fix][broker] Prevent replicator from getting stuck when dispatch rate limiter has no permits#26005
Conversation
7fed1bd to
16ad2d7
Compare
…e limiter has no permits
16ad2d7 to
25ed1ac
Compare
|
Hi @poorbarcode, this one adjusts when |
| if (!isWritable()) { | ||
| log.debug("Throttling replication traffic because producer is not writable"); | ||
| // Minimize the read size if the producer is disconnected or the window is already full | ||
| messagesToRead = 1; | ||
| } |
There was a problem hiding this comment.
this changes the behavior of the existing code when it's moved here.
There's also a bug in the existing code. This check should be done before acquiring permits. It doesn't make sense that permits and rate limit is calculated based on a different amount than what is used.
There was a problem hiding this comment.
One additional problem is that there's not a way to specify the Netty watermark limits which are used to determine the "writability" of a Netty channel. By default it's a very small value and it could be useful to allow more buffering than the Netty defaults allow.
Motivation
PersistentReplicator.readMoreEntries()created anInFlightTaskbefore checking the replicator dispatch rate limiter.When replicator dispatch throttling was enabled and the rate limiter had no message or byte permits, the method scheduled a retry and returned without issuing
cursor.asyncReadEntriesOrWait(...). The newly-created task stayed inentries == null, so it looked like a pending cursor read even though no read request existed.On the next retry,
hasPendingRead()returned true and the replicator stopped scheduling further reads. This could leave geo-replication stuck with backlog when replicator dispatch throttling is enabled.Modifications
Compute producer and rate-limiter permits before creating the in-flight read task.
Create the
InFlightTaskonly after confirming that a real cursor read will be issued. This preserves the invariant that anentries == nullin-flight task corresponds to an actual pending cursor read.Added a unit test covering the no-permit rate-limiter path for both message and byte throttling, verifying that no pending in-flight read task is created.
Verifying this change
This change added tests and can be verified as follows:
./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.persistent.PersistentReplicatorInflightTaskTest.testRateLimiterWithoutPermitsDoesNotCreateInFlightTask./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.persistent.PersistentReplicatorInflightTaskTest.testAcquirePermitsIfNotFetchingSchema./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.ReplicatorRateLimiterTest.testReplicatorRateLimiterMessageReceivedAllMessages./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.ReplicatorRateLimiterTest.testReplicatorRateLimiterByBytesDoes this pull request potentially affect one of the following parts: