tomerr90 opened a new pull request, #30144:
URL: https://github.com/apache/flink/pull/30144
## What is the purpose of the change
When a `SourceReaderBase` has a `RateLimiterStrategy` (FLIP-535), the task
thread uses a whole core while it waits for a permit. While the permit is
pending, `pollNext` returns `MORE_AVAILABLE` without emitting anything, and
`isAvailable()` doesn't take the permit into account, so the mailbox loop calls
`pollNext` again at once. This pull request makes the reader wait for the
permit instead, as `RateLimitedSourceReader` already does.
## Brief change log
- While the permit is pending, `pollNextWithRateLimiting` returns
`NOTHING_AVAILABLE`.
- `isAvailable()` returns the pending permit future, so the task resumes
once the rate limiter grants it.
- Without a rate limiter the permit future is always complete, so that
path is unchanged.
## Verifying this change
This change added tests and can be verified as follows:
- Added
`SourceReaderBaseTest#testWaitsForRateLimiterPermitInsteadOfPolling`. It polls
the reader the way a source task does (again at once after `MORE_AVAILABLE`,
otherwise only once `isAvailable()` completes) and counts the polls, with a
rate limiter whose permit the test completes by hand, so there is no timing.
While the permit is pending the reader is polled twice; without the fix the
test fails with "expected: 2 but was: 100".
- The existing rate-limiting tests in `SourceReaderBaseTest` pass
unchanged, and so does the rest of `flink-connector-base`.
- Manually verified with a local job: an endless
`SingleThreadMultiplexSourceReaderBase` source limited by
`RateLimiterStrategy.perSecond(10)`, parallelism 1. Over a 10 s window, the
source task thread went from 99.8% of a core to 0.3%, at the same 10 records/s.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: no. `SourceReaderBase` is `@PublicEvolving`, but no
signatures change.
- The serializers: no
- The runtime per-record code paths (performance sensitive): no. Only the
rate-limited path changes. Without a rate limiter, `isAvailable()` does one
extra `isDone()` check on an already completed future.
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
The bug affects every release since 2.2.0. Once this is approved, I'll open
backports to `release-2.4`, `release-2.3` and `release-2.2`. The commit
cherry-picks cleanly onto all three, and `SourceReaderBaseTest` passes on each.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Opus 5.5
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]