Skip to content

feat(storage): multi-scheme DataStore with lazy per-scheme backend routing#7555

Open
EngHabu wants to merge 1 commit into
mainfrom
storage-multi-scheme
Open

feat(storage): multi-scheme DataStore with lazy per-scheme backend routing#7555
EngHabu wants to merge 1 commit into
mainfrom
storage-multi-scheme

Conversation

@EngHabu

@EngHabu EngHabu commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Generalizes the storage layer's scheme routing so a single DataStore can serve any URL scheme and container, instead of being pinned to one configured backend.

  • The configured Type is built eagerly as the primary backend — it owns the InitContainer and GetBaseContainerFQN.
  • Every other scheme (s3://, gs://, abfs://, redis://, ...) is dialed lazily the first time a matching reference is seen and memoized for reuse (creation is serialized so each scheme is dialed at most once under concurrency).
  • A new optional Config.Schemes map allows per-scheme backend overrides (kind, stow config, redis connection). Schemes absent from the map are dialed with ambient credentials (provider default credential chain — IAM/instance profile, GCP ADC, workload identity, env vars).
  • Unknown schemes fall back to the primary store, preserving pre-routing behavior.
  • Cross-scheme CopyRaw (e.g. redis -> s3, s3 -> gs) routes through the router itself via plain ReadRaw/WriteRaw.

This replaces the previous single-purpose scheme_routing_store.go (which only split redis from a blob store) with a general routing_store.go.

RegisterStowScheme is added alongside RegisterStowKind so out-of-tree stow backends can be taught to the router.

Changes

  • routing_store.go (new) — lazy, memoizing, scheme-dispatching RawStore
  • scheme_routing_store.go (removed) — superseded
  • config.goSchemes map[string]SchemeConfig + SchemeConfig
  • stow_store.goschemeToStowKind/kindToScheme maps, primarySchemeForConfig, RegisterStowScheme, stowFactory
  • redis_store.goredisFactory for lazy redis dialing
  • rawstores.goRefreshConfig wires the routing store and threads the configured HTTP client
  • routing_store_internal_test.go (new) — routing/lazy-creation/fallback coverage

Test plan

  • go test ./flytestdlib/storage/...
  • Verify primary scheme resolves to the eager store (no second dial)
  • Verify ambient-credential dial for an unconfigured scheme

🤖 Generated with Claude Code

…uting

Replace the single-purpose redis scheme-routing store with a general
routing store. The configured Type is built eagerly as the primary
backend (owning the InitContainer and GetBaseContainerFQN); every other
scheme (s3://, gs://, abfs://, redis://, ...) is dialed lazily on first
reference and memoized for reuse, so one DataStore can serve any
scheme/container. Schemes absent from the optional per-scheme config map
are dialed with ambient credentials. Cross-scheme CopyRaw routes through
the store itself.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 18, 2026 16:59

Copilot AI left a comment

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.

Pull request overview

This PR generalizes flytestdlib/storage so a single DataStore can route operations across multiple URL schemes (e.g. s3://, gs://, abfs://, redis://) by wrapping the configured primary backend in a lazy, memoizing routing RawStore.

Changes:

  • Added a new routingStore that dispatches by scheme and lazily dials/memoizes per-scheme backends.
  • Extended storage config with Schemes map[string]SchemeConfig to support per-scheme backend overrides.
  • Updated stow/redis stores and RefreshConfig wiring to support eager primary backend + lazy secondary backends, plus added focused routing-store tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
flytestdlib/storage/stow_store.go Adds scheme<->kind mapping, primary-scheme derivation, and a stow backend factory + dial helper for lazy secondary schemes.
flytestdlib/storage/scheme_routing_store.go Removes the previous redis-vs-default router in favor of the generalized router.
flytestdlib/storage/routing_store.go New generalized router with lazy instantiation/memoization and scheme fallback behavior.
flytestdlib/storage/routing_store_internal_test.go New internal tests covering lazy creation, memoization, fallback, and concurrency behavior.
flytestdlib/storage/redis_store.go Refactors redis construction and adds redisFactory for lazy redis backend dialing.
flytestdlib/storage/rawstores.go Wires RefreshConfig to build the eager primary store and wrap it with the routing store, threading the configured HTTP client.
flytestdlib/storage/protobuf_store_test.go Updates expectations to reflect routing store always wrapping the primary backend.
flytestdlib/storage/config.go Adds Schemes + SchemeConfig to support per-scheme overrides (stow kind/config, redis config).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +68 to +72
scheme, ok := kindToScheme[kind]
if !ok {
return "", fmt.Errorf("no scheme registered for stow kind [%v]", kind)
}
return scheme, nil
Comment on lines +90 to +94
// RegisterStowScheme associates a URL scheme with a stow kind so the DataStore can lazily dial it
// when a reference with that scheme is encountered. Pair it with RegisterStowKind to teach
// flytestdlib about an out-of-tree stow backend.
func RegisterStowScheme(scheme, kind string) error {
if existing, ok := schemeToStowKind[scheme]; ok && existing != kind {
Comment on lines +304 to +308
if redisCfg.Addr == "" {
_, host, _, err := ref.Split()
if err != nil {
return nil, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants