Files
greptimedb/src/session
discord9 76209d6179 feat(frontend): add TTL-based PromQL range cache (#10798)
* feat(frontend): add TTL-based PromQL range cache

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

* feat(frontend): add rollup cache reset endpoint

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

* feat(frontend): honor nocache for rollup cache

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

* fix(frontend): key rollup cache by table id and invalidate on DDL

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

* fix(frontend): set transitional rollup cache bounds

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

* fix(frontend): trim rollup cache to ttl and reset

Remove the reset token and all DDL/heartbeat invalidation so the
transitional cache has one freshness rule (ttl) and one manual escape
(reset). Charge variable-sized keys, honor POST-form nocache, fail on
schema changes instead of falling back, and drop duplicate TTL/dead
checks.

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

* docs(frontend): drop stale invalidation wording

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

* fix(frontend): bound rollup cache key and weight

Share one QueryIdentity across a plan's chunk keys, refuse chunks whose
weight does not fit a u32, and reject ttl values longer than moka accepts.
Clarify schema-mismatch and wall-clock tail docs.

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

* docs(frontend): regenerate config.md for rollup_cache tail

config/config.md was hand-updated and kept the previous wording of the
rollup_cache.tail comment. Run make config-docs so it matches the example
TOMLs, which is what CI checks.

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

* test(integration): expect rollup_cache in the /config snapshot

test_config_api compares the whole TOML the /config endpoint returns with a
hardcoded expectation. The rollup cache adds a [rollup_cache] section, so
append it with the values the frontend defaults serialize to.

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

* refactor(frontend): rename rollup cache to promql_rollup_cache

Rename the config key, the options and config types, the cache itself,
the instance accessors, the reset endpoint and the session hint so the
name says what is cached. query_cache becomes promql_query_cache for the
same reason: it holds PromQL range-query chunks only.

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

* feat(frontend): log the promql rollup cache config when enabled

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

* feat(frontend): size the promql rollup cache from system memory by default

Derive max_bytes from total memory like the OTLP trace aux cache
(1/128, floor 32MiB, cap 8GiB) instead of a fixed 256MiB, so a small
frontend does not give up a quarter of its memory and a large host gets
a useful budget. An explicit max_bytes still wins.

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

* refactor(frontend): move the promql rollup cache wiring out of instance.rs

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

* refactor(query): expose plan_is_native from the native planner

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

* fix(frontend): key promql rollup cache chunks on the output schema

The metric engine auto-alters a logical table when a new label arrives,
which keeps the table id but changes the schema. Keying on the id alone
let one request meet an old-schema hit with a new-schema fill and fail
until the ttl. The output schema of the built plan is now a key
dimension, so a schema change misses; a disagreement left after that is
a race with an ALTER, and the request bypasses to its original plan
instead of failing.

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

* perf(frontend): execute consecutive promql rollup cache misses as one window

A cold request executed every missed chunk as its own subwindow, each
re-reading the range its first point folds. Consecutive misses now run
as one window and the rows are split back into chunks before insert.

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

* perf(frontend): size promql rollup cache chunks in steps and drop empty-chunk guards

A fixed-time chunk holds chunk/step points and degrades to one point at
a large step: a 7d panel at a 10m step became 1008 single-point chunks
that all had to be looked up and merged even when warm. A chunk is now
at least MIN_CHUNK_STEPS points wide, so the chunk count tracks points
rather than range (7d at 10m: 50 chunks).

plan_chunks never emits an empty chunk, so the guards in lookup and
insert, the EmptyChunk bypass, Lookup::Bypass and Insert::Bypassed are
gone along with the two tests that built an empty key by hand.

Also applies the reviewer's doc suggestions and dedupes the tests that
asserted one behavior at three layers.

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

* docs(frontend): regenerate config.md for promql_rollup_cache

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

* fix(frontend): copy split promql rollup cache chunks before storing them

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

* fix(frontend): store empty promql rollup cache chunks as complete answers

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

* refactor(frontend): key the promql rollup cache on the arrow schema directly

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

* fix(frontend): only bypass the promql rollup cache for a set nocache hint

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

* docs(frontend): record that rollup cache annotations belong to the read

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

* perf(frontend): read contiguous direct spans as one window

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

* docs(frontend): fix stale rollup cache comments and pin lookback_ms

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

---------

Signed-off-by: discord9 <discord9@163.com>
2026-12-02 12:05:25 +00:00
..