s3-orchestrator

readpath

import "github.com/afreidah/s3-orchestrator/internal/proxy/readpath"

Index

Variables

ErrUsageLimitSkip is the sentinel a Probe returns when it declined to attempt a backend purely because its usage limit would be exceeded. Failover counts these separately from genuine failures so the final “all backends declined for usage limits” outcome can be reported as core.ErrUsageLimitExceeded rather than as the last underlying error.

var ErrUsageLimitSkip = errors.New("backend skipped: usage limits exceeded")

func NoopCleanup

func NoopCleanup()

NoopCleanup is the cleanup a Probe returns when there is nothing for the orchestrator to release: error paths where the callback already cancelled its own timeout, and the GET success path where the cancel is attached to the body’s Close.

type Core

Core is the subset of *infra.Core the Failover orchestrator needs: backend registry + lookup, and the accounting Recorder that owns the per-backend usage / per-operation metric semantics.

type Core interface {
    Backends() map[string]backend.ObjectBackend
    BackendOrder() []string
    Acct() *accounting.Recorder
}

type Failover

Failover orchestrates per-key read failover across backends. One instance per object.Manager; safe for concurrent reads.

type Failover struct {
    // contains filtered or unexported fields
}

func New

func New(infraCore Core, stores core.MetadataStore, cache LocationCache, parallelBroadcast bool, degradedBroadcastParallelism int, degradedReadsEnabled bool) *Failover

New constructs a Failover. When degradedReadsEnabled is false, a DB outage surfaces as ErrServiceUnavailable instead of broadcasting.

func (*Failover) Read

func (f *Failover) Read(ctx context.Context, operation, key string, probe Probe) (string, error)

Read runs the full read-with-failover protocol: starts the span, resolves all locations for the key, and tries each backend in turn. On core.ErrDBUnavailable falls back to broadcastRead. Returns the winning backend name and any error.

type LocationCache

LocationCache is the subset of the object-package location cache the orchestrator needs to remember and reuse degraded-mode winners. Declared as an interface here (not *object.LocationCache) to avoid the import cycle that would otherwise form (object imports readpath for Failover).

type LocationCache interface {
    Get(key string) (backendName string, ok bool)
    Set(key, backendName string)
}

type Probe

Probe is the per-backend callback the caller provides. loc carries the matching ObjectLocation row so callbacks that need encryption metadata can read it directly without a side-channel lookup; loc is nil in degraded-mode broadcasts where the DB is unreachable. beName is always populated (loc.BackendName during failover, or the degraded-mode caller’s chosen name) so callbacks have a single source for span / usage attribution.

The callback owns its own timeout context and is responsible for releasing it on the error path. On success it returns a cleanup func the orchestrator invokes once the winner is declared; that cleanup either releases the timeout immediately (HEAD - no streaming body) or is a no-op because the callback already attached the cancel to the result body’s Close (GET).

type Probe func(ctx context.Context, beName string, loc *core.ObjectLocation, b backend.ObjectBackend) (size int64, cleanup func(), err error)

Generated by gomarkdoc