Repository navigation
MAPREDUCE-7545. Make TaskId.hashCode independent of the JVM. - #8754
Conversation
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>
|
🎊 +1 overall
This message was automatically generated. |
|
@slfan1989 @pan3793 Would you mind reviewing this one? It's a one-line change plus a unit test. |
slfan1989
left a comment
There was a problem hiding this comment.
+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!
|
@joseluisll Thanks for the contribution! Merged into trunk. |
Description of PR
JIRA: MAPREDUCE-7545. Make TaskId.hashCode independent of the JVM.
TaskId.hashCodemixed ingetTaskType().hashCode().TaskTypeis an enum, so that is anidentity hash: it changes from one JVM to the next, and so does the iteration order of every
HashMapkeyed byTaskId.Hash the task type's ordinal instead.
Expected result: a
TaskId's hash is now a function of its fields alone, identical acrossJVMs and runs. Task iteration order stops depending on the classpath, and
TestRuntimeEstimators— which fails withexpected: <3> but was: <1>speculations undersome orders — stops flaking. No behaviour changes beyond the hash;
equalscompares tasktypes by reference, which the ordinal agrees with.
How was this patch tested?
New unit test
TestIds#testTaskIdHashCodeUsesTheTaskTypeOrdinalasserts the computed hashfor every
TaskType, so the identity hash cannot come back unnoticed.hadoop-mapreduce-client-commonandhadoop-mapreduce-client-app(which holdsTestRuntimeEstimators) pass.For code changes:
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.
LICENSE,LICENSE-binary,NOTICE-binaryfiles?AI Tooling
If an AI tool was used:
where is the name of the AI tool used.
https://www.apache.org/legal/generative-tooling.html
Contains content generated by Claude Code.