GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][test] Fix flaky TransactionTest.testTakeSnapshotBeforeBuildTxnProducer by merlimat · Pull Request #27524 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Problem

TransactionTest.testTakeSnapshotBeforeBuildTxnProducer (CI - Unit - Brokers - Broker Group 1) fails its first
attempt after about 4 s, then passes on the retry. Since 5 Nov it has been retried in 7 runs (42130366119,
42267334022, 42291423772, 42360527568, 42395838918, 42540979342, 42642222908). Every first attempt fails the same way:

org.awaitility.core.ConditionTimeoutException: Assertion condition defined as a lambda expression in
org.apache.pulsar.broker.transaction.TransactionTest expected [false] but found [true] within 4 seconds.

The test reads the tnx/ns1 transaction buffer snapshot topic from latest. It expects that topic to stay empty
until its own topic takes its first snapshot. But all transactional topics in a namespace write their snapshots to
this one topic. Topics that earlier methods left loaded in tnx/ns1 keep taking snapshots. TopicTransactionBuffer
re-arms a timer every transactionBufferSnapshotMinTimeInMillis (2 s in this test base). When the timer fires, the
buffer takes a snapshot if its max read position moved since the last one, after a commit, an abort or a plain
publish:

private void takeSnapshotByTimeout() {
    if (changeMaxReadPositionCount.get() > 0) {
        takeSnapshot();
    }
    this.timer.newTimeout(TopicTransactionBuffer.this, takeSnapshotIntervalTime, TimeUnit.MILLISECONDS);
}

When such a snapshot lands after the reader attaches and before the first check, hasMessageAvailable() returns
true. The test never reads that message, so the check stays true for all 4 s. The retry passes because
TestRetrySupport runs cleanup() and setup() before it, so the retry starts on new brokers with no leftover
topics.

A local run of the whole class reproduced the CI failure. When the method started, two leftover topics in tnx/ns1
had pending changes, and both wrote into the reader's window:

  • testAsyncSendAndAckWithSchema wrote 31 ms after the method started. It was left from testSendAndAckWithSchema,
    whose commit came about 2 s earlier.
  • testEndTBRecoveringWhenManagerLedgerDisReadable wrote 1 s after the method started, after an abort.

The broker is working as designed: topics in a namespace are expected to write their snapshots to the namespace's
snapshot topic. The bug is the test's assumption that a shared namespace stays quiet.

Example

String topic = "persistent://" + NAMESPACE1 + "/testSnapShot";
...
Reader<TransactionBufferSnapshot> reader = pulsarClient
        .newReader(Schema.AVRO(TransactionBufferSnapshot.class))
        .startMessageId(MessageId.latest)
        .topic(NAMESPACE1 + "/" + SystemTopicNames.TRANSACTION_BUFFER_SNAPSHOT)   // shared by all of tnx/ns1
        .create();
Awaitility.await().atMost(waitSnapShotTime * 2, TimeUnit.MILLISECONDS)          // 4 s
        .untilAsserted(() -> Assert.assertFalse(reader.hasMessageAvailable()));  // a leftover topic's snapshot
                                                                                 // keeps this true

Change

Test only. The test creates a namespace of its own and reads that namespace's snapshot topic, which only its own
topic writes to:

// A namespace keeps the snapshots of all its topics in one system topic, and the topics that other methods
// leave loaded in NAMESPACE1 keep taking periodic snapshots into it: read a namespace with only this topic.
String namespace = TENANT + "/testTakeSnapshotBeforeBuildTxnProducer";
admin.namespaces().createNamespace(namespace);
String topic = "persistent://" + namespace + "/testSnapShot";
...
        .topic(namespace + "/" + SystemTopicNames.TRANSACTION_BUFFER_SNAPSHOT);

The later checks also read only this topic's snapshots now: the first snapshot at entry -1, then the one at entry 3.
Before, they had to skip other topics' snapshots, and could match one by coincidence.

Testing

  • Repro (temporary patch, not included): a leftover topic in tnx/ns1 commits a transaction before the reader is
    created. Right after the reader attaches, the topic gets a plain publish, and its snapshot timer task is run directly
    (TopicTransactionBuffer.run(null)). The patch then waits until tnx/ns1's snapshot topic has advanced. On master
    both attempts fail with exactly the CI message. With the fix and the same patch, the test passes on its first
    attempt.
  • ./gradlew :pulsar-broker:test --tests 'org.apache.pulsar.broker.transaction.TransactionTest': 38/38 passed with
    no retries in 4 runs before the merge with master, and again after it. On master, 1 of 2 class runs failed this
    method's first attempt.
  • ./gradlew quickCheck passes.

The first retry annotation is from 5 Nov 23:34 UTC. #27376 (merged 5 Nov 21:06 UTC) stopped running a full GC after
every test method (273-388 ms each in CI). That shortened the gaps between methods, which makes a leftover topic's 2 s
timer more likely to fire inside this method's window. This is likely, but not proven.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
merlimat added 2 commits November 9, 2026 08:48
@merlimat
[fix][test] Fix flaky TransactionTest.testTakeSnapshotBeforeBuildTxnP…
a9ac033
…roducer

The test reads tnx/ns1's __transaction_buffer_snapshot topic from latest and
expects nothing there until its own topic takes its first snapshot. Every
transactional topic in the namespace writes its snapshots to that topic, and
the topics that earlier methods leave loaded keep taking periodic ones
(transactionBufferSnapshotMinTimeInMillis = 2 s) after a commit or an abort.
One that lands after the reader attaches keeps hasMessageAvailable() true,
so the 4 s await fails; the retry runs on fresh brokers and passes.

Give the test a namespace of its own, so its reader only sees the snapshots
of its own topic.
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/fix-flaky-ta…
5afa3b6
…ke-snapshot-before-build-txn-producer
@merlimat merlimat added the area/test label Nov 9, 2026
codelipenghui
codelipenghui approved these changes Nov 9, 2026
View reviewed changes
@merlimat
merlimat merged commit 441e30e into apache:master Nov 9, 2026
44 of 45 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@merlimat
merlimat deleted the mmerli/fix-flaky-take-snapshot-before-build-txn-producer branch November 9, 2026 22:27
lhotari pushed a commit that referenced this pull request Nov 11, 2026
@merlimat @lhotari
[fix][test] Fix flaky TransactionTest.testTakeSnapshotBeforeBuildTxnP…
92f147d
…roducer (#27524)

(cherry picked from commit 441e30e)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 11, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Fix flaky TransactionTest.testTakeSnapshotBeforeBuildTxnP…
188fd57
…roducer (apache#27524)

(cherry picked from commit 441e30e)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Fix flaky TransactionTest.testTakeSnapshotBeforeBuildTxnP…
62e9e13
…roducer (apache#27524)

(cherry picked from commit 441e30e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area/test cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@merlimat @codelipenghui @lhotari
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.