Skip to main content

Module jit_partitions

Module jit_partitions 

Source
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§

JitBucket
A planned bucket with the partition specs grouped from its blocks.
JitPartitionConfig
Configuration for Just-In-Time (JIT) partition generation.
PartitionFreshnessRow
One lakehouse_partitions candidate row, as fetched by fetch_freshness_candidates: (begin_insert_time, end_insert_time, file_schema_hash, source_data_hash, file_size). Fields are pub so analytics/tests/ can build rows directly, without a live database.

Enums§

BlockOrder
How source blocks are ordered before being cut into JIT partitions.
BucketSizing
How insert-time buckets are sized.
ConflictRetry
What to do after a mandatory write lost an overlap race.
Coverage
What a bucket needs: nothing, or its specs written with the given retire mode.
RangeConvention
How a partition row’s insert range relates to a half-open bucket, which depends on who wrote the row.

Functions§

batch_windows
Packs consecutive planned buckets into batch query windows, greedily closing a window just before it would exceed target_rows_per_query.
blocks_insert_time_range
Returns the real [min, max] insert_time range covered by blocks, independent of list order. Always use this instead of reading blocks[0]/blocks[last]: under BlockOrder::EventTime the list is sorted by event time, not insert time, so its endpoints are no longer the insert-time extremes.
decide_conflict_retry
Decides what to do with a bucket whose write hit the no-overlap constraint, from the rows fetched again afterwards. A concurrent writer that committed after the first retire SELECT is listed in refetched, so the retry’s retire mode is derived from it.
fetch_freshness_candidates
Fetches every lakehouse_partitions row for view_meta whose insert range inclusively overlaps range (begin_insert_time <= range.end AND end_insert_time >= range.begin), with the narrowing applied in Rust by the caller (spec_is_up_to_date, resolve_bucket_coverage).
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 in stream_metadata (built once per call to generate_process_jit_partitions by fetch_stream_metadata_map) rather than rebuilding it per row – this is the lean projection’s fetch-and-parse half.
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, grouped by the insert-time bucket plan_buckets assigned them to.
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 for net_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_id only – no stream-level column (streams.dependencies_metadata/objects_metadata/tags/properties/format) may be added to the SELECT list. 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 in analytics/tests/jit_batch_windows_tests.rs. array_has("streams.tags", ...) stays in the WHERE clause: filtering needs no projection.
resolve_bucket_coverage
Judges every bucket against the candidate rows and cascades: writing a stale bucket retires rows (those inside its spec hulls for Containment, those intersecting them for Overlap), which can strip coverage from a bucket that relied on one of them. Verdicts only move from covered to stale, so the loop ends in at most buckets.len() passes, and the query that triggers the writes never reads a bucket its own writes just emptied.
spec_is_up_to_date
Filters candidates down to the rows with exactly the spec’s insert range, then applies the rows.len() == 1 / file_schema_hash / exact object-count checks. Used by the BlockOrder::EventTime views (thread_spans/net_spans) only: their cut points can move between jit_update runs, so a later run’s spec can be narrower than an already-written partition that still overlaps it, and an overlap test would call that stale, wider partition up to date and leave it in place forever. Exact equality reports “not up to date” instead, so the write falls through to RetireMatch::Overlap (see write_partition.rs). The InsertTime views judge freshness per bucket with resolve_bucket_coverage.
update_insert_time_jit_view
Brings an InsertTime JIT view of one process up to date for query_range: sizes buckets from the range, writes the stale ones, then promotes closed history to the range’s rung.
write_partition_from_blocks
Writes a partition from a set of blocks, retiring the rows retire_match selects (see RetireMatch; same_run_ranges is only meaningful for Overlap).