nicktelford opened a new pull request, #22648: URL: https://github.com/apache/kafka/pull/22648
The transaction buffer's staging map (`pendingWrites`) is written exclusively by the owning `StreamThread`, but it must also serve point-in-time, snapshot-isolated reads from interactive-query (IQ) threads. It was a `ConcurrentSkipListMap` so that IQ readers could traverse it safely while the owner mutated it concurrently. That concurrency came at a cost: every owner `get`/`put` on the hot path paid skip-list overhead even though the owner is the sole mutator, regressing `StreamThread` throughput. This change replaces the `ConcurrentSkipListMap` with a plain `TreeMap` guarded by the buffer's existing `snapshotLock`. Owner writes take the write lock; non-owner (IQ) reads take the read lock; owner reads and scan-copies run lock-free, because the owner is the only thread that ever mutates the map. Because an owner scan iterates the same `TreeMap` it may concurrently mutate, the owner eagerly copies the bounded staging range up front to avoid a same-thread `ConcurrentModificationException`. The same locking discipline is applied across `RocksDBTransactionBuffer`'s `stage`, `stageDeleteRange`, `get`, and `scan` paths. It also fixes a pre-existing copy-on-write bug in the `rangeTombstones` handling. The shallow `TreeMap` copy shared its mutable `List<Bytes>` values with the original, so range-deleting the same `from` key twice mutated a list still being traversed by an in-flight non-owner iterator, corrupting its view. The affected value lists are now deep-copied on write so iterators retain a stable snapshot. New concurrency and `ConcurrentModificationException` regression tests in `AbstractTransactionBufferTest` and `RocksDBTransactionBufferTest` cover these paths. 🤖 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]
