
proxy
Package proxy is the domain orchestration layer that coordinates multi-backend S3 storage. It routes writes, manages failover reads, handles multipart uploads, drains backends, and exposes dashboard data. Workers receive the Ops interface instead of direct access.
Index
- type BackendManager
- func NewBackendManager(cfg *BackendManagerConfig) *BackendManager
- func (m *BackendManager) AdmissionSem() chan struct{}
- func (m *BackendManager) ClearCache()
- func (m *BackendManager) ClearDrainState()
- func (m *BackendManager) Close()
- func (m *BackendManager) DeleteOrEnqueue(ctx context.Context, be backend.ObjectBackend, backendName, key, reason string, sizeBytes int64)
- func (m *BackendManager) FlushUsage(ctx context.Context) error
- func (m *BackendManager) GetDashboardData(ctx context.Context) (*dashboard.Data, error)
- func (m *BackendManager) GetDirectoryChildren(ctx context.Context, prefix, startAfter string, maxKeys int) (*core.DirectoryListResult, error)
- func (m *BackendManager) IntegrityConfig() *config.IntegrityConfig
- func (m *BackendManager) LifecycleConfig() *config.LifecycleConfig
- func (m *BackendManager) MoveObject(ctx context.Context, req *writepath.MoveRequest) (int64, error)
- func (m *BackendManager) NearUsageLimit(threshold float64) bool
- func (m *BackendManager) ProcessLifecycleRules(ctx context.Context, rules []config.LifecycleRule) (deleted, failed int)
- func (m *BackendManager) ReconcileBackend(ctx context.Context, backendName, bucket string, knownBuckets []string) (*worker.ReconcileResult, error)
- func (m *BackendManager) RecordUsage(backendName string, apiCalls, egress, ingress int64)
- func (m *BackendManager) RedisCounterConfigured() bool
- func (m *BackendManager) SelectReplicaTarget(ctx context.Context, size int64, exclusion map[string]bool) (string, error)
- func (m *BackendManager) SetIntegrityConfig(cfg *config.IntegrityConfig)
- func (m *BackendManager) SetLifecycleConfig(cfg *config.LifecycleConfig)
- func (m *BackendManager) SetUsageFlushConfig(cfg *config.UsageFlushConfig)
- func (m *BackendManager) Stores() core.MetadataStore
- func (m *BackendManager) SyncBackend(ctx context.Context, backendName, bucket string, knownBuckets []string) (imported, skipped int, err error)
- func (m *BackendManager) UpdateUsageLimits(limits map[string]core.UsageLimits)
- func (m *BackendManager) UsageFlushConfig() *config.UsageFlushConfig
- func (m *BackendManager) WireDrain(d *drain.Manager)
- type BackendManagerConfig
type BackendManager
BackendManager manages multiple storage backends with quota tracking. Embeds *infra.Core for non-store infrastructure (backends, usage, admission, draining, metrics) and holds the per-role store views and hot-reloadable configuration. Store-touching write-path helpers are methods on *BackendManager (manager_writepath.go); pure infra primitives stay on *infra.Core.
Workers (rebalancer, replicator, scrubber, …) are resolved through DI at the call site rather than carried on the manager. The dashboard aggregator, hot-reload paths, and tests that previously read mgr.Replicator etc. now invoke do.Invoke directly.
DrainManager is the one dependency wired post-construction via WireDrain. The cycle (drain.Manager needs *BackendManager and mgr.MultipartManager) makes constructor injection impractical without redesigning drain.Core. Code paths that depend on DrainManager (FlushUsage, ClearDrainState) nil-guard the field so a manager constructed without WireDrain (every test path that does not need drain behavior) remains usable.
func NewBackendManager
NewBackendManager constructs a BackendManager. Required dependencies (cfg, Stores, Dashboard, Metrics) panic via must.NotNil at construction so a wiring bug surfaces immediately at DI assembly rather than NPE’ing N call frames deep on the first request. Numeric config invariants (negative timeouts, ordering rules) are the config validator’s responsibility; the constructor trusts the values it receives.
func (*BackendManager) AdmissionSem
AdmissionSem returns the shared admission semaphore, or nil if none is configured. The HTTP admission controller should use this channel so that HTTP requests and background services share one concurrency budget.
func (*BackendManager) ClearCache
ClearCache removes all entries from the location cache.
func (*BackendManager) ClearDrainState
ClearDrainState removes all entries from the draining map. Used by tests to reset state between runs. No-op when DrainManager has not been wired (tests that do not need drain behavior skip WireDrain).
func (*BackendManager) Close
Close stops every background cache eviction goroutine the manager owns: the object location cache and the multipart per-upload DEK cache. Safe to call multiple times.
func (*BackendManager) DeleteOrEnqueue
DeleteOrEnqueue forwards to the write coordinator. Worker and drain interfaces accept *BackendManager and call DeleteOrEnqueue on it; the implementation lives on the coordinator now, but the call site shape stays the same.
func (*BackendManager) FlushUsage
FlushUsage flushes accumulated in-memory usage counters to the database. Backends that have completed draining are skipped because their DB records (including backend_usage) have been removed. When DrainManager has not been wired (tests that do not exercise drain behavior) the skip set is empty and every backend’s counters flush.
func (*BackendManager) GetDashboardData
GetDashboardData delegates to the dashboard.Aggregator and enriches the result with drain status and circuit-breaker health from the BackendManager’s in-memory state.
func (*BackendManager) GetDirectoryChildren
GetDirectoryChildren delegates to the dashboard.Aggregator.
func (*BackendManager) IntegrityConfig
IntegrityConfig returns the current integrity configuration.
func (*BackendManager) LifecycleConfig
LifecycleConfig returns the current lifecycle configuration.
func (*BackendManager) MoveObject
MoveObject forwards to the write coordinator’s shared move primitive (#924). Drain and rebalancer both pass their narrow consumer interface (drain.Core, worker.DataMover) here so the StreamCopy + MoveObjectLocation CAS + orphan-cleanup branches + source-delete accounting all funnel through one implementation - the same way DeleteOrEnqueue does.
func (*BackendManager) NearUsageLimit
NearUsageLimit returns true if any backend is approaching its usage limits.
func (*BackendManager) ProcessLifecycleRules
ProcessLifecycleRules evaluates all lifecycle rules and deletes expired objects. Returns total deleted and failed counts. Terminates processing of a rule when a full batch produces zero successful deletions, preventing infinite loops when backends are unhealthy.
func (*BackendManager) ReconcileBackend
ReconcileBackend reconciles a single backend against the metadata store using a bounded-memory sorted-merge: both sides are walked in lex key order and diffed in lockstep. The S3 walk and DB cursor each cap their in-flight buffer, so memory is independent of object count.
Behaviour: imports keys present on the backend but not in the DB, and deletes DB rows whose keys are no longer on the backend. Keys owned by sibling virtual buckets stored on the same backend are left alone in both directions - sibling buckets are reconciled by their own pass.
func (*BackendManager) RecordUsage
RecordUsage increments the in-memory usage counters for a backend. Exposed for admin operations that bypass the normal manager request path.
func (*BackendManager) RedisCounterConfigured
RedisCounterConfigured returns true when the counter backend is a Redis backend, regardless of health status. Used by the flush service to decide whether an advisory lock is needed - the lock must be held even during fallback to prevent double-counting when Redis recovers mid-flush.
func (*BackendManager) SelectReplicaTarget
SelectReplicaTarget picks a target backend for a replication copy using the same routing strategy as normal writes. Excludes backends that already hold a copy of the object.
func (*BackendManager) SetIntegrityConfig
SetIntegrityConfig atomically stores the integrity configuration. The scrubber’s own SetConfig is invoked separately by the caller (serve) since the scrubber is a top-level DI service after #676 B.
func (*BackendManager) SetLifecycleConfig
SetLifecycleConfig atomically stores the lifecycle configuration.
func (*BackendManager) SetUsageFlushConfig
SetUsageFlushConfig atomically stores the usage flush configuration.
func (*BackendManager) Stores
Stores returns the wrapped metadata-store contract. Exposed for transport handlers that need direct store access (multipart bookkeeping in s3api, per-backend stats / data drop in admin).
func (*BackendManager) SyncBackend
SyncBackend scans a backend’s S3 bucket and imports pre-existing objects into the proxy database. Objects already tracked for the backend are skipped. knownBuckets is the full list of configured virtual bucket names, used to distinguish objects belonging to other buckets from externally-uploaded objects that need the bucket prefix prepended. Returns counts of imported vs skipped objects.
func (*BackendManager) UpdateUsageLimits
UpdateUsageLimits replaces the per-backend usage limits. Safe to call concurrently with request handling.
func (*BackendManager) UsageFlushConfig
UsageFlushConfig returns the current usage flush configuration.
func (*BackendManager) WireDrain
WireDrain installs the drain.Manager: stores it on BackendManager so dashboard rendering and drain-aware tests can reach it, and points backendCore.drainMgr at it so eligibility filters see drain state. Called by the drain DI provider after both values exist. The dependency cycle between drain.Manager and BackendManager prevents passing the drain manager through the constructor.
type BackendManagerConfig
BackendManagerConfig holds the parameters for creating a BackendManager. Stores carries the metadata-store contract. Metrics carries the narrow proxy.metrics.Deps used by MetricsCollector.
Generated by gomarkdoc