koodin9 opened a new pull request, #19226:
URL: https://github.com/apache/iceberg/pull/19226
## Problem
`CommitState` starts the commit interval when the coordinator is created, so
every new coordinator
waits a full `iceberg.control.commit.interval-ms` before its first commit,
no matter how long ago
the last commit was.
A coordinator is created when its task starts and when the leader partition
is assigned to a
task. If that happens more often than the commit interval, no coordinator
lives long enough to
commit. A rolling restart of the Connect workers is the common case: the
sink's consumer group
rebalances twice per worker, a couple of minutes apart, and commits stop
until the restarts end
and one more interval has passed. The connector commits source offsets only
as part of a commit,
so consumer lag grows for the whole period.
We hit this in a fork that stops the coordinator on every `close()`. With a
5 minute interval, a
rolling restart of 8 workers produced no commit for about 20 minutes.
On `main` today the coordinator often survives an eager rebalance, because
`close()` cannot tell
that it lost the leader partition while the group is rebalancing (#17637).
Once that is fixed
(#18687), every eager rebalance stops and recreates the coordinator, and the
interval restarts
each time. A restart of the leader task already resets it today.
## Change
When a coordinator starts, it reads the time of the last snapshot it
committed and continues the
commit interval from there.
- `Coordinator.start()` looks up, for each configured table, the latest
snapshot on the commit
branch that carries the connector's `kafka.connect.offsets.*` summary
property, and takes the
most recent timestamp across tables. Snapshots written by something else,
like compaction, are
skipped.
- `CommitState.resumeCommitInterval()` sets the start of the interval to
that time.
- The first commit request is sent no sooner than
`iceberg.control.commit.startup-grace-ms`
(new, default 15 seconds) after the coordinator starts. Workers are
created on the first
`save()` and read the control topic from the latest offset, so a request
sent before a worker
is subscribed is never seen by it and the commit ends as a partial commit.
With the defaults (interval 5 min, grace 15 s):
| Last commit when the coordinator starts | First commit request |
|---|---|
| 2 min ago | in 3 min |
| 4 min 50 s ago | in 15 s |
| 7 min ago | in 15 s |
| none found | in 5 min (unchanged) |
Nothing changes when there is no previous commit to continue from: tables
are routed
dynamically, the table does not exist yet, it has no snapshot committed by
this connector, or
the lookup fails (logged at warn). The lookup runs on the coordinator
thread, so it does not
delay `open()`.
The snapshot lookup shares `lastCommittedSnapshot()` with the existing
offset lookup, which is
why `lastCommittedOffsets()` and `lastCommittedOffsetsForTable()` are
touched. Their behavior is
the same.
## Questions for reviewers
- **A new config.** The grace period could reuse
`iceberg.control.commit.timeout-ms` instead. I
kept it separate because the two pull in opposite directions: during a
rolling restart the
wait has to fit between two rebalances, so it should be short, while the
timeout is usually
set generously.
- **Most recent commit across tables.** A commit request goes to all tables
at once, so the most
recent snapshot is the best estimate of when the last commit cycle ran.
Using the oldest would
make a connector with one idle table commit right after every coordinator
start.
- **Clocks.** The snapshot timestamp comes from the coordinator that
committed it, and is
compared with the local clock. A timestamp in the future is treated as
now. Skew otherwise
shifts the first commit by the same amount.
## Testing
- `TestCommitState`: the interval continues from a recent commit, is
deferred by the grace
period when the commit is older than the interval, treats a future
timestamp as now, and is
reached immediately when the grace period is 0.
- `TestCoordinator.testLastCommitTime`: no snapshot, a connector snapshot, a
later snapshot
without the offsets property, a missing table, and dynamic routing.
- `TestCoordinator.testCommitIntervalResumesFromLastCommit`: a coordinator
started after the
interval has elapsed sends a commit request on its first `process()`. This
test fails without
the change.
- `TestCoordinator.testCommitIntervalStartsWhenNoLastCommit`: without a
previous commit the
coordinator waits for a full interval as before.
- Ran `:iceberg-kafka-connect:iceberg-kafka-connect:test`, `spotlessCheck`,
`checkstyleMain` and
`checkstyleTest`.
I have not yet run a rolling restart against a build of this branch.
---
**AI Disclosure**
- Model: Claude Fable 5.2
- Platform/Tool: Claude Code
- Human Oversight: fully reviewed
- Prompt Summary: Port a fix from our fork that continues the commit
interval from the last committed snapshot; the code, tests and this description
are generated
🤖 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]