nicktelford opened a new pull request, #23728: URL: https://github.com/apache/kafka/pull/23728
During a long rebalance, a `StreamThread` can use native memory without limit and fail with an out-of-memory error. When the uncommitted state store bytes exceed `statestore.uncommitted.max.bytes`, `StreamThread#maybeCommit` forces a commit. But `TaskManager` skips commits during a rebalance, and `runOnceWithoutProcessingThreads` continues to process records. Thus the uncommitted bytes continue to increase. RocksDB keeps these bytes in a `WriteBatchWithIndex` in native memory, outside the block cache and the write buffers. At the start of each iteration of the processing loop, `StreamThread` now calls `maybePauseProcessingForUncommittedBytes()`, which checks `shouldCommitDueToUncommittedBytes()`. Because `maybeCommit` commits at the end of each iteration, the bytes exceed the limit at this point only when that commit was skipped or failed. So the check needs no extra state. While processing is paused, the thread does not process records or run punctuators, because both write to the state stores. It continues to poll, so the rebalance can complete, and it continues to call `maybeCommit`. Processing resumes when a commit succeeds, or when a commit on partition revocation flushes the buffers. The thread logs the pause and the resume at INFO level. This change decreases throughput during a long rebalance, but it prevents the out-of-memory error. `GlobalStreamThread` does not need this change, because one thread writes to its stores, checks the bytes and flushes them, and nothing skips that flush. A separate pull request will apply the same pause to processing threads. Two new `StreamThreadTest` tests cover the change. `shouldNotProcessOrPunctuateWhileUncommittedBytesExceedLimit` shows that the thread polls and tries to commit, but does not process or punctuate, while the commit is skipped. `shouldResumeProcessingOnceUncommittedBytesAreCommitted` shows that processing stays paused for the iteration in which the rebalance completes, and resumes only after the commit succeeds. 🤖 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]
