Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix missing rewrite of table fragments during migration to sql backend #19813

Open
wants to merge 4 commits into
base: release-2.0
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions src/ctl/src/cmd_impl/meta/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::{BTreeSet, HashMap, HashSet};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::time::Duration;

use anyhow::Context;
Expand Down Expand Up @@ -59,14 +59,17 @@ use risingwave_meta_model_v2::{
use risingwave_pb::catalog::table::PbTableType;
use risingwave_pb::catalog::{
PbConnection, PbDatabase, PbFunction, PbIndex, PbSchema, PbSecret, PbSink, PbSource,
PbSubscription, PbTable, PbView,
PbStreamSourceInfo, PbSubscription, PbTable, PbView,
};
use risingwave_pb::common::WorkerType;
use risingwave_pb::hummock::{
CompactTaskAssignment, HummockPinnedSnapshot, HummockPinnedVersion, HummockVersionStats,
};
use risingwave_pb::meta::table_fragments::State;
use risingwave_pb::meta::PbSystemParams;
use risingwave_pb::secret::PbSecretRef;
use risingwave_pb::stream_plan::stream_node::PbNodeBody;
use risingwave_pb::stream_plan::PbStreamNode;
use risingwave_pb::user::grant_privilege::PbObject as GrantObject;
use risingwave_pb::user::PbUserInfo;
use sea_orm::ActiveValue::Set;
Expand Down Expand Up @@ -468,6 +471,9 @@ pub async fn migrate(from: EtcdBackend, target: String, force_clean: bool) -> an
table.database_id = *db_rewrite.get(&table.database_id).unwrap();
table.schema_id = *schema_rewrite.get(&table.schema_id).unwrap();
});
// rewrite secret ids.
visit_secret_ref_mut(&mut stream_node, &secret_rewrite);

let mut fragment = fragment.into_active_model();
fragment.stream_node = Set((&stream_node).into());
Fragment::insert(fragment)
Expand Down Expand Up @@ -561,7 +567,12 @@ pub async fn migrate(from: EtcdBackend, target: String, force_clean: bool) -> an
if let Some(info) = &mut src.info {
for secret_ref in info.format_encode_secret_refs.values_mut() {
secret_ref.secret_id = *secret_rewrite.get(&secret_ref.secret_id).unwrap();
dependent_secret_ids.insert(secret_ref.secret_id);
}
if let Some(table) = &mut info.external_table {
for secret_ref in table.secret_refs.values_mut() {
secret_ref.secret_id =
*secret_rewrite.get(&secret_ref.secret_id).unwrap();
}
}
}
object_dependencies.extend(dependent_secret_ids.into_iter().map(|secret_id| {
Expand Down Expand Up @@ -968,6 +979,62 @@ pub async fn migrate(from: EtcdBackend, target: String, force_clean: bool) -> an
Ok(())
}

fn visit_secret_ref_mut(stream_node: &mut PbStreamNode, secret_rewrite: &HashMap<u32, u32>) {
let visit_map_secret_refs = |refs: &mut BTreeMap<String, PbSecretRef>| {
for secret_ref in refs.values_mut() {
secret_ref.secret_id = *secret_rewrite.get(&secret_ref.secret_id).unwrap();
}
};
let visit_info = |info: &mut PbStreamSourceInfo| {
for secret_ref in info.format_encode_secret_refs.values_mut() {
secret_ref.secret_id = *secret_rewrite.get(&secret_ref.secret_id).unwrap();
}
if let Some(table) = &mut info.external_table {
for secret_ref in table.secret_refs.values_mut() {
secret_ref.secret_id = *secret_rewrite.get(&secret_ref.secret_id).unwrap();
}
}
};

let visit_body = |body: &mut PbNodeBody| match body {
PbNodeBody::Source(node) => {
if let Some(inner) = &mut node.source_inner {
visit_map_secret_refs(&mut inner.secret_refs);
inner.info.as_mut().map(visit_info);
}
}
PbNodeBody::Sink(node) => {
if let Some(desc) = &mut node.sink_desc {
visit_map_secret_refs(&mut desc.secret_refs);
desc.format_desc
.as_mut()
.map(|desc| visit_map_secret_refs(&mut desc.secret_refs));
}
}
PbNodeBody::StreamFsFetch(node) => {
if let Some(inner) = &mut node.node_inner {
visit_map_secret_refs(&mut inner.secret_refs);
inner.info.as_mut().map(visit_info);
}
}
PbNodeBody::StreamCdcScan(node) => {
node.cdc_table_desc
.as_mut()
.map(|desc| visit_map_secret_refs(&mut desc.secret_refs));
}
PbNodeBody::CdcFilter(_) => {}
yezizp2012 marked this conversation as resolved.
Show resolved Hide resolved
PbNodeBody::SourceBackfill(node) => {
visit_map_secret_refs(&mut node.secret_refs);
node.info.as_mut().map(visit_info);
}
_ => {}
};
visit_body(stream_node.node_body.as_mut().unwrap());
for input in &mut stream_node.input {
visit_secret_ref_mut(input, secret_rewrite);
}
}

async fn load_current_id(meta_store: &MetaStoreRef, category: &str, start: Option<u64>) -> u64 {
let category_gen_key = format!("{}_id_next_generator", category);
let res = meta_store
Expand Down
Loading