Expand description
Management of process-specific partitions built on demand
Just-in-time (JIT) partition generation groups a view’s source blocks (queried from
blocks_view in ORDER BY insert_time, block_id order) into SourceDataBlocksInMemory
partitions no larger than JitPartitionConfig::max_nb_objects.
JitPartitionConfig::block_order (see BlockOrder) picks between two orderings for the
blocks a partition ends up holding: InsertTime (the SQL order, unchanged) for views that
decode blocks independently, and EventTime for views that build cross-block trees or rely on
event-time-sorted rows within a partition file. group_blocks_into_partitions is the single
place both variants are cut, and it upholds one invariant regardless of ordering: every emitted
partition’s [min_insert_time, max_insert_time] range is non-overlapping with, and
non-decreasing relative to, every other emitted partition’s – the precondition the
lakehouse_partitions_no_overlap exclusion constraint enforces at insert time. See
group_blocks_into_partitions’s own docs for how that invariant is upheld under
BlockOrder::EventTime, where the natural size-based cut point is not always safe, and for
the one (production-unreachable) shape it does not cover.
Note that this is an insert-time invariant only. It says nothing about partitions’
event-time ranges, which for the block-derived views are computed from block
begin_ticks/end_ticks. By design both micromegas_tracing and the Unreal producer now stamp
a single shared timestamp per flush, used for both the outgoing block’s close and the
replacement block’s begin, so consecutive blocks touch exactly and adjacent partitions’ event
bounds do not overlap by construction. Data from producer versions predating that fix can still
carry strictly-overlapping block ticks; ThreadSpansView’s recorded max_sort_key_time is what
makes that harmless to the Concatenated scan check (partitioned_execution_plan::partition_bounds
prefers it over the looser max_event_time) rather than requiring every source block to be
re-ingested. See the ordering-invariant notes on View::get_scan_output_ordering and
tasks/completed/thread_spans_segment_boundary_overlap_plan.md.
Structs§
- JitPartition
Config - Configuration for Just-In-Time (JIT) partition generation.
- Partition
Freshness Row - One
lakehouse_partitionscandidate row, as fetched byfetch_freshness_candidates:(begin_insert_time, end_insert_time, file_schema_hash, source_data_hash). Fields arepubsoanalytics/tests/jit_freshness_tests.rscan build rows directly, without a live database.
Enums§
- Block
Order - How source blocks are ordered before being cut into JIT partitions.
Functions§
- batch_
windows - Packs consecutive insert-time buckets of
[insert_range.begin, insert_range.end)(stepping byslice, so every bucket edge isslice-aligned toinsert_range.begin) into batch query windows, greedily closing a window just before it would exceedtarget_rows_per_query. - blocks_
insert_ time_ range - Returns the real
[min, max]insert_timerange covered byblocks, independent of list order. Always use this instead of readingblocks[0]/blocks[last]: underBlockOrder::EventTimethe list is sorted by event time, not insert time, so its endpoints are no longer the insert-time extremes. - fetch_
process_ blocks - Fetches and parses one batch window’s worth of process-scoped blocks (
process_batch_sql), looking up each block’s stream metadata instream_metadata(built once per call togenerate_process_jit_partitionsbyfetch_stream_metadata_map) rather than rebuilding it per row – this is the lean projection’s fetch-and-parse half. - find_
up_ to_ date_ partitions - One candidates fetch over
[specs.first().min, specs.last().max](specs have ascending, non-overlapping insert ranges), then the matcher per spec, run to a fixpoint. An emptyspecsreturnsOk(vec![])without issuing any fetch – reachable at every call site, sincegenerate_*_jit_partitionsreturns no specs when the range holds no blocks. - generate_
process_ jit_ partitions - generate_process_jit_partitions lists the partitions that are needed to cover a time span for a specific process these partitions may not exist or they could be out of date Generates JIT partitions for a given time range filtered by process.
- generate_
stream_ jit_ partitions - generate_stream_jit_partitions lists the partitiions that are needed to cover a time span these partitions may not exist or they could be out of date Generates JIT partitions for a given time range.
- generate_
stream_ jit_ partitions_ segment - Generates a segment of JIT partitions.
- group_
blocks_ into_ partitions - Groups a segment’s source blocks into JIT partitions.
- group_
contiguous_ block_ chains - Splits an event-time-ordered block list into maximal chains whose tick coverage is unbroken, so
each chain can be decoded into one cross-block tree (a call tree for
thread_spans, a net span tree fornet_spans). - is_
jit_ partition_ up_ to_ date - is_jit_partition_up_to_date compares a partition spec with the partitions that exist to know if it should be recreated Checks if a JIT partition is up to date.
- process_
batch_ sql - The process-variant batch query: block columns plus
stream_idonly – no stream-level column (streams.dependencies_metadata/objects_metadata/tags/properties/format) may be added to theSELECTlist. Re-adding one would reintroduce the per-row stream-blob-copy memory hazard the lean projection removes, with no test failing except the projection guard inanalytics/tests/jit_batch_windows_tests.rs.array_has("streams.tags", ...)stays in theWHEREclause: filtering needs no projection. - resolve_
up_ to_ date_ fixpoint - The pure fixpoint at the heart of
find_up_to_date_partitions(see that function’s docs for the derivation): runsspec_is_up_to_dateonce for every spec againstcandidates, then drains a worklist of specs that might need re-evaluation because a neighbor newly became stale. Because specs have ascending, non-overlapping insert ranges, a candidate row can be entirely contained in at most two specs’ ranges, and only when those two specs are adjacent in the sorted order (sharing a boundary point, for a degeneratebegin == endrow) – so the only specs whose verdict can ever change as a consequence of specibecoming stale arei’s immediate neighbors, indexi - 1andi + 1. A spec is re-evaluated against a candidate set that drops rows entirely contained in some other, currently-stale spec’s insert range (never its own range – a row a spec would itself retire is not evidence about its own freshness); if that recompute still comes back stale, the spec is marked stale (it is never recomputed again – once stale, verdicts are monotone by construction, with no separate clamping step needed) and its own neighbors are pushed onto the worklist in turn. Takes an already-fetchedcandidatesand does no I/O, soanalytics/tests/jit_freshness_tests.rscan drive it directly without a livePgPool. - spec_
is_ up_ to_ date - Filters
candidatesdown to the rows the per-spec SQL used to return (exact range equality forBlockOrder::EventTime, exact match for a degenerateBlockOrder::InsertTimerange, inclusive overlap otherwise), then applies the samerows.len() == 1/file_schema_hash/ object-count checksis_jit_partition_up_to_datealways has. - write_
partition_ from_ blocks - Writes a partition from a set of blocks.