Skip to content

[fix][broker] Decode topic name in the scalable topic migrate endpoint - #26711

Merged
merlimat merged 1 commit into
apache:masterfrom
TimurRakhmatullin86:fix/migrate-decode-topic-name
Sep 29, 2026
Merged

merlimat merged 1 commit into
apache:masterfrom
TimurRakhmatullin86:fix/migrate-decode-topic-name

Conversation

@TimurRakhmatullin86

Copy link
Copy Markdown
Contributor

Motivation

The scalable-topic migrate endpoint (POST .../persistent/{tenant}/{namespace}/{topic}/migrateToScalable) declares its {topic} path segment @Encoded but spliced it straight into the derived topic identities without URL-decoding — unlike its sibling createScalableTopic, which calls Codec.decode first. For any local name containing a character the admin client percent-encodes in the REST path (a space, a non-ASCII character, …), every identity the endpoint derived was wrong:

  • Migrating a b checked existence of persistent://t/ns/a%20b, so the request 404s ("Topic does not exist") even though the topic exists.
  • If a topic literally named like the encoded spelling exists, the endpoint would authorize against, existence-check, and terminate that other topic, and write the scalable record under topic://t/ns/a%20b — an identity no v5 client lookup ever derives (clients resolve the scalable identity from the raw local name via TopicName#toScalableTopic), so the migrated record is invisible to clients and to the PIP-475 recreate guard.

Modifications

Decode the @Encoded segment with Codec.decode before building the topic names, exactly as createScalableTopic already does. Added ScalableTopicsMigrateTest, which drives the endpoint with a mocked pipeline and asserts the authorization target, the metadata-lookup name, and the existence-check name all use the decoded local name (a%20b → a b, caf%C3%A9 → café).

This is the migrate write-path; the read-side endpoints in the same resource share the same missing-decode and would be coherent follow-ups.

Verifying this change

Covered by the added unit test ScalableTopicsMigrateTest. It fails without the fix (expected [persistent://tenant/ns/a b] but found [persistent://tenant/ns/a%20b]) and passes with it.

Found by code inspection while working on the related TopicName#toScalableTopic identity fix (#26668).

Does this pull request potentially affect one of the following parts:

  • Dependencies: no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The threading model: no
  • The binary protocol: no
  • The REST endpoints: behavior fix only (the migrate endpoint now resolves encoded topic names correctly)
  • The admin CLI options: no
  • The metrics: no
  • Anything that affects deployment: no

Documentation

  • doc-not-needed

migrateToScalable spliced the @encoded path segment straight into the
scalable and persistent topic identities, unlike its sibling
createScalableTopic, which URL-decodes it first. For any local name
containing a character the admin client percent-encodes in the REST
path (space, non-ASCII, ...), every identity the endpoint derived was
wrong:

- Migrating "a b" checked existence of persistent://t/ns/a%20b, so the
  request 404ed even though the topic exists.
- If a topic literally named like the encoded spelling existed, the
  endpoint would authorize, existence-check, and terminate that other
  topic instead, and write the scalable record under an identity no V5
  lookup ever derives: clients resolve the scalable identity from the
  raw local name (TopicName#toScalableTopic), so the migrated record
  would be invisible to them and to the PIP-475 recreate guard.

Decode the segment with Codec.decode before building the names, exactly
as the create path does.
@merlimat merlimat added this to the 5.0.0 milestone Sep 25, 2026
@merlimat
merlimat merged commit cda6601 into apache:master Sep 29, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants