mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 05:34:02 +00:00
* 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>