Files
greptimedb/src/mito2
jeremyhi 5952a49e2f fix(mito2): wait for a Leader lease before committing after a catchup (#10544)
* fix(mito2): wait for a Leader lease before committing after a catchup

On a datanode whose writes need a lease, a catchup makes a migration
target writable before the route points to it. Until a Leader or
StagingLeader lease of a heartbeat sent after the catchup applies, such
a region commits to its manifest only replayed WAL tails and what it
commits while downgrading; any other commit fails with the retryable
RegionLeaseNotReceived in ManifestContext::update_locked. No flush or
compaction trigger starts work for it, a write over its own write buffer
is rejected as for a staging region, and a close that must flush
downgrades it first.

The lease that ends the wait tells the region's worker once. The worker
schedules the engine-full and region-full flushes and, if the region is
then a writable leader, starts a compaction, builds missing indexes in
async index mode and persists the metadata the opener backfilled.

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

* test(mito2): refuse a discard of pending tails while awaiting the Leader lease

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

* fix(mito2): keep extension indexes in the lease-end index pass

The index pass at the end of a wait for the Leader lease is a flush
build of every file, which builds no extension index, so it replaced
the index of a compacted file whose sketch the compaction built. It now
skips files that have an extension index, as the background build after
a compaction does, through the same check.

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

* fix(mito2): drop the FileMeta import the moved check left unused

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

* test(mito2): share the sketch region setup of the index build tests

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

* test(mito2): check the lease-end index candidates where they are chosen

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

* test(mito2): select and test the whole-region index builds in one function

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

* fix(mito2): start no checkpoint while awaiting the Leader lease in every publication mode

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

* fix(mito2): pin no memtable while persisting backfilled metadata

The backfilled metadata save keeps only the region metadata and SST
format across its manifest write instead of the whole version, so a
flush applied meanwhile frees its memtable. Test that a save the end of
a lease wait spawns asks the worker to reload the region it fences, and
describe update_locked as the lease check around the shared write that
a tail replay makes directly.

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

* test(mito2): test the backfill save's reload request on the task itself

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

* refactor(mito2): address the review of the lease wait carve

Name the spawned backfill task for both of its steps, select the
whole-region index builds from file handles, reuse promote_with_lease
in the new tail replay tests, and make the docs, AGENTS.md and comments
say what the code does: the hook entry points, the discard that the
lease check refuses, the background flush triggers and the region write
buffer threshold of a waiting region.

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

* docs(mito2): describe the hook entry point as the write behind update_locked

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

* test(mito2): check the deferred compaction as it is scheduled

The replay's commit clears the pending tails before the worker decides on its compaction, so a count read after the replay could miss a compaction scheduled during the wait. The listener now checks the wait whenever a compaction is scheduled.

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

* fix(mito2): build index retries refused while awaiting the Leader lease after it

A retry of an index build whose publication found the schema changed has no caller to try again. When the region awaits its Leader lease the worker refused it, and the lease-end pass does not cover files with an extension index or build types other than flush. The worker now keeps such retries per region and re-issues them through the normal handler when the lease ends the wait with the region a writable leader. Closing or dropping the region clears them.

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

* test(mito2): gate the deferred compaction check on the end of the replay

The worker reports the replay's end after it handled the replay's commit and its compaction decision, so the check no longer needs to watch the region. The retry test needs no WAL listener.

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

* test(mito2): publish the end of a tail replay with release ordering

A test that observes the end of a replay then reads counts the worker's earlier callbacks set, so the end is stored with release and read with acquire.

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

* fix(mito2): forget kept index build retries when the worker cleans up

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

---------

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
2026-11-20 13:05:34 +00:00
..

Mito

Mito is GreptimeDB's default region engine.

About Mito

The Alfa Romeo MiTo is a front-wheel drive, three-door supermini designed by Centro Stile Alfa Romeo.

"You can't be a true petrolhead until you've owned an Alfa Romeo."

-- by Jeremy Clarkson

Benchmarks

Run benchmarks in this crate:

cargo bench -p mito2 -F test