Files
jeremyhi 0ae7c1826b feat: add an admin function to discard pending WAL tails (#10477)
* feat: add an admin function that discards a datanode's pending WAL tails

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

* fix: refuse a tail discard over an unconfirmed manifest update and address review

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

* test: drop the integration test that repeats the admin function's region form

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

* fix: refuse a tail discard while a tail replay's update is uncertain

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

* build: pin greptime-proto to the branch that adds the pending tails truncate kind

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

* test: record the region id case of the discard_pending_tails sqlness test

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

* fix: track the uncertain replay update only without conditional publication and pin the truncate wire format

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

* test: simplify the truncate wire test

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

* test: cover the discard requests sent to regions and the metric data region

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

* test(mito2): pin the WAL history a discard relies on after a crash

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

* test(common-function): describe the mock pending tails discard

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

* fix(operator): report discard failures per region and clarify pending tails docs

Log each failed region of a by-table pending tails discard with its region id
and the tails the other regions discarded, derive the unsupported message from
the truncate kind, drop the unused feature parameter, document that a discard
raises the flushed entry id to the tail bound, and test discarding a kept tail
after a replay commit with an uncertain result.

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

* fix(operator): warn with the partial discard count and state the WAL history check precisely

Format request.rs, log the tails discarded by the regions that succeeded at
warn level when another region fails, state in the docs that an open checks WAL
history through the flushed entry id where the log store checks history and
that whoever adds a tail ensures it for every node that may lead the region,
and rename two tests after the outcomes they assert.

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

* docs(mito2): note that accepting missing WAL history opens a region past a discarded bound

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

* docs(mito2): rewrap the pending tails discard handler doc

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

* refactor(store-api): discard pending WAL tails with a dedicated region request

Carry the discard as RegionRequest::DiscardPendingTails, decoded from the
DiscardPendingTailsRequest body, instead of a truncate kind. Mito handles it as
a worker control request, so the truncate path no longer special-cases it;
the Metric Engine forwards it to a physical region's data region; the
frontend builds it for a region or for every region of a table, sharing the
table lookup with the discard of unflushed data. The wire fixture now pins the
new request body.

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

* refactor(metric-engine): give the pending tails discard its own error context

Report a failed discard as a pending tails discard rather than a truncate in
the Metric Engine, pin that Mito handles the discard as a worker control
request, state that physical_region_ids returns a logical table's physical
regions, and drop leftovers from the truncate kind in the tests.

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

* build: pin greptime-proto to the dedicated pending tails discard request

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

* build: pin greptime-proto to the merged pending tails discard request

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

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-19 10:50:58 +00:00

45 lines
1.4 KiB
SQL

CREATE TABLE discard_pending_tails_test (
host STRING PRIMARY KEY,
val DOUBLE,
ts TIMESTAMP TIME INDEX
) PARTITION ON COLUMNS (host) (
host < 'm',
host >= 'm'
) ENGINE = mito;
INSERT INTO discard_pending_tails_test VALUES ('kept', 1, 1), ('remains', 2, 2);
-- No region of the table has pending tails from the node, so nothing is discarded.
ADMIN discard_pending_tails('discard_pending_tails_test', 1);
SELECT host, val FROM discard_pending_tails_test ORDER BY host;
-- The function must only be available through ADMIN.
-- SQLNESS REPLACE \nDid\syou\smean.*
SELECT discard_pending_tails('discard_pending_tails_test', 1);
DROP TABLE discard_pending_tails_test;
CREATE TABLE discard_pending_tails_physical (
ts TIMESTAMP TIME INDEX,
val DOUBLE
) ENGINE = metric WITH ("physical_metric_table" = "");
CREATE TABLE discard_pending_tails_logical (
host STRING PRIMARY KEY,
val DOUBLE,
ts TIMESTAMP TIME INDEX
) ENGINE = metric WITH ("on_physical_table" = "discard_pending_tails_physical");
ADMIN discard_pending_tails('discard_pending_tails_physical', 1);
-- Logical Metric Engine tables share their physical regions with other logical tables.
ADMIN discard_pending_tails('discard_pending_tails_logical', 1);
DROP TABLE discard_pending_tails_logical;
DROP TABLE discard_pending_tails_physical;
-- A region id reaches the region path; this one belongs to no table.
ADMIN discard_pending_tails(4398046511104, 1);