Stellarhold170NT opened a new pull request, #24368: URL: https://github.com/apache/kafka/pull/24368
### Motivation This fixes KAFKA-21279. Write operations of the new group coordinator build their records first and apply them to the state machine when the batch is built (`if (replay) coordinator.replay(...)`), before the batch is durably appended to the `__consumer_offsets` partition. The fence and leave paths cancel the timers of the departing members eagerly, while the records are being built. When the append fails, `failCurrentBatch` calls `revertLastWrittenOffset`, which restores the timeline-backed state via the snapshot registry and thereby resurrects the members — but the timer cancellations live outside the snapshot registry (`CoordinatorTimerImpl` keeps its tasks in a plain `ConcurrentHashMap`), so they are never undone. A member restored by such a revert stays in the group without a session timeout and can never be fenced or timed out again — a zombie member. This is the same root cause tracked by KAFKA-19023; its timer rework (#23913) addresses it by making timers snapshottable. ### Changes Since the snapshot registry has no listener API and timers are not part of the timeline state, this adds a revert hook on the shard API: - `CoordinatorShard#onLastWrittenOffsetReverted(long offset)`: a new default (no-op) callback, following the pattern of the existing `onLoaded`, `onMetadataUpdate` and `onUnloaded` hooks. - `SnapshottableCoordinator#revertLastWrittenOffset` invokes it right after `snapshotRegistry.revertToSnapshot(offset)`. - `GroupCoordinatorShard` delegates the callback to `GroupMetadataManager`. - `GroupMetadataManager#onLastWrittenOffsetReverted` iterates the reverted group state and re-arms the session timeout of every consumer and streams group member via `CoordinatorTimer#scheduleIfAbsent`, mirroring what `onLoaded` does when loading a group. Timers which were not canceled keep their original deadlines (hence `scheduleIfAbsent`); the rebalance, join and sync timers of a restored member are re-established by its next heartbeat, while the re-armed session timeout remains the safety net for members which never heartbeat again. Share groups are not touched: their fence path does not cancel timers eagerly. ### Testing - Added `GroupMetadataManagerTest#testOnLastWrittenOffsetRevertedReArmsSessionTimeouts` — verifies that the callback re-arms the session timeout of a member present in the reverted state whose timers were canceled. - Added `GroupMetadataManagerTest#testOnLastWrittenOffsetRevertedDoesNotResurrectRemovedMembers` — verifies that the callback does not resurrect timers for members which are no longer part of the group after a successful leave. - `./gradlew :coordinator-common:compileJava :coordinator-common:compileTestJava :group-coordinator:compileJava :group-coordinator:compileTestJava` plus targeted `:coordinator-common:test --tests CoordinatorRuntimeTest` and the two new tests in `:group-coordinator:test`. -- 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]
