Skip to content

BulkLoad write path + storage durability hardening (#382) - #383

Merged
nockawa merged 13 commits into
mainfrom
feature/bulkload-and-durability-hardening
May 27, 2026
Merged

nockawa merged 13 commits into
mainfrom
feature/bulkload-and-durability-hardening

Conversation

@nockawa

@nockawa nockawa commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Closes #382.

Umbrella PR for the work on feature/bulkload-and-durability-hardening. Squash-merge expected.

What's in this PR

BulkLoad write path (P1-P5)

Opt-in throughput-first write API that skips per-row WAL and brackets a bulk with a BulkBegin / BulkEnd manifest pair. Trades per-row durability for throughput on a strictly opt-in API.

  • New BulkLoadSession — exclusive per-engine, thread-affine; wraps a UnitOfWork + recycling Transactions with internal SuppressWalSerialization (BL-01)
  • New BulkLoadOptions / BulkLoadProgress, BulkLoadCheckpointTimeoutException / BulkSessionAlreadyActiveException / BulkSessionClosedException
  • New BulkManifestHeader + BulkPageRange + WalChunkType.BulkBegin / BulkEnd
  • DatabaseEngine.BeginBulkLoad + bulk-session gate
  • Transaction.DestroyBulk fast path (skips IsAlive's random EntityMap lookup)
  • BitmapL3.FreeRange + ManagedPagedMMF.FreePages(int firstPage, int count) for the discarded-bulk recovery path
  • WalRecovery recognises the new chunk types; v1 deviation: visibility correctness via the existing UowRegistry void path (UR-03 / UR-05), not explicit page-free at Phase 3b — documented in claude/design/Durability/BulkLoad/03-recovery.md
  • Design docs + ADR + durability rules BL-01..04

Engine ALC lifecycle fix

ArchetypeRegistry now refcounts per-engine, releases every Type reference on dispose so collectible session ALCs can be GC-reclaimed. Resolves the Workbench session-close leak.

Workbench Data Browser + File Map per-kind rendering

  • New read-only Data Browser view + non-generic entity access surface on the engine (EntityAccessor.ECS.cs, EntityRef.cs)
  • File Map (dbmap*): per-kind colouring, L0 ordering, region/hit-test rework, metrics, search, scale tests

CP-04 / #301 hardening

  • ChunkBasedSegment.AllocateChunk + FreeChunk use ChangeSet-tracked IncrementDirty (not bare EnsureDirtyAtLeast(1)) to close the bitmap-revert race on contended metadata pages
  • New CP-04-safe AllocateChunk(ChangeSet, ref ChunkAccessor) overload keeps ACW > 0 continuously from ClearChunk through caller's first write
  • ChunkBasedSegment.Grow capped-doubling at 1024 pages — avoids catastrophic single-allocation requests at scale

Storage integrity hardening + detector

  • BitmapL3.SetL1 — Interlocked.Or → Interlocked.CompareExchange; bulk-of-64 allocator no longer leaks orphan bits on partial-collision
  • LogicalSegment.Grow patches OLD tail's LogicalSegmentNextRawDataPBID — chain is now an actively-maintained invariant
  • EnsureDirtyAtLeast(2) on every CreateOrGrow write path — closes lost-write window when callers pass null ChangeSet
  • Chain ↔ Directory cross-check at Load — throws with precise diff on mismatch
  • CheckpointManager shutdown fixes — unconditional final cycle (no LSN gate) + removed _shutdown early-exit that skipped fsync + DC-decrement
  • DatabaseEngine.RunStorageIntegrityCheck() + StorageIntegrityReport — popcount canary, in-memory chain/dir check, ChunkBasedSegment capacity invariant
  • Debug.Assert(bytesRead == PageSize) in PagedMMF.RequestPageEpoch — defensive against short async reads

Workbench fixture infrastructure

Directory-per-database layout (no schema-DLL collisions across DBs), Dev Fixture API + UI useBulkLoad toggle, stale dockview-API cleanup on session close.

Tests

  • BulkLoadReopenIntegrationTest [Explicit] — 1M / 3M / 8.5M / 17M scales, reopen state assertion
  • UnknownPagesDiagnosticTest [Explicit] — std/bulk × scale {1, 10, 100}, full integrity + raw-disk probing
  • BulkLoadRecoveryTests, BulkLoadWriteTests, BulkManifestTests, BitmapL3FreeRangeTests, ArchetypeRegistryLifecycleTests

Comment width pass

All added prose comments rewrap at ~150 cols, never exceed 160 per .editorconfig.

Known residual

#381 — Page-cache durability flake at scale on clean shutdown — non-deterministic. The chain ↔ directory integrity check added on this PR catches it deterministically at Load; smaller scales (1× / 10×) stably clean; x100 fails ~60% with precise diagnostics. Investigation paths A–E documented in #381 — next session.

Acceptance criteria

See #382 — all 15 acceptance items checked; remaining boxes for PR review + squash-merge.

🤖 Generated with Claude Code

nockawa added 13 commits May 23, 2026 18:22
- BulkLoad write path (P1-P5): opt-in throughput API skipping per-row WAL via BulkBegin/BulkEnd manifest pair; new BulkLoadSession + recovery.
- Engine ALC lifecycle fix: ArchetypeRegistry refcounts per-engine, releases Type refs on dispose so collectible session ALCs can GC-unload.
- Workbench Data Browser (read-only) + non-generic entity access surface on the engine.
- File Map per-kind rendering: dbmap colour scheme, L0 ordering, hit-test, metrics, scale tests.
- CP-04 / #301 hardening: ChunkBasedSegment AllocateChunk/FreeChunk use ChangeSet-tracked IncrementDirty + new CP-04-safe accessor overload.
- ChunkBasedSegment.Grow capped-doubling at 1024 pages: avoids catastrophic single-allocation requests at scale.
- BitmapL3.SetL1 CAS fix: replaced non-undoable Interlocked.Or with CompareExchange; eliminates orphan-bit leak on partial-collision.
- LogicalSegment.Grow patches OLD tail's NextRawDataPBID: chain is now an actively-maintained invariant, not vestigial dead code.
- EnsureDirtyAtLeast(2) on every CreateOrGrow write path: closes the lost-write window when callers pass null ChangeSet.
- Chain<->Directory cross-check at LogicalSegment.Load: throws with precise diff on mismatch; loud detector for lost-writes.
- CheckpointManager shutdown fixes: unconditional final cycle (no LSN gate) + removed _shutdown early-exit that skipped fsync.
- DatabaseEngine.RunStorageIntegrityCheck + StorageIntegrityReport: audit API for popcount canary, chain/dir check, chunk-segment capacity invariant.
- PagedMMF short-disk-read defensive Debug.Assert against stale bytes in cache slot from partial reads.
- Workbench fixture: directory-per-database layout + Dev Fixture useBulkLoad toggle + stale dockview-API cleanup on session close.
- Tests: BulkLoadReopenIntegration, UnknownPagesDiagnostic, BulkLoadRecovery, BulkLoadWrite, BulkManifest, BitmapL3FreeRange, ArchetypeRegistryLifecycle.
- Comment width pass: all added prose comments rewrap at ~150 cols per .editorconfig.

Known residual: #381 (page-cache durability flake at scale) now deterministically caught by the chain/directory integrity check.

Closes #382.
…durability-hardening

# Conflicts:
#	tools/Typhon.Workbench/ClientApp/src/libs/dbmap/dbMapRenderer.ts
#	tools/Typhon.Workbench/ClientApp/src/panels/SystemDag/SystemDagCanvas.tsx
#	tools/Typhon.Workbench/ClientApp/src/panels/SystemsQueriesNavigator/SystemsQueriesNavigatorPanel.tsx
#	tools/Typhon.Workbench/ClientApp/src/panels/SystemsQueriesNavigator/__tests__/SystemsQueriesNavigator.test.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/DockHost.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/MenuBar.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/Shell.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/WelcomeScreen.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/__tests__/conformance.test.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/__tests__/viewRegistry.test.ts
#	tools/Typhon.Workbench/ClientApp/src/shell/commands/baseCommands.ts
#	tools/Typhon.Workbench/ClientApp/src/shell/commands/openDbMap.ts
#	tools/Typhon.Workbench/ClientApp/src/shell/dialogs/ConnectDialog.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/dialogs/tabs/DevFixtureTab.tsx
#	tools/Typhon.Workbench/ClientApp/src/shell/viewRegistry.ts
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.

BulkLoad write path + storage durability hardening (umbrella)

1 participant