From bf1c1dba764989cc17b8c6972290de496702832a Mon Sep 17 00:00:00 2001 From: zwang28 <70626450+zwang28@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:04:10 +0800 Subject: [PATCH] fix(meta): include secret in meta backup for etcd meta store (#17908) --- src/meta/src/backup_restore/meta_snapshot_builder.rs | 4 +++- src/meta/src/backup_restore/restore_impl/v1.rs | 1 + src/meta/src/model/mod.rs | 3 ++- src/storage/backup/src/meta_snapshot_v1.rs | 11 ++++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/meta/src/backup_restore/meta_snapshot_builder.rs b/src/meta/src/backup_restore/meta_snapshot_builder.rs index bb8a1eb919fd..6696bd534b78 100644 --- a/src/meta/src/backup_restore/meta_snapshot_builder.rs +++ b/src/meta/src/backup_restore/meta_snapshot_builder.rs @@ -21,7 +21,7 @@ use risingwave_backup::meta_snapshot_v1::{ClusterMetadata, MetaSnapshotV1}; use risingwave_backup::MetaSnapshotId; use risingwave_hummock_sdk::version::{HummockVersion, HummockVersionDelta}; use risingwave_pb::catalog::{ - Connection, Database, Function, Index, Schema, Sink, Source, Subscription, Table, View, + Connection, Database, Function, Index, Schema, Secret, Sink, Source, Subscription, Table, View, }; use risingwave_pb::hummock::HummockVersionStats; use risingwave_pb::meta::SystemParams; @@ -124,6 +124,7 @@ impl MetaSnapshotV1Builder { .ok_or_else(|| anyhow!("cluster id not found in meta store"))? .into(); let subscription = Subscription::list_at_snapshot::(&meta_store_snapshot).await?; + let secret = Secret::list_at_snapshot::(&meta_store_snapshot).await?; self.snapshot.metadata = ClusterMetadata { default_cf, @@ -144,6 +145,7 @@ impl MetaSnapshotV1Builder { system_param, cluster_id, subscription, + secret, }; Ok(()) } diff --git a/src/meta/src/backup_restore/restore_impl/v1.rs b/src/meta/src/backup_restore/restore_impl/v1.rs index cc0fdb1baa41..0ceee8daa40b 100644 --- a/src/meta/src/backup_restore/restore_impl/v1.rs +++ b/src/meta/src/backup_restore/restore_impl/v1.rs @@ -199,5 +199,6 @@ async fn restore_metadata( restore_system_param_model(&meta_store, &[snapshot.metadata.system_param]).await?; restore_cluster_id(&meta_store, snapshot.metadata.cluster_id.into()).await?; restore_metadata_model(&meta_store, &snapshot.metadata.subscription).await?; + restore_metadata_model(&meta_store, &snapshot.metadata.secret).await?; Ok(()) } diff --git a/src/meta/src/model/mod.rs b/src/meta/src/model/mod.rs index 6b5f629a7c04..07f57ff1d6f6 100644 --- a/src/meta/src/model/mod.rs +++ b/src/meta/src/model/mod.rs @@ -207,7 +207,8 @@ macro_rules! for_all_metadata_models { ($macro:ident) => { $macro! { // These items should be included in a meta snapshot. - // So be sure to update meta backup/restore when adding new items. + // Make sure to update the meta backup&restore methods accordingly when adding new items, + // referring to https://github.com/risingwavelabs/risingwave/pull/15371/commits/c5a75320845a38cfb43241ddee16fd5c0e47833b { risingwave_pb::hummock::HummockVersionStats }, { crate::hummock::model::CompactionGroup }, { risingwave_pb::catalog::Database }, diff --git a/src/storage/backup/src/meta_snapshot_v1.rs b/src/storage/backup/src/meta_snapshot_v1.rs index b66609ed4eb2..9b4145ea2563 100644 --- a/src/storage/backup/src/meta_snapshot_v1.rs +++ b/src/storage/backup/src/meta_snapshot_v1.rs @@ -20,7 +20,7 @@ use itertools::Itertools; use risingwave_common::util::iter_util::ZipEqFast; use risingwave_hummock_sdk::version::HummockVersion; use risingwave_pb::catalog::{ - Connection, Database, Function, Index, Schema, Sink, Source, Subscription, Table, View, + Connection, Database, Function, Index, Schema, Secret, Sink, Source, Subscription, Table, View, }; use risingwave_pb::hummock::{CompactionGroup, HummockVersionStats, PbHummockVersion}; use risingwave_pb::meta::{SystemParams, TableFragments}; @@ -72,6 +72,10 @@ impl Display for ClusterMetadata { writeln!(f, "{:#?}", self.system_param)?; writeln!(f, "cluster_id:")?; writeln!(f, "{:#?}", self.cluster_id)?; + writeln!(f, "subscription:")?; + writeln!(f, "{:#?}", self.subscription)?; + writeln!(f, "secret:")?; + writeln!(f, "{:#?}", self.secret)?; Ok(()) } } @@ -121,6 +125,7 @@ pub struct ClusterMetadata { pub system_param: SystemParams, pub cluster_id: String, pub subscription: Vec, + pub secret: Vec, } impl ClusterMetadata { @@ -146,6 +151,7 @@ impl ClusterMetadata { Self::encode_prost_message(&self.system_param, buf); Self::encode_prost_message(&self.cluster_id, buf); Self::encode_prost_message_list(&self.subscription.iter().collect_vec(), buf); + Self::encode_prost_message_list(&self.secret.iter().collect_vec(), buf); Ok(()) } @@ -175,6 +181,8 @@ impl ClusterMetadata { let cluster_id: String = Self::decode_prost_message(&mut buf)?; let subscription: Vec = Self::try_decode_prost_message_list(&mut buf).unwrap_or_else(|| Ok(vec![]))?; + let secret: Vec = + Self::try_decode_prost_message_list(&mut buf).unwrap_or_else(|| Ok(vec![]))?; Ok(Self { default_cf, @@ -195,6 +203,7 @@ impl ClusterMetadata { system_param, cluster_id, subscription, + secret, }) }