Skip to content

fix(bucket): use endian-safe MurmurHash block loads - #1019

Merged
wgtmac merged 1 commit into
apache:mainfrom
manuzhang:codex/fix-bucket-hash-endian
Oct 16, 2026
Merged

wgtmac merged 1 commit into
apache:mainfrom
manuzhang:codex/fix-bucket-hash-endian

Conversation

@manuzhang

@manuzhang manuzhang commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Native word loads in MurmurHash3 produce incorrect Iceberg bucket hashes on big-endian hosts and rely on aligned input. Read blocks safely in little-endian order so bucket values match the Iceberg specification across architectures.

  • Keep the internal 32-bit hash helper, accept size_t lengths, return the numeric hash directly, and remove the unused 128-bit variants.
  • Hash integer and long values by mixing their low and high 32-bit halves directly, avoiding byte swaps and serialization through memory.
  • Preserve upstream refactor: guard oversized bucket hash input in BucketIndex #1023's oversized-input checks: HashBytes retains the INT32_MAX limit for Java compatibility, and BucketIndex returns InvalidArgument for oversized string, binary, or fixed values before hashing. Correct the comments to distinguish this compatibility limit from the raw helper's size_t length.
  • Keep object-store path entropy on the internal MurmurHash3 helper, independently of bucket transforms.
  • Add small canonical byte, integer, byte-literal bucket, and filename-prefix regressions. Byte-vector fixtures use at most 40 bytes; their expected values were generated from the pinned SMHasher reference and cross-checked with mmh3 5.3.1. No multi-gigabyte test or allocation is included.

Part of #1000. Squashed into one commit on upstream main at 60e67fa.

Compatibility

Existing bucketed data written by older C++ libraries on big-endian hosts requires migration. For int/long 34, the hash changes from 1403955681 to 2017239379, and bucket[100] changes from 81 to 79. After upgrading, bucket partition pruning can skip files with the old assignment and silently omit matching rows.

Read affected tables with an unfiltered scan, apply row filters after reading, and rewrite the data into corrected buckets with matching partition metadata before relying on filtered scans. A filtered rewrite can itself omit affected files. There is no hash-version marker, legacy-hash compatibility mode, or automatic migration.

Little-endian hashes remain compatible within the supported input lengths. Newly generated object-store entropy prefixes can change on big-endian hosts; existing files retain their manifest-recorded paths.

Validation

  • Pre-commit checks on all changed files and git diff --check passed.
  • All five tests in bucket_util_test.cc and one focused filename-prefix check passed in a standalone binary linked with the production sources: under 0.01 seconds and about 5 MiB peak resident memory.
  • Compile checks accepted noexcept and rejected int and uint32_t length parameters on the local 64-bit build.

The full local utility/table suite was not run.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 15:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open findings
What changed in this PR

This PR makes MurmurHash3 block loads endian-safe and alignment-safe to ensure stable bucket hashing across architectures (notably big-endian hosts), and adds regression/golden-vector tests to lock in canonical results.

Changes:

  • Replace MurmurHash3 block reads with ReadLittleEndian and switch block pointers to byte-addressed (uint8_t*) across x86_32, x86_128, and x64_128 variants.
  • Add canonical SMHasher-derived golden vectors (including offset 0–7 and block/tail boundary coverage) for all three MurmurHash3 variants.
  • Add canonical bucket-value tests for multiple literal types (int/long/string/binary/fixed/UUID) and register the new test in util_test.
File Description
src/​iceberg/​util/​murmurhash3_internal.cc Uses endian-safe, unaligned-safe little-endian loads for MurmurHash3 blocks.
src/​iceberg/​test/​murmurhash3_internal_test.cc Adds golden-vector tests (SMHasher fixtures) covering offsets, lengths, and seeds.
src/​iceberg/​test/​bucket_util_test.cc Adds canonical bucket regression vectors for multiple literal input types.
src/​iceberg/​test/​CMakeLists.txt Registers the new MurmurHash3 internal test in the util test target.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/iceberg/util/murmurhash3_internal.cc Outdated
Comment thread src/iceberg/test/murmurhash3_internal_test.cc Outdated
Copilot AI balanced review requested due to automatic review settings October 15, 2026 02:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The shared-only CI configuration links bundle tests against hidden symbols, causing linker failures.

1 open finding
2 resolved since last review

🧠 Review effort: Balanced

Comment thread .github/workflows/test.yml Outdated
Copilot AI balanced review requested due to automatic review settings October 15, 2026 02:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No blocking issues remain in the focused implementation, caller updates, or regression coverage.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 03:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No blocking issues were identified in the implementation, updated callers, or regression coverage.

0 open findings

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 04:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The described 2 GiB runtime regression is missing, leaving the length-narrowing boundary untested.

1 open finding

🧠 Review effort: Balanced

Comment thread src/iceberg/util/murmurhash3_internal.cc
Copilot AI balanced review requested due to automatic review settings October 15, 2026 05:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No blocking issues remain in the hashing changes, caller updates, or regression coverage; the big-endian migration requirement is documented.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 15, 2026 05:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Legacy big-endian bucket assignments can cause silent query omissions after upgrading, requiring human confirmation of migration and release safeguards.

0 open findings

🧠 Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open findings

🧠 Review effort: Lite

Comment thread src/iceberg/location_provider.cc
Comment thread src/iceberg/util/bucket_util.cc Outdated
Comment thread src/iceberg/util/murmurhash3_internal.cc
Read unaligned blocks in canonical little-endian order, accept size_t lengths, and mix integer halves directly. Keep path entropy on the raw helper and preserve upstream bucket input validation.

Cover canonical byte hashes, integer encoding, byte literal buckets, and path prefixes with small regressions.
@manuzhang
manuzhang force-pushed the codex/fix-bucket-hash-endian branch from ff28fc0 to 40640a6 Compare October 15, 2026 10:00
Copilot AI balanced review requested due to automatic review settings October 15, 2026 10:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

h1 = ROTL32(h1, 13);
h1 = h1 * 5 + 0xe6546b64;
for (size_t i = 0; i < nblocks; ++i) {
hash = MixHash(hash, ReadLittleEndian<uint32_t>(data));

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.

Checked the new path against the SMHasher reference and it's bit-identical, and _Long matches Guava's hashLong. No CI leg is big-endian though, so the fix this PR is named for stays unverified - the new tests only have teeth on the sanitizer job.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I intentionally leave it out of this PR since it's a CI change and might need more discussion. Besides, I've also checked no other iceberg projects have set up a big-endian host CI. It could be a follow up if we decide to add one.

@wgtmac
wgtmac merged commit 7f24700 into apache:main Oct 16, 2026
15 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.

4 participants