Partition time-series parts by date and prune them on a windowed PEEK #15

Open
opened 2026-10-23 11:29:27 +00:00 by aleksei · 0 comments
Owner

Context

ParquetTsdbUnit stores immutable parts and reads every visible part on every query: engine::execute (both the Arrow fast path and the JSON fallback) starts from store::read_parts/read_batches, and the filter is applied afterwards. A windowed PEEK therefore costs O(total history), not O(window).

Measured on the current adapter (debug build, one compacted part, 1 088 symbols × 365 days = 397 120 rows):

  • PEEK window (3 days, no limit): 3.37 s
  • PEEK window + sort -date + limit 3: 3.41 s
  • PEEK one symbol, same window: 2.87 s

For a service that appends ~1 088 series points a day and reads a 3-day window at every boundary, this grows linearly with the run's age. Row-group statistics (#10) skip data inside a part, but they still open and scan every part; date-partitioned parts would let a windowed query avoid most parts altogether.

Scope

  1. Partition parts by date. Write each part with a bounded UTC date span (one part per day, or a configurable span). Record each part's [minDate, maxDate] in the manifest alongside the file name, or derive it from the part's statistics once when the part is written.
  2. Prune parts from the manifest before reading. Translate the FIQL date predicate (date/dateTime key) into a closed/open interval; read only parts whose span overlaps it. A query without a date predicate, or a predicate the translator does not understand, reads all parts (conservative, no false negatives).
  3. Keep compaction partition-aware. Compaction must not merge parts across a partition boundary into one wide part; it may merge parts inside a span. A rewrite that loses the span metadata must fall back to reading the part.
  4. Migration. A directory whose parts.json has no span metadata (or legacy parts) is read as today and can be repartitioned on serve/compaction; no data loss, no silent empty reads.
  5. Manifest remains the commit point. The atomic part write + manifest switch, at-least-once redelivery and orphan cleanup semantics stay exactly as adr/parquet.md describes.
  6. Observability. Log skipped parts and row groups at debug, with the predicate interval and the part span.

Acceptance criteria

  • Existing eve_e2e tsdb tests and semantics unchanged; a query with no date filter returns the same rows and order.
  • A new benchmark at 1 088 series × 1 year shows a 3-day window reading only the overlapping parts: latency and peak memory do not grow with the total number of days, only with the overlapping span.
  • A conservative fallback is covered by a test (missing/legacy metadata, unsupported predicate, predicate on a non-date field).
  • Compaction and serve preserve or rebuild the span metadata; a crash between part write and manifest switch leaves no visible partial part.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p eve_tsdb_parquet, cargo test -p eve_e2e --test tsdb --test app pass.
  • adr/parquet.md documents the partition layout, the manifest span metadata, pruning and the fallback.

Non-goals

  • Row-group statistics and streaming top-k — #10.
  • Arrow transform fast path — #11.
  • Changing the public TsdbUnit API or the query language.
  • Distributed execution; this stays the local single-process profile.
## Context `ParquetTsdbUnit` stores immutable parts and reads **every visible part** on every query: `engine::execute` (both the Arrow fast path and the JSON fallback) starts from `store::read_parts`/`read_batches`, and the filter is applied afterwards. A windowed `PEEK` therefore costs O(total history), not O(window). Measured on the current adapter (debug build, one compacted part, 1 088 symbols × 365 days = 397 120 rows): - `PEEK` window (3 days, no limit): **3.37 s** - `PEEK` window + `sort -date` + `limit 3`: **3.41 s** - `PEEK` one symbol, same window: **2.87 s** For a service that appends ~1 088 series points a day and reads a 3-day window at every boundary, this grows linearly with the run's age. Row-group statistics (#10) skip data inside a part, but they still open and scan every part; date-partitioned parts would let a windowed query avoid most parts altogether. ## Scope 1. **Partition parts by date.** Write each part with a bounded UTC date span (one part per day, or a configurable span). Record each part's `[minDate, maxDate]` in the manifest alongside the file name, or derive it from the part's statistics once when the part is written. 2. **Prune parts from the manifest before reading.** Translate the FIQL date predicate (`date`/`dateTime` key) into a closed/open interval; read only parts whose span overlaps it. A query without a date predicate, or a predicate the translator does not understand, reads all parts (conservative, no false negatives). 3. **Keep compaction partition-aware.** Compaction must not merge parts across a partition boundary into one wide part; it may merge parts inside a span. A rewrite that loses the span metadata must fall back to reading the part. 4. **Migration.** A directory whose `parts.json` has no span metadata (or legacy parts) is read as today and can be repartitioned on `serve`/compaction; no data loss, no silent empty reads. 5. **Manifest remains the commit point.** The atomic part write + manifest switch, at-least-once redelivery and orphan cleanup semantics stay exactly as `adr/parquet.md` describes. 6. **Observability.** Log skipped parts and row groups at debug, with the predicate interval and the part span. ## Acceptance criteria - Existing `eve_e2e` tsdb tests and semantics unchanged; a query with no date filter returns the same rows and order. - A new benchmark at 1 088 series × 1 year shows a 3-day window reading only the overlapping parts: latency and peak memory do not grow with the total number of days, only with the overlapping span. - A conservative fallback is covered by a test (missing/legacy metadata, unsupported predicate, predicate on a non-date field). - Compaction and `serve` preserve or rebuild the span metadata; a crash between part write and manifest switch leaves no visible partial part. - `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo test -p eve_tsdb_parquet`, `cargo test -p eve_e2e --test tsdb --test app` pass. - `adr/parquet.md` documents the partition layout, the manifest span metadata, pruning and the fallback. ## Non-goals - Row-group statistics and streaming top-k — #10. - Arrow transform fast path — #11. - Changing the public `TsdbUnit` API or the query language. - Distributed execution; this stays the local single-process profile.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zoo/eve#15
No description provided.