Skip to content

refactor: consolidate parser write internals (#380 part 3a) - #390

Merged
oglassdev merged 8 commits into
mainfrom
cleanup/parser-consolidation
Sep 24, 2026
Merged

oglassdev merged 8 commits into
mainfrom
cleanup/parser-consolidation

Conversation

@oglassdev

Copy link
Copy Markdown
Owner

Part 3a of #380: consolidates duplicated internals of crates/jet3/src. There is no behavior change and no public API change. Only crates/jet3/src/** is touched; docs, oracle, CLI and testkit are unchanged.

What was consolidated

  1. One row-write driver (write/driver.rs).
    • Before: insert_row, delete_row, update_row and update_field each repeated the same sequence: open, check sort order, load the writable table, apply the column rule policy, prepare cascades, plan, publish.
    • After: driver::apply runs that sequence once and dispatches on relationship::mutation::Change. Each public function (and its *_with_hook test entry) is now a two-line wrapper with the same signature.
    • The rule refusal still runs only for replace and field changes. cascade::prepare returns None for inserts before doing any work, so the order of checks and budget charges is unchanged.
    • driver::row_layout replaces three copies of the layout-and-contiguity loop. insert_page::minimum_row replaces four copies of the all-null row encoding.
  2. One data-page editor (row/data_page.rs).
    • Before: insert_page, update_page and delete_page each had their own directory validation, slot classification, free-space check and directory rewriting, plus a wrapper trio for every operation (append/append_physical/append_inner, and the same for replace and remove). There were also separate increment_count/check_count/decrement_count helpers.
    • After: DataPageEditor::open(page, owner, source, budget) owns the shared primitives: live_rows, the packed free-space check, write_slot and write_free. The operations are short methods, append/replace/remove, that take a physical argument. check_table_rows and count_table_row replace the three count helpers.
    • Each operation still lives in its own file, so the support-matrix evidence paths stay valid.
    • Error strings and the charging for each operation are unchanged: items charged for append, 2× work units for replace and remove, and 4 work units for the row-update count check (now charged at the call site).
  3. Catalog system rows defined once (catalog/system_rows.rs).
    • ObjectRow, AceRow and RelationshipRow expose their values as named columns in stored order. Database creation encodes them against its fixed layouts. Schema edits insert them by column name.
    • The owner/SID constants and the table and relationship grant pairs were hard-coded in 5 places. They now live in AceRow::table_grants and AceRow::relationship_grants.
    • The creation-only CatalogSeed/AceSeed types and the duplicated MSysRelationships layout are gone.
  4. Catalog property payload decoding. properties::values::StoredProperties classifies an LvProp value (null, inline or external) for both the stored-properties reader and the schema-edit loader. I also added crate-private raw_bytes() methods on InlineLongValue and LongValueChunkValue, replacing 7 identical match arms in properties, schema, create/api and validate.
  5. Allocation maps. global_locator() replaces the global-map locator that was hard-coded in six places. mutation_map::owned_page replaces the page tag, marker and owner check that was repeated in the index load, the released-page search and the long-value load.
  6. Bounded vector growth. format::resource::grow is now the single growth routine. Both reserve helpers call it: the resource one charges 1 work unit per existing item, the page-edits one charges size_of::<T>(). Each keeps its own error mapping.

Deliberately left for part 3b

  • Rest of the property loader. The two loaders still stream external payloads separately. They use different error types and texts ("property declared length" vs "property length") and different allocation charging: buffer() checks the decoded-value limit, while reserve() is page-edit growth. Merging them further would change errors.
  • RowDirectory vs DataPageDirectory. These are different layers. DataPageDirectory is the format decoder, which catalog pages also use with their own errors. RowDirectory adds the owner, slot-width and overflow-pointer checks and the locators, and maps failures to the public RowDirectoryError. Merging them would push table-row semantics into format/.
  • MapPatches vs PendingMap. These are two stages, not two ways to do one thing. MapPatches checks the membership of one page across the global, owned and available maps. It then stages into PageEdits' PendingMap through map_bit.
  • Local push helpers. Their semantics differ: catalog_pages reserves exactly one slot without doubling or work units, mutation pushes only when a value is present, storage removes duplicates, and the index and blob helpers are domain methods. The only plain reserve-plus-push is in relationship_graph_plan.
  • Creation self-check vs validate/. create/api.rs and graph_schema_check.rs compare the written image against the request (catalog rows, columns, indexes and initial rows) and return ImageCheckError::Mismatch details. validate/ checks structural consistency without the request. These are different checks with different errors, so routing one through the other would change behavior.

Verification

  • scripts/golden-check.sh 430a6cb (same tree as the reworded fda34e7) ran after every step. Every run reported 1923 files: 1923 identical, 0 differ, 0 only-base, 0 only-head.
  • cargo test -p jet3: 823 passed + 6 ignored (lib), 17 integration, 2 doc. The counts are unchanged; tests that called the removed page helpers now call DataPageEditor directly.
  • cargo check -p jet3 --all-targets --target x86_64-pc-windows-gnu: clean.
  • just ready: passes.
  • Production lines in crates/jet3/src (excluding *_tests.rs, tests.rs and testkit.rs): 41,914 → 41,849.

🤖 Generated with Claude Code

@oglassdev
oglassdev merged commit 9ee8a73 into main Sep 24, 2026
10 checks passed
@oglassdev
oglassdev deleted the cleanup/parser-consolidation branch September 24, 2026 18:42
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.

1 participant