Phase G0 Day 2 ships storaged: aws-sdk-go-v2 wrapper + chi routes
binding 127.0.0.1:3211 with 256 MiB MaxBytesReader, Content-Length
up-front 413, and a 4-slot non-blocking semaphore returning 503 +
Retry-After:5 when full. Acceptance smoke (6/6 probes) PASSES against
the dedicated MinIO bucket lakehouse-go-primary, isolated from the
Rust system's lakehouse bucket during coexistence.
Cross-lineage scrum on the shipped code:
- Opus 4.7 (opencode): 1 BLOCK + 3 WARN + 3 INFO
- Qwen3-coder (openrouter): 2 BLOCK + 1 WARN + 1 INFO (3 false positives)
- Kimi K2-0905 (openrouter, after route-shopping past opencode's 4k
cap and the direct adapter's empty-content reasoning bug):
1 BLOCK + 2 WARN + 1 INFO
Fixed:
C1 buildRegistry ctx cancel footgun → context.Background()
(Opus + Kimi convergent; future credential refresh chains)
C2 MaxBytesReader unwrap through manager.Uploader multipart
goroutines → Content-Length up-front 413 + string-suffix fallback
(Opus + Kimi convergent; latent 500-instead-of-413 in 5-256 MiB range)
C3 Bucket.List unbounded accumulation → MaxListResults=10_000 cap
(Opus + Kimi convergent; OOM guard)
S1 PUT response Content-Type: application/json (Opus single-reviewer)
Strict validateKey policy (J approved): rejects empty, >1024B, NUL,
leading "/", ".." path components, CR/LF/tab control characters.
DELETE exposed at HTTP layer (J approved option A) for symmetry +
smoke ergonomics.
Build clean, vet clean, all unit tests pass, smoke 6/6 PASS after
every fix round. go.mod 1.23 → 1.24 (required by aws-sdk-go-v2).
Process finding worth recording: opencode caps non-streaming Kimi at
max_tokens=4096; the direct kimi.com adapter consumed 8192 tokens of
reasoning but surfaced empty content; openrouter/moonshotai/kimi-k2-0905
delivered structured output in ~33s. Future Kimi scrums should default
to that route.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
// BucketRegistry resolves logical bucket names → *Bucket. G0 holds
|
|
// exactly one bucket ("primary"); G2 (multi-bucket federation, per
|
|
// Rust ADR-017) extends this to many. Keeping the registry as a
|
|
// distinct type now means cmd/storaged never has to be refactored
|
|
// when G2 lands — every handler already routes through Resolve.
|
|
package storaged
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
var ErrBucketUnknown = errors.New("storaged: unknown bucket")
|
|
|
|
// BucketRegistry is a thread-safe map of logical name → *Bucket.
|
|
// In G0 only "primary" is registered; the registry exists so that
|
|
// when G2 multi-bucket lands we add buckets in registry.go and the
|
|
// HTTP layer is unchanged.
|
|
type BucketRegistry struct {
|
|
mu sync.RWMutex
|
|
buckets map[string]*Bucket
|
|
}
|
|
|
|
func NewRegistry() *BucketRegistry {
|
|
return &BucketRegistry{buckets: make(map[string]*Bucket)}
|
|
}
|
|
|
|
// Register adds a bucket under its logical name. Re-registering the
|
|
// same name is rejected — G0 services build the registry once at
|
|
// startup and a duplicate is almost always a config bug.
|
|
func (r *BucketRegistry) Register(b *Bucket) error {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
if _, exists := r.buckets[b.name]; exists {
|
|
return fmt.Errorf("bucket %q already registered", b.name)
|
|
}
|
|
r.buckets[b.name] = b
|
|
return nil
|
|
}
|
|
|
|
// Resolve returns the bucket for a logical name. G0 callers pass
|
|
// "primary" since that's the only one registered.
|
|
func (r *BucketRegistry) Resolve(name string) (*Bucket, error) {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
b, ok := r.buckets[name]
|
|
if !ok {
|
|
return nil, fmt.Errorf("%w: %q", ErrBucketUnknown, name)
|
|
}
|
|
return b, nil
|
|
}
|
|
|
|
// Names returns the registered logical names (sorted-order not
|
|
// guaranteed). Useful for /health surface or debug dumps.
|
|
func (r *BucketRegistry) Names() []string {
|
|
r.mu.RLock()
|
|
defer r.mu.RUnlock()
|
|
out := make([]string, 0, len(r.buckets))
|
|
for name := range r.buckets {
|
|
out = append(out, name)
|
|
}
|
|
return out
|
|
}
|