[SPARK-58857][K8S] Bind the result of Utils.randomize in LocalDirsFeatureStep - #58103
Open
LuciferYang wants to merge 1 commit into
Open
[SPARK-58857][K8S] Bind the result of Utils.randomize in LocalDirsFeatureStep#58103LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
…tureStep `configurePod` calls `randomize` on the local dirs resolved from configuration but drops the return value, so that branch emits them in configured order. `Utils.randomize` shuffles a copy (`randomizeInPlace(seq.iterator.toArray)`) and returns it, so the caller sees no change to the argument; the in-place variant is `Utils.randomizeInPlace`. The sibling call fifteen lines earlier, for the pod-template branch, binds the result and works. Both calls came in with SPARK-39755, which exists to randomize these dirs. An earlier revision of that PR used `randomizeInPlace`; review suggested `Utils.randomize`, and the next revision adopted it at both sites, binding the result at one and dropping it at the other. Binding the result also makes two conversions redundant, since `randomize` already returns a `Seq`, which leaves the `ArrayImplicits` import unused. Note this has no measurable I/O consequence: `DiskBlockManager` hashes filenames across the dirs it is given, so each executor already spreads files evenly whatever order it receives, and in this branch every dir is an emptyDir on one node filesystem. What changes is that the randomization the JIRA and release note describe now happens.
pan3793
approved these changes
Aug 19, 2026
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.
What changes were proposed in this pull request?
Bind the result of
Utils.randomizeinLocalDirsFeatureStep.configurePod, so the local dirs resolved from configuration are actually shuffled.Binding the result also makes two
toImmutableArraySeqconversions redundant, sincerandomizealready returns aSeq, which in turn leaves theArrayImplicitsimport unused.Why are the changes needed?
configurePodcallsrandomizeon the resolved dirs and discards the return value:Utils.randomize[T](seq: IterableOnce[T]): Seq[T]israndomizeInPlace(seq.iterator.toArray).toImmutableArraySeq. It shuffles a fresh copy and returns it, so the caller observes nothing on the argument. The genuinely mutating variant isUtils.randomizeInPlace. The sibling call fifteen lines earlier, for the pod-template branch, binds the result and works.Both calls arrived in the same commit, 9f9af2a (SPARK-39755, "Improve
LocalDirsFeatureStepto randomize local directories"). An earlier revision of that PR usedrandomizeInPlace; review suggestedUtils.randomize, and the next revision adopted it at both sites, binding the result at one and dropping it at the other.So on this branch
SPARK_LOCAL_DIRS, the emptyDir volume list, and thespark-local-dir-Nto path pairing come out in configured order, identically for every pod in an application.One thing this PR deliberately does not claim: there is no measurable I/O or capacity benefit.
DiskBlockManager.getFileselects a directory bynonNegativeHash(filename) % localDirs.length, which already spreads files near-uniformly within each executor whatever order it receives, and in this branch every path is an emptyDir this step creates, so they share one node filesystem (or RAM underspark.kubernetes.local.dirs.tmpfs). What changes is that the randomization SPARK-39755 added, and which its JIRA and release note describe, now happens; the suite's// SPARK-39755 : Changes the method to test randomizationcomment currently describes behavior that never occurs.If reviewers would rather not have the randomization at all, deleting the call as dead code is a reasonable alternative and I am happy to switch. The argument for fixing rather than deleting is parity with the sibling branch and with SPARK-39755's stated intent.
Does this PR introduce any user-facing change?
The order of
SPARK_LOCAL_DIRSand of the generated emptyDir volume mounts now varies between pods instead of matching the configured order. No API or configuration change, and the set of directories and their mount paths are unchanged.How was this patch tested?
A test added to
LocalDirsFeatureStepSuitethat runsconfigurePodten times with four configured dirs and requires that not every run produces the same order. It also asserts, on each run, that the set of dirs is preserved, that the volume mounts are namedspark-local-dir-1..4, and that the mount paths in order equal theSPARK_LOCAL_DIRSvalue, so a fix that scrambles the two out of step would fail.Confirmed to fail against the unfixed tree, deterministically rather than flakily:
(That run predated the JIRA id, hence the placeholder in the test name.)
After the fix, a false failure would need all ten runs to draw the same permutation of four elements, about 1.4e-13.
build/sbt -Pkubernetes 'kubernetes/testOnly org.apache.spark.deploy.k8s.features.LocalDirsFeatureStepSuite':Because the fix makes both branches genuinely random, I ran the suite six times in total to check the pre-existing tests survive real reordering; all six runs were 5/5.
kubernetes/scalastyleandkubernetes/Test/scalastylereport 0 errors.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5)