Commit Graph
6784 Commits
Author SHA1 Message Date
AumandClaude Opus 5.5 6ffb0ec793 feat: answer scalar COUNT on Mito from SST metadata (#9891)
* feat: answer scalar COUNT on Mito from SST metadata

Behind `experimental_metadata_aggr` (off by default), ScanHintRule marks
an ungrouped scalar COUNT directly over a Mito scan. Mito then proves the
scan's row count without reading SST data. Every file intersecting the
query time range must be covered by the static predicates and have a
known manifest row count. In deduplicating regions it must also share no
(time, primary key) point with another file or a memtable, and its
`__op_type` Parquet statistics must show no deletions. The statistics are
read through the SST metadata caches, only for files that pass the
manifest checks. RegionScanExec publishes the proven count as exact
statistics, which lets DataFusion replace the scan with a literal. Other
scans are unchanged.

Overlaps are found with one time sweep over a segment tree of compressed
primary key bounds, in O(N log N). The pairwise check remains as the
test oracle and benchmark baseline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito): cover metadata COUNT and address core review

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito): match metadata aggregate fixture region IDs

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): prove SST row counts before publishing exact statistics

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): add SQLness coverage for the SST footer marker

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): verify tightened partition bounds and source estimates

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): keep lazy footer reads sendable

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): use valid sequence fences and SST owners

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): validate SST key bounds before metadata count

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): verify SST time bounds before metadata count

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): own SST inputs to asynchronous bound checks

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): match displayed scan names in COUNT fallback

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): keep SST replacements coherent with metadata counts

Signed-off-by: aumnertic <aumnertic@gmail.com>

* refactor(cmd): reuse the replacement SST reader during validation

Signed-off-by: aumnertic <aumnertic@gmail.com>

* test(mito2): verify listed SST sizes against object storage

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): keep metadata count proofs within the SST read set

Signed-off-by: aumnertic <aumnertic@gmail.com>

* docs(mito2): use the actual scan memory limit key

Signed-off-by: aumnertic <aumnertic@gmail.com>

* fix(mito2): gate metadata counts on trusted SST dedup markers

Record the provenance of engine-written dedup markers in the manifest.
Clear it for external imports and preserve it during internal transfers.
Require this proof for metadata counts over non-append multi-row SSTs.

Keep the live file metadata consistent when an import supersedes a
background publication, and cover checkpoint downgrade and reopen.

Signed-off-by: aumnertic <aumnertic@gmail.com>

---------

Signed-off-by: aumnertic <aumnertic@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 11:43:27 +00:00
discord9 6c047d02b7 fix(promql): widen the regression intercept so a far horizon stops overflowing (#10724)
* fix(promql): widen the regression intercept so a far horizon stops overflowing

predict_linear added the fold offset to the evaluation time in i64; both are
legal and their sum is not, so a statement anchored far in the past was refused
even though it answers an empty matrix elsewhere. The intercept is i128 now and
the kernel adds there; the admission guard keeps only the fold offset, which is
a per-sample shift that has nowhere to live outside i64.

Signed-off-by: discord9 <discord9@163.com>

* docs(promql): cut the window-overflow comments to the non-obvious why

The added commentary restated code and existing invariants: native_tree_supported
grew a second copy of its own refusal list plus a section on what the runtime still
decides, and each test carried a paragraph narrating reasoning its name and assertion
messages already state.

Keep one sentence per non-obvious fact and narrow the stale predict_linear half of
the admission list to what the predicate now refuses. Added comment lines: 122 -> 15.

Signed-off-by: discord9 <discord9@163.com>

---------

Signed-off-by: discord9 <discord9@163.com>
2026-11-30 11:15:45 +00:00
shuiyisong 89990fa715 fix(promql): preserve precision in native histogram range sums and av… (#10657)
* fix(promql): preserve precision in native histogram range sums and averages

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* test(promql): cover avg_over_time overflow before histogram downscale

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

---------

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
2026-11-30 11:08:32 +00:00
discord9 c25a1f462d test(fuzz): materialise before a repartition merge (#10738)
* test(fuzz): materialise before a repartition merge

Since #10646 a merge is refused while a participant still holds an SST stamped by
another region, which is exactly what a split hands its children. The three
repartition fuzz targets merge right after splitting, so the statement failed and the
target panicked on every run.

Compact with the strict-window mode before issuing a merge: it rewrites even a lone
inherited file under the region's own expression, which is what the refusal asks for.
Splits keep running without a compaction, and a failed statement still panics.

Signed-off-by: discord9 <discord9@163.com>

* docs(fuzz): trim the pre-merge comments to the reason

The three blocks said the same thing at length; the commit message and the PR carry the
full rationale, the code only needs why the compaction is there and why it precedes the
chaos injection.

Signed-off-by: discord9 <discord9@163.com>

* test(fuzz): share the strict-window compaction, drop it from chaos

Review: the chaos target creates a fresh table, inserts and runs a single repartition,
so no split precedes the merge and nothing can hold a foreign SST; the compaction only
costs time there. The other two targets now call one helper in utils next to the
existing compact_table instead of repeating the statement and its error context.

Signed-off-by: discord9 <discord9@163.com>

---------

Signed-off-by: discord9 <discord9@163.com>
2026-11-30 10:58:22 +00:00
dennis zhuang 4d8e55909a feat(promql): fold native histograms over multi-input trees natively (#10677)
* feat(promql): fold native histograms over multi-input trees natively

A histogram statement reading more than one selector through raw sources
declined as soon as it needed placement, so `sum(h1 + h2)`,
`sum without (instance) (h1 or h2)` or `histogram_count(sum(h1 + h2))`
ran their fold on the legacy plan.

Such a tree is segmented like a float one: each operand's per-series
prefix publishes frames, and the fold runs once above all of them with
histogram state. A bare vector-vector pairing of histograms keeps the
composed plan, one frame per operand.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* feat(promql): run histogram pairs over raw sources natively

Drop the gate that sent a vector-vector histogram pairing to the composed
binary route. Evaluated as one node over both raw sources, `h1 + h2`,
`sum(h1 + h2) * 2` and their kin answer the same values, so the gate only
fixed a plan shape. The tests that pinned that shape now assert the
pairing and its answer instead, and two stale comments say what the kind
walk and the segment gate actually do.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): pin that a histogram pair reads both raw sources

With the pairing gate restored, the composed route still roots a Binary
with the same fills and columns, so the test passed either way. Assert
that each operand is an instant selection over its own raw source, which
only the single-node route builds.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-30 10:48:22 +00:00
dennis zhuang db03534e07 test(promql): share native test helpers and fixture parsing (#10749)
vector_match and select tests parsed the narthex-golden-vector fixtures with their own copies of the reference golden parser, and vector_match kept private copies of metric_of, labels_of, points_of, canonical_bits and close. Parse both fixture formats through grid_series::reference, share one float-field schema helper, and reuse golden::parse_metric in select. No production code changes.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-30 10:39:38 +00:00
dennis zhuang a8d50b4ee1 refactor(promql): walk native runtime children through one accessor (#10747)
Eight recursive passes over RuntimeNode each matched all twenty RuntimeOp
variants to reach the same four child shapes. They now go through
children()/children_mut(), and each pass keeps only its node-specific logic.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-30 10:38:48 +00:00
dennis zhuang 7b60bb66e7 refactor(promql): define each duplicated native rule once (#10748)
- Go math.Max/Min: ScalarFunction::apply calls map's go_max/go_min.
- kahan_inc: the aggregate kernel uses functions::kahan_inc.
- Range function names: RangeFunction::name() and without_arguments()
  replace the tables in display, range_eval/histogram, the native
  compiler and the golden test.
- by/without to kernel grouping: Grouping::{labels, names, kernel}
  replace the conversions in native aggregate, execute and plan.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-30 10:32:49 +00:00
dennis zhuang 9fc061d125 feat(promql): apply OTLP delta math per series in native rate and increase (#10673)
* feat(promql): pick OTLP delta math per series in native rate and increase

rate and increase over a table that carries otlp_aggregation_temporality
declined with delta_temporality_under_rate_or_increase. The existing
plan picks the math per series: a series marked "delta" holds
increments, so increase is the Kahan sum of the window and rate is
that sum over the range in seconds, while every other series keeps the
counter math.

A range evaluator of rate or increase over raw input now checks each
series' labels when it starts and evaluates a delta series with the
sum kernel, outside the batch path. A rate or increase that reads its
window directly is admitted; one that reads it through another
expression, a histogram field, or a range modifier still declines.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): cover offset and @ for native delta rate and increase

Pins the delta sum against the existing plan when the window is moved by
`offset` or anchored by `@`, and puts the misplaced doc comments of
`kernel` and `root_subquery` back on their functions.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* refactor(promql): decide batch eligibility for a delta window in one check

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-30 10:03:49 +00:00
Yingwen cd296475ba feat(mito2): group Narthex sample blocks within physical parts (#10712)
* feat(mito2): store Narthex samples in independently prunable groups

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito2): retain samples format version 1

Signed-off-by: evenyag <realevenyag@gmail.com>

* style(mito2): format grouped samples test helpers

Signed-off-by: evenyag <realevenyag@gmail.com>

* perf(mito2): streamline grouped Narthex samples and frame exact keys

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): validate key directory entry alignment

Signed-off-by: evenyag <realevenyag@gmail.com>

* perf(mito2): reuse continued keys and coalesce sample directory reads

Signed-off-by: evenyag <realevenyag@gmail.com>

* style(mito2): use crate-relative key page imports

Signed-off-by: evenyag <realevenyag@gmail.com>

* test(mito2): inline the raw key frame wire example

Signed-off-by: evenyag <realevenyag@gmail.com>

* docs(mito2): clarify grouped samples integrity and version policy

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-30 09:55:26 +00:00
Weny Xu 9b60ed4cc0 feat(index): align MG capacity with KLL and add indexed Puffin blob lookups (#10711)
* feat(index): configure frequent items and index Puffin footer keys

Signed-off-by: WenyXu <wenymedia@gmail.com>

* test(puffin): use fixed-size chunks in the window read benchmark

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-30 05:29:01 +00:00
jeremyhi 64b636e75c fix(mito2): hand a follower over while an earlier instance's tail replay runs (#10699)
* fix(mito2): hand a follower over while an earlier instance's tail replay runs

The worker now records the instance each running tail replay replays.
A running replay refuses a handover only if it replays the registered
instance and has not reported its end, so a follower opened after a
close no longer waits for the closed instance's replay; that replay's
edit never applies to the new instance (`apply_tails_edit` checks the
instance). One replay per region still runs at a time.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(mito2): restore two engine-level handover assertions

A handover whose request names no source fails before the log store
hands anything over and commits nothing; with the source named, a retry
hands the region over. A catchup again of a region that awaits its
Leader lease, carrying a reported entry, records no handoff floor and no
tail and replays this node's entries.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs(mito2): clarify handover replay wording from review

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-30 05:09:21 +00:00
Weny Xu a65e46855d fix(mito2): read committed compaction inputs during edit and alter (#10706)
Signed-off-by: WenyXu <wenymedia@gmail.com>
v1.4.0-nightly-20261130
2026-11-30 04:02:01 +00:00
shuiyisong 86a81cc91d fix: pre-encode sparse primary keys for exemplar and SQL writes (#10625)
* fix: pre-encode sparse primary keys for exemplar and SQL writes

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* fix: preserve sparse write guards and WAL policy

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* perf: skip sparse key decoding on initial routing

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* fix: preserve sparse primary key order across upgrades and repartitioning

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* fix: reject exemplar writes without destination preflight

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* test: compact sparse partitions before merging

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* fix: clippy

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* test(compat): drop git-commit version constraint

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* refactor: simplify sparse write and exemplar paths

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

* refactor: remove sparse key order check

Signed-off-by: shuiyisong <xixing.sys@gmail.com>

---------

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
2026-11-30 03:48:58 +00:00
Vishal Kotak 8934000c9c fix(mito): keep delete markers in time series memtable last_non_null dedup (#10717)
Signed-off-by: Vishal Kotak <vishal.sanjiv.kotak@gmail.com>
2026-11-30 03:41:19 +00:00
dayan02dev f8cec77262 fix(mito): keep deleted values out of flat last_non_null reads (#10726)
* test(mito): cover two puts older than a delete in flat last_non_null dedup

test_flat_last_non_null_strategy_delete_middle now has a second put
older than the delete at ts 3. Its field1 must not fill the null field1
of the newest put. This fails on main: the row reads back as (31, 33).

The merge_mode sqlness case deletes a row written by two puts and
rewrites it with a NULL field while another series sits in an SST. On
main the NULL reads back as the value from before the delete.

Signed-off-by: dayan02dev <pawarudayan92@gmail.com>

* fix(mito): keep the delete barrier across flat last_non_null merges

FlatLastNonNull::dedup_by_partitions returned only whether the last
range has a delete. When the buffered row and the next batch formed a
single range without a delete row, the barrier passed in from the
previous batch was used for that merge but not returned, so the next
put older than the delete filled the null fields again.

Signed-off-by: dayan02dev <pawarudayan92@gmail.com>

* docs(mito): note the inherited delete in flat last_non_null dedup comments

Signed-off-by: dayan02dev <pawarudayan92@gmail.com>

---------

Signed-off-by: dayan02dev <pawarudayan92@gmail.com>
2026-11-30 02:48:46 +00:00
Yingwen fe4c603ea8 refactor(mito2): retire Parquet series and range indexes (#10709)
* refactor(mito2): retire Parquet companion indexes and two-phase series scans

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): read native series files with SST lifetime pins

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): remove retired scan and cache plumbing

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): finish isolating Narthex scan preparation

Signed-off-by: evenyag <realevenyag@gmail.com>

* test(mito2): verify retries while a failed range reader is pinned

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito2): import the set used by Narthex partition filters

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito2): remove stale series scan errors and lint failures

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): centralize Narthex manifest paths

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito2): propagate per-series scan errors and account for buffered batches

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): use Narthex names for series-index maintenance

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): read Narthex samples through the owning SST handle

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito2): keep the original Parquet series distributor

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-29 01:15:25 +00:00
Yingwen c7752a3ce6 feat(mito2): show SST levels in verbose analyze output (#10713)
* feat(mito2): show SST levels in verbose analyze output

Signed-off-by: evenyag <realevenyag@gmail.com>

* test: update verbose scan expectations for SST levels

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-28 15:19:21 +00:00
Ömer 9aebf3a821 fix(delete): route deletes using partition columns on value-partitioned tables (#10710)
fix(query,operator): retain partition columns when routing delete requests

Preserve non-key partition columns across DataFusion DML delete projection and Deleter::trim_columns so RowSplitter evaluates partition expressions against the row's actual value rather than NULL, and cover trim_columns schema/row alignment in operator unit tests.

Fixes #10705

Signed-off-by: Ömer <60585342+zaidrain06@users.noreply.github.com>
2026-11-27 16:14:06 +00:00
Yingwen 2ce6a668c9 fix(mito): defer field filters for last_non_null scans (#10707)
Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-27 16:01:50 +00:00
Dragon Roar 2c6b951597 docs(rfc): propose an in-memory frontend write retry queue (#10045)
* docs(rfc): add a durable frontend write retry queue RFC

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): revise the durable write retry queue RFC

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): base the write queue TTL on a monotonic clock

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): make the write retry queue in-memory for v1

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): note ledger lock contention and rationale for queue defaults

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): narrow the in-memory retry queue design

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): bound replay memory with permits and answer review gaps

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): rename the retry queue RFC to match its in-memory v1 scope

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): shrink the retry queue record and derive its replay bound

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): scope write retry queue to in-memory core v1

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): revise the write retry queue RFC for review

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clarify retry queue outcome accounting and client timing

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): tighten retry queue lifecycle consistency

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): render retry queue flow as Mermaid

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix retry queue front matter and spacing

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): revise in-memory write retry queue proposal

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): finalize in-memory write retry queue design

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): align retry queue semantics and terminology

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): incorporate three enhancements into write retry queue design

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): refine retry queue admission, routing, and ordering semantics

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): Eliminate redundant descriptions

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): fix In-Memory Frontend Write Retry Queue rfc

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): Check for omissions and make up for deficiencies

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): Check for omissions and make up for deficiencies2

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): Check for omissions and make up for deficiencies3

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): refine in-memory frontend write retry queue design

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clarify RetryHint propagation, live-write ordering risks, and settlement validation

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clarify write retry queue ownership and replay semantics

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clarify Datanode compatibility and UNDROP replay risk

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clarify UNDROP identity validation

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): specify submission disposition and replay lifecycle

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clarify UNDROP replay and outage rollback

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clarify in-memory frontend write retry queue semantics

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): define replay attempt history and settlement precedence

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): address retry queue connection-timeout

Signed-off-by: lczllx <2181719471@qq.com>

* docs(rfc): clean up retry queue RFC

Signed-off-by: lczllx <2181719471@qq.com>

---------

Signed-off-by: lczllx <2181719471@qq.com>
2026-11-27 15:17:41 +00:00
Samarth Jaiswal 3be82bd956 fix: parse csv numbers from text for BIGINT UNSIGNED and with skip_bad_records in COPY FROM (#10643)
* fix: parse csv numbers from text for BIGINT UNSIGNED and with skip_bad_records

COPY FROM a csv file read a BIGINT UNSIGNED column with the inferred
type, so 9007199254740993e0 went through a Float64 and lost its last
digit, or turned into NULL when the column was inferred as a string.

With skip_bad_records the DECIMAL and BIGINT UNSIGNED columns were read
by Arrow's csv reader. It dropped the digits of a decimal beyond the
scale, returned 0.00 for some numbers in scientific notation, and
rejected 0e0 and unsigned integers in scientific notation, so those
records were skipped.

Both csv paths now read such a column as a string and parse it from
its text, like the json path does.

Signed-off-by: Samarth Jaiswal <samarthjaiswal30@gmail.com>

* fix: parse numbers for the table type with skip_bad_records

The skip_bad_records reader takes its column types from the table. The
columns to parse from text were still chosen by the inferred type, so a
BIGINT UNSIGNED column inferred as a boolean from a first value of true
went back to Arrow's reader, and a later 9007199254740993e0 was skipped.

Choose them by the table type there.

Signed-off-by: Samarth Jaiswal <samarthjaiswal30@gmail.com>

---------

Signed-off-by: Samarth Jaiswal <samarthjaiswal30@gmail.com>
2026-11-27 15:17:16 +00:00
Yvan Wang cdd7f13354 test(metric-engine): pin cancelling an add-column request while the physical alter is pending (#10679)
Holds the physical alter of a dropped add-column request in Mito with an
EventListener, so a request for another column deterministically reads
the same metadata, allocates the same column id, and is rejected once the
first alter lands. Asserts the InvalidArguments/NonRetryable outcome and
that a manual retry allocates the next id. No production change.

Closes #10377

Signed-off-by: Yvan Wang <131545713+BootstrapperSBL@users.noreply.github.com>
2026-11-27 15:16:03 +00:00
dennis zhuang 3fae53f153 refactor(promql): trim native PromQL comments and redundant tests (#10704)
* refactor(promql): trim native PromQL comments and redundant tests

Production code is unchanged: only comments change in non-test files.
Comments that restated code, narrated history, or cross-referenced other
comments are removed; comments that contradicted the code are corrected.
Tests that drove the same branch as a surviving test or golden case are
removed, and src/promql/AGENTS.md gains comment and test rules.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): preserve recursive map validation coverage

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): preserve empty-close and empty grouping coverage

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-27 15:11:46 +00:00
jeremyhi 3e4dc0b75e fix(mito2): keep a region open when a flush-on-close cannot flush it (#10689)
* fix(mito2): keep a region open when a flush-on-close cannot flush it

A close with `flush_on_close` whose region holds rows in its memtable but
cannot flush in its current state, for example a follower, used to skip the
flush and close the region anyway. It now fails with the retryable
`FlushableRegionState` error and leaves the region open, so the caller
retries and the retry flushes once the region can. The close reads whether
the region can flush once. Closes without `flush_on_close` are unchanged.

A metric physical region is reported by its data region, which closes first,
so once a close has closed the data region its metadata region keeps no lease.
A retry that finds the data region closed and the metadata region a follower
waives the requested flush of the metadata region. That close keeps the
region's unflushed rows that are in a WAL; a region without a WAL loses them,
as before this change.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs: state what a refused flush-on-close leaves to the caller

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-27 14:20:08 +00:00
dennis zhuang 15ca57ca20 fix(promql): publish legacy columns for native TQL in CTEs and flows (#10666)
* fix(promql): keep the native name column out of TQL CTEs and flows

The native rows layout always appends a per-row `__name__` column. The
Prometheus HTTP response reads it, but two SQL-visible consumers took it
as part of the statement's columns:

- A hybrid CTE published it after the existing planner's columns, so
  `WITH t (ts, val) AS (TQL EVAL ... metric)` failed with a column count
  mismatch on the native route.
- A TQL flow matched it against the sink table and failed with "found 4
  flow output columns and 3 sink table columns".

A CTE now publishes exactly the existing planner's columns over the
native plan. A TQL flow plans its query with the native route off, like
CREATE VIEW does, because its output columns are the sink table's schema
and the native route also names value columns differently.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(flow): plan TQL flows on the native route with the existing columns

The previous commit kept a TQL flow's sink schema stable by forcing the
existing PromQL planner. Plan it like a TQL CTE instead: run natively and
publish the existing planner's columns over the native plan.

`LogicalPlanner::plan_relation` plans a statement whose columns are read
by SQL. The CTE path and `sql_to_df_plan` both use it.

The standalone test harness now starts the flow consistency check task,
which `ADMIN FLUSH_FLOW` syncs with, so the flow test can run the flow
and compare the sink table and rows with the existing route's.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): pair per-series columns by role when a TQL CTE or flow runs natively

publish_legacy_schema paired the columns it could not match by name by
type alone, so a series with two string labels left both label columns
ambiguous and the statement fell back to the existing plan. Per-series
outputs such as rate(), topk(), offset binaries and label_replace() over
a table with more than one tag never ran natively in a CTE or a flow.

Pair the time index by its marker, labels by name, and the remaining
value columns in order, with the same casts as before.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test: start the flow check task only in the flow test

The standalone harness started the flow consistent-check task for every
instance. The task runs on the global runtime and holds the flow engine,
and nothing stopped it, so it outlived the instance and each rebuild
started another one. The harness now exposes the flow engine, and the
flow test that needs ADMIN FLUSH_FLOW starts the task and stops it.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): check a two-field TQL CTE keeps each value column

The native route pairs value columns with the existing ones by position.
Two fields with different values make a swapped pair visible.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* style: format the two-field CTE test

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(flow): key a TQL sink table on every label of the answer

The sink table of a TQL flow took its primary key from the innermost
aggregate when the plan had one. In `m / scalar(sum(m))` that aggregate
groups by time alone, so the labels of `m` were created as DOUBLE fields,
written as NULL, and every series collapsed into one row per timestamp.
The native route has no such aggregate and keyed on the labels, so the
two routes created different sinks for the same flow.

Every string column of a PromQL answer is a label of its output series,
so the sink now keys on all of them on both routes.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(flow): keep writing a TQL sink that has the native __name__ column

Before TQL flows were planned with `plan_relation`, a native TQL flow
auto-created its sink from the native plan's own columns: the value named
by that route, the labels, and `__name__` as a primary key column. The
relation plan publishes neither, so such a flow failed sink validation
and stopped writing.

When the sink has a `__name__` column, plan the statement with `plan`,
which is what these flows ran before. They keep writing the same columns
and the same `__name__` values: the metric name for a selector, NULL
where PromQL drops the name.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-27 12:13:15 +00:00
dennis zhuang c2a66803ff fix(mito2): read narthex tables partitioned on a non-tag column (#10665)
* fix(mito2): report one identity for a narthex series across regions

Prepared narthex reads with explicit labels prefixed each series key with
the region id. The prefix dates from when identity was the (table_id, tsid)
hash and kept colliding series in different regions apart. Since #10330 the
key is the exact sparse key, so the prefix protects nothing, but it still
gives the fragments of one series in two regions different primary keys.
SeriesRepartitionExec groups raw chunks by primary key, so those fragments
never met in one owner: native PromQL returned duplicate series or failed
with "input repeated an exact series identity" on a time-partitioned table.

Use the exact key as the only candidate key and drop the separate merge
key. The storage-api and raw chunk docs now require the identity to be the
same in every region instead of allowing a region-qualified one.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(mito2): filter narthex rows by a non-tag partition rule

A narthex scan applied the region's partition rule to series-index rows
during discovery. Those rows carry tags only, so a rule on any other
column, such as `PARTITION ON COLUMNS (ts)`, failed to compile against
them, and every read of such a region failed with "Failed to coerce
partition expr against the schema", in SQL and PromQL alike.

Keep series-level filtering for rules that reference tags only. Apply any
other rule to sample rows, with the series' own values for the tags the
rule references, since a file shared after repartition can hold rows of
both partitions within one series. Compaction reads without the region
predicate, so this filter is the only thing that keeps the other
partition's rows out of its output.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): check native reads of a time-partitioned narthex table

Every series of a narthex table partitioned on the time index is split
across two regions. Native PromQL over it, and SQL, must answer like the
same rows held whole in one default-storage region, standalone and
distributed. This covers both the partition rule on sample rows and the
region-independent series identity that lets the frontend merge the
fragments.

The promql guide no longer claims that a series split across regions is
not merged.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(mito2): value __table_id from the series in a sample partition rule

A partition rule that mixes `__table_id` with a non-tag column, which
repartitioning a metric table can produce, is evaluated on sample rows.
The filter looked `__table_id` up among the series' tag values, where the
series index never puts it, so every read of such a region failed with
"missing partition tag". Take it from the series' table ID instead.

The time-partition test now also covers a tag + time rule and a
`__table_id` + time rule.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): say which sample conflicts across regions and why

A raw merge that finds two different samples of one series at one
timestamp now names the series and the timestamp, and gives the likely
cause: a table partitioned on a non-tag column, with the sample written
on both sides of a partition bound, so each region kept one version.
Behavior is unchanged; the query still fails.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-27 12:10:37 +00:00
dennis zhuang 8c861ced8b fix(mito2): apply time predicates before last-row selection on narthex reads (#10664)
* fix(mito2): apply narthex time filters before row selection

Narthex prepared reads applied every predicate conjunct after the merge,
where a LastRow selector had already kept one row per series. A time
predicate that is not a plain range (`ts != x`, `ts IN (..)`) then
rejected the selected row and the series disappeared, while other formats
return the newest matching row.

Time-only conjuncts commute with dedup on (series, time), so run them on
each sample source before the merge and keep the rest after it.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* docs(mito2): note why hoisted time filters are never volatile

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-27 10:24:53 +00:00
discord9 fea71143b2 test(perf): cover short series and enforce the native PromQL route (#10523)
* test(perf): add a short-series case and widen the native-eligible query matrix

Signed-off-by: discord9 <discord9@163.com>

* test(perf): register the short-series case in the heavy set

`many_short_series` (100,000 series x 8 samples, 8 SSTs) is the same size
class as the high-cardinality cases that already live in `HEAVY_CASES`: the
per-series setup dominates, and the self-hosted runner has been lost on
fixtures of this size before. Leaving it out of both lists meant nothing ran
it; putting it in the routine set would charge every PR regression for it.

Register it in `HEAVY_CASES` (so `/query-regression heavy` and the
`heavy` workflow-dispatch token select it) and describe the case next to the
other heavy ones in `tests/perf/README.md`.

Signed-off-by: discord9 <discord9@163.com>

* test(perf): fix the short-series case's comments and heavy selection

The case measured shapes whose comments described other shapes: the plain grid
does not cover the offset/pinned/host-filtered queries, `[10m:1m]` holds ten
aligned inner points per left-open outer window (not eleven, so two outer points
are twenty inner evaluations), and the #7913 subquery uses a five-minute inner
step rather than a one-minute one. The README also said the short case rewrites
`__name__`; it rewrites `dst`.

Registering the case in `HEAVY_CASES` also left `test_heavy_selects_the_heavy_case_set`
red, because its expectation still listed three paths; add the fourth and bring
the README's heavy description in line with the four-case set.

Signed-off-by: discord9 <discord9@163.com>

* test(perf): fail a perf case that silently measures the legacy PromQL route

The native PromQL route is off by default and declines a query it cannot take
by returning `None`, which the planner turns into the legacy plan without a
word. A perf case that means to time the native route therefore timed legacy
whenever the hint was absent, and nothing in the report said so.

A query now declares `require_native = true` on a `TQL ANALYZE ... FORMAT JSON`
statement. The runner parses the statement with the SQL parser to keep a
commented-out keyword or a look-alike `SELECT` from standing in for it, states
`query.experimental_native_promql=true` in the request hints on both targets,
and runs the same statement once per target before warmup. That response's
`plan` cells are JSON plan trees; the assertion walks their `children` and
reads only node `name` values, because a node's `param` carries the rest of its
plan line, where a label value or a filter can spell anything. A name of
`FusedSeries` or `FusedSeriesExec` (as a whole word) keeps the query; anything
else records a `validation_errors` entry naming the case, query, and target,
reports no benchmark measurement for it, and fails the run. Declaring the flag
on any other statement is a configuration error reported before either target
is contacted, because only that form answers the plan of the query being timed.

The structured form is required because text plan lines can start with a label
value: only the tree is evidence. Cases without the flag send the requests they
sent before, which a test pins by comparing the built headers.

Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit 792d8cfbf05ca352d3a915cf40036a0219651970)

* test(perf): reject a prom_http query that only looks like a TQL analyze

`require_native` is checked against the statement text, so a `kind = "prom_http"`
entry carrying a `TQL ANALYZE ... FORMAT JSON` string passed the pre-flight
check and was then posted to the Prometheus range endpoint, which answers no
plan tree: the run failed as a request error instead of the configuration error
the docs promise. Reject the kind explicitly and cover that exact combination.

Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit 868b474027b58602174a8aedca316d9d5c54a08e)

* test(perf): assert the native route in the new native cases

The 19 short-series queries and the six queries added for the remote-write
case's eligible table now declare `require_native` and are measured as
`TQL ANALYZE VERBOSE FORMAT JSON`, so the runner proves from the JSON plan
tree that each one ran on the fused-series route before its latency counts.

The three selectors on the `TIMESTAMP(9)`/`append_mode` table keep plain
`TQL ANALYZE VERBOSE` and no flag: that table can never route natively, so
requiring the route there would fail the run by design.

Signed-off-by: discord9 <discord9@163.com>

* test(perf): fold two rate points per outer step in the subquery case

At a one-minute inner step the first outer evaluation of
`max_over_time(rate(m[5m])[10m:1m])` saw a single raw sample in its rate window
and the second folded one valid rate point, so the subquery's fold was barely
exercised. At thirty seconds both outer points fold two valid rate points, and
the comment states the new arithmetic: twenty aligned inner points per outer
one, forty inner evaluations in total.

Signed-off-by: discord9 <discord9@163.com>

---------

Signed-off-by: discord9 <discord9@163.com>
2026-11-27 10:07:53 +00:00
dennis zhuang 95e69f80c3 fix(promql): plan a float function over a split native histogram sum (#10663)
fix(promql): declare float columns for a float function over a split histogram sum

`histogram_count(sum(h))` and `histogram_quantile(0.9, sum(rate(h[2m])))`
over native histograms failed to plan on the native route: the split
counted the statement's value columns by the type of the exported state
(a histogram), while the columns carry the root's kind (Float), so it
counted zero and returned a plan error. Count value columns of either
value type; the layout declares one kind for all of them.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-27 09:19:22 +00:00
jeremyhi 34cddcabaa feat(log-store): list the regions that hold unreleased object store WAL entries (#10687)
* feat(log-store): list the regions that hold unreleased object store WAL entries

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs(log-store): say where the bound of the unreleased regions comes from

The bound is the largest entry id the store has ever indexed: the catalog
keeps it after the object that held it is removed. The test comment now
describes what its assertion shows.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-27 09:11:15 +00:00
dennis zhuang 01523bec3d fix(promql): treat equal histogram start timestamps as no reset (#10660)
* fix(promql): treat equal histogram start timestamps as no reset in native route

Prometheus isStartTimestampReset returns false when the previous and
current samples carry the same start timestamp, before any other check.
The native rule skipped that check, so two samples whose shared start
timestamp is later than the earlier sample (which remote write v2
accepts) were counted as a counter reset: resets() answered 1 instead
of 0 and increase()/rate() added the earlier value back.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): share the start-timestamp reset rule between routes

The legacy planner still read two samples sharing a start timestamp later
than the earlier sample as a reset, so resets() answered 1 there and 0 on
the native route. Both routes now call one rule that follows Prometheus
isStartTimestampReset.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): pin a bucket drop under an unchanged start timestamp as a reset

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-27 08:51:39 +00:00
jeremyhi d88f5da7bb fix(meta): check for a follower on the migration target before opening the candidate (#10684)
* fix(meta): check for a follower on the migration target before opening the candidate

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* refactor(meta): propagate route errors in the follower check on the migration target

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-27 08:51:07 +00:00
dennis zhuang 8d4e9464d9 feat(mito): store native histograms in narthex samples (#10667)
* feat(mito): store native histograms in Narthex samples

A physical table whose single value field is the canonical
greptime_native_histogram struct can now use sst_format = 'narthex'.

The samples format gets column encoding 8, which lays out a block's
histogram field child by child: each struct child is encoded with the
nullable XOR codec of encoding 5, integers ZigZag-mapped, and a list as
its nullable lengths followed by its flattened items. The chunk header
names the child count and child kinds, the manifest records the field
type as "native_histogram", and a block whose field chunk encoding does
not match its manifest type is rejected. Writers and bulk memtable
parts cut a block before a histogram chunk's size bound would pass the
1 MiB chunk limit, and a Narthex region rejects a sample that cannot
fit one chunk before accepting the write.

The prepared columnar reader now serves histogram fields, so native
PromQL raw scans read Narthex histogram regions; float-only projections
still skip histogram chunks.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(mito): cover Narthex histogram bulk limits and sidecar reads

Add tests for paths the histogram change relies on but no test pinned:
the bulk write path refusing an oversized histogram sample before WAL
and memtable, the bulk memtable splitting large histograms into blocks
whose chunks stay within the samples chunk limit, and native PromQL
reading histograms from a columnar series-index sidecar on a Parquet
metric table, compared with the plain Parquet answer.

Also wrap three long lines in the samples format doc.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* docs(mito): state that the block size formula does not bound histogram buffers

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(mito): release read-ahead before failing a histogram reservation

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* docs(mito): pin the native histogram chunk layout and child order

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(mito): check bulk histogram sizes after filling missing columns

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-27 08:05:30 +00:00
discord9 1819183c51 fix(mito2): treat a primary key order change as incompatible (#10326)
fix(mito2): treat a primary key order change as incompatible (#10248)

`has_same_columns_and_pk_encoding` compared the primary key encoding but not
the primary key order itself, so an SST encoded with another key order could
be merged as if the keys were identical. Deduplication compares the encoded
key bytes, so such rows are not deduplicated and COUNT/SUM silently drift.

Compare `primary_key` as well and route an order change through the compat
path, where `is_primary_key_same` rejects it loudly. The compat reader cannot
reorder a key - it can only append missing tags or rewrite the encoding.

The `TableMeta::add_columns` half of the original report is already
implemented on main (the key keeps its order and new key columns are appended
in request order), so this change keeps only the remaining gap.

Signed-off-by: discord9 <discord9@163.com>
2026-11-27 07:33:11 +00:00
jeremyhi 951dd733b7 feat(mito2): hand a region over from its source without replaying in catchup (#10641)
* feat(mito2): hand a region over from its source without replaying in catchup

A catchup that makes a region writable and carries the last entry id its
source reported, on a region whose manifest is published conditionally,
now hands the region over instead of replaying any WAL:

- It refuses a region with rows in its memtable with a retryable error,
  since the handoff floor would skip their entries and a reopen would
  drop them. Other regions still reopen as before.
- It hands the region over to the log store once, with a bound covering
  the reported entry, the flushed entry id and every pending tail.
- Its catchup commit records this node's handoff floor (that bound) and,
  when the source has entries after where the manifest recovers its WAL
  from, a reported tail of the source over them, raising the committed
  sequence by 2^40 so writes accepted during the background replay
  outrank the replayed rows. The edit applies to the region's version
  under the manifest lock, before the region is promoted.
- It then releases this node's WAL up to where the region now replays
  it, keeping this node's pending tails.

If the source has such entries and the request names no source, the
catchup fails without committing. The datanode takes the source from
`UpgradeRegion::location_id`, which the metasrv already sets to the
region's previous leader; the metric engine passes it to the data region
only, since it loads the logical tables from the metadata region when
the catchup ends.

Other catchups replay this node's WAL after the manifest's replay start,
which includes this node's handoff floor, and release it capped by this
node's pending tails, as an open does.

While a region is in a catchup, a manifest sync and a follower's
skip-WAL option change are refused with a retryable error.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): apply a handover's edit on the region worker

The catchup task commits a handover outside the worker and sends the
committed edit to the region worker, which applies it in order with the
edits of flushes and compactions, seeds the node lease and promotes the
region. If the instance was replaced or stopped meanwhile, the worker
ends the catchup and clears its registration; a task outside the worker
then releases this node's WAL up to the committed manifest's replay
start and replies RegionNotFound.

A handover is refused while the region's tail replay has not reported
its end, and the worker reads whether the manifest is published
conditionally without taking the manifest lock. The refusals of a
manifest sync and a follower's skip-WAL change follow the instance in a
catchup, or a fenced instance while a catchup or reload is registered,
so a follower opened after a close is not refused for its predecessor's
catchup; a sync applies them before and after its role check.

The handover tests are cut, merged and share their support code.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-27 07:08:08 +00:00
Weny Xu fa11a2fea1 fix(mito2): allow table compaction publication after adding nullable sparse tags (#10681)
* fix(mito2): allow table compaction publication after adding nullable sparse tags

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(mito2): publish table compaction across schema changes

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 06:18:06 +00:00
discord9 bceb12f71b perf(promql): look the routed identity up once per message (#10549)
`RepartitionStream::poll_next` searched the pending-group map three times for
the same identity on every drained message: `contains_key`, then `insert`, then
`get_mut`, with no mutation in between. One `BTreeMap::entry` does the same work
once and moves the key into the tree instead of cloning it.

The charge stays strictly before the insert: the vacant arm registers and calls
`try_grow`, and the group only exists when that succeeded, so a refused pool
still leaves nothing behind. The entry is confined to one block because
`OccupiedEntry` is not `Drop`, so the failure path can call `lease.fail` after
the borrow ends. Duplicate detection, the ordered rescan, the `KeyThenTime`
watermark and the accounting are untouched.

Why this one: profiling (`perf report --no-inline`, 5 s, 999 Hz) puts B-tree
comparison at 9.84% of samples on `topk_5_rate_5m` and 8.94% on
`sum_by_host_ratio_ignoring_instance`; only the two redundant searches go away,
so the realisable saving is below those ceilings, and on `rate_5m` the same
comparison is 0.08%, i.e. nothing.

Signed-off-by: discord9 <discord9@163.com>
2026-11-27 04:48:39 +00:00
Weny Xu 59b108af84 fix(procedure): recover from the last readable checkpoint (#10612)
* fix(procedure): recover from the last readable checkpoint

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(procedure): keep unreadable checkpoints out of GC checks

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(procedure): use the SNAFU selector for corrupt checkpoints

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 03:45:22 +00:00
discord9 9abcdd7af3 fix(table): do not extract time range from mixed IN lists (#10357)
A time-index IN list containing a non-literal item was narrowed to the
envelope of its literal items. The non-literal item can match any
timestamp, so the scan could prune rows that satisfy the predicate.
Abandon the whole IN unless every item is a literal; all-literal lists
keep the existing envelope behavior.

Signed-off-by: discord9 <discord9@163.com>
2026-11-27 02:36:11 +00:00
discord9 0127d63865 fix(mito2): require a region to own its files before a remap (#10646)
* fix(mito2): require a region to own its files before a remap

A remap (split or merge) moves file references between regions. Today mito2 checks
only that the inputs come from the same table, so a merge can be applied while a
participant still holds files another region created; a later compaction then
materialises a copy of the same rows and both references survive the file-id
dedup, so the merged region reads those rows twice.

Reject such a remap instead: every participating region must hold only files whose
creation expression equals that region's own partition expression. The error names
each offending (region, file, creator expression) so the caller can compact the
region and retry. A one-source-to-many-targets split is exempt: no target combines
file sets there and the region predicate keeps a split's rows apart.

This trades a merge-time error and a compaction for the per-reference row range
that #10616 adds.

Signed-off-by: discord9 <discord9@163.com>

* fix(mito2): treat a file without a recorded creator as the region's own

Files written before the partition expression was recorded carry no creator, so
their provenance cannot be established and the read path does not narrow them
either. The merge guard compared such a file against the region's expression and
rejected it, which would break the first repartition of an upgraded table.

Also state the remedy as it is: the operator aborts the repartition, compacts and
retries; nothing triggers that compaction automatically, and a region in a staging
session is skipped by the compaction scheduler, so the abort comes first.

Signed-off-by: discord9 <discord9@163.com>

* fix(mito2): report only the region and file that a merge must settle

The refusal does not need to restate either partition expression: the operator acts
on the region, and no production caller parses the message. Drops the expression
rendering and its now unreachable None arm.

Signed-off-by: discord9 <discord9@163.com>

* docs(mito2): drop the comments the trimmed diagnostics left behind

Removes the orphaned renderer doc, stops the unit-test comment from promising
creator diagnostics, describes the error payload as it is, and corrects the claim
that a creator-less file is not narrowed on read.

Signed-off-by: discord9 <discord9@163.com>

* fix(mito2): reject an unstamped file on merge, and bound the refusal message

An unstamped SST can still hold rows of both children of an earlier split, so
letting it through a merge re-admits the duplicate: both children inherit it, one
compacts into its own file, and the merged region then holds the same rows under
two file ids. A split stays exempt, so an unstamped table can still repartition;
its regions materialise (compaction stamps the output) before merging.

Lists at most eight offending files and counts the rest, so a wide table cannot
produce an unbounded message.

Signed-off-by: discord9 <discord9@163.com>

* fix(mito2): check merge ownership before the target routes are published

The remap-time guard fires while fetching manifests, which the procedure does after
UpdateMetadata::ApplyStaging has published the target write routes: a reused target
can acknowledge a write that the rollback then routes elsewhere, and the row is
flushed later under the old expression. Move the decision ahead of publication.

Every incoming edge to ApplyStaging now asks each merge source leader, through
RemapManifest with a validate-only flag, whether every file it holds records its own
expression; the check reads the ordinary manifest, writes nothing and leaves the
region out of staging. A refusal therefore keeps the old routes in force. The flag is
serde-defaulted, so an older datanode ignores it and its ordinary remap is refused
because the region is not in staging - a failure, not a silent pass. The remap-time
guard stays as the second line of defence.

The failure now reaches the SQL caller with the offending region and file: Collect
keeps the sub-procedure errors instead of only their counts.

Signed-off-by: discord9 <discord9@163.com>

* fix(meta-srv): keep the refusal's cause and its retryability

Collect formatted the child failure with Display alone, so ProcedureExec's "Failed to
execute procedure" hid the region and file the operator needs; render the whole source
chain instead, and assert in the test that the parent error names a known region and
file.

A mailbox timeout on the pre-publication check became a terminal "compact the region"
error, although metasrv treats the timeout as retryable. Propagate anything whose
retry hint is retryable, and build the offender list - and its compaction advice - only
from non-retryable failures.

Signed-off-by: discord9 <discord9@163.com>

* fix(mito2): use one predicate for merge ownership at both stages

Preflight skipped every single-source group, while the remap guard exempted only a
one-to-many mapping: a one-to-one repartition could therefore be refused after the
target routes were published. Both stages now read the same rule from the persisted
mapping - a group needs the check iff some target is fed by two or more distinct
sources - expressed once in store-api and used by the preflight and by is_split.

A one-to-one repartition hands its target one source's files and combines nothing, so
it is exempt at both stages instead of being refused late.

Signed-off-by: discord9 <discord9@163.com>

* test: materialise before merging in the repartition integration tests

Both tests merge regions that still reference an SST written by an ancestor, which the
merge guard refuses. Compact with the strict-window mode first - it rewrites even a
lone inherited file - and keep the merges they were written for.

Signed-off-by: discord9 <discord9@163.com>

---------

Signed-off-by: discord9 <discord9@163.com>
2026-11-26 15:27:47 +00:00
Weny Xu 5cd42ef86b fix(mito2): make table compaction publication retries idempotent (#10651)
* fix(mito2): make table compaction publication retries idempotent

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(mito2): allow table compaction publication across region option changes

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(mito2): preserve exact sequence reads across table compaction publication

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(mito2): guard mixed compaction inputs after sequence preservation is enabled

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(mito2): check sequence policy before verifying compaction outputs

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-26 15:24:59 +00:00
Yingwen 13442db700 feat(mito): compact native series indexes within a coverage window (#10649)
* feat(mito): compact native series indexes within a coverage window

Signed-off-by: evenyag <realevenyag@gmail.com>

* test(mito): allow destination index maintenance after remap

Signed-off-by: evenyag <realevenyag@gmail.com>

* docs: keep index scheduling policy out of the format spec

Signed-off-by: evenyag <realevenyag@gmail.com>

* docs(mito): clarify the scope of native format specifications

Signed-off-by: evenyag <realevenyag@gmail.com>

* style(mito): use a crate-rooted path for the balance predicate

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): merge adjacent index watermarks and rotate past unusable groups

Signed-off-by: evenyag <realevenyag@gmail.com>

* test(mito): type window timestamps as milliseconds

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): skip incompatible merge groups and reject stale invalidation

Signed-off-by: evenyag <realevenyag@gmail.com>

* perf(mito): read exact series keys directly from columnar dictionaries

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): rotate after failed index writes and propagate lazy read errors

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): discover series from samples when a window index read fails

Signed-off-by: evenyag <realevenyag@gmail.com>

* style(mito): use crate visibility for series discovery

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-26 13:00:13 +00:00
discord9 e8eb093b72 fix(mito): refresh the removed-file count when GC clears its records (#10636)
Clearing deleted files from the manifest does not commit a manifest version,
and the count reported to metasrv was only recomputed on open, create, commit
and checkpoint. A region that goes write-idle after a GC pass therefore kept
reporting the files GC had already deleted, indefinitely.

That stale count feeds the GC score, so such a region kept winning a candidate
slot on a table while it had nothing left to reclaim, and a region with real
garbage behind it could stay outside the top-N.

Recompute the count at the clearing site, exactly like the other five places
that change removed_files. The read path is untouched: region_statistic still
loads one atomic.

Signed-off-by: discord9 <discord9@discord9.com>
2026-11-26 10:23:01 +00:00
dennis zhuang c887958b03 Merge commit from fork
Add query.remote_allowed_hosts and query.allow_server_credentials to
frontend, datanode and standalone.

- query.remote_allowed_hosts: when set, object stores built from SQL
  statements send every request, including credential requests, through an
  HTTP transport that only allows the listed hosts and does not follow
  redirects. Blocked requests are logged with their host and port.
- query.allow_server_credentials = false: an object store without
  credentials in its connection options cannot use the server's own
  credentials.

Independent of the options, explicit credentials are validated: incomplete
S3/OSS key pairs, an S3 session token without keys, an Azure account key
without a known account name, and a GCS credential that is not a service
account key are rejected. Only the type, private key and client email of a
GCS service account key are passed to the signer.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-26 18:40:08 +08:00
Yingwen 82dec23d17 fix(query): prune logical metric scans by table ID (#10645)
* fix(query): prune logical metric scans by table ID

Signed-off-by: evenyag <realevenyag@gmail.com>

* perf(query): skip redundant single-region metric pruning

Signed-off-by: evenyag <realevenyag@gmail.com>

* perf(query): skip table ID pruning for tag-only metric routes

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-26 08:54:30 +00:00
jeremyhi 4a95c6bb9d fix(mito2): run the work held back by the Leader lease wait once the region can run it (#10618)
* fix(mito2): retry the work held back by the wait for a Leader lease

A region that a catchup made writable waits for its Leader lease before it
commits. When the lease ends the wait while the region is staging, in a
change or not a leader, the missing-index pass, the index build retries the
wait refused and the save of the backfilled partition expression were
dropped, and nothing ran them later.

Keep that work per region in the worker (`deferred_lease_work`) until the
region is a writable leader with its lease. Every path that makes it one
runs it: the end of an ALTER, an edit, a failed EnterStaging, a truncate or
discard (after the index build scheduler retires its queued builds), the end
of staging, a failed drop, a failed close-time flush, and a promotion
outside the worker, which now notifies the worker on an actual transition
into a writable leader only. A backfill save that finds the region in
another state, such as a change the worker started after spawning it,
reports back and the worker defers it. Close and drop remove the work.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): keep deferred lease work across role changes and late reports

A refused index build retry stays due until the region is a writable leader with its lease; the backfill save checks the state once under the manifest lock; a deferral reported by a closed or dropped instance adds no work to a later one; tests replace sleeps with hooks and cover a failed close-time flush.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): keep deferred lease work a role change stops while it runs

An index build retry that a role change outside the worker stops in the scheduling loop stays due, and a missing-index pass that the region's state stops puts the whole deferred work back instead of ending with the save.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): keep a refused retry where its region's state refuses it

Each state check of an index build retry keeps the retry it refuses, so no separate earlier check can disagree with it; a promotion outside the worker notifies it from the state the role change actually replaced; the test gate moves to test_util.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(mito2): cover an index build retry refused by a follower or staging region

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): end the lease wait a direct promotion counts as a lease

A direct conversion to Leader records a Leader lease; the end of the wait it may cause now reaches the worker, which runs the work the wait held back.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* refactor(mito2): run deferred lease work from one sweep after each batch

The worker sweeps its deferred work after a batch that may change a region's state, instead of from each handler that makes a region writable. An entry records which of the missing-index pass, the backfill save and the index build retries are due, so a refusal unrelated to the lease records only its retry, and a kept retry's callers are answered at once.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(mito2): keep one deferred lease work test per kind of transition

With one sweep after each batch, the completion-point cases tested the same mechanism through different handlers; the redundant cases are dropped, and a test checks that a deferred backfill save does not re-run the missing-index pass.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(mito2): read Promotion in the candidate demotion test

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* fix(mito2): run the work a lease wait held back after its batch

The end of the wait only records the work; the sweep after the batch runs it, after whatever the same batch dispatched, such as a truncate or an ALTER.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(mito2): check the stopped missing-index pass with a refused request

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* test(mito2): keep a refused retry through a catchup replacement

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* refactor(mito2): sweep deferred lease work after every batch

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs(mito2): rewrap the doc of notify_if_became_writable

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

* docs(mito2): say where the deferred lease work sweep allocates and why the entry is put back whole

Signed-off-by: jeremyhi <fengjiachun@gmail.com>

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-26 08:11:34 +00:00
Yingwen 686005c2c9 feat(mito): build native series indexes with certified time-window coverage (#10615)
* feat(mito): stream exact sample keys into native PoC series files

Signed-off-by: evenyag <realevenyag@gmail.com>

* feat(mito): evaluate native series window frontiers in the pinned scan

Signed-off-by: evenyag <realevenyag@gmail.com>

* feat(mito): publish native window builds through serialized region edits

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): validate full index coverage across publication and recovery

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): repair incompatible native indexes and isolate sidecar capacity

Signed-off-by: evenyag <realevenyag@gmail.com>

* test(mito): fill the sidecar budget in native repair coverage

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito): remove source file IDs from native series indexes

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): release memtable snapshots before native index I/O

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): preserve local sidecar source list encoding

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): expose Narthex series entry to production writer

Signed-off-by: evenyag <realevenyag@gmail.com>

* feat: build incremental Narthex series indexes from manifest coverage

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): reuse series indexes across compatible schema changes

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito): simplify native series index coverage and publication

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito): require a window for native series indexes

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito): remove tag rename handling from series index reads

Signed-off-by: evenyag <realevenyag@gmail.com>

* feat(mito): batch native series index builds by uncovered file count

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): configure the native series index file threshold via TOML

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-26 05:16:09 +00:00
Alex Castillo González 83dd79491a fix: honor LIMIT when copying a table to a file (#10639)
* fix: honor LIMIT when copying a table to a file

Signed-off-by: Alex <alex.castillog33@gmail.com>

* test: verify zero-row COPY CSV output

Signed-off-by: Alex <alex.castillog33@gmail.com>

* style: format COPY LIMIT regression setup

Signed-off-by: Alex <alex.castillog33@gmail.com>

---------

Signed-off-by: Alex <alex.castillog33@gmail.com>
2026-11-26 04:27:18 +00:00
Weny Xu d96699c104 fix: skip inactive datanodes during inspection and expire stale registrations (#10630)
* fix(metasrv): cap idle datanode registration retention at one minute

Signed-off-by: WenyXu <wenymedia@gmail.com>

* fix(metasrv): derive datanode registration retention from the lease

Signed-off-by: WenyXu <wenymedia@gmail.com>

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-26 02:18:57 +00:00