Skip to content

[KYUUBI #7668][SPARK] Use UUIDv7 for executor podNamePrefix to avoid same-millisecond collision - #7669

Closed
littlexyw wants to merge 1 commit into
apache:masterfrom
littlexyw:kyuubi-7668-executor-podname-uuidv7
Closed

[KYUUBI #7668][SPARK] Use UUIDv7 for executor podNamePrefix to avoid same-millisecond collision#7669
littlexyw wants to merge 1 commit into
apache:masterfrom
littlexyw:kyuubi-7668-executor-podname-uuidv7

Conversation

@littlexyw

@littlexyw littlexyw commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Why are the changes needed?

On Kubernetes, SparkSQLEngine.generateExecutorPodNamePrefixForK8s built the executor podNamePrefix as kyuubi-<user>-<epoch-millis>. When two engines for the same user (same resolvedUserName) are launched within the same millisecond in the same namespace — e.g. a burst of short-lived engines from the same user, or two Kyuubi servers racing to launch engines for a USER share level — the two engines get an identical spark.kubernetes.executor.podNamePrefix. Their executor pod names (<prefix>-exec-<id>) then collide inside the namespace, and one of the two apps fails to create executors until the other releases the names.

This PR replaces the epoch-millis suffix with a UUIDv7 from the existing UuidUtils.generateUUIDv7 helper. UUIDv7 keeps the 48-bit epoch millis in its leading bits so pod names remain roughly time-ordered when listed by name, while the trailing 74 bits of secure randomness make same-millisecond collisions essentially impossible. The oversized-user-name fallback path is switched to the same UUIDv7 for consistency.

How was this patch tested?

  • Added a concurrent unit test generate executor pod name prefix should be unique for concurrent calls with the same user in SparkSQLEngineSuite that fans out 1000 prefix generations across 10 threads for the same user and asserts every generated prefix is unique. Under the pre-fix epoch-millis implementation this test necessarily fails, since many calls land on the same millisecond and produce identical prefixes.
  • The existing [KYUUBI #3385] generate executor pod name prefix with user or UUID test still passes (sanitization, length cap, and pod-log-directory length invariants unchanged).

Was this patch assisted by generative AI tooling?

Assisted-by: Claude Opus 4.7

@pan3793 pan3793 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But please fill PR description seriously.

…avoid same-millisecond collision

SparkSQLEngine.generateExecutorPodNamePrefixForK8s built the podNamePrefix
as `kyuubi-<user>-<epoch-millis>`. Two engines for the same user launched
within the same millisecond in the same namespace ended up with an identical
`spark.kubernetes.executor.podNamePrefix`, causing their executor pods
(`<prefix>-exec-<id>`) to collide inside the namespace and one of the two
apps to fail creating executors.

Replace the epoch-millis suffix with a UUIDv7 from the existing
`UuidUtils.generateUUIDv7` helper. UUIDv7 keeps the 48-bit epoch millis in
its leading bits so pod names remain roughly time-ordered when listed by
name, while the trailing 74 bits of secure randomness make same-millisecond
collisions essentially impossible. The oversized-user-name fallback path is
switched to the same UUIDv7 for consistency.

Add a concurrent unit test that fans out 1000 prefix generations across 10
threads for the same user and asserts every generated prefix is unique.
@littlexyw
littlexyw force-pushed the kyuubi-7668-executor-podname-uuidv7 branch from eb16a9f to b29ebc7 Compare August 31, 2026 02:29
@pan3793 pan3793 added this to the v1.12.1 milestone Aug 31, 2026
@pan3793 pan3793 closed this in f35e7df Aug 31, 2026
pan3793 pushed a commit that referenced this pull request Aug 31, 2026
…same-millisecond collision

### Why are the changes needed?

On Kubernetes, `SparkSQLEngine.generateExecutorPodNamePrefixForK8s` built the executor podNamePrefix as `kyuubi-<user>-<epoch-millis>`. When two engines for the same user (same `resolvedUserName`) are launched within the same millisecond in the same namespace — e.g. a burst of short-lived engines from the same user, or two Kyuubi servers racing to launch engines for a `USER` share level — the two engines get an identical `spark.kubernetes.executor.podNamePrefix`. Their executor pod names (`<prefix>-exec-<id>`) then collide inside the namespace, and one of the two apps fails to create executors until the other releases the names.

This PR replaces the epoch-millis suffix with a UUIDv7 from the existing `UuidUtils.generateUUIDv7` helper. UUIDv7 keeps the 48-bit epoch millis in its leading bits so pod names remain roughly time-ordered when listed by name, while the trailing 74 bits of secure randomness make same-millisecond collisions essentially impossible. The oversized-user-name fallback path is switched to the same UUIDv7 for consistency.

### How was this patch tested?

- Added a concurrent unit test `generate executor pod name prefix should be unique for concurrent calls with the same user` in `SparkSQLEngineSuite` that fans out 1000 prefix generations across 10 threads for the same user and asserts every generated prefix is unique. Under the pre-fix epoch-millis implementation this test necessarily fails, since many calls land on the same millisecond and produce identical prefixes.
- The existing `[KYUUBI #3385] generate executor pod name prefix with user or UUID` test still passes (sanitization, length cap, and pod-log-directory length invariants unchanged).

### Was this patch assisted by generative AI tooling?
Assisted-by: Claude Opus 4.7

Closes #7669 from littlexyw/kyuubi-7668-executor-podname-uuidv7.

Closes #7668

b29ebc7 [littlexyw] [KYUUBI #7668][SPARK] Use UUIDv7 for executor podNamePrefix to avoid same-millisecond collision

Authored-by: littlexyw <shea_wong@163.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
(cherry picked from commit f35e7df)
Signed-off-by: Cheng Pan <chengpan@apache.org>
@pan3793

pan3793 commented Aug 31, 2026

Copy link
Copy Markdown
Member

thanks, merged to master/1.12

@pan3793

pan3793 commented Aug 31, 2026

Copy link
Copy Markdown
Member

Merge Summary:

Posted by merge_kyuubi_pr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants