Skip to content

Prefetch the Sparkey index by default for side inputs - #6029

Open
kellen wants to merge 2 commits into
mainfrom
kellen/sparkey-load-index
Open

kellen wants to merge 2 commits into
mainfrom
kellen/sparkey-load-index

Conversation

@kellen

@kellen kellen commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Sparkey side inputs now prefetch the hash index (.spi) into the page cache when a reader is opened on a worker, using SparkeyReader.load(LoadMode.INDEX) from sparkey-java 3.7.0. With the index resident, a cold lookup needs one disk read (into the log) instead of up to two.

This matters most for large Sparkeys that don't fit in memory on network-attached disks: Hyperdisk-balanced has roughly 450–530µs per random read in our benchmarks, and provisioning more IOPS does not reduce it, so halving reads per lookup is the main remaining lever.

Changes

  • ShardedSparkeyReader.load now works. It didn't override load(LoadMode, Executor), so it fell back to the interface's no-op default and returned a completed result with 0 bytes. Calling load() on a sharded reader, which is what asLargeMapSideInput and friends produce by default (64 shards), silently did nothing. It now loads every shard and combines the results.
  • Prefetching is on by default. SparkeyUri.getReader(rfu, loadMode) applies the mode after opening. Each local file is prefetched at most once per JVM, since all DoFn instances on a worker share the page cache. Loading is asynchronous, and failures are logged instead of failing the pipeline.
  • New loadMode parameter (default SparkeyIO.DefaultLoadMode = LoadMode.INDEX; pass LoadMode.NONE to disable) on:
    • sc.sparkeySideInput, sc.typedSparkeySideInput, sc.cachedStringSparkeySideInput
    • asSparkeySideInput, asTypedSparkeySideInput, asCachedStringSparkeySideInput, asLargeMapSideInput, asLargeMultiMapSideInput, asLargeSetSideInput
    • largeHashJoin, largeHashLeftOuterJoin, largeHashFullOuterJoin, largeHashIntersectByKey, largeHashSubtractByKey (the variants that take an rhs SCollection)
  • The deprecated SCollection[SparkeyUri] helpers use the default.

Compatibility

  • Binary: previous signatures are kept as private[sparkey] overloads. These are public in bytecode, so jobs compiled against 0.16.1 keep linking, while source callers resolve to the new methods. The MiMa exclusions added to build.sbt cover private internals (side-input class constructors and a private helper), plus one real 2.12-only break, which needs a maintainer decision: on Scala 2.12, overloading the @experimental sc.typedSparkeySideInput and sc.cachedStringSparkeySideInput renames their compiled value-class extension methods ($extension → $extension0/1). Jobs compiled against 0.16.1 on 2.12 that call these two would need recompiling. 2.13 is unaffected. If that's not acceptable for a 0.16.x release, the alternative is to drop loadMode from those two methods; they'd still prefetch by default.
  • Source: SparkeySourceCompatTest, in a package outside sparkey, checks that existing calls with Int literals for numShards still compile on 2.12 and 2.13. One test inside the package needed 8.toShort, because it can see the private overloads.
  • Behavior: side inputs now read the index once in the background at startup on each worker. LoadMode.NONE restores the old behavior.

Test plan

  • scio-extra/testOnly com.spotify.scio.extra.sparkey.* com.spotify.scio.extra.sparkeycompat.* on 2.13 and 2.12
  • New tests: sharded load(INDEX) requests exactly the sum of all shards' index sizes; getReader with a load mode; largeHashJoin, largeHashIntersectByKey and asLargeMapSideInput with LoadMode.NONE; source compatibility from outside the package
  • mimaReportBinaryIssues on 2.13 and 2.12, scalafmtCheckAll
  • Note: SparkeyTest "support concurrent sharded writes from JobTest" is flaky on 2.12 on unmodified main too (NPE in RunEnforcementJobTest, 2 of 3 runs on 8087d1c80). I also saw a single 5-minute timeout in it on this branch, which didn't recur in later runs.

🤖 Generated with Claude Code

Sparkey side inputs now call SparkeyReader.load(LoadMode.INDEX) when a
reader is opened on a worker, so cold lookups need one disk read (into the
log) instead of up to two. Each local file is prefetched at most once per
JVM, asynchronously, and failures are logged rather than failing the job.

ShardedSparkeyReader did not override load(), so it fell back to the
interface's no-op default: calling load() on a sharded reader (the default
for asLargeMapSideInput & co, with 64 shards) silently did nothing. It now
loads every shard and combines the results.

All side input constructors, including the largeHash* methods that build
Sparkey side inputs internally, take a `loadMode` parameter (default
SparkeyIO.DefaultLoadMode = LoadMode.INDEX); pass LoadMode.NONE to disable.
The previous signatures are kept as private[sparkey] overloads for binary
compatibility.

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.88235% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.32%. Comparing base (8087d1c) to head (d18bf3a).

Files with missing lines Patch % Lines
...scala/com/spotify/scio/extra/sparkey/package.scala 46.15% 21 Missing ⚠️
...ra/sparkey/PairLargeHashSCollectionFunctions.scala 41.66% 7 Missing ⚠️
...la/com/spotify/scio/extra/sparkey/SparkeyUri.scala 86.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6029      +/-   ##
==========================================
- Coverage   62.39%   62.32%   -0.08%     
==========================================
  Files         326      326              
  Lines       11877    11925      +48     
  Branches      835      840       +5     
==========================================
+ Hits         7411     7432      +21     
- Misses       4466     4493      +27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

This branch has not been deployed

No deployments
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.

1 participant