Skip to content

[X-2692] Vortex Segment Cache#4

Closed
ch-sc wants to merge 6 commits intodevelopfrom
ch-sc/vortex-datafusion-segment-cache
Closed

[X-2692] Vortex Segment Cache#4
ch-sc wants to merge 6 commits intodevelopfrom
ch-sc/vortex-datafusion-segment-cache

Conversation

@ch-sc
Copy link
Copy Markdown
Collaborator

@ch-sc ch-sc commented May 8, 2026

Summary

VortexSource had no way to share segment bytes across queries. Every DataFusion query re-read the same zone-map and data segments from object storage, even though for an unchanged file those bytes are identical. This change adds a cross-query, cross-file segment cache, plumbed end-to-end from VortexSource down to VortexOpenOptions.

The naive approach of passing one Arc<dyn SegmentCache> for all files is unsafe: SegmentId is a file-local u32 index, e.g., segment 5 from file A and segment 5 from file B would alias to the same cache entry and silently serve wrong data.

This PR introduces a SegmentCacheBuilder indirection that namespaces per-file caches by a FileIdentity (path + content version) so a single shared cache is correct across many files.

The SegmentCacheBuilder builder hands out per-file SegmentCache views from one shared backing store, namespaced by FileIdentity (path + etag/size-mtime). VortexSource::with_segment_cache_builder(...) wires it through. Build one NamespacedMokaSegmentCacheBuilder per process, reuse for every query — file-safe, overwrite-safe, cross-query reuse.

The InstrumentedSegmentCacheBuilder decorator SegmentCacheBuilder — it wraps another builder and adds hit/miss/store metrics to every per-file cache that builder produces.

Usage

  use std::sync::Arc;
  use vortex::layout::segments::{
      InstrumentedSegmentCacheBuilder, NamespacedMokaSegmentCacheBuilder,
  };
  use vortex_datafusion::VortexSource;

  // Built once per process / SessionContext:
  let cache = Arc::new(InstrumentedSegmentCacheBuilder::new(
      NamespacedMokaSegmentCacheBuilder::new(2 << 30), // 2 GB shared budget
      metrics_registry,
      vec![],
  ));

  // Reused for every VortexSource:
  let source = VortexSource::new(schema, session)
      .with_segment_cache_builder(Arc::clone(&cache));

ch-sc added 6 commits May 6, 2026 13:15
Signed-off-by: Christoph Schulze <christoph.schulze@polygon.io>
…rtex-datafusion-segment-cache

Signed-off-by: Christoph Schulze <christoph.schulze@polygon.io>
Signed-off-by: Christoph Schulze <christoph.schulze@polygon.io>
Signed-off-by: Christoph Schulze <christoph.schulze@polygon.io>
Signed-off-by: Christoph Schulze <christoph.schulze@polygon.io>
Signed-off-by: Christoph Schulze <christoph.schulze@polygon.io>
@ch-sc
Copy link
Copy Markdown
Collaborator Author

ch-sc commented May 8, 2026

Closing this as we need to merge into vortex 0.65.0 and this one is way ahead. Switched to new PR: #5

@ch-sc ch-sc closed this May 8, 2026
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