mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 05:34:02 +00:00
* feat(store-api): ask an engine whether a region is a confirmed leader Add RegionEngine::is_confirmed_leader. It answers None for a region the engine does not find, Some(false) for a follower or, on a node that requires leases to confirm its leaders, for a leader that a catchup promoted and that no Leader or StagingLeader lease has confirmed since, and Some(true) otherwise. The default answers from the role alone, with the mapping RegionServer::is_region_leader uses. Document that set_region_role_with_lease also returns false while a catchup runs on the region or it waits for a reload, and that a catchup also applies to a leader that is not confirmed. Signed-off-by: jeremyhi <fengjiachun@gmail.com> * fix(mito2): catch a writable region awaiting its Leader lease up again A migration that rolls back after its catchup can leave the target region writable but waiting for a Leader lease that never comes, while the source keeps acknowledging writes. A later upgrade must catch it up again instead of treating it as ready. - MitoEngine::is_confirmed_leader reads the role and the lease wait of one instance together under the promotion fence lock. - begin_catchup checks, under that lock, whether the region still awaits its lease; if it does, it demotes the region, raises the downgrade time so earlier Leader leases are ignored, and marks the catchup. The handler then cancels the region's tail replay and reopens it if its memtable is not empty or its manifest changed. A catchup in progress or a pending reload answers RegionBusy before any demotion. - Before a remote WAL replay the catchup waits until the entries the region acknowledged on this node are durable. If the wait fails, the catchup fails and the region stays a follower. - While a catchup runs, a Leader or StagingLeader lease is still recorded and still extends the deadline, but neither promotes the region nor ends its wait; the catchup promotes it when it ends with set_writable. A catchup that fails or does not set the region writable lets the next lease promote it. - MitoRegion::stop marks the fence stopped, and remove_region stops the region before it leaves the region map, so neither a catchup nor a Leader lease promotes a closed instance; such a catchup answers RegionNotFound. - MitoEngine::extend_leader_deadline lets an engine that groups regions extend the deadline of a region that was not handed a lease. Every catchup uses the source's replay checkpoint as before. Signed-off-by: jeremyhi <fengjiachun@gmail.com> * fix(metric-engine): confirm a physical region only with both its regions A physical region is a confirmed leader only if both its metadata and its data region are, since a catchup may have promoted one without the other. A Leader lease that the metadata region ignores, for example while it catches up, is still not handed to the data region, but it is now recorded for the data region and extends its deadline, as mito does for a lease it ignores. Signed-off-by: jeremyhi <fengjiachun@gmail.com> * fix(datanode): catch up an upgraded region that is not a confirmed leader The upgrade handler asks the engine once whether the region is a confirmed leader and reports only such a region ready without a catchup. A writable region that still awaits its Leader lease is sent a catchup with set_writable, which catches it up again. Signed-off-by: jeremyhi <fengjiachun@gmail.com> * refactor(mito2): share the end of a successful catchup Move the part of a successful catchup that finalizes the leadership of a promoted region, ends the catchup and replies into CatchupFinish, so another catchup path can end the same way. No behaviour change. Also fold two doc comment lines in region.rs that ran past 100 columns. Signed-off-by: jeremyhi <fengjiachun@gmail.com> * fix(mito2): replace a region caught up again only if its replay succeeds A catchup of a region that awaits its Leader lease opened its replacement, registered it at once and dropped the old memtable before the replay. If the durability wait or the replay then failed, the next Leader lease could promote the empty or partial replacement, and a retry read the smaller last entry id of the replacement, so it no longer waited for the entries the region had acknowledged. Now the old instance stays registered while an unregistered replacement opened from its manifest waits for durability and replays the WAL outside the worker. The worker registers and promotes the replacement only if the replay succeeded and the old instance is still registered, does not wait for a reload or a flush, and neither committed nor took a write meanwhile, with or without the WAL. The catchup demotes the old instance unless it is in a transient leader state, so a failed edit can make it writable again. Otherwise the old instance ends its catchup, so a later Leader lease can promote it with its memtable. A region that a failed catchup again demoted still awaits its lease, so a retry takes the same path. Every catchup from a remote WAL now also fails if its replay ends below the last entry the region acknowledged on this node. A manifest sync of a follower that awaits its Leader lease is refused, since it would replace the memtable the region keeps. Signed-off-by: jeremyhi <fengjiachun@gmail.com> * chore(mito2): log a refused manifest sync and drop two restating comments Signed-off-by: jeremyhi <fengjiachun@gmail.com> * test: consolidate the catch-up-again tests Signed-off-by: jeremyhi <fengjiachun@gmail.com> * test(mito2): cover rows dropped by a catchup again and fix review nits Signed-off-by: jeremyhi <fengjiachun@gmail.com> --------- Signed-off-by: jeremyhi <fengjiachun@gmail.com>