Skip to content

Fix sharded indexing dropping segments with negative hashCode#3334

Open
yashs33244 wants to merge 1 commit into
castorini:masterfrom
yashs33244:fix-sharding-negative-modulo
Open

Fix sharded indexing dropping segments with negative hashCode#3334
yashs33244 wants to merge 1 commit into
castorini:masterfrom
yashs33244:fix-sharding-negative-modulo

Conversation

@yashs33244

Copy link
Copy Markdown
Contributor

getSegmentPaths(shardCount, currShard) filtered with x.toString().hashCode() % shardCount == currShard. Java % keeps the dividend's sign and String.hashCode() is negative for roughly half of inputs, so the result can be negative and match no currShard in [0, shardCount-1]. Those segments are then indexed by no shard and silently dropped (a quick check drops ~half of segments on a random set).

Switched to Math.floorMod(...) in DocumentCollection and in the C4Collection override (whose NumberFormatException fallback also returns a raw hashCode()). Added a testShardedPartition regression test asserting the shards partition the collection: every segment lands in exactly one shard (complete and disjoint). It runs for all collection subclasses.

Copilot AI review requested due to automatic review settings July 6, 2026 05:34

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.

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.

2 participants