Repository navigation
[fix][broker] Delete scalable topics when deleting a namespace or a tenant - #26869
Merged
merlimat merged 1 commit intoOct 12, 2026
Merged
Conversation
…enant Namespace deletion only listed regular topics, so it never saw the scalable topics of a namespace: a delete without force was not refused while scalable topics existed, and a forced delete left their records, their segment managed ledgers and their schema behind. On ZooKeeper and Oxia it failed at the end instead, when deleting /managed-ledgers/<ns> while the segment domain was still under it, even after every scalable topic was deleted (their empty parent nodes stay): a 409 after the retries on ZooKeeper, a 500 on Oxia, whose not-empty error was not retried, and either way the namespace stayed marked deleted. - List the scalable topics with the regular ones. Any of them makes a delete without force fail with 409. A forced delete deletes them through the scalable-topic delete, after the regular user topics, then deletes the segment topics still in the namespace. - Clear /topics/<ns> and the segment domain of /managed-ledgers/<ns> with the other namespace metadata, not recursively, and /topics/<tenant> when deleting a tenant. - Retry the namespace delete on Oxia's NotEmptyException too, which now exposes its path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Namespace deletion only lists regular topics: the persistent topics under
/managed-ledgers/<ns>/persistent,the loaded non-persistent topics and the partitioned topics. A scalable topic (
topic://) lives elsewhere:its record under
/topics/<ns>, the managed ledgers of its segment topics under/managed-ledgers/<ns>/segment,and its schema. So namespace deletion never sees scalable topics:
/managed-ledgers/<ns>(not recursively)while the
segmentdomain is still under it. It fails even after every scalable topic was deleted first: thescalable-topic delete leaves the empty parents
/managed-ledgers/<ns>/segment/<topic>and/managed-ledgers/<ns>/segmentbehind (Oxia never removes them; ZooKeeper removes its empty container nodeseventually). On ZooKeeper this ends in a 409 after the 5 retries. On Oxia the not-empty error is a
MetadataStoreException.NotEmptyException, which the retry does not recognize, so it is a 500 right away.Either way the namespace is left marked
deleted, so lookups and topic creation in it are refused.the schema behind, and a namespace re-created with the same name has the old scalable topics again.
Tenant deletion deletes each namespace the same way, so it fails the same way, and it never deleted
/topics/<tenant>.Example
NamespacesBase.internalRetryableDeleteNamespaceAsync0lists and deletes only the regular topics:and
internalClearZkSourcesthen deletes/managed-ledgers/<ns>/persistentand/managed-ledgers/<ns>,neither recursively, with nothing for
/managed-ledgers/<ns>/segmentor/topics/<ns>.Modifications
Namespace deletion lists the scalable topics too (
ScalableTopicResources.listScalableTopicsAsync). Any of themmakes a delete without force fail with 409 "Cannot delete non empty namespace", before the namespace is marked
deleted. A forced delete deletes them through the scalable-topic delete (internal admin), which also deletes
their segment topics and their schema, after the regular user topics and before the system topics (deleting a
segment topic deletes its topic policies). Then it deletes the segment topics still in the namespace
(
TopicResources.listSegmentTopicsAsync, from/managed-ledgers/<ns>/segment/<topic>/<descriptor>): thescalable-topic delete makes a single attempt at each of its segment topics, and one left behind would keep the
namespace from being deleted.
internalClearZkSourcesalso deletes/topics/<ns>and the segment domain (each/managed-ledgers/<ns>/segment/<topic>, then/managed-ledgers/<ns>/segment), not recursively: a node thatstill has children is a topic created during the deletion, which the retry deletes.
The retry also recognizes Oxia's not-empty error;
MetadataStoreException.NotEmptyExceptionnow exposes thepath, like ZooKeeper's
KeeperException.NotEmptyException.Tenant deletion deletes
/topics/<tenant>, recursively like/managed-ledgers/<tenant>.A regular topic with the name of a scalable topic (the
persistent://topic it was migrated from, or anon-persistent topic) shares its schema. It is deleted before the scalable topic, whose delete deletes the schema.
Verifying this change
This change added tests and can be verified as follows. Each new integration test fails without the change:
ScalableTopicNamespaceDeleteTest(in-memory store): a delete without force is refused; a forced namespace ortenant delete deletes the records, the segment ledgers and the schema, also for a migrated topic and with a
same-named non-persistent topic; segment topics left behind by a scalable-topic delete are deleted; a re-created
namespace starts empty.
ScalableTopicNamespaceDeleteZooKeeperTest(MockZooKeeper) andV5MultiBrokerNamespaceDeleteTest(Oxia): forceddelete, delete after the scalable topics were deleted, segment topics left behind, refused delete without force
that leaves the namespace usable, tenant delete, and a node left under the namespace now failing with the 409
on Oxia.
TopicResourcesTest#testListSegmentTopics.The tests don't elect controllers: until the scalable-topic delete stops them (a separate fix), a controller that
is still running puts its lock back under the deleted record, which on Oxia re-creates the record node and fails
the
/topics/<ns>cleanup.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes