Skip to content

Commit

Permalink
fix(meta): remove custom serde (#19463)
Browse files Browse the repository at this point in the history
  • Loading branch information
zwang28 authored Nov 19, 2024
1 parent 1c29c81 commit 5b9cf24
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 45 deletions.
48 changes: 4 additions & 44 deletions src/storage/backup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,8 +55,8 @@ pub struct MetaSnapshotMetadata {
#[serde(default)]
pub format_version: u32,
pub remarks: Option<String>,
#[serde(default, with = "table_id_key_map")]
pub state_table_info: HashMap<TableId, StateTableInfo>,
#[serde(default)]
pub state_table_info: HashMap<u32, StateTableInfo>,
pub rw_version: Option<String>,
}

Expand All @@ -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()),
}
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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<S>(
map: &HashMap<TableId, StateTableInfo>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let map_as_str: HashMap<String, &StateTableInfo> =
map.iter().map(|(k, v)| (k.to_string(), v)).collect();
map_as_str.serialize(serializer)
}

pub fn deserialize<'de, D>(
deserializer: D,
) -> Result<HashMap<TableId, StateTableInfo>, D::Error>
where
D: Deserializer<'de>,
{
let map_as_str: HashMap<String, StateTableInfo> =
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()
}
}
2 changes: 2 additions & 0 deletions src/storage/hummock_sdk/src/state_table_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/hummock/backup_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b9cf24

Please sign in to comment.