Eloverblik

Dokumentation · Data og kilder

The chunk planner (elo_core.plan)

The planner decides which windows of which metering points are requested, and what each answer does to them. It implements §6.1–§6.3 of docs/architecture/phase-1.md as pure functions: no clock (the instant is passed in), no database, no network. The worker keeps the chunks in ingest.chunk (B08b), the capture tool in chunks.jsonl (B06b); both run this one implementation.

Values

ValueWhat it is
ChunkOne row of ingest.chunk: MP, purpose (1 first load, 2 bootstrap, 3 re-fetch), window of local dates [date_from, date_to), state 1–10, attempts, solo, parent and lineage, the two retry counters, next_try_at, the last code and fetch
MpStatereadable_from, first_load_to, daily_ok_through, current_access of ingest.mp_state, and listed_with_relation: whether the latest list shows the MP with a relation and not moved out (the list shows a root: a child takes its root's flags, chunks.mp_states, B09)
ItemAnswer(code, delivered, applied)One chunk's item in a response that arrived. applied is false for a validation failure, a parse error, an unsupported unit or resolution
Failure(kind, code)The request as a whole: TRANSIENT (503, read timeout, no response, a crash), RATE_LIMITED (429), BAD_REQUEST (400 with its code)
RequestUp to 10 chunk IDs of one account and one window

One request

  1. next_request(chunks, now): the due chunks of the newest window, batched by account and window, at most 10; a solo or parked chunk alone. oldest_first=True for the capture's exhaustive search. 2. start_request(chunks, request): attempts + 1 on each chunk, committed before the send (C4). 3. apply_response(chunks, mps, request, response, now=, new_id=, has_data=, fetch_id=): the outcome table of §6.2 for each chunk, then for each MP of the request the edge search and the readable anchor. Returns all chunks (changed ones in place, new ones appended, so writing them in order does every update before every insertion, the order of C3), the MP states, and the MPs whose ID was refused (invalid_mp_ids, status 4).

fetch_id is required, and each request's outcome is consumed once. Pass the raw.fetch.fetch_id of the row transaction A wrote before the send: one per send, a later send with a larger one (the identity column gives both). Every chunk the outcome is applied to records it as last_fetch_id, for every kind of outcome, 429 and the ladder's split included. A chunk whose last_fetch_id is that fetch or a later one ignores the outcome; when every chunk of the request does, nothing changes at all. So the same response delivered twice, or an older response arriving after a newer one was applied, changes no state and no counter. The caller must still recover a request left unanswered (apply Failure(TRANSIENT) with its fetch_id) before it reserves the next send of those chunks, and commit the application together with the completion of its raw.fetch row: the planner cannot see a reservation that has no outcome yet.

Time. Pass aware instants in any zone. Waits are added and instants compared in UTC: next_try_at and closed_at come back in UTC, a one-hour wait is an elapsed hour across a DST change, and due gives the same answer for the same instant however it is spelt. Local dates (today, the window) are Copenhagen's.

new_id() gives a new chunk_id. has_data(mp_id, date_from, date_to) says whether a local day of the window is stored for the MP, this response's days included. The anchor needs it: ingest.chunk does not record whether a done chunk delivered a day.

What an answer does:

AnswerChunk
10000done; a bootstrap chunk without a delivered day: no_data
30015no_data, tried again after 1, 7 and 30 days, then empty
A refusal (30018, 30017, 30010, 30016, 20010, 40014, 20012)outside; one day: not_available; a bootstrap chunk: no_data. Never a change of current_access (C8)
20003, 20004, 20008invalid, and the MP in invalid_mp_ids
20011Unchanged; parked at attempts = 8
applied = False, a missing item, a code §6.2 does not nameunresolved
TRANSIENTThe ladder: solo at 3 attempts, split once at the middle day at 5 (a root longer than a day), parked at 8. A parked chunk is tried after 1 hour, 6 hours, 1 day, then daily, and is unresolved after 8 tries
RATE_LIMITEDUnchanged; the attempt is given back
BAD_REQUESTunresolved with the code; never sent again

Planning

FunctionWhenWhat it adds
tileAn MP without chunks[window start, today) in calendar quarters (PT1H) or months (PT15M, unknown); first_load_to = today
plan_dailyEvery daily run, per MPAwaiting first data: one-day bootstrap chunks from the watermark up to yesterday. Otherwise the gap of §6.5 step 2 when today − 14 lies after the watermark. Normally nothing
restoreAn MP listed with a relation againFirst-load chunks from the watermark to today; readable_from cleared
plan_refetch(chunks, mp, ...)make refetch MP FROM TOPurpose-3 chunks over the days of the range before the watermark that no open chunk covers. Days from the watermark on are not planned yet; the planner plans them, and make refetch should say so when the range reaches past it

The watermark is max(first_load_to, daily_ok_through): every day before it has a chunk of purpose 1 or 2 or was fetched by a successful daily request. It only moves later. No function plans a day that a chunk of purpose 1 or 2 already covers in any state but split. Because a re-fetch stays before the watermark, no open re-fetch overlaps a day the planner will plan, so every planned day gets its chunk of purpose 1 or 2 when it is planned, and the exclusion constraint never refuses one (B06av-01).

The access edges

Kilde: docs/planner.md i løsningens repository.