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][broker] Delete the schema and topic policies when another cluster deletes the partitioned topic metadata first during GC by merlimat · Pull Request #27588 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Motivation

ReplicationTopicGcUsingGlobalZKTest.testTopicGC[partitioned] passes only on retry in master's scheduled CI runs (42969468365, 43018959386). The first attempt times out after 60 s with expected [true] but found [false]: one cluster's topic policies or schema are still there after both partitions and the partitioned topic metadata are gone.

This is a broker bug, not a test bug. With a shared configuration store (global ZK), the clusters share the partitioned topic metadata, but each cluster has its own schema and topic policies. When a partition goes inactive, PersistentTopic.checkGC() deletes it, and then tryToDeletePartitionedMetadata() does one of two things:

  • If the partitioned topic metadata is gone, it calls deleteSchemaAndPoliciesIfAllPartitionsDeleted().
  • Otherwise it calls its own cluster's deletePartitionedTopic admin API, which deletes the schema, the topic policies and the metadata.

Both clusters' replicators go idle at the same moment, so both clusters GC their partition within about 100 ms of each other. If cluster r1 deletes the shared metadata after r2 has checked that it exists, but before r2's admin call reads it, that call returns 404:

DELETE .../tp_-69527b14-.../partitions?force=false&deleteSchema=true  status=404
WARN  NamespaceResources - Failed to unmark the topic as deleted
WARN  PersistentTopic - Inactive topic deletion failed {topic=...-partition-0}
  PulsarAdminException$NotFoundException: Partitioned Topic ... not found

Then r2's GC chain fails and r2's schema and topic policies are never deleted. r2's partition is already gone, so GC never visits the topic again. In production, a partitioned topic recreated later with the same name picks up the stale policies and schema.

The race is old. #27537 made the test hit it more often: the test's GC interval went from 5 s to 1 s, so the two clusters' GC passes land close together far more often.

Modifications

  • PersistentTopic.tryToDeletePartitionedMetadata(): when deleting the partitioned topic metadata fails with NotFoundException, another broker deleted the metadata first. The code now falls back to deleteSchemaAndPoliciesIfAllPartitionsDeleted(), which is what it already does when it finds the metadata missing up front. Other failures still propagate.
                            ).exceptionallyCompose(ex -> {
                                if (FutureUtil.unwrapCompletionException(ex) instanceof NotFoundException) {
                                    // Another broker deleted the partitioned topic metadata first, ...
                                    return deleteSchemaAndPoliciesIfAllPartitionsDeleted();
                                }
                                return CompletableFuture.failedFuture(ex);
                            });
  • New test ReplicationTopicGcUsingGlobalZKTest.testPartitionedTopicMetadataDeletedByRemoteClusterDuringGc reproduces the interleaving deterministically, without sleeps:
    • It stops the periodic GC and waits until both partitions have been inactive for the configured 2 s, reading the package-visible lastActive.
    • It lets r2's executor run the partition deletion, then holds r2's next executor task. By then r2 has found the partitioned topic metadata and marked it deleted.
    • It GCs r1's partition, waits for r1 to delete the metadata, releases r2, and checks that both clusters' schema and topic policies are deleted.

Verifying this change

  • The new test fails without the fix on both the first attempt and the retry. r2's admin delete gets 404, and r2's topic policies are still there after 10 s. With the fix it passed in 6 of 6 runs.
  • ReplicationTopicGcTest and ReplicationTopicGcUsingGlobalZKTest pass: 4 + 5 tests.
  • A scratch test that GCs both clusters' partitions at the same instant leaked r2's policies in 2 of 10 iterations without the fix. With the fix it passed 30 of 30, even though every iteration hit the 404.
  • ./gradlew quickCheck passes.

Sorry, something went wrong.

Uh oh!

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

All reactions
@merlimat
[fix][broker] Delete the schema and topic policies when another clust…
7e96208
…er deletes the partitioned topic metadata first during GC

With a shared configuration store (global ZK), the partitioned topic metadata is shared by the clusters, while the
schema and topic policies are per cluster. When both clusters GC their copy of an inactive partition at about the
same time, the one that loses the race to delete the partitioned topic metadata gets a 404 from its own
deletePartitionedTopic call: the deletion fails, and its schema and topic policies are left behind for good since
the partition is already gone and GC never visits it again.

Treat a NotFoundException from that deletion as "the metadata is already gone" and delete this cluster's schema
and topic policies as the branch for missing metadata already does.

This made ReplicationTopicGcUsingGlobalZKTest.testTopicGC[partitioned] flaky: since apache#27537 the GC runs every
second, so both clusters' GC passes land close together far more often.
codelipenghui
codelipenghui approved these changes Nov 11, 2026
View reviewed changes
@merlimat
merlimat merged commit f918744 into apache:master Nov 11, 2026
44 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Nov 11, 2026
@merlimat @lhotari
[fix][broker] Delete the schema and topic policies when another clust…
76fe99e
…er deletes the partitioned topic metadata first during GC (#27588)

(cherry picked from commit f918744)
@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][broker] Delete the schema and topic policies when another clust…
6ab9d9e
…er deletes the partitioned topic metadata first during GC (apache#27588)

(cherry picked from commit f918744)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][broker] Delete the schema and topic policies when another clust…
ab3ea5b
…er deletes the partitioned topic metadata first during GC (apache#27588)

(cherry picked from commit f918744)
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

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.