Phase G0 Day 4 ships ingestd: multipart CSV upload, Arrow schema
inference per ADR-010 (default-to-string on ambiguity), single-pass
streaming CSV → Parquet via pqarrow batched writer (Snappy compressed,
8192 rows per batch), PUT to storaged at content-addressed key
datasets/<name>/<fp_hex>.parquet, register manifest with catalogd.
Acceptance smoke 6/6 PASS including idempotent re-ingest (proves
inference is deterministic — same CSV always produces same fingerprint)
and schema-drift → 409 (proves catalogd's gate fires on ingest traffic).
Schema fingerprint is SHA-256 over (name, type) tuples in header order
using ASCII record/unit separators (0x1e/0x1f) so column names with
commas can't collide. Nullability intentionally NOT in the fingerprint
— a column gaining nulls isn't a schema change.
Cross-lineage scrum on shipped code:
- Opus 4.7 (opencode): 4 WARN + 3 INFO (after 2 self-retracted BLOCKs)
- Kimi K2-0905 (openrouter): 1 BLOCK + 2 WARN + 1 INFO
- Qwen3-coder (openrouter): 2 BLOCK + 2 WARN + 2 INFO
Fixed (2, both Opus single-reviewer):
C-DRIFT: PUT-then-register on fixed datasets/<name>/data.parquet
meant a schema-drift ingest overwrote the live parquet BEFORE
catalogd's 409 fired → storaged inconsistent with manifest.
Fix: content-addressed key datasets/<name>/<fp_hex>.parquet.
Drift writes to a different file (orphan in G2 GC scope); the
live data is never corrupted.
C-WCLOSE: pqarrow.NewFileWriter not Closed on error paths leaks
buffered column data + OS resources per failed ingest.
Fix: deferred guarded close with wClosed flag.
Dismissed (5, all false positives):
Qwen BLOCK "csv.Reader needs LazyQuotes=true for multi-line" — false,
Go csv handles RFC 4180 multi-line quoted fields by default
Qwen BLOCK "row[i] OOB" — already bounds-checked at schema.go:73
and csv.go:201
Kimi BLOCK "type assertion panic if pqarrow reorders fields" —
speculative, no real path
Kimi WARN + Qwen WARN×2 "RecordBuilder leak on early error" —
false convergent. Outer defer rb.Release() captures the current
builder; in-loop release runs before reassignment. No leak.
Deferred (6 INFO + accepted-with-rationale on 3 WARN): sample
boundary type mismatch (G0 cap bounds peak), string-match
paranoia on http.MaxBytesError, multipart double-buffer (G2 spool-
to-disk), separator validation, body close ordering, etc.
The D4 scrum produced fewer real findings than D3 (2 vs 6) — both
were architectural hazards smoke wouldn't catch because the smoke's
"schema drift → 409" assertion was passing even in the corrupted-
state world. The 409 fires correctly; what was wrong was the PUT
having already mutated the live parquet before the validation check.
Opus's PUT-then-register read of the order is exactly the kind of
architectural insight the cross-lineage scrum is designed to surface.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
123 lines
4.0 KiB
Go
123 lines
4.0 KiB
Go
// Package shared also provides the TOML config loader. Per ADR
|
|
// equivalent of Rust ADR-006 (TOML config over env vars), every
|
|
// service reads `lakehouse.toml` with sane defaults and env
|
|
// overrides. Config is hot-reload-unaware in G0; reload-on-SIGHUP
|
|
// is a G1+ concern.
|
|
package shared
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
// Config is the unified Lakehouse config. Each service reads only
|
|
// the section it cares about, but they all share the same file so
|
|
// operators have one place to look.
|
|
type Config struct {
|
|
Gateway ServiceConfig `toml:"gateway"`
|
|
Storaged ServiceConfig `toml:"storaged"`
|
|
Catalogd CatalogConfig `toml:"catalogd"`
|
|
Ingestd IngestConfig `toml:"ingestd"`
|
|
Queryd ServiceConfig `toml:"queryd"`
|
|
S3 S3Config `toml:"s3"`
|
|
Log LogConfig `toml:"log"`
|
|
}
|
|
|
|
// IngestConfig adds ingestd-specific knobs. ingestd needs to PUT
|
|
// parquet to storaged AND register manifests with catalogd, so it
|
|
// holds two upstream URLs in addition to its own bind.
|
|
type IngestConfig struct {
|
|
Bind string `toml:"bind"`
|
|
StoragedURL string `toml:"storaged_url"`
|
|
CatalogdURL string `toml:"catalogd_url"`
|
|
}
|
|
|
|
// CatalogConfig adds catalogd-specific knobs on top of the standard
|
|
// bind. StoragedURL points at the storaged service for manifest
|
|
// persistence; G0 defaults to the localhost bind.
|
|
type CatalogConfig struct {
|
|
Bind string `toml:"bind"`
|
|
StoragedURL string `toml:"storaged_url"`
|
|
}
|
|
|
|
// ServiceConfig is the per-binary bind config. Default Bind ""
|
|
// means "use the service's hardcoded G0 default" — see DefaultConfig.
|
|
type ServiceConfig struct {
|
|
Bind string `toml:"bind"`
|
|
}
|
|
|
|
// S3Config holds S3-compatible storage settings. Endpoint blank →
|
|
// AWS default. Bucket "" → "lakehouse-primary".
|
|
type S3Config struct {
|
|
Endpoint string `toml:"endpoint"`
|
|
Region string `toml:"region"`
|
|
Bucket string `toml:"bucket"`
|
|
AccessKeyID string `toml:"access_key_id"`
|
|
SecretAccessKey string `toml:"secret_access_key"`
|
|
UsePathStyle bool `toml:"use_path_style"`
|
|
}
|
|
|
|
// LogConfig — slog level for now; structured fields land G1+.
|
|
type LogConfig struct {
|
|
Level string `toml:"level"`
|
|
}
|
|
|
|
// DefaultConfig returns the G0 dev defaults. Ports are shifted to
|
|
// 3110+ to coexist with the live Rust lakehouse on 3100/3201-3204
|
|
// during the migration. G5 cutover flips gateway back to 3100.
|
|
func DefaultConfig() Config {
|
|
return Config{
|
|
Gateway: ServiceConfig{Bind: "127.0.0.1:3110"},
|
|
Storaged: ServiceConfig{Bind: "127.0.0.1:3211"},
|
|
Catalogd: CatalogConfig{Bind: "127.0.0.1:3212", StoragedURL: "http://127.0.0.1:3211"},
|
|
Ingestd: IngestConfig{
|
|
Bind: "127.0.0.1:3213",
|
|
StoragedURL: "http://127.0.0.1:3211",
|
|
CatalogdURL: "http://127.0.0.1:3212",
|
|
},
|
|
Queryd: ServiceConfig{Bind: "127.0.0.1:3214"},
|
|
S3: S3Config{
|
|
Endpoint: "http://localhost:9000",
|
|
Region: "us-east-1",
|
|
Bucket: "lakehouse-primary",
|
|
UsePathStyle: true,
|
|
},
|
|
Log: LogConfig{Level: "info"},
|
|
}
|
|
}
|
|
|
|
// LoadConfig reads `lakehouse.toml` from path; if path is empty or
|
|
// the file doesn't exist, returns DefaultConfig. Any decode error is
|
|
// fatal (we don't want a misconfigured service silently falling back
|
|
// to defaults — that's the kind of bug you find at 2am).
|
|
//
|
|
// Per Opus + Qwen WARN #3: when path WAS given but the file is
|
|
// missing, log a warning so silent default-fallback doesn't hide
|
|
// misconfiguration. Empty path is fine (caller didn't ask for a
|
|
// file); non-empty + missing is suspicious.
|
|
func LoadConfig(path string) (Config, error) {
|
|
cfg := DefaultConfig()
|
|
if path == "" {
|
|
return cfg, nil
|
|
}
|
|
b, err := os.ReadFile(path)
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
slog.Warn("config file not found, using defaults",
|
|
"path", path,
|
|
"hint", "create the file or pass -config /path/to/lakehouse.toml")
|
|
return cfg, nil
|
|
}
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("read config: %w", err)
|
|
}
|
|
if err := toml.Unmarshal(b, &cfg); err != nil {
|
|
return cfg, fmt.Errorf("parse config: %w", err)
|
|
}
|
|
return cfg, nil
|
|
}
|