Skip to content

feat: WIP multi-step scheduling continuation#46

Open
define-null wants to merge 3 commits into
masterfrom
defnull/net-681-multi-step-scheduling-3
Open

feat: WIP multi-step scheduling continuation#46
define-null wants to merge 3 commits into
masterfrom
defnull/net-681-multi-step-scheduling-3

Conversation

@define-null

@define-null define-null commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What is this PR about?

Multi-step scheduling: correctness fixes, Postgres scale work, shared ring machinery.

This iteration takes the multi-step scheduler from test-scale to production-shaped data. Three tracks: fix two correctness bugs, push the per-cycle heavy lifting into Postgres, and consolidate the hash-ring code both schedulers duplicated. The reshuffle simulator gains the dataset operations and metrics to measure it.

Correctness

  • Weight-strategy desync: the pk and current-placement vectors were built from the original chunk order while the scheduler input came from the weight strategy's filtered/reordered list — placements got attributed to the wrong chunk and uncovered chunks were still scheduled. Both now derive from the same filtered list.
  • Phantom assignment rows: the worker tombstone's FK forced an assignment id to be minted in Phase A, leaking an unused row on every Phase B shortage rollback. Replaced with a bare drop-tick (no FK); id minting moves to Phase B.

Postgres performance & scale

  • Twin-table set-diffing: the app-side reconcile becomes a twin ideal table diffed in pure SQL and promoted by a transactional rename; several fetches and post-write phases collapse into single round-trips.
  • GiST range index for the overlap probe: replaces the O(N²) nearest-left btree walk on new datasets.
  • chunk replace/copy fast paths: batch corrections in one transaction, O(P) readiness resolution, server-side copy, cycle-scoped cleanup.
  • Server-side routing visible set: drops the large per-cycle visible-pk array upload; the set is derived from the same metadata predicate server-side.
  • Leaner IdealMapping: per-chunk HashSet + outer BTreeMap become a positional Vec, canonicalized only at the COPY boundary.

Shared ring machinery: extracted into src/rings.rs; WorkerRingCache rebuilds rings only when the worker id list changes, so a steady fleet reuses them across cycles.

Per-dataset schema: a schemas table plus chunks.schema_id lets files be derived from the schema instead of stored per-chunk; adds a tables_present bitmap and per-pipeline chunk types so the hot read decodes a slim row.

Reshuffle simulator: step-triggered copy/replace sourced from live storage; ideal-vs-ideal shuffle metric with stale-capacity reporting; stale-% column; debug-only table row counts; benchmarking paths, jemalloc, and a deploy image.

The pg-vs-in-memory oracle suite stays green throughout, with new tests for the schema and correction paths.

@define-null define-null force-pushed the defnull/net-681-multi-step-scheduling-3 branch 5 times, most recently from f7758cb to 74dd9a3 Compare July 4, 2026 03:03
@define-null define-null changed the base branch from defnull/net-681-multi-step-scheduling-2 to master July 8, 2026 15:08
@define-null define-null force-pushed the defnull/net-681-multi-step-scheduling-3 branch from 814ecd6 to 5f0a965 Compare July 8, 2026 15:18
…uction-shaped data. Three tracks: fix two correctness bugs, push the per-cycle heavy lifting into Postgres, and consolidate the hash-ring code both schedulers duplicated. The reshuffle simulator gains the dataset operations and metrics to measure it.

**Correctness**
- **Weight-strategy desync**: the pk and current-placement vectors were built from the original chunk order while the scheduler input came from the weight strategy's filtered/reordered list — placements got attributed to the wrong chunk and uncovered chunks were still scheduled. Both now derive from the same filtered list.
- **Phantom assignment rows**: the worker tombstone's FK forced an assignment id to be minted in Phase A, leaking an unused row on every Phase B shortage rollback. Replaced with a bare drop-tick (no FK); id minting moves to Phase B.

**Postgres performance & scale**
- **Twin-table set-diffing**: the app-side reconcile becomes a twin ideal table diffed in pure SQL and promoted by a transactional rename; several fetches and post-write phases collapse into single round-trips.
- **GiST range index for the overlap probe**: replaces the O(N²) nearest-left btree walk on new datasets.
- **chunk replace/copy fast paths**: batch corrections in one transaction, O(P) readiness resolution, server-side copy, cycle-scoped cleanup.
- **Server-side routing visible set**: drops the large per-cycle visible-pk array upload; the set is derived from the same metadata predicate server-side.
- **Leaner IdealMapping**: per-chunk `HashSet` + outer `BTreeMap` become a positional `Vec`, canonicalized only at the COPY boundary.

**Shared ring machinery**: extracted into `src/rings.rs`; `WorkerRingCache` rebuilds rings only when the worker id list changes, so a steady fleet reuses them across cycles.

**Per-dataset schema**: a `schemas` table plus `chunks.schema_id` lets files be derived from the schema instead of stored per-chunk; adds a `tables_present` bitmap and per-pipeline chunk types so the hot read decodes a slim row.

**Reshuffle simulator**: step-triggered copy/replace sourced from live storage; ideal-vs-ideal shuffle metric with stale-capacity reporting; stale-% column; debug-only table row counts; benchmarking paths, jemalloc, and a deploy image.

The pg-vs-in-memory oracle suite stays green throughout, with new tests for the schema and correction paths.
@define-null define-null force-pushed the defnull/net-681-multi-step-scheduling-3 branch from 5f0a965 to c22d18c Compare July 8, 2026 15:39
@define-null define-null marked this pull request as ready for review July 8, 2026 15:42
@define-null define-null changed the title Defnull/net 681 multi step scheduling 3 feat: WIP multi-step scheduling continuation Jul 8, 2026
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