You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
persistentWorker.takeSnapshotSegmentAsync(abortedSegment, position) gets called on another thread (transactionExecutorProvider).
It would be useful to have clear consistency boundaries in the SnapshotSegmentAbortedTxnProcessorImpl implementation since breaking thread safety rules will lead to hard-to-debug issues.
Status on current master (bcac33d), from the triage of #22384 (now closed):
On master, every read and write of aborts, segmentIndex and unsealedTxnIds from the transaction buffer now runs under the TopicTransactionBuffer monitor: the marker callbacks, isTxnAborted, handleTransactionMessage and the timer snapshot. The recovery code linked above was rewritten into doRecoverFromSnapshot in #26335. Two races remain in SnapshotSegmentAbortedTxnProcessorImpl, which is only used with transactionBufferSegmentedSnapshotEnabled=true:
TopicTransactionBuffer.getStats → generateSnapshotStats takes no lock. It iterates aborts, segmentIndex and indexes while the managed-ledger callback thread mutates them (under the buffer monitor). The likely result is a ConcurrentModificationException or inconsistent numbers from the topic stats admin call.
PersistentWorker.updateIndexWhenExecuteTheLatestTask reads unsealedTxnIds on the segment writer's completion thread without the buffer monitor.
Interleaving: thread A runs putAbortedTxnAndPosition → unsealedTxnIds.add(T) under the buffer monitor, while thread W (completing writeSnapshotSegmentAsync) iterates the same LinkedList in convertTypeToTxnIDData. W throws a ConcurrentModificationException, the segment task fails after indexes.put, sequenceID.getAndIncrement() in takeSnapshotSegmentAsync is skipped, and the task stays at the head of the queue until the next append retries it.
this.unsealedTxnIds = new LinkedList<>() is a plain write that comes after taskQueue.add in putAbortedTxnAndPosition. In theory W could see the new empty list and still see taskQueue.size() == 1. It would then persist an index whose maxReadPosition is past the last sealed abort, without that sealed segment's IDs. This reordering is legal under the JMM but unlikely in practice.
A fix should take a consistent copy of unsealedTxnIds (and of maxReadPosition) under the buffer monitor, or hand it over explicitly with the task. generateSnapshotStats should run under the same monitor. A concurrency test that runs aborts while segments are being written and stats are being polled would be needed to land it.
Activity
lhotari commentedon Feb 26, 2024
related to #21304 and #22119
nikam14 commentedon Mar 28, 2024
@lhotari can you review above mentioned PR.
lhotari commentedon Jul 19, 2025
Some more issues here:
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/SnapshotSegmentAbortedTxnProcessorImpl.java
Lines 170 to 171 in 1b7e4a7
persistentWorker.takeSnapshotSegmentAsync(abortedSegment, position)gets called on another thread (transactionExecutorProvider).It would be useful to have clear consistency boundaries in the
SnapshotSegmentAbortedTxnProcessorImplimplementation since breaking thread safety rules will lead to hard-to-debug issues.merlimat commentedon Oct 22, 2026
Status on current master (bcac33d), from the triage of #22384 (now closed):
On master, every read and write of
aborts,segmentIndexandunsealedTxnIdsfrom the transaction buffer now runs under theTopicTransactionBuffermonitor: the marker callbacks,isTxnAborted,handleTransactionMessageand the timer snapshot. The recovery code linked above was rewritten intodoRecoverFromSnapshotin #26335. Two races remain inSnapshotSegmentAbortedTxnProcessorImpl, which is only used withtransactionBufferSegmentedSnapshotEnabled=true:TopicTransactionBuffer.getStats→generateSnapshotStatstakes no lock. It iteratesaborts,segmentIndexandindexeswhile the managed-ledger callback thread mutates them (under the buffer monitor). The likely result is aConcurrentModificationExceptionor inconsistent numbers from the topic stats admin call.PersistentWorker.updateIndexWhenExecuteTheLatestTaskreadsunsealedTxnIdson the segment writer's completion thread without the buffer monitor.putAbortedTxnAndPosition→unsealedTxnIds.add(T)under the buffer monitor, while thread W (completingwriteSnapshotSegmentAsync) iterates the sameLinkedListinconvertTypeToTxnIDData. W throws aConcurrentModificationException, the segment task fails afterindexes.put,sequenceID.getAndIncrement()intakeSnapshotSegmentAsyncis skipped, and the task stays at the head of the queue until the next append retries it.this.unsealedTxnIds = new LinkedList<>()is a plain write that comes aftertaskQueue.addinputAbortedTxnAndPosition. In theory W could see the new empty list and still seetaskQueue.size() == 1. It would then persist an index whosemaxReadPositionis past the last sealed abort, without that sealed segment's IDs. This reordering is legal under the JMM but unlikely in practice.A fix should take a consistent copy of
unsealedTxnIds(and ofmaxReadPosition) under the buffer monitor, or hand it over explicitly with the task.generateSnapshotStatsshould run under the same monitor. A concurrency test that runs aborts while segments are being written and stats are being polled would be needed to land it.