From 5b9cf248a15ce1af4381809d0a3bdc464c4d3d31 Mon Sep 17 00:00:00 2001 From: zwang28 <70626450+zwang28@users.noreply.github.com> Date: Wed, 20 Nov 2024 01:16:35 +0800 Subject: [PATCH] fix(meta): remove custom serde (#19463) --- src/storage/backup/src/lib.rs | 48 ++----------------- .../hummock_sdk/src/state_table_info.rs | 2 + src/storage/src/hummock/backup_reader.rs | 2 +- 3 files changed, 7 insertions(+), 45 deletions(-) diff --git a/src/storage/backup/src/lib.rs b/src/storage/backup/src/lib.rs index 37fa28f4fe260..847efba5f26be 100644 --- a/src/storage/backup/src/lib.rs +++ b/src/storage/backup/src/lib.rs @@ -34,7 +34,6 @@ use std::collections::{HashMap, HashSet}; use std::hash::Hasher; use itertools::Itertools; -use risingwave_common::catalog::TableId; use risingwave_common::RW_VERSION; use risingwave_hummock_sdk::state_table_info::StateTableInfo; use risingwave_hummock_sdk::version::HummockVersion; @@ -56,8 +55,8 @@ pub struct MetaSnapshotMetadata { #[serde(default)] pub format_version: u32, pub remarks: Option, - #[serde(default, with = "table_id_key_map")] - pub state_table_info: HashMap, + #[serde(default)] + pub state_table_info: HashMap, pub rw_version: Option, } @@ -78,7 +77,7 @@ impl MetaSnapshotMetadata { .state_table_info .info() .iter() - .map(|(id, info)| (*id, info.into())) + .map(|(id, info)| (id.table_id, info.into())) .collect(), rw_version: Some(RW_VERSION.to_owned()), } @@ -119,7 +118,7 @@ impl From<&MetaSnapshotMetadata> for PbMetaSnapshotMetadata { state_table_info: m .state_table_info .iter() - .map(|(t, i)| (t.table_id, i.into())) + .map(|(t, i)| (*t, i.into())) .collect(), rw_version: m.rw_version.clone(), } @@ -134,42 +133,3 @@ impl From<&MetaSnapshotManifest> for PbMetaSnapshotManifest { } } } - -mod table_id_key_map { - use std::collections::HashMap; - use std::str::FromStr; - - use risingwave_common::catalog::TableId; - use serde::{Deserialize, Deserializer, Serialize, Serializer}; - - use crate::StateTableInfo; - - pub fn serialize( - map: &HashMap, - serializer: S, - ) -> Result - where - S: Serializer, - { - let map_as_str: HashMap = - map.iter().map(|(k, v)| (k.to_string(), v)).collect(); - map_as_str.serialize(serializer) - } - - pub fn deserialize<'de, D>( - deserializer: D, - ) -> Result, D::Error> - where - D: Deserializer<'de>, - { - let map_as_str: HashMap = - HashMap::deserialize(deserializer).unwrap_or_else(|_| HashMap::new()); - map_as_str - .into_iter() - .map(|(k, v)| { - let key = u32::from_str(&k).map_err(serde::de::Error::custom)?; - Ok((TableId::new(key), v)) - }) - .collect() - } -} diff --git a/src/storage/hummock_sdk/src/state_table_info.rs b/src/storage/hummock_sdk/src/state_table_info.rs index b15919fb2b065..3a0978b4f8f5b 100644 --- a/src/storage/hummock_sdk/src/state_table_info.rs +++ b/src/storage/hummock_sdk/src/state_table_info.rs @@ -17,7 +17,9 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone)] pub struct StateTableInfo { + #[serde(default)] pub committed_epoch: u64, + #[serde(default)] pub compaction_group_id: u64, } diff --git a/src/storage/src/hummock/backup_reader.rs b/src/storage/src/hummock/backup_reader.rs index 7fa2ee9dd9058..a09e2ca2bed74 100644 --- a/src/storage/src/hummock/backup_reader.rs +++ b/src/storage/src/hummock/backup_reader.rs @@ -195,7 +195,7 @@ impl BackupReader { .snapshot_metadata .iter() .find(|v| { - if let Some(m) = v.state_table_info.get(&table_id) { + if let Some(m) = v.state_table_info.get(&table_id.table_id()) { return epoch == m.committed_epoch; } false