Skip to main content

mito2/region/
catchup.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::Arc;
16use std::time::Instant;
17
18use common_telemetry::{info, warn};
19use futures::try_join;
20use snafu::{OptionExt, ensure};
21use store_api::ManifestVersion;
22use store_api::logstore::LogStore;
23use store_api::region_request::RegionCatchupRequest;
24use store_api::storage::{RegionId, SequenceNumber};
25
26use crate::engine::region_hook::PendingManifestHook;
27use crate::error::{self, Result};
28use crate::lease::{GrantedLeases, NodeLease};
29use crate::manifest::action::{
30    HandoffFloor, PendingTail, RegionEdit, RegionManifest, UptoKind, WalRecoveryEdit,
31    cap_wal_release,
32};
33use crate::manifest::manager::RegionManifestManager;
34use crate::region::MitoRegion;
35use crate::region::opener::{check_wal_history, replay_memtable};
36use crate::wal::entry_distributor::WalEntryReceiver;
37use crate::wal::{EntryId, Wal};
38
39/// How far a handover raises the committed sequence above the largest sequence this node knows
40/// the region used, in the manifest or on this node, so that writes accepted while the recorded
41/// tail is replayed outrank its rows. Those rows keep the sequences their source gave them, which
42/// this node does not know: the gap allows the source fewer than 2^40 sequences that the manifest
43/// does not record.
44const HANDOVER_SEQUENCE_GAP: SequenceNumber = 1 << 40;
45/// The largest committed sequence a handover raises a region to, which allows about 2^22
46/// handovers that record a tail. A handover that would pass it fails, leaving the sequences above
47/// it to the region's writes, which allocate them without checking for overflow.
48const MAX_HANDOVER_SEQUENCE: SequenceNumber = 1 << 62;
49
50/// What a takeover, a catchup that carries no entry its source reported, prepares before the
51/// worker checks the region.
52#[derive(Debug, Clone, Copy)]
53pub(crate) struct TakeoverPrepared {
54    /// The latest manifest version in storage when the takeover began. The takeover commits
55    /// the version after it.
56    pub(crate) version: ManifestVersion,
57    /// When reading that version returned. Only a lease of a heartbeat sent later counts.
58    pub(crate) read_at: Instant,
59    /// The bound the listing of the source's WAL returned, at or above every entry in the listed
60    /// objects.
61    pub(crate) bound: EntryId,
62    /// The candidate lease id of the migration's registration of the region.
63    pub(crate) candidate_lease_id: u64,
64}
65
66/// The candidate lease a takeover waits for before it commits.
67pub(crate) struct CandidateLease<'a> {
68    pub(crate) prepared: TakeoverPrepared,
69    pub(crate) leases: &'a GrantedLeases,
70    pub(crate) node_lease: &'a NodeLease,
71}
72
73impl CandidateLease<'_> {
74    /// Waits for a lease of the region's candidate, see [GrantedLeases::wait_for_candidate_lease].
75    pub(crate) async fn wait(&self, region: &MitoRegion) -> Result<()> {
76        let region_id = region.region_id;
77        self.leases
78            .wait_for_candidate_lease(
79                self.node_lease,
80                region_id,
81                self.prepared.candidate_lease_id,
82                self.prepared.read_at,
83                || region.manifest_ctx.is_stopped(),
84            )
85            .await
86            .map_err(|reason| error::CandidateLeaseNotReceivedSnafu { region_id, reason }.build())
87    }
88
89    /// Checks again that the lease of this node has not expired, that the latest lease of the
90    /// region is the candidate's, and that the manifest `manager` holds is the version the
91    /// takeover began from.
92    pub(crate) fn check(&self, region_id: RegionId, manager: &RegionManifestManager) -> Result<()> {
93        let TakeoverPrepared {
94            candidate_lease_id,
95            read_at,
96            ..
97        } = self.prepared;
98        ensure!(
99            !(self.node_lease.is_enabled() && self.node_lease.is_expired()),
100            error::CandidateLeaseNotReceivedSnafu {
101                region_id,
102                reason: "the lease of this node expired",
103            }
104        );
105        self.leases
106            .get(region_id)
107            .and_then(|lease| lease.of_candidate_after(candidate_lease_id, read_at))
108            .unwrap_or_else(|| Err("no lease sent after the catchup began".to_string()))
109            .map_err(|reason| {
110                error::CandidateLeaseNotReceivedSnafu { region_id, reason }.build()
111            })?;
112        ensure!(
113            manager.manifest().manifest_version == self.prepared.version,
114            error::RegionBusySnafu { region_id }
115        );
116        Ok(())
117    }
118}
119
120/// Returns the source of a takeover: a catchup that makes `region`, whose manifest is published
121/// conditionally, writable and names a source but no entry the source reported.
122pub(crate) fn takeover_source(request: &RegionCatchupRequest, region: &MitoRegion) -> Option<u64> {
123    match (
124        request.set_writable,
125        request.entry_id,
126        request.source_node_id,
127    ) {
128        (true, None, Some(source)) if region.manifest_ctx.is_conditional_publication() => {
129            Some(source)
130        }
131        _ => None,
132    }
133}
134
135/// Hands a region whose manifest is published conditionally over to this node `node_id`, which
136/// becomes its writer, from the source node `source_node_id` that reported `upto` as its last
137/// entry or, in a takeover (`candidate` is set), whose WAL listing returned `upto`, a bound at or
138/// above every entry in the listed objects; entries of the source above `upto` are not recovered.
139/// Replays nothing.
140///
141/// The log store first hands the region over (see [Wal::handoff]); a takeover also waits for the
142/// lease of its candidate meanwhile. Then the catchup commits, after the manifest the region
143/// holds (in a takeover, the version it began from), this node's handoff floor, the bound that
144/// hand-off returned, and, if `upto` is above where the manifest recovers the source's WAL from,
145/// a tail of the source up to `upto` (of kind Reported, or Listed in a takeover), raising the
146/// committed sequence by [HANDOVER_SEQUENCE_GAP]. The tail is replayed in the background once the
147/// region is writable.
148///
149/// Returns the receipt of the manifest hook and the committed edit, which the region's worker
150/// applies to the region's version, in order with the edits of flushes and compactions.
151///
152/// Fails before the log store handoff if there are entries to recover and the request names
153/// no source, or if the region has no sequences left for another handover.
154pub(crate) async fn hand_over<S: LogStore>(
155    region: &MitoRegion,
156    wal: &Wal<S>,
157    node_id: Option<u64>,
158    source_node_id: Option<u64>,
159    upto: EntryId,
160    candidate: Option<CandidateLease<'_>>,
161) -> Result<(PendingManifestHook, RegionEdit)> {
162    let region_id = region.region_id;
163    let node_id = node_id.with_context(|| error::UnexpectedSnafu {
164        reason: format!("No node id to hand region {region_id} over to"),
165    })?;
166    let upto_kind = if candidate.is_some() {
167        UptoKind::Listed
168    } else {
169        UptoKind::Reported
170    };
171    let bound = {
172        let manifest = region.manifest_ctx.manifest().await;
173        let bound = handoff_entry_id(upto, manifest.flushed_entry_id, &manifest.pending_tails);
174        // A handover that cannot commit after this manifest fails before the log store hands the
175        // region over. The commit builds the edit again for the manifest it commits after.
176        handover_edit(
177            &manifest,
178            region.version_control.current().last_sequence,
179            HandoffFloor {
180                node_id,
181                entry_id: bound,
182            },
183            source_node_id,
184            upto,
185            upto_kind,
186        )?;
187        bound
188    };
189    let handoff = wal.handoff(region_id, &region.provider, bound);
190    let floor = match &candidate {
191        // An abandoned hand-off leaves a raised sequence floor and a release record of the
192        // unchanged watermark, which only keep this node's later ids higher. If the candidate wait
193        // fails, the log store may still persist them while the region's local history
194        // (`start_region_history`) is not registered; this attempt commits no handover, and a later
195        // successful hand-off registers the history.
196        Some(candidate) => try_join!(handoff, candidate.wait(region))?.0,
197        None => handoff.await?,
198    };
199    let mut manager = region.manifest_ctx.manifest_manager.write().await;
200    if let Some(candidate) = &candidate {
201        candidate.check(region_id, &manager)?;
202    }
203    let edit = handover_edit(
204        &manager.manifest(),
205        region.version_control.current().last_sequence,
206        HandoffFloor {
207            node_id,
208            entry_id: floor,
209        },
210        source_node_id,
211        upto,
212        upto_kind,
213    )?;
214    let pending = region
215        .manifest_ctx
216        .commit_catchup_locked(&mut manager, edit.clone())
217        .await?;
218    Ok((pending, edit))
219}
220
221pub struct RegionCatchupTask<S> {
222    entry_receiver: Option<WalEntryReceiver>,
223    region: Arc<MitoRegion>,
224    replay_checkpoint_entry_id: Option<u64>,
225    expected_last_entry_id: Option<u64>,
226    /// The largest entry id the region acknowledged on this node.
227    acknowledged_entry_id: u64,
228    /// Whether the catchup makes the region writable on this node.
229    set_writable: bool,
230    /// Id of this node.
231    node_id: Option<u64>,
232    allow_stale_entries: bool,
233    wal: Wal<S>,
234}
235
236impl<S: LogStore> RegionCatchupTask<S> {
237    pub fn new(region: Arc<MitoRegion>, wal: Wal<S>, allow_stale_entries: bool) -> Self {
238        Self {
239            entry_receiver: None,
240            region,
241            replay_checkpoint_entry_id: None,
242            expected_last_entry_id: None,
243            acknowledged_entry_id: 0,
244            set_writable: false,
245            node_id: None,
246            allow_stale_entries,
247            wal,
248        }
249    }
250
251    /// Sets whether the catchup makes the region writable on this node.
252    pub(crate) fn with_set_writable(mut self, set_writable: bool) -> Self {
253        self.set_writable = set_writable;
254        self
255    }
256
257    /// Sets the id of this node, whose WAL the catchup replays.
258    pub(crate) fn with_node_id(mut self, node_id: Option<u64>) -> Self {
259        self.node_id = node_id;
260        self
261    }
262
263    /// Sets the expected last entry id.
264    pub(crate) fn with_expected_last_entry_id(
265        mut self,
266        expected_last_entry_id: Option<u64>,
267    ) -> Self {
268        self.expected_last_entry_id = expected_last_entry_id;
269        self
270    }
271
272    /// Sets the largest entry id the region acknowledged on this node, which the replay of a
273    /// remote WAL waits to be durable and must reach.
274    pub(crate) fn with_acknowledged_entry_id(mut self, acknowledged_entry_id: u64) -> Self {
275        self.acknowledged_entry_id = acknowledged_entry_id;
276        self
277    }
278
279    /// Sets the entry receiver.
280    pub(crate) fn with_entry_receiver(mut self, entry_receiver: Option<WalEntryReceiver>) -> Self {
281        self.entry_receiver = entry_receiver;
282        self
283    }
284
285    /// Sets the replay checkpoint entry id.
286    pub(crate) fn with_replay_checkpoint_entry_id(
287        mut self,
288        replay_checkpoint_entry_id: Option<u64>,
289    ) -> Self {
290        self.replay_checkpoint_entry_id = replay_checkpoint_entry_id;
291        self
292    }
293
294    pub async fn run(&mut self) -> Result<()> {
295        if self.region.provider.is_remote_wal() {
296            self.remote_wal_catchup().await
297        } else {
298            self.local_wal_catchup().await
299        }
300    }
301
302    async fn remote_wal_catchup(&mut self) -> Result<()> {
303        let flushed_entry_id = self.region.version_control.current().last_entry_id;
304        // Entries up to where the manifest recovers this node's WAL from are flushed, left to
305        // the pending tails or below this node's handoff floor.
306        let (replay_from_entry_id, release_entry_id) = {
307            let manifest = self.region.manifest_ctx.manifest().await;
308            let replay_from_entry_id = self
309                .replay_checkpoint_entry_id
310                .unwrap_or(flushed_entry_id)
311                .max(flushed_entry_id)
312                .max(manifest.wal_replay_start(self.node_id));
313            let release_entry_id =
314                cap_wal_release(&manifest.pending_tails, self.node_id, replay_from_entry_id);
315            (replay_from_entry_id, release_entry_id)
316        };
317        let region_id = self.region.region_id;
318        info!(
319            "Trying to replay memtable for region: {region_id}, provider: {:?}, replay from entry id: {replay_from_entry_id}, flushed entry id: {flushed_entry_id}",
320            self.region.provider
321        );
322        let version = self.region.version_control.current().version;
323        // A catchup that makes the region writable and carries the entry id its source reported
324        // hands the region over to this node's log store; of the catchups of a region whose
325        // manifest is published conditionally, only a catchup again gets here, the others are
326        // handed over by [hand_over]. From now on the region takes ids above every id the
327        // source, the manifest or a pending tail used, so a later rise of its flushed entry id
328        // passes none of its new entries, and this node's log store holds its history from here
329        // on. A catchup that still has to replay entries above where its
330        // replay starts hands nothing over, so if it cannot reach them it leaves nothing behind.
331        if self.set_writable
332            && let Some(reported_entry_id) = self.expected_last_entry_id
333            && reported_entry_id <= replay_from_entry_id
334            && !version.options.skip_wal
335        {
336            let entry_id = handoff_entry_id(
337                reported_entry_id,
338                version.flushed_entry_id,
339                &version.pending_tails,
340            );
341            self.wal
342                .handoff(region_id, &self.region.provider, entry_id)
343                .await?;
344        }
345        check_wal_history(&self.wal, &self.region.provider, &version).await?;
346        let timer = Instant::now();
347        // The replay reads only what the log store has made durable.
348        self.wal
349            .durability_barrier(region_id, &self.region.provider)
350            .wait(self.acknowledged_entry_id)
351            .await?;
352        let wal_entry_reader = self
353            .entry_receiver
354            .take()
355            .map(|r| Box::new(r) as _)
356            .unwrap_or_else(|| self.wal.wal_entry_reader(&self.region.provider, region_id));
357        let on_region_opened = self.wal.on_region_opened();
358        let last_entry_id = replay_memtable(
359            &self.region.provider,
360            wal_entry_reader,
361            region_id,
362            replay_from_entry_id,
363            release_entry_id,
364            &self.region.version_control,
365            self.allow_stale_entries,
366            on_region_opened,
367        )
368        .await?;
369        info!(
370            "Elapsed: {:?}, region: {region_id}, provider: {:?} catchup finished. replay from entry id: {replay_from_entry_id}, flushed entry id: {flushed_entry_id}, last entry id: {last_entry_id}, expected: {:?}, acknowledged: {}.",
371            timer.elapsed(),
372            self.region.provider,
373            self.expected_last_entry_id,
374            self.acknowledged_entry_id
375        );
376        // The replay also reaches the entries the region acknowledged on this node.
377        let expected_last_entry_id = self
378            .expected_last_entry_id
379            .unwrap_or_default()
380            .max(self.acknowledged_entry_id);
381        ensure!(
382            // The replayed last entry id may be greater than the `expected_last_entry_id`.
383            last_entry_id >= expected_last_entry_id,
384            error::UnexpectedSnafu {
385                reason: format!(
386                    "Failed to catchup region {}, it was expected to replay to {} (expected: {:?}, acknowledged: {}), but actually replayed to {}",
387                    region_id,
388                    expected_last_entry_id,
389                    self.expected_last_entry_id,
390                    self.acknowledged_entry_id,
391                    last_entry_id,
392                ),
393            }
394        );
395        Ok(())
396    }
397
398    async fn local_wal_catchup(&mut self) -> Result<()> {
399        let version = self.region.version_control.current();
400        let mut flushed_entry_id = version.last_entry_id;
401        let region_id = self.region.region_id;
402        let latest_entry_id = self
403            .wal
404            .store()
405            .latest_entry_id(&self.region.provider)
406            .unwrap_or_default();
407        info!(
408            "Skips to replay memtable for region: {}, flushed entry id: {}, latest entry id: {}",
409            region_id, flushed_entry_id, latest_entry_id
410        );
411
412        if latest_entry_id > flushed_entry_id {
413            warn!(
414                "Found latest entry id is greater than flushed entry id, using latest entry id as flushed entry id, region: {}, latest entry id: {}, flushed entry id: {}",
415                region_id, latest_entry_id, flushed_entry_id
416            );
417            flushed_entry_id = latest_entry_id;
418            self.region.version_control.set_entry_id(flushed_entry_id);
419        }
420        let on_region_opened = self.wal.on_region_opened();
421        on_region_opened(region_id, flushed_entry_id, &self.region.provider).await?;
422        Ok(())
423    }
424}
425
426/// Returns the entry id a hand-off of the region has to cover: the largest of `upto` (the source's
427/// reported entry, or the listed bound in a takeover), its flushed entry id and the bounds of its
428/// pending tails.
429fn handoff_entry_id(
430    upto: EntryId,
431    flushed_entry_id: EntryId,
432    pending_tails: &[PendingTail],
433) -> EntryId {
434    pending_tails
435        .iter()
436        .map(|tail| tail.upto)
437        .fold(upto.max(flushed_entry_id), EntryId::max)
438}
439
440/// Returns the edit of a handover to `floor.node_id` (see [hand_over]) that commits after
441/// `manifest`, recording a tail whose bound is of kind `upto_kind`. `last_sequence` is the largest
442/// sequence the region used on this node.
443fn handover_edit(
444    manifest: &RegionManifest,
445    last_sequence: SequenceNumber,
446    floor: HandoffFloor,
447    source_node_id: Option<u64>,
448    upto: EntryId,
449    upto_kind: UptoKind,
450) -> Result<RegionEdit> {
451    let region_id = manifest.metadata.region_id;
452    let mut edit = RegionEdit {
453        wal_recovery: WalRecoveryEdit {
454            pending_tails: None,
455            handoff_floor: Some(floor),
456        },
457        ..Default::default()
458    };
459    // Entries of the source up to here are flushed, in its tails or below its handoff floor.
460    let after = manifest.wal_replay_start(source_node_id);
461    if after >= upto {
462        return Ok(edit);
463    }
464    let node_id = source_node_id.with_context(|| error::InvalidRequestSnafu {
465        region_id,
466        reason: format!(
467            "the request names no source of the entries in ({after}, {upto}] to recover"
468        ),
469    })?;
470    let committed_sequence = manifest
471        .committed_sequence
472        .unwrap_or_default()
473        .max(manifest.flushed_sequence)
474        .max(last_sequence)
475        .checked_add(HANDOVER_SEQUENCE_GAP)
476        .filter(|sequence| *sequence <= MAX_HANDOVER_SEQUENCE)
477        .with_context(|| error::UnexpectedSnafu {
478            reason: format!("Region {region_id} has no sequences left for another handover"),
479        })?;
480    let mut tails = manifest.pending_tails.clone();
481    tails.push(PendingTail {
482        node_id,
483        after,
484        upto,
485        upto_kind,
486    });
487    edit.committed_sequence = Some(committed_sequence);
488    edit.wal_recovery.pending_tails = Some(tails);
489    Ok(edit)
490}
491
492#[cfg(test)]
493mod tests {
494    use std::collections::BTreeMap;
495
496    use super::*;
497    use crate::error::Error;
498    use crate::manifest::action::{RegionChange, RegionManifestBuilder};
499    use crate::sst::FormatType;
500    use crate::test_util::tail;
501
502    const NODE_ID: u64 = 1;
503    const SOURCE: u64 = 2;
504
505    /// Returns a manifest flushed through entry 10 and sequence 9, with sequence 7 committed,
506    /// the given tails and the handoff floor of [SOURCE].
507    fn manifest(tails: Vec<PendingTail>, source_floor: Option<EntryId>) -> RegionManifest {
508        let mut builder = RegionManifestBuilder::default();
509        builder.apply_change(
510            0,
511            RegionChange {
512                metadata: crate::test_util::memtable_util::metadata_for_test(),
513                sst_format: FormatType::PrimaryKey,
514                append_mode: None,
515            },
516        );
517        builder.apply_edit(
518            1,
519            RegionEdit {
520                flushed_entry_id: Some(10),
521                flushed_sequence: Some(9),
522                committed_sequence: Some(7),
523                wal_recovery: WalRecoveryEdit {
524                    pending_tails: Some(tails),
525                    handoff_floor: source_floor.map(|entry_id| HandoffFloor {
526                        node_id: SOURCE,
527                        entry_id,
528                    }),
529                },
530                ..Default::default()
531            },
532        );
533        builder.try_build().unwrap()
534    }
535
536    fn floor(entry_id: EntryId) -> HandoffFloor {
537        HandoffFloor {
538            node_id: NODE_ID,
539            entry_id,
540        }
541    }
542
543    #[test]
544    fn test_handover_records_source_entries_after_its_recovery_start() {
545        let other = tail(3, 10, 30);
546        for (tails, source_floor, after) in [
547            (vec![], None, 10),
548            (vec![tail(SOURCE, 10, 20), other.clone()], None, 20),
549            (vec![tail(SOURCE, 10, 20)], Some(25), 25),
550        ] {
551            let manifest = manifest(tails.clone(), source_floor);
552            let edit = handover_edit(
553                &manifest,
554                12,
555                floor(50),
556                Some(SOURCE),
557                40,
558                UptoKind::Reported,
559            )
560            .unwrap();
561
562            let mut expected = tails;
563            expected.push(tail(SOURCE, after, 40));
564            assert_eq!(edit.wal_recovery.pending_tails, Some(expected));
565            assert_eq!(edit.wal_recovery.handoff_floor, Some(floor(50)));
566            // Above the sequence the region used, which is above those in the manifest.
567            assert_eq!(edit.committed_sequence, Some(12 + HANDOVER_SEQUENCE_GAP));
568            assert_eq!(edit.flushed_entry_id, None);
569        }
570        let edit = handover_edit(
571            &manifest(vec![], None),
572            0,
573            floor(50),
574            Some(SOURCE),
575            40,
576            UptoKind::Reported,
577        )
578        .unwrap();
579        assert_eq!(edit.committed_sequence, Some(9 + HANDOVER_SEQUENCE_GAP));
580        let mut raised = manifest(vec![], None);
581        raised.committed_sequence = Some(20);
582        let edit =
583            handover_edit(&raised, 12, floor(50), Some(SOURCE), 40, UptoKind::Reported).unwrap();
584        assert_eq!(edit.committed_sequence, Some(20 + HANDOVER_SEQUENCE_GAP));
585    }
586
587    #[test]
588    fn test_handover_without_new_source_entries_records_only_the_floor() {
589        for (tails, source_floor, source, reported) in [
590            (vec![], None, Some(SOURCE), 10),
591            (vec![tail(SOURCE, 10, 40)], None, Some(SOURCE), 40),
592            (vec![], Some(40), Some(SOURCE), 40),
593            // Without new entries the source need not be known.
594            (vec![], None, None, 8),
595        ] {
596            let manifest = manifest(tails, source_floor);
597            let edit = handover_edit(
598                &manifest,
599                12,
600                floor(50),
601                source,
602                reported,
603                UptoKind::Reported,
604            )
605            .unwrap();
606            assert_eq!(
607                edit,
608                RegionEdit {
609                    wal_recovery: WalRecoveryEdit {
610                        pending_tails: None,
611                        handoff_floor: Some(floor(50)),
612                    },
613                    ..Default::default()
614                }
615            );
616        }
617    }
618
619    #[test]
620    fn test_handover_fails_if_the_source_of_new_entries_is_unknown() {
621        // Another node's tail and floor do not count for an unknown source.
622        let mut manifest = manifest(vec![tail(3, 10, 40)], None);
623        manifest.handoff_floors = BTreeMap::from([(3, 45)]);
624        let error =
625            handover_edit(&manifest, 12, floor(50), None, 40, UptoKind::Reported).unwrap_err();
626        assert!(matches!(error, Error::InvalidRequest { .. }), "{error:?}");
627    }
628
629    #[test]
630    fn test_handover_fails_without_sequences_left() {
631        let manifest = manifest(vec![], None);
632        let last_sequence = MAX_HANDOVER_SEQUENCE - HANDOVER_SEQUENCE_GAP;
633        let edit = handover_edit(
634            &manifest,
635            last_sequence,
636            floor(50),
637            Some(SOURCE),
638            40,
639            UptoKind::Reported,
640        )
641        .unwrap();
642        assert_eq!(edit.committed_sequence, Some(MAX_HANDOVER_SEQUENCE));
643        let error = handover_edit(
644            &manifest,
645            last_sequence + 1,
646            floor(50),
647            Some(SOURCE),
648            40,
649            UptoKind::Reported,
650        )
651        .unwrap_err();
652        assert!(matches!(error, Error::Unexpected { .. }), "{error:?}");
653    }
654}