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
| Value | What it is |
|---|---|
Chunk | One 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 |
MpState | readable_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) |
Request | Up to 10 chunk IDs of one account and one window |
One request
next_request(chunks, now): the due chunks of the newest window, batched by account and window, at most 10; asoloorparkedchunk alone.oldest_first=Truefor the capture's exhaustive search. 2.start_request(chunks, request):attempts + 1on 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:
| Answer | Chunk |
|---|---|
10000 | done; a bootstrap chunk without a delivered day: no_data |
30015 | no_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, 20008 | invalid, and the MP in invalid_mp_ids |
20011 | Unchanged; parked at attempts = 8 |
applied = False, a missing item, a code §6.2 does not name | unresolved |
TRANSIENT | The 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_LIMITED | Unchanged; the attempt is given back |
BAD_REQUEST | unresolved with the code; never sent again |
Planning
| Function | When | What it adds |
|---|---|---|
tile | An MP without chunks | [window start, today) in calendar quarters (PT1H) or months (PT15M, unknown); first_load_to = today |
plan_daily | Every daily run, per MP | Awaiting 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 |
restore | An MP listed with a relation again | First-load chunks from the watermark to today; readable_from cleared |
plan_refetch(chunks, mp, ...) | make refetch MP FROM TO | Purpose-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
- Edge search (level 2), inside
apply_response: anoutsidefirst-load chunk next to adoneone is halved and the half next todoneis requested; a one-day piece is requested alone, and a refusal makes itnot_available. The MP's newest chunk counts today's side asdonewhile the MP is listed with a relation. Only chunks inside the API's window are searched. - Exhaustive search (level 3),
exhaustive_search(...)andprobe_window(...): everyoutsidechunk in the range is halved and both halves requested, down to single days; a piece that was never requested is requested whole first. A call does one step; call it again after the queue has drained, until it returns the chunks unchanged. - Readable anchor:
readable_fromis the first day of the unbroken run ofdonechunks ending with the newestdonechunk that has a stored day and nothingoutsideornot_availableafter it. It only ever moves earlier. When a bootstrap chunk ends the wait, anot_availableday directly before is asked once more. complete(chunks, mp_id, date_from, date_to)is §6.4 step 3: every day is in a chunk that isdone,not_available,no_data,emptyorinvalid.
Kilde: docs/planner.md i løsningens
repository.