Commit Graph
6767 Commits
Author SHA1 Message Date
WenyXu 8d92d710ef chore(deps): pin rebased sketch proto branch
Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:19:12 +00:00
WenyXu a1947edecf fix(mito2): adapt PoC integrations to upstream metadata sharing
Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:19:12 +00:00
WenyXu 26d1c0a11f feat(puffin): batch uncompressed blob reads with a byte budget
Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:19:12 +00:00
WenyXu 495aa8ed95 fix: fence reads across repartition data handoff
Reject query planning during repartition handoff and keep new targets pending until all manifests have been applied. Carry planned partition versions to datanodes and validate the pinned scan snapshot, including retiring merge sources. Preserve retryable read errors and cover cached routes, transport, metric mapping, and scope changes.

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:19:12 +00:00
WenyXu a77c5c1b32 fix: defer reads from repartition targets until metadata is ready
Hide newly allocated targets until logical-region metadata synchronization completes. Refresh cached pending routes from authoritative metadata and stop staging entry when cache invalidation fails. Cover route persistence, allocation replay, rollback, stale caches, and failure paths.

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:18:50 +00:00
WenyXu cc25156bea feat(sketch): expose deterministic file sampling over region RPC
Add optional file-sampling requests and unscaled sample diagnostics, validate limits, and preserve the fields through region RPC conversion. Pin the published proto revision in the standalone OSS workspace; retain Cargo-generated lockfile dependency-edge normalization.

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:18:50 +00:00
WenyXu 0dea53971f feat(sketch): expose metric table sketches through region RPC
Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:18:50 +00:00
WenyXu 21502416a0 fix(metric): route sparse primary keys during partitioned ingestion
Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:18:01 +00:00
WenyXu b9006fe4a0 feat(mito2): expose Region-bound sketch readers
Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:18:01 +00:00
WenyXu 3e0ab794b1 feat(storage): define in-process sketch reader contracts
Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-27 12:18:01 +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
discord9 51082c6d4e feat(promql): answer the shapes the native route refused for want of a rule (#10611)
* feat(promql): answer the shapes the native route refused for want of a rule

Three refusals in the native fused route were admissions, not missing
capability. Each is answered here against main's own structure.

**Grouping by `__name__` over several sources.** A tree reading more than one
named source could not report the label a `by (__name__)` keeps, because only a
discovered source declared it. Every metric-bound input now declares its name as
a source tag when the tree reads more than one, and the two refusals that
guarded this - in the planner and in `segment_tree` - are gone with
`groups_by_metric_name`.

**A `__field__` matcher over an input with no table.** The matcher names the only
field layout such an input can declare, so it answers an empty frame of that
field. An operator other than `=` stays refused: it asks what set of fields the
tables carry, and there is no table to ask.

**A canonical merge over a partitioned table.** `per_source_inputs` now covers
`any_partitioned && contains_canonical_merge`, so the boundary's producer runs
above the regions and reads a raw-series source instead of a bare scan, which is
what the distributed planner already does.

Two smaller rules complete the kind walk: `output_field_kind` covered Window,
Instant, Map, Binary and Aggregate and fell through for the rest, so a statement
rooted at a vector operation, `info` or a parameterized map named no kind at all
- each answers a kind already written one arm away, and the catch-all is gone so
a variant added later has to be classified. A comparison between two different
kinds produces no sample (`elem_binop` skips it), so its column is the empty
float layout the arithmetic arm already names.

Finally, a value field is classified by what the raw series scan produces rather
than by its catalog type, and admitted where the statement's shape makes the
existing planner publish `Float64` for it too: arithmetic, `min`/`max`, the
float-answering aggregates and the range functions whose value window is a
float. A `BIGINT` table's `sum(m)` and its bare `m` stay refused - DataFusion's
`sum` answers `Int64`, and a bare selector copies the column's own type, so
admitting either would publish a column the existing plan publishes differently.

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

* test(promql): pin a whole-vector operator standing on an aggregate

The kind walk now names what a vector operation answers, so a ranking over an
evaluated aggregate plans on this route - and the split declines it, which keeps
the route rather than losing it: `split_aggregate` answers `None` and segmentation
takes the whole statement.

Both facts are load-bearing enough to pin. The plan-level test asserts a fused
node and no final split for `topk`, `bottomk`, `limitk`, `limit_ratio` and
`sort` over an aggregate, with a bare-scan control; the integration test compares
the rows the two routes answer for the shapes both of them can run, and inspects
the plan that actually executed to confirm the ranking sits above the evaluated
input.

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

* fix(promql): an integer fold is not a float once something casts it

The numeric admission asked what type the existing plan publishes for a field,
and read every arithmetic operator as publishing `Float64`. That is true of the
operator, not of what it wraps: `sum(v) * 1` over `BIGINT` sums the integers
first and casts afterwards, so `9007199254740993` and `-9007199254740992` answer
`1.0` there, while the raw scan casts each value before summing and answers
`0.0`. Admitting that shape would have answered a different number.

An arithmetic operator now publishes a float only when the fold under it does
too. `sum(int_field) * 1`, `sum(int_field) + 1` and `count(m) + 1` keep the
existing plan; `sum(rate(m[5m]))`, `m * 2` and the aggregates that answer a float
of their own stay native.

The series-scan preflight refused the raw path for every field of an ordinary
table whenever the store was configured columnar, and nothing above could turn
that refusal into a fallback, so a query `main` answered with 40 became a planning
error. Only the prepared columnar reader is gated now: a table whose region needs
preparation keeps the refusal, and one that merely lacks columnar coverage is
served by the ordinary scan.

The test that pinned the error is replaced by one that pins the answer: a
columnar-configured store over ordinary `INTEGER` and `FLOAT` tables answers
`sum_over_time` and `avg_over_time` from the ordinary scan, equal to the existing
route.

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

---------

Signed-off-by: discord9 <discord9@163.com>
2026-11-25 18:18:25 +00:00
dennis zhuang 3ce70bdf57 fix(mito2): release write buffer memory that bulk memtable encoding saves (#10565)
* fix(mito2): release memtable memory that encoding parts saves

BulkMemtable counted every written batch against the write buffer and kept the count after merging parts into encoded parts, which hold a fraction of those bytes. Flushes fired long before the memory limit. Merges now release the bytes they save through AllocTracker::on_deallocation, which keeps the mutable and total write buffer usage consistent with freezing.

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

* docs(mito2): drop a stale comment on install_merged_parts

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

* fix(mito2): account bulk memtable part replacements in both directions

Merging can install parts larger than the ones it removes, and sealing
small writes replaces the buffered fragments with one sorted part.
Track both as replacements so the allocated bytes match the held parts.

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

* fix(mito2): keep bulk memtable data charged until its last reader drops

Charge each part of a bulk memtable through a MemoryCharge that the
memtable and the ranges reading the part share. Replacing parts by a
merge, or dropping a flushed memtable, releases the write buffer
budget only after scans that still read the old parts finish. The
memtable statistics report the parts it holds.

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

* fix(mito2): keep charges with memtable iterators and wake workers only when needed

Iterators and encoded data built from a bulk memtable range now hold the
part's charge, since flush drops its ranges before reading them.

A memtable now releases its parts one by one, so release_mem frees
memory without waking every worker unless writes may be stalled on the
global limit. Dropping the tracker still wakes them once, as before.

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

* fix(mito2): charge encoded memtable parts for their parquet metadata

An encoded part keeps its parsed ParquetMetaData next to its bytes, but
its write-buffer charge only covered the bytes. Charge the metadata's
memory size too, so wide schemas and many row groups count toward the
limit. `size_bytes()` still means the encoded data length.

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

* fix(mito2): size flush reads and count written data by decoded bytes

Memtable stats now carry the decoded size of their rows next to the
bytes they hold. An encoded bulk memtable holds far fewer bytes than its
rows decode to, so sizing flush batches and row groups, the region's
written bytes and the WAL estimate by held bytes picked too many rows
and undercounted written data.

A bulk memtable reports the bytes written into it, as before encoding
was charged by held bytes; an encoded range reports its decoded size.
Write buffer accounting and flush selection still use held bytes.

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

* docs(mito2): explain why flush sizing and written bytes use decoded bytes

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

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-25 13:54:39 +00:00
dennis zhuang f3f4e31c6f fix(mito2): estimate compaction memory per output (#10566)
* perf(mito2): read compaction inputs concurrently regardless of encode parallelism

Compaction read its inputs with the output encode parallelism, which defaults to 1, so one task fetched and decoded every input. Inputs are now read by at least 8 concurrent tasks; encoding is unchanged.

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

* test(mito2): blocked compaction producers must not hold read permits

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

* fix(mito2): reserve compaction memory for read-ahead of small row groups

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

* fix(mito2): charge compaction read-ahead per row group and only for merged inputs

A batch never spans row groups, so cap the per-batch estimate at one row
group. An output with a single input reads it without a channel, so it
keeps the row group estimate.

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

* fix(mito2): model compaction admission on the merge of each output

Outputs of a unit merge one after another, so reserve the largest
output instead of every input of the unit. Per output, count each
reader's row group, the batches read ahead when inputs are read
concurrently, the input batches the merge retains until an output
batch, and the batches between the merge and the writer. Inputs
without row group statistics are read serially, since admission cannot
size their read-ahead.

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

* fix(mito2): cap the compaction merge estimate by the input data

The merge output and the batches past the readers can never hold more
rows or bytes than the inputs, so tiny files no longer get charged for
full 64 MiB batches.

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

* fix(mito2): keep compaction reads as on main and size read-ahead by its parallelism

Compaction reads inputs serially again unless the experimental output
parallelism is above 1, as before this branch. Admission charges the
read-ahead of each input only when the inputs are read in parallel.

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

* fix(mito2): bound merged batch estimates by the widest available rows

One wide row in one input made every row of the batches past the readers
count as wide. Fill those batches with the widest rows first, taking no
more rows from an input than it has.

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

* fix(mito2): count the LastNonNull dedup batch and share the merge parallelism

LastNonNull dedup keeps the previous output batch until the next one
arrives; admission now reserves it. Admission and the merge read the
output parallelism from one function, and the estimate notes that inputs
without FileMeta statistics make the batch size approximate.

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

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-25 13:00:42 +00:00
discord9 22807a772e perf(promql): stop building label-set tables where they cannot collide (#10514)
* perf(promql): stop building label-set tables where they cannot collide

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

* fix(promql): let a canonical merge sit below a split aggregate

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

* test(promql): identify native pieces by what they read, not by rendered text

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

* perf(promql): judge a metadata drop by its labels alone

The plan-time proof of whether two series can share a canonical label set asked
two things: whether the labels tell them apart, and whether the scan's key
columns do. The second half was defensive against storage series that differ
only in a nullable tag holding NULL versus an empty string, which canonical
comparison already treats as one label set.

Every tag column of a metric-engine table is nullable, so that half was false
for ordinary tables, and a root merge was inserted above point-wise shapes that
cannot fold two series at all. A deep binary was cut into pieces by it, and a
disjoint scan went from two routers to four.

Judge the drop by the labels only. The physical partition-identity rule keeps
its own copy of the key-column question; the plan no longer reads it, and a
scanner whose pieces one storage series can reach is still collected under its
primary key before any name-dropping kernel sees them.

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

* test(promql): admit a histogram fold on a nullable table, name the risk counter

The fold-admission test ran on a stable-key fixture, which hid that the shapes
it names decline on a nullable one; run it on the metric-engine fixture instead.
A drop above a fold needs no collection there, which a new test pins.

Rename what the plan could not prove from "skipped" to "unproved" throughout,
including the test hook, now that the counter counts that rather than a
collection.

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

* fix(promql): a kernel that answers one series per label set proves the drop above it

`100 * (1 - avail / size)` kept a canonical merge above its vector-vector match.
The match already files its rows by the result label set and refuses two values
of one field at one point, so the broadcast above it removes a name no two of
its series were told apart by; judging that drop by its sources alone got it
wrong. A fold, a match between two vectors, a set operation, `info`,
`count_values` and the histogram functions answer one series per label set by
construction, and the proof now says so.

A merge is deliberately not one of them: it answers one series per *canonical*
label set, which still carries the name, so a drop above it can fold
`a{job="x"}` and `b{job="x"}` and must be collected.

With the proof fixed, the ranking case no longer collects between the fold and
the sort, so the test that pinned the old shape now reads the fold inside the
ranking's own tree.

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

* test(promql): a fold may plan as a collected split

With the drop judged by its labels alone, `sum(label_replace(...))` no longer
keeps a collection above the fold, so the fold plans as partial state per
partition with the canonical merge below it instead of a complete aggregate
over assembled series. The rows, the legacy comparison and the cross-partition
collision all stay the same, so the three assertions that pinned the complete
shape now accept either, and check that the merge is still there.

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

* fix(promql): derive a window's labels as the runtime drops them

A window that drops the metric name removes every metadata label at runtime
(`__name__`, `__type__`, `__unit__`), but the plan derived only `__name__` as
gone. A fold above such a window was therefore judged unproved - it could still
see a `__unit__` the runtime had already removed - and collected a canonical
merge. That merge made the segment non-commutative with a bare scan under it,
so the admission gate declined the whole statement and it was quietly replanned
as legacy.

Derive the labels the runtime leaves behind instead. The test that pinned the
old derivation now says both things it was covering: a scan that still carries
`__type__` is still collected, and a map that already removed it is not.

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

* test(promql): a single-metric drop needs one fused node, not two

With the drop judged by its labels alone, `histogram_arithmetic * 2` on a
single-metric table needs no root merge, so the statement runs as one fused
node instead of a producer and a consumer. Accept either count and say why.

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

* fix(promql): report a cross-partition label-set collision instead of folding it

A label rewrite that gives two series one label set is collected by a canonical
merge, and a split keeps that merge inside its per-partition prefix. Two
colliding series that landed in different partitions were therefore each folded
apart, and the state router added the two partial states - a value no label set
ever stood for - where Prometheus reports `vector cannot contain metrics with the
same labelset`.

Refuse the split across a canonical merge, in `split` and in `admit_prefix`,
so the statement takes the boundary shape instead: each partition's producer
collects what its own scan holds, the canonical router routes every piece of one
label set to one owner, and the fold above reads whole series. Two colliding
series are then reported wherever they were scanned.

A discovered selector is a union of one source per metric, so a segment over it
already reads frames that name their own metric: accept it in
`build_evaluated_segment` the way `build_inner_segment` already does, which
keeps `{host="a"}`-style selectors from declining once the split no longer
carries them.

A histogram fold above a boundary has no execution on this route (only the
split's state carries one), so those statements keep the plan they have on
`main`; the existing route reports their collision through its window function.

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

* docs(promql): the drop chain pays one merge, not the key columns

The example claimed the merge was paid over a table whose key columns can spell
the `NULL`/`''` pair. That pair is not part of the labels' proof any more, so no
merge is paid for it: the merge in the example is the one the chain's first drop
pays, and every drop above a merge asks only about the metadata labels. State
that instead of a cause that no longer exists.

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

* test(promql): keep the pair the labels cannot prove apart

The window test asked the pass for a metric-less selection, so the collection it
asserted was paid for by the multi-metric guard rather than by the pair the test
is about. `zone=""` and an absent `zone` meet after `rate` even when the metric
name is known, and #10412 caught that with a node-level occupancy tracker.

That tracker is gone here: the drop is judged by the labels alone, and the empty
value a kernel also removes is deliberately outside that proof - collecting it
would put a canonical merge over every statement whose kernel drops the metadata
labels. The pair therefore leaves the window as two pieces of one label set,
which the PR description records under "What this gives up" and "Out of scope".

The case is restored as the shape #10412 approved and marked ignored with that
reason, so the behaviour it pins stays in the record instead of being dropped
again; the metric-less case it had replaced is kept as its own test.

Also drops a disjunct `is_sourced_plan` already covers.

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

---------

Signed-off-by: discord9 <discord9@163.com>
2026-11-25 10:40:30 +00:00
dennis zhuang 0813fc3527 fix(mito2): size old SSTs from size statistics and move the downgrade target to v1.2.0 (#10585)
* test(compat): downgrade to v1.2.1 instead of v1.1.4

SSTs written since #10528 can have inverted-index segments that cross row
group boundaries. Readers older than v1.2.0 do not split such segments and
return fewer rows, so v1.1.x is no longer a supported downgrade target.

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

* fix(cmd): record the decoded row group size of a replacement SST

sst_replace set max_row_group_decoded_size to 0 for the replacement file.
Compute it from the replacement footer with the helper writers use, which
is now public in mito2.

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

* fix(mito2): derive decoded value bytes from size statistics for old SSTs

SSTs written before #10528 have no greptime:max_row_group_value_bytes or
greptime:max_row_value_width footer keys, so a row group of repeated large
dictionary-encoded values was sized by its encoded bytes on the first
compaction and read after upgrade.

When the keys are absent, sum the unencoded_byte_array_data_bytes size
statistic of each row group's byte array column chunks instead, skipping
columns that readers decode as Arrow dictionaries like the writer does.
Parquet writers record the statistic whenever column statistics are
enabled, which mito did by default with parquet >= 53 (v0.12.0).

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

* fix(mito2): count only top-level var-len columns in the size statistics fallback

The fallback summed every non-dictionary byte array leaf, including leaves
nested in structs such as JSON2 columns, which the footer keys do not
count. New files without var-len values write no keys, so they took the
fallback and got a larger decoded size than before.

Count only leaves that are top-level string or binary columns, which
matches var_len_value_bytes and leaves key-less new files unchanged. Drop
the early exit, which dictionary primary keys defeated anyway.

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

* perf(mito2): index the Arrow schema by root column in the size statistics fallback

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

* test(compat): look up an inverted index segment that crosses a row group boundary after downgrade

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

* test(compat): also downgrade to v1.2.0, the oldest reader that splits index segments

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

* fix(mito2): treat unparseable footer size keys as absent

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

* docs(compat): state the v1.2.0 downgrade floor

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

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-25 08:48:16 +00:00
shuiyisong 455acb3461 fix: reject primary key encoding options on logical metric tables (#10624)
Signed-off-by: shuiyisong <xixing.sys@gmail.com>
2026-11-25 07:17:41 +00:00
Chenglong Zheng 0851700911 feat(meta): add object-store authority state machine and single writer (#10588)
* feat: add object-store authority state machine and single writer

Signed-off-by: hahaha <a310608318@gmail.com>

* fix: validate conditional resignations and retry renewal reads

Signed-off-by: hahaha <a310608318@gmail.com>

* refactor: clarify object-store authority naming

Signed-off-by: hahaha <a310608318@gmail.com>

---------

Signed-off-by: hahaha <a310608318@gmail.com>
2026-11-25 06:46:52 +00:00
1110a0af36 fix(meta): preserve table column order and primary key indices during reconciliation (#10251)
* fix(meta): preserve table column order and primary key indices during reconciliation

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* fix(meta): address maintainer review on column order and PK validation during reconciliation

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* style(meta): simplify nested if blocks in reconciliation utils

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* test(meta): use OutputData::pretty_print for SHOW CREATE TABLE verification

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* test(meta): drop unused mut in reconcile_table integration test

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* test(meta): make reconcile SHOW CREATE TABLE assertion formatting-tolerant

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* test(meta): cargo fmt reconcile assertion

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* test(integration): parse quoted SHOW CREATE output in reconcile test

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* style(tests): rustfmt reconcile_table SHOW CREATE assertions

Signed-off-by: Tyagiquamar <104281681+Tyagiquamar@users.noreply.github.com>
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* style(tests): fix clippy collapsible str replace in reconcile_table

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* fix(meta): address reconcile_table review on tests and docs

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* test(integration): fix q8 SHOW CREATE TABLE assertion with check_output_stream

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(meta): take reconcile primary key order from the region tags

build_table_meta_from_column_metadatas preserved the stale table_meta
primary key order, so a consistent reconcile kept the post-ADD-COLUMN
key (a, b) instead of restoring the regions' [b, a] and a later
UseMetasrv SyncColumns rewrote the region key over SSTs encoded with the
old order. The key order now follows the input tags, which the reconcile
paths feed in region key order; the ResolveColumnMetadata consistent
branch re-applies reorder_tag_columns so the region's key must match its
tag columns. Column order still comes from table_meta for #10249.

cargo test -p common-meta reconciliation: 41 passed.

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* style(meta): wrap the tag-order loop for rustfmt

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* fix(meta): address reconcile_table review on test fixtures and guards

Address review comments from @WenyXu and @killme2008:
- Add ALTER TABLE q8 ADD COLUMN c INT before table reconciliation to exercise stale key repair with added columns.
- Remove redundant else-continue guard in the tag ordering loop.
- Clarify rustdoc explaining physical versus logical table reconciliation paths.
- Share new_test_q8_raw_table_info fixture helper across reconciliation tests.

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>

* test(meta): cover partition key order during reconciliation

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

---------

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Signed-off-by: Tyagiquamar <104281681+Tyagiquamar@users.noreply.github.com>
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: dennis zhuang <killme2008@gmail.com>
2026-11-25 01:10:12 +00:00
Samarth Jaiswal f4ff272f37 fix: keep exact DECIMAL and BIGINT UNSIGNED values in COPY FROM csv and json (#10560)
* fix: keep exact DECIMAL and UInt64 values in COPY FROM csv and json

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

* style: format the reader schema test

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

* test: add the expected output of the exact numbers case

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

* fix: round decimals with extra fractional digits in COPY FROM

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

* fix: parse decimals from text in COPY FROM csv and json

Arrow's decimal decoding is wrong for some numbers in scientific
notation and drops the digits beyond the scale. Read a decimal column
as a string and parse it, so that every digit is used and the value is
rounded as the cast from a float did.

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

* fix: read unsigned integers from text and reject empty strings in COPY FROM json

Arrow's json reader parses an integer in scientific notation through a
Float64, so 9007199254740993e0 lost its last digit in a BIGINT UNSIGNED
column. Such a column is now read as text and parsed from every digit,
like a DECIMAL column.

An empty json string loaded into a DECIMAL column as NULL. It is an
error again, and only an empty csv field is read as NULL.

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

---------

Signed-off-by: Samarth Jaiswal <samarthjaiswal30@gmail.com>
2026-11-24 18:18:35 +00:00
fys 93ddb89ffc fix(query): correct filtering and ordering for file engine scans (#10547)
* fix(query): retain row filters for file engine scans

Signed-off-by: fys <fengys1996@gmail.com>

* fix(query): skip time-series scan hints for file regions

Signed-off-by: fys <fengys1996@gmail.com>

---------

Signed-off-by: fys <fengys1996@gmail.com>
2026-11-24 18:18:30 +00:00
jeremyhi 0dfd6e70cf feat: hand a region over to the object store WAL during catchup (#10589)
* feat(log-store): hand a region over to the object store WAL

Add LogStore::handoff, called before a region becomes writable on a log
store. Once it returns, every id the log store assigns the region is
above the given entry id and every id it assigned the region before,
also after a restart; no entry became obsolete, and check_region_history
accepts the region. The default does nothing.

The object store WAL raises its next object sequence above the object
holding that id, sealing the open batch first if it holds ids under the
current sequence, and keeps a release record of the region's current
watermark for the next sealed batch. It answers once that object is
durable and indexed, in both acknowledgement modes, and then records
that the region's history starts in the store. Hand-offs within one
flush interval share the object.

A store that is failing or lacks I/O permission keeps the floor and the
record and fails the call with a retryable error. If the open batch
cannot be sealed, a durable store has rolled it back and applies both at
once; an enqueued store keeps the batch and applies the largest deferred
floor of each region once it is sealed, unless the store stops first. A
hand-off handled after stop began fails as stopped and keeps nothing.

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

* feat(mito2): hand a region over and claim the next manifest version in catchup

A catchup that makes a region writable and carries the entry id its
source reported hands the region over to the log store before the WAL
history check. The hand-off covers the reported id, the flushed entry id
and every pending tail's upto. A catchup that still has to replay entries
above where its replay starts hands nothing over, so if it cannot reach
them it leaves nothing behind; on the object store WAL it cannot read
them from this node's prefix.

Before the region is promoted, the catchup commits an empty edit as the
version after the manifest the region holds. It runs only under
conditional manifest publication and requires a Follower with no pending
reload and not stopped. It skips the Leader deadline check, starts no
checkpoint and applies only if no checkpoint covers its version. A
writer that committed other content at that version conflicts with it;
the conflict fails the catchup with a retryable error and leaves the
region a Follower that is not fenced. Two catchups that start from the
same manifest version are not told apart.

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

* fix(log-store): prune cancelled hand-off waiters and correct the hand-off docs

A hand-off whose caller stopped waiting left its closed response in the
actor until the record's object was sealed, so repeated cancelled
hand-offs during a long outage accumulated one dead waiter each. Prune
closed responses on admission, as the durability waiters do.

Document that errors other than a failing store or a missing I/O permit
keep the retry hint the object store reports, and that a hand-off pending
when stop begins fails as stopped in the durable mode when its object's
create had not started. Add a test for an issued id in the open batch.

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

* test(log-store): describe what a hand-off after stop keeps

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

* fix(mito2): hand over and commit a region caught up again before its swap

A catchup again replays into an unregistered replacement. It now hands the
region over in that replay and makes the catchup commit of the replacement in
handle_caught_up_again, after the checks of the old instance and under its
manifest lock, so no refusal follows the commit.

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

* fix(mito2): fire the catchup commit's manifest hook without manifest locks

commit_catchup returns the receipt of its manifest hook. A catchup again fires
it once it no longer holds the old instance's manifest lock, so a hook that
reads the manifest cannot queue behind a writer waiting for that lock.

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

* docs(log-store): say which object answers a hand-off pending at stop

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

* docs(mito2): note when the catchup commit's manifest hook fires

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

* test(log-store): cover a hand-off in the open batch when stop begins

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

* refactor(log-store): return the hand-off bound and tidy its docs and tests

LogStore::handoff returns the bound it raised the region above; the default
returns the entry id. The object store WAL defers a hand-off only when the
open batch it cannot seal is not empty. The two open-batch seal tests are one
test now, which also checks the returned bound.

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

* docs(mito2): describe the catchup commit's cost and hook, and guard the hand-off gate

Documents the worker stall of a catchup again's commit, the writable catchup
in the region hook coverage, and the replacement's commit in catch_up_again.
Logs a failed catchup commit. Adds cases for a catchup that does not make the
region writable and for a region that skips the WAL.

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

* fix(mito2): keep Leader leases off a caught-up replacement while its hook runs

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

* docs(mito2): tie the replacement's fence to set_writable and tidy the catchup docs and tests

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

* docs(store-api): say which assigned ids the hand-off bound covers

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

* docs: describe the replacement's lease fence and the hand-off bound precisely

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

* fix(mito2): skip the hand-off for a region without a WAL provider

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

* docs(mito2): name the catchup commit as the exception to the manifest fencing rule

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

* test(mito2): cover the hand-off of a region without a WAL provider

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

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-24 16:22:18 +00:00
Lei, HUANG 9ecd84f622 fix(mito2): decouple table compaction upload and Arrow budgets (#10607)
* fix(mito2): decouple table compaction upload and Arrow budgets

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* test(mito2): prune redundant table compaction checks

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(mito2): cap GCS compaction objects at 5 TiB

Apply the GCS service limit even when the operator omits its object limit. Keep stricter advertised limits and the multipart part-count limit, and cover all three with geometry tests that perform no uploads.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* test(mito2): require an SST part before its final input batch

Gate the payload of the last source row group on the first Parquet part from its target. A writer that buffers until close can no longer pass the lossless multipart regression.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* refactor(mito2): isolate enterprise buffered uploads

Move the bounded SST and Puffin upload adapter and its regression test behind one gated module declaration. Leave the shared chunk transfer in the Apache-licensed parent and register the new enterprise source in both license lists.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* docs(mito2): describe ObjectStoreWriter bytes as accepted for upload

Bounded uploads stage bytes in a local part buffer before they reach the object store, so output_bytes counts accepted bytes rather than bytes already submitted. The only reader takes the value after a successful close, when both counts agree.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* refactor(mito2): rename the compaction compute estimate

MemoryLimits::compute_bytes returned the estimated working set that admit()
compares against the compute budget, while UploadBudget::compute_bytes holds
that budget. Rename the method to estimate_compute_bytes and name the
admission local accordingly so the estimate and the budget are not read as
the same quantity. The budget field keeps its visibility because source
admission still bounds footer memory by it.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* test(mito2): rename the source-less table compaction fixture

Rename `Fixture::empty` to `Fixture::without_source`. The constructor still creates the scheduler environment, access layer and config and only skips writing the input SST, so the old name suggested a state-less fixture. The new name mirrors `with_source`; both call sites are updated.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* fix(mito2): check the upload object limit inside the bounded writer

Move the object-limit check from the Parquet SST writer into UploadBuffer::write so every caller of the bounded buffer is covered and the remaining-allowance subtraction cannot underflow. Make check_size private; the Puffin adapter keeps its own check and the limit error still surfaces as MultiRegionCompactionResource. Cover writes accepted up to the limit and the rejected next write.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

* docs(mito2): document index writer upload policies

IndexWriteBuffer variants select different object-store writers: the default writer, exact-size parts, or a serial upload buffered through the enterprise adapter. Document each policy and explain that IndexObjectWriter boxes the bounded side because that adapter is returned as an opaque type.

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>

---------

Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
2026-11-24 15:33:23 +00:00
shuiyisong 81e60511b5 ci: make nightly merge opt-out and simplify Docbot labels (#10601)
* ci: make nightly merge opt-out and simplify Docbot labels

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

* ci: scope nightly label migration and sync to main

Use the saved nightly preference only for PRs targeting main at both
snapshot and apply time. Clean up docs-not-required across all bases.

Restore the skip label when it is removed while the opt-out box is
checked.

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

* ci: honor cleared nightly opt-outs on retry

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

---------

Signed-off-by: shuiyisong <xixing.sys@gmail.com>
2026-11-24 10:42:29 +00:00
Yingwen 21d6a25dfb refactor(mito2): share SST reading with multi-region compaction (#10583)
* refactor(mito2): share SST reading with multi-region compaction

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

* fix(mito2): charge only materialized routing columns

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

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-11-24 10:35:40 +00:00
dennis zhuang 890540f248 fix(table): keep the primary key order when adding columns (#10591)
TableMeta::add_columns rebuilt primary_key_indices from column positions,
so ADD COLUMN on a table whose key is not in column order (or with a key
column added FIRST/AFTER) rewrote the table key, while regions keep their
key and append new tags at the end. Keep the existing key order and append
new key columns in request order.

Refs #10248

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-11-24 10:28:33 +00:00
Weny Xu 044e659b2d fix(meta): persist segmented procedure checkpoints atomically on RDS (#10604)
* fix(meta): persist segmented procedure checkpoints atomically on RDS

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

* fix(meta): fall back when MySQL packet limit lookup fails

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

* fix(meta): use atomic checkpoint batches on memory and raft backends

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

* fix(meta): preserve large KV writes when batching on RDS

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

---------

Signed-off-by: WenyXu <wenymedia@gmail.com>
2026-11-24 09:18:56 +00:00
discord9 a6cc055e83 refactor(promql): fold legacy histogram aggregates through the native accumulator (#10483)
* refactor(promql): fold legacy histogram aggregates through the native accumulator

The legacy prom_native_histogram_agg_sum/_avg accumulators kept their own sum, weighted
mean, incompatibility flag and reset evidence beside the native HistogramAccumulator that
10199 added, so the two could answer the same aggregate differently. The legacy
accumulator now holds that fold and delegates push, merge, state and size to it; only the
state frame still differs, and its layout, field names and order are unchanged.

The legacy frame declares neither a compensation component nor a mean mode, so a state
carries the fold's answer: the running sum with its compensation folded in, or the running
mean of its samples. That is what a reader of the frame adds or weights, and it keeps the
residual of samples already folded into one position. It is not a lossless Kahan state --
folding the compensation back into one f64 rounds again, so a partition holding [1e16, 1]
still exports 1e16 and merging it with [-1e16] answers 0.

An exponential sample meeting custom buckets poisons the whole position, as the legacy
reconcile() returning None did: the position answers null and the evidence says why,
rather than skipping the sample or failing the query. Reset evidence is OR-ed from the
state's two booleans instead of re-observing the merged histogram's hint, which the fold
already accounted for.

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

* fix(promql): read a legacy sum's start timestamp from the fold it exports

The two tests #10420 wrote read `accumulator.value`, which this refactor replaced with the
native fold, so the crate did not build. They read `state_histogram()` now.

That path answers a derived histogram: `finished_histogram` compacts it, which clears the start
timestamp along with the empty buckets. So a single-sample sum no longer republishes the sample's
own timestamp - the timestamp is still inside the fold, but the answer is a derived one and says
so. The test that required the timestamp to survive is renamed and asserts the export instead.

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

* fix(promql): drop a position whose histogram cannot be read

A histogram whose spans and buckets disagree is one this crate cannot read. The accumulator this
refactor replaced met that disagreement through `legacy_bridge::add`'s `None` and dropped the
position with a warning; delegating to the native fold turned it into an error for the whole query,
so a table holding one went from answering with the group removed to failing.

The fold now records the position as incompatible and drops it, which is the answer the legacy path
gave. `an_illegally_shaped_histogram_drops_its_position_rather_than_failing_the_query` pins it for
both kinds: the push answers `Ok`, the position's state is empty, and the warning names the
incompatible schemas.

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

* fix(promql): drop a state frame whose histogram cannot be read

`merge_batch` reads a partition's exported histogram the same way `push_histogram` reads a sample,
and made the same change: a state frame whose spans and buckets disagree became an error for the
whole statement, where the legacy path recorded the position as incompatible and dropped it. The
merge half now records it the same way, so a partition this crate cannot read is dropped rather
than failing the query.

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

* test(promql): pin what a one-sample fold does to an explicit empty bucket

The fold answers through `finished_histogram`, which compacts an explicit zero bucket away, so a
`sum` or `avg` over a single sample answers `[1]` where that sample carried `[1, 0]`. The legacy
accumulator kept the bucket before this refactor, because it handed a one-sample group's histogram
back untouched; the native `Aggregate` node has always answered the compacted form, so the two
paths agree now.

`promql_eq` tells an explicit zero bucket from an absent one, so `sum(h)` is no longer equal to the
single sample `h` it folded. Both tests document that, and the second one takes the answer through
a partial state round trip - `state()` into a fresh accumulator's `merge_batch()` - to show the
boundary does not re-introduce the bucket.

The comments on the three places that drop an unreadable layout now say what the code does rather
than how it differs from the accumulator this replaced: a layout this crate cannot read drops the
position as a whole, with the warning below, instead of failing the query.

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

---------

Signed-off-by: discord9 <discord9@163.com>
2026-11-24 09:16:36 +00:00