Skip to content

MAPREDUCE-7545. Make TaskId.hashCode independent of the JVM. - #8754

Merged
slfan1989 merged 1 commit into
apache:trunkfrom
joseluisll:MAPREDUCE-7545
Oct 4, 2026
Merged

slfan1989 merged 1 commit into
apache:trunkfrom
joseluisll:MAPREDUCE-7545

Conversation

@joseluisll

@joseluisll joseluisll commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Description of PR

JIRA: MAPREDUCE-7545. Make TaskId.hashCode independent of the JVM.

TaskId.hashCode mixed in getTaskType().hashCode(). TaskType is an enum, so that is an
identity hash: it changes from one JVM to the next, and so does the iteration order of every
HashMap keyed by TaskId.

Hash the task type's ordinal instead.

Expected result: a TaskId's hash is now a function of its fields alone, identical across
JVMs and runs. Task iteration order stops depending on the classpath, and
TestRuntimeEstimators — which fails with expected: <3> but was: <1> speculations under
some orders — stops flaking. No behaviour changes beyond the hash; equals compares task
types by reference, which the ordinal agrees with.

How was this patch tested?

New unit test TestIds#testTaskIdHashCodeUsesTheTaskTypeOrdinal asserts the computed hash
for every TaskType, so the identity hash cannot come back unnoticed.
hadoop-mapreduce-client-common and hadoop-mapreduce-client-app (which holds
TestRuntimeEstimators) pass.

For code changes:

  • Does the title of this PR start with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')?
  • Object storage: Have the integration tests been executed and the endpoint
    declared according to the connector-specific documentation? Note: Automated CI
    testing doesn't cover all cases so manual testing with cloud storage is still
    required.
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE, LICENSE-binary, NOTICE-binary files?

AI Tooling

If an AI tool was used:

Contains content generated by Claude Code.

TaskId.hashCode mixed in getTaskType().hashCode(). TaskType is an enum, and
an enum's hashCode is its identity hash, which HotSpot draws from a sequence
that shifts with whatever else asked for identity hashes first: which jars
are on the classpath, which classes get initialized. So every HashMap keyed
by TaskId iterated in an order that depended on the environment rather than
on the tasks.

TestRuntimeEstimators depends on that order. The five slow maps it builds
are speculated in the order the speculator meets them, and it expects three
speculations to win. In some orders only one does, and the test then fails
deterministically on that environment:

  We got the wrong number of successful speculations.
    ==> expected: <3> but was: <1>

It does, for instance, on GitHub Actions with the classpath HADOOP-19970
produces, while passing locally on the same commit. Consuming four extra
identity hashes before the test starts reproduces the failure locally.

Hash the task type's ordinal instead. The hash no longer changes between
JVMs, so neither does the order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 1m 13s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 54m 47s trunk passed
+1 💚 compile 1m 5s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 compile 0m 52s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 checkstyle 0m 49s trunk passed
+1 💚 mvnsite 0m 56s trunk passed
+1 💚 javadoc 0m 59s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 56s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 43s trunk passed
+1 💚 shadedclient 38m 35s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 34s the patch passed
+1 💚 compile 0m 31s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javac 0m 31s the patch passed
+1 💚 compile 0m 32s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 javac 0m 32s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 20s the patch passed
+1 💚 mvnsite 0m 33s the patch passed
+1 💚 javadoc 0m 27s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 28s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 24s the patch passed
+1 💚 shadedclient 45m 22s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 1m 16s hadoop-mapreduce-client-common in the patch passed.
+1 💚 asflicense 0m 54s The patch does not generate ASF License warnings.
157m 6s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8754/1/artifact/out/Dockerfile
GITHUB PR #8754
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux d7d55d73858b 5.15.0-185-generic #195-Ubuntu SMP Fri Jun 19 17:11:50 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / fc8d006
Default Java Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8754/1/testReport/
Max. process+thread count 572 (vs. ulimit of 10000)
modules C: hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common U: hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8754/1/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@joseluisll

joseluisll commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@slfan1989 @pan3793 Would you mind reviewing this one? It's a one-line change plus a unit test.
This is currently failing Test mr on #8699. It is not caused by that PR either — the ordering it triggers on is environment-specific, which is why the same commit passes locally and why #8704, which contains #8699, passes.

@slfan1989 slfan1989 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1.

Using the task type ordinal removes the identity hash dependency while preserving the equals/hashCode contract.

I verified that the new regression test fails before the fix and that all four TestIds tests pass afterward.

Cross-JVM hash checks and protobuf round-trip map lookups also passed.

Thanks for the fix!

@slfan1989
slfan1989 merged commit 6a2309f into apache:trunk Oct 4, 2026
6 checks passed
@slfan1989

Copy link
Copy Markdown
Contributor

@joseluisll Thanks for the contribution! Merged into trunk.

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.

3 participants