krishvishal commented on code in PR #2675: URL: https://github.com/apache/iggy/pull/2675#discussion_r2781395575
########## core/metadata/src/stm/snapshot.rs: ########## @@ -0,0 +1,336 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use serde::{Deserialize, Serialize, de::DeserializeOwned}; +use std::fmt; + +#[derive(Debug)] +pub enum SnapshotError { + /// A required section is missing from the snapshot. + MissingSection(&'static str), + /// Serialization failed. + Serialize(rmp_serde::encode::Error), + /// Deserialization failed. + Deserialize(rmp_serde::decode::Error), + /// Slab ID mismatch during snapshot restore. + SlabIdMismatch { + section: &'static str, + expected: usize, + actual: usize, + }, + /// Duplicate section name detected in snapshot. + DuplicateSection(String), +} + +impl fmt::Display for SnapshotError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + SnapshotError::MissingSection(name) => { + write!(f, "missing snapshot section: {}", name) + } + SnapshotError::Serialize(e) => write!(f, "snapshot serialization failed: {}", e), + SnapshotError::Deserialize(e) => write!(f, "snapshot deserialization failed: {}", e), + SnapshotError::SlabIdMismatch { + section, + expected, + actual, + } => { + write!( + f, + "slab ID mismatch in section '{}': expected {}, got {}", + section, expected, actual + ) + } + SnapshotError::DuplicateSection(name) => { + write!(f, "duplicate snapshot section name: {}", name) + } + } + } +} + +impl std::error::Error for SnapshotError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + SnapshotError::Serialize(e) => Some(e), + SnapshotError::Deserialize(e) => Some(e), + _ => None, + } + } +} + +/// The outer envelope for a complete metadata snapshot. +/// +/// Contains metadata about the snapshot and a collection of sections, +/// where each section corresponds to one state machine's serialized state. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SnapshotEnvelope { Review Comment: Removed `SnapshotEnvelope`. Now we store each snapshot struct and serialize it in one shot. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
