Skip to content

Storage Engine v4 — Parent: option plumbing + magic-byte dispatch#867

Open
c1-squire-dev[bot] wants to merge 1 commit into
mainfrom
pquerna/storage-v4-parent
Open

Storage Engine v4 — Parent: option plumbing + magic-byte dispatch#867
c1-squire-dev[bot] wants to merge 1 commit into
mainfrom
pquerna/storage-v4-parent

Conversation

@c1-squire-dev
Copy link
Copy Markdown
Contributor

@c1-squire-dev c1-squire-dev Bot commented May 24, 2026

Summary

First commit in the v3 storage-engine stack (RFC 0004). No behavior change — adds the option-plumbing API that downstream stacks build on:

  • dotc1z.EngineSQLite / EnginePebble engine constants (default EngineSQLite).
  • dotc1z.C1ZFormatV3 constant + C1Z3FileHeader = []byte("C1Z3\x00").
  • WithEngine(Engine) / WithC1FEngine(Engine) functional options.
  • ReadHeaderFormat(io.ReadSeeker) C1ZFormat — magic-byte dispatch reading the first 5 bytes to distinguish v1 (C1Z\0\0) from v3 (C1Z3\0).
  • Build tag //go:build batonsdkv2 reserved for the engine package; not yet referenced (Stacks 1-5 add the gated code).

tracker.md (committed under docs/rfcs/0004-storage-engine-v4/) tracks the work remaining across the stack.

Stack order

This is the parent of:

  • Stack 1 — protos + codec
  • Stack 2 — c1z3 envelope format
  • Stack 3 — Pebble engine + canonical GrantRecord path
  • Stack 4 — cross-engine compaction via IngestAndExcise
  • Stack 5 — equivalence runner + microtests + benchmark CLIs

Test plan

  • make lint clean
  • make test/pkg PKGS=./pkg/dotc1z/... passes
  • CI green on this PR before stacking the next

🤖 Generated with Claude Code

Comment thread pkg/dotc1z/c1file.go Outdated
Comment on lines +297 to +308
// See WithC1FV2GrantsWriter for details.
// WithEngine selects the storage engine for newly created .c1z files.
// Default is EngineSQLite (v1 format). EnginePebble enables the v3
// engine; under default build tags it returns ErrEngineNotAvailable
// when the file is opened.
//
// Reading existing files dispatches on the file's magic byte and is
// independent of this option.
func WithEngine(engine Engine) C1ZOption {
return func(o *c1zOptions) {
o.engine = engine
}
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.

🟡 Suggestion: The WithEngine doc comment is inserted directly after the WithV2GrantsWriter doc comment with no blank line, so Go treats them as a single comment block. This means WithEngine's godoc starts with "WithV2GrantsWriter toggles the slim-blob writer path for grants…" and WithV2GrantsWriter (line 312) loses its doc comment entirely. Add a blank line to separate them.

Suggested change
// See WithC1FV2GrantsWriter for details.
// WithEngine selects the storage engine for newly created .c1z files.
// Default is EngineSQLite (v1 format). EnginePebble enables the v3
// engine; under default build tags it returns ErrEngineNotAvailable
// when the file is opened.
//
// Reading existing files dispatches on the file's magic byte and is
// independent of this option.
func WithEngine(engine Engine) C1ZOption {
return func(o *c1zOptions) {
o.engine = engine
}
// WithEngine selects the storage engine for newly created .c1z files.
// Default is EngineSQLite (v1 format). EnginePebble enables the v3
// engine; under default build tags it returns ErrEngineNotAvailable
// when the file is opened.
//
// Reading existing files dispatches on the file's magic byte and is
// independent of this option.
func WithEngine(engine Engine) C1ZOption {
return func(o *c1zOptions) {
o.engine = engine
}
}
// WithV2GrantsWriter toggles the slim-blob writer path for grants.
// See WithC1FV2GrantsWriter for details.

Comment thread pkg/dotc1z/c1file.go
v2GrantsWriter bool

// engine is the storage engine to use for newly created files.
// Reads dispatch on magic byte regardless of this value. Default
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.

🟡 Suggestion: The zero value of Engine is "", not EngineSQLite ("sqlite"). The comment says "Default is EngineSQLite" but code that later checks engine == EngineSQLite won't match the zero value. Consider initializing this field to EngineSQLite in the constructor, or documenting that "" means "use SQLite" so downstream switch statements handle it correctly.

@github-actions
Copy link
Copy Markdown
Contributor

ghost commented May 24, 2026

General PR Review: Storage Engine v4 — Parent: option plumbing + magic-byte dispatch

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Review mode: full
View review run

Review Summary

This PR adds foundational plumbing for the v3 storage engine: Engine type and constants (EngineSQLite, EnginePebble), C1ZFormat enum with magic-byte dispatch via ReadHeaderFormat, and WithEngine/WithC1FEngine functional options. The two suggestions from the previous review are now addressed — the WithEngine doc comment is properly separated from WithV2GrantsWriter, and the zero-value engine field is explicitly normalized to EngineSQLite in NewC1File. Tests cover header detection, seeker rewind, option threading, and default engine normalization. No new issues found.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

Copy link
Copy Markdown
Contributor

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found.

@btipling btipling self-assigned this May 24, 2026
Comment thread pkg/dotc1z/c1file.go
… dispatch

Adds the SDK-side scaffolding that the storage-engine-v4 stack depends on,
with zero behavior change when the new options are unset.

  - `pkg/dotc1z/format.go` — `C1ZFormat` enum (V1, V3, Unknown), the
    `C1Z3FileHeader` magic bytes, `Engine` type with `EngineSQLite` /
    `EnginePebble` constants, `ErrEngineNotAvailable` sentinel, and
    `ReadHeaderFormat` (format-aware peer of `ReadHeader`).
  - `pkg/dotc1z/c1file.go` — new `engine` field on `C1File` and
    `c1zOptions`; new `WithC1FEngine` and `WithEngine` options.
  - `pkg/dotc1z/format_test.go` — coverage of magic-byte detection,
    seeker rewind, format String(), engine constants, sentinel.
  - `docs/rfcs/0004-storage-engine-v4/tracker.md` — work tracker for
    the rest of the PR stack.

The Pebble engine itself, the v3 envelope reader/writer, the codegen
plugin, and the equivalence harness land in subsequent stacked PRs.
Default-tag builds get no new dependencies; the v3 engine package is
`//go:build batonsdkv2`-gated and arrives in Stack 1.

Refs: RFC v4 (canonical at `/pebble-baton-sdk/rfc-v4.md` in the squire
planner).
@c1-squire-dev
Copy link
Copy Markdown
Contributor Author

c1-squire-dev Bot commented May 24, 2026

Review feedback addressed in commit 464a8f3 (force-pushed):

btipling — `WithEngine` option was dropped during `c1zOptions → c1fopts` translation. Fixed: threaded through in `NewC1ZFile` (line ~362), plus regression test `TestWithEngineThreadsToC1File` that fails on the old code and passes now.

pr-review bot — Two findings:

  1. `WithEngine` doc comment merged into the preceding `WithV2GrantsWriter` block. Fixed: moved `WithEngine` (with its own doc) above `WithV2GrantsWriter` so each function gets its own godoc.
  2. `engine` field zero value `""` didn't equal `EngineSQLite` (`"sqlite"`). Fixed: `NewC1File` normalizes `""` → `EngineSQLite` after applying options, plus regression test `TestEngineDefaultsToSQLite`.

Stacks 1–5 have been rebased forward onto the new Parent and force-pushed. A combined squash PR #874 is also up for macro-level review of the whole stack at once.

Copy link
Copy Markdown
Contributor

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants