From 211d7bcee572e7bc1cd50b48248e745bb93820bd Mon Sep 17 00:00:00 2001 From: zwang28 <70626450+zwang28@users.noreply.github.com> Date: Tue, 10 Oct 2023 16:58:07 +0800 Subject: [PATCH] feat(meta): define model V2 for hummock metadata (#12674) --- src/common/src/system_param/mod.rs | 4 +- .../backup_restore/meta_snapshot_builder.rs | 1 - src/meta/src/backup_restore/restore.rs | 15 +- src/meta/src/hummock/manager/mod.rs | 33 +-- src/meta/src/hummock/model/mod.rs | 3 - src/meta/src/hummock/model/version.rs | 46 --- src/meta/src/model_v2/compaction_config.rs | 29 ++ src/meta/src/model_v2/compaction_status.rs | 29 ++ src/meta/src/model_v2/compaction_task.rs | 30 ++ .../src/model_v2/hummock_pinned_snapshot.rs | 28 ++ .../src/model_v2/hummock_pinned_version.rs | 28 ++ .../src/model_v2/hummock_version_delta.rs | 35 +++ .../src/model_v2/hummock_version_stats.rs | 29 ++ src/meta/src/model_v2/migration/src/lib.rs | 6 +- .../migration/src/m20231008_020431_hummock.rs | 264 ++++++++++++++++++ src/meta/src/model_v2/mod.rs | 7 + src/meta/src/model_v2/prelude.rs | 7 + 17 files changed, 506 insertions(+), 88 deletions(-) delete mode 100644 src/meta/src/hummock/model/version.rs create mode 100644 src/meta/src/model_v2/compaction_config.rs create mode 100644 src/meta/src/model_v2/compaction_status.rs create mode 100644 src/meta/src/model_v2/compaction_task.rs create mode 100644 src/meta/src/model_v2/hummock_pinned_snapshot.rs create mode 100644 src/meta/src/model_v2/hummock_pinned_version.rs create mode 100644 src/meta/src/model_v2/hummock_version_delta.rs create mode 100644 src/meta/src/model_v2/hummock_version_stats.rs create mode 100644 src/meta/src/model_v2/migration/src/m20231008_020431_hummock.rs diff --git a/src/common/src/system_param/mod.rs b/src/common/src/system_param/mod.rs index 5215e1cc144e..0b35d53ae7e8 100644 --- a/src/common/src/system_param/mod.rs +++ b/src/common/src/system_param/mod.rs @@ -51,8 +51,8 @@ macro_rules! for_all_params { { bloom_false_positive, f64, Some(0.001_f64), false }, { state_store, String, None, false }, { data_directory, String, None, false }, - { backup_storage_url, String, Some("memory".to_string()), false }, - { backup_storage_directory, String, Some("backup".to_string()), false }, + { backup_storage_url, String, Some("memory".to_string()), true }, + { backup_storage_directory, String, Some("backup".to_string()), true }, { max_concurrent_creating_streaming_jobs, u32, Some(1_u32), true }, { pause_on_next_bootstrap, bool, Some(false), true }, } diff --git a/src/meta/src/backup_restore/meta_snapshot_builder.rs b/src/meta/src/backup_restore/meta_snapshot_builder.rs index e54c9f443f12..ef98c1158fd2 100644 --- a/src/meta/src/backup_restore/meta_snapshot_builder.rs +++ b/src/meta/src/backup_restore/meta_snapshot_builder.rs @@ -191,7 +191,6 @@ mod tests { let v_ = v.clone(); async move { v_ } }; - hummock_version.insert(&meta_store).await.unwrap(); let err = builder .build(1, get_ckpt_builder(&hummock_version)) .await diff --git a/src/meta/src/backup_restore/restore.rs b/src/meta/src/backup_restore/restore.rs index 36e493686956..ab4696e62f9b 100644 --- a/src/meta/src/backup_restore/restore.rs +++ b/src/meta/src/backup_restore/restore.rs @@ -152,7 +152,6 @@ async fn restore_default_cf( async fn restore_metadata(meta_store: S, snapshot: MetaSnapshot) -> BackupResult<()> { restore_default_cf(&meta_store, &snapshot).await?; - restore_metadata_model(&meta_store, &[snapshot.metadata.hummock_version]).await?; restore_metadata_model(&meta_store, &[snapshot.metadata.version_stats]).await?; restore_metadata_model( &meta_store, @@ -290,7 +289,7 @@ mod tests { use itertools::Itertools; use risingwave_backup::meta_snapshot::{ClusterMetadata, MetaSnapshot}; use risingwave_common::config::{MetaBackend, SystemConfig}; - use risingwave_pb::hummock::HummockVersion; + use risingwave_pb::hummock::{HummockVersion, HummockVersionStats}; use risingwave_pb::meta::SystemParams; use crate::backup_restore::restore::restore_impl; @@ -331,8 +330,8 @@ mod tests { let backup_store = get_backup_store(opts.clone()).await.unwrap(); let nonempty_meta_store = get_meta_store(opts.clone()).await.unwrap(); dispatch_meta_store!(nonempty_meta_store.clone(), store, { - let hummock_version = HummockVersion::default(); - hummock_version.insert(&store).await.unwrap(); + let stats = HummockVersionStats::default(); + stats.insert(&store).await.unwrap(); }); let empty_meta_store = get_meta_store(opts.clone()).await.unwrap(); let system_param = get_system_params(); @@ -377,13 +376,6 @@ mod tests { .unwrap(); dispatch_meta_store!(empty_meta_store, store, { - let restored_hummock_version = HummockVersion::list(&store) - .await - .unwrap() - .into_iter() - .next() - .unwrap(); - assert_eq!(restored_hummock_version.id, 123); let restored_system_param = SystemParams::get(&store).await.unwrap().unwrap(); assert_eq!(restored_system_param, system_param); }); @@ -547,7 +539,6 @@ mod tests { .unwrap(); dispatch_meta_store!(empty_meta_store, store, { - assert!(HummockVersion::list(&store).await.unwrap().is_empty()); assert!(SystemParams::get(&store).await.unwrap().is_none()); }); } diff --git a/src/meta/src/hummock/manager/mod.rs b/src/meta/src/hummock/manager/mod.rs index 29dd913df7a3..d49649a7dc91 100644 --- a/src/meta/src/hummock/manager/mod.rs +++ b/src/meta/src/hummock/manager/mod.rs @@ -437,29 +437,16 @@ impl HummockManager { .collect(); let mut redo_state = if self.need_init().await? { - // For backward compatibility, try to read checkpoint from meta store. - let versions = HummockVersion::list(self.env.meta_store()).await?; - let checkpoint_version = if !versions.is_empty() { - let checkpoint = versions.into_iter().next().unwrap(); - tracing::warn!( - "read hummock version checkpoint from meta store: {:#?}", - checkpoint - ); - checkpoint - } else { - // As no record found in stores, create a initial version. - let default_compaction_config = self - .compaction_group_manager - .read() - .await - .default_compaction_config(); - let checkpoint = create_init_version(default_compaction_config); - tracing::info!("init hummock version checkpoint"); - HummockVersionStats::default() - .insert(self.env.meta_store()) - .await?; - checkpoint - }; + let default_compaction_config = self + .compaction_group_manager + .read() + .await + .default_compaction_config(); + let checkpoint_version = create_init_version(default_compaction_config); + tracing::info!("init hummock version checkpoint"); + HummockVersionStats::default() + .insert(self.env.meta_store()) + .await?; versioning_guard.checkpoint = HummockVersionCheckpoint { version: Some(checkpoint_version.clone()), stale_objects: Default::default(), diff --git a/src/meta/src/hummock/model/mod.rs b/src/meta/src/hummock/model/mod.rs index a2e5d1748f35..66c12d90836b 100644 --- a/src/meta/src/hummock/model/mod.rs +++ b/src/meta/src/hummock/model/mod.rs @@ -17,7 +17,6 @@ mod compaction_group_config; mod compaction_status; mod pinned_snapshot; mod pinned_version; -mod version; mod version_delta; mod version_stats; @@ -25,12 +24,10 @@ pub use compaction_group_config::CompactionGroup; pub use compaction_status::*; pub use pinned_snapshot::*; pub use pinned_version::*; -pub use version::*; pub use version_delta::*; /// Column family names for hummock. /// Deprecated `cf_name` should be reserved for backward compatibility. -const HUMMOCK_VERSION_CF_NAME: &str = "cf/hummock_0"; const HUMMOCK_VERSION_DELTA_CF_NAME: &str = "cf/hummock_1"; const HUMMOCK_PINNED_VERSION_CF_NAME: &str = "cf/hummock_2"; const HUMMOCK_PINNED_SNAPSHOT_CF_NAME: &str = "cf/hummock_3"; diff --git a/src/meta/src/hummock/model/version.rs b/src/meta/src/hummock/model/version.rs deleted file mode 100644 index d6a85ae745c6..000000000000 --- a/src/meta/src/hummock/model/version.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2023 RisingWave Labs -// -// Licensed 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 prost::Message; -use risingwave_hummock_sdk::HummockVersionId; -use risingwave_pb::hummock::HummockVersion; - -use crate::hummock::model::HUMMOCK_VERSION_CF_NAME; -use crate::model::{MetadataModel, MetadataModelResult}; - -/// `HummockVersion` tracks `Sstables` in given version. -impl MetadataModel for HummockVersion { - type KeyType = HummockVersionId; - type PbType = HummockVersion; - - fn cf_name() -> String { - String::from(HUMMOCK_VERSION_CF_NAME) - } - - fn to_protobuf(&self) -> Self::PbType { - self.clone() - } - - fn to_protobuf_encoded_vec(&self) -> Vec { - self.encode_to_vec() - } - - fn from_protobuf(prost: Self::PbType) -> Self { - prost - } - - fn key(&self) -> MetadataModelResult { - Ok(0) - } -} diff --git a/src/meta/src/model_v2/compaction_config.rs b/src/meta/src/model_v2/compaction_config.rs new file mode 100644 index 000000000000..6f8345734586 --- /dev/null +++ b/src/meta/src/model_v2/compaction_config.rs @@ -0,0 +1,29 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed 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 sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "compaction_config")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub compaction_group_id: i64, + #[sea_orm(column_type = "JsonBinary", nullable)] + pub config: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/meta/src/model_v2/compaction_status.rs b/src/meta/src/model_v2/compaction_status.rs new file mode 100644 index 000000000000..587246339506 --- /dev/null +++ b/src/meta/src/model_v2/compaction_status.rs @@ -0,0 +1,29 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed 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 sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "compaction_status")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub compaction_group_id: i64, + #[sea_orm(column_type = "JsonBinary", nullable)] + pub status: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/meta/src/model_v2/compaction_task.rs b/src/meta/src/model_v2/compaction_task.rs new file mode 100644 index 000000000000..d3211b96d9a6 --- /dev/null +++ b/src/meta/src/model_v2/compaction_task.rs @@ -0,0 +1,30 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed 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 sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "compaction_task")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: i64, + #[sea_orm(column_type = "JsonBinary")] + pub task: Json, + pub context_id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/meta/src/model_v2/hummock_pinned_snapshot.rs b/src/meta/src/model_v2/hummock_pinned_snapshot.rs new file mode 100644 index 000000000000..170f35dd5d35 --- /dev/null +++ b/src/meta/src/model_v2/hummock_pinned_snapshot.rs @@ -0,0 +1,28 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed 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 sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "hummock_pinned_snapshot")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub context_id: i32, + pub min_pinned_snapshot: i64, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/meta/src/model_v2/hummock_pinned_version.rs b/src/meta/src/model_v2/hummock_pinned_version.rs new file mode 100644 index 000000000000..6e2f34a5f735 --- /dev/null +++ b/src/meta/src/model_v2/hummock_pinned_version.rs @@ -0,0 +1,28 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed 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 sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "hummock_pinned_version")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub context_id: i32, + pub min_pinned_id: i64, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/meta/src/model_v2/hummock_version_delta.rs b/src/meta/src/model_v2/hummock_version_delta.rs new file mode 100644 index 000000000000..100dd82eafe9 --- /dev/null +++ b/src/meta/src/model_v2/hummock_version_delta.rs @@ -0,0 +1,35 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed 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 sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "hummock_version_delta")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: i64, + pub prev_id: i64, + #[sea_orm(column_type = "JsonBinary", nullable)] + pub group_deltas: Option, + pub max_committed_epoch: i64, + pub safe_epoch: i64, + pub trivial_move: bool, + #[sea_orm(column_type = "JsonBinary", nullable)] + pub gc_object_ids: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/meta/src/model_v2/hummock_version_stats.rs b/src/meta/src/model_v2/hummock_version_stats.rs new file mode 100644 index 000000000000..1a7e990df405 --- /dev/null +++ b/src/meta/src/model_v2/hummock_version_stats.rs @@ -0,0 +1,29 @@ +// Copyright 2023 RisingWave Labs +// +// Licensed 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 sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "hummock_version_stats")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: i64, + #[sea_orm(column_type = "JsonBinary")] + pub stats: Json, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/src/meta/src/model_v2/migration/src/lib.rs b/src/meta/src/model_v2/migration/src/lib.rs index 6f5c6f3a041a..570bc75d08e9 100644 --- a/src/meta/src/model_v2/migration/src/lib.rs +++ b/src/meta/src/model_v2/migration/src/lib.rs @@ -1,12 +1,16 @@ pub use sea_orm_migration::prelude::*; mod m20230908_072257_init; +mod m20231008_020431_hummock; pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { fn migrations() -> Vec> { - vec![Box::new(m20230908_072257_init::Migration)] + vec![ + Box::new(m20230908_072257_init::Migration), + Box::new(m20231008_020431_hummock::Migration), + ] } } diff --git a/src/meta/src/model_v2/migration/src/m20231008_020431_hummock.rs b/src/meta/src/model_v2/migration/src/m20231008_020431_hummock.rs new file mode 100644 index 000000000000..ab01980990f3 --- /dev/null +++ b/src/meta/src/model_v2/migration/src/m20231008_020431_hummock.rs @@ -0,0 +1,264 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + macro_rules! assert_not_has_tables { + ($manager:expr, $( $table:ident ),+) => { + $( + assert!( + !$manager + .has_table($table::Table.to_string()) + .await? + ); + )+ + }; + } + assert_not_has_tables!( + manager, + CompactionTask, + CompactionConfig, + CompactionStatus, + HummockPinnedVersion, + HummockPinnedSnapshot, + HummockVersionDelta, + HummockVersionStats + ); + + manager + .create_table( + Table::create() + .table(CompactionTask::Table) + .col( + ColumnDef::new(CompactionTask::Id) + .big_integer() + .not_null() + .primary_key(), + ) + .col( + ColumnDef::new(CompactionTask::Task) + .json_binary() + .not_null(), + ) + .col( + ColumnDef::new(CompactionTask::ContextId) + .integer() + .not_null(), + ) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(CompactionConfig::Table) + .col( + ColumnDef::new(CompactionConfig::CompactionGroupId) + .big_integer() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(CompactionConfig::Config).json_binary()) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(CompactionStatus::Table) + .col( + ColumnDef::new(CompactionStatus::CompactionGroupId) + .big_integer() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(CompactionStatus::Status).json_binary()) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(HummockPinnedVersion::Table) + .col( + ColumnDef::new(HummockPinnedVersion::ContextId) + .integer() + .not_null() + .primary_key(), + ) + .col( + ColumnDef::new(HummockPinnedVersion::MinPinnedId) + .big_integer() + .not_null(), + ) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(HummockPinnedSnapshot::Table) + .col( + ColumnDef::new(HummockPinnedSnapshot::ContextId) + .integer() + .not_null() + .primary_key(), + ) + .col( + ColumnDef::new(HummockPinnedSnapshot::MinPinnedSnapshot) + .big_integer() + .not_null(), + ) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(HummockVersionDelta::Table) + .col( + ColumnDef::new(HummockVersionDelta::Id) + .big_integer() + .not_null() + .primary_key(), + ) + .col( + ColumnDef::new(HummockVersionDelta::PrevId) + .big_integer() + .not_null(), + ) + .col(ColumnDef::new(HummockVersionDelta::GroupDeltas).json_binary()) + .col( + ColumnDef::new(HummockVersionDelta::MaxCommittedEpoch) + .big_integer() + .not_null(), + ) + .col( + ColumnDef::new(HummockVersionDelta::SafeEpoch) + .big_integer() + .not_null(), + ) + .col( + ColumnDef::new(HummockVersionDelta::TrivialMove) + .boolean() + .not_null(), + ) + .col(ColumnDef::new(HummockVersionDelta::GcObjectIds).json_binary()) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(HummockVersionStats::Table) + .col( + ColumnDef::new(HummockVersionStats::Id) + .big_integer() + .not_null() + .primary_key(), + ) + .col( + ColumnDef::new(HummockVersionStats::Stats) + .json_binary() + .not_null(), + ) + .to_owned(), + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + macro_rules! drop_tables { + ($manager:expr, $( $table:ident ),+) => { + $( + $manager + .drop_table( + Table::drop() + .table($table::Table) + .if_exists() + .cascade() + .to_owned(), + ) + .await?; + )+ + }; + } + drop_tables!( + manager, + CompactionTask, + CompactionConfig, + CompactionStatus, + HummockPinnedVersion, + HummockPinnedSnapshot, + HummockVersionDelta, + HummockVersionStats + ); + Ok(()) + } +} + +#[derive(DeriveIden)] +enum CompactionTask { + Table, + Id, + Task, + ContextId, +} + +#[derive(DeriveIden)] +enum CompactionConfig { + Table, + CompactionGroupId, + Config, +} + +#[derive(DeriveIden)] +enum CompactionStatus { + Table, + CompactionGroupId, + Status, +} + +#[derive(DeriveIden)] +enum HummockPinnedVersion { + Table, + ContextId, + MinPinnedId, +} + +#[derive(DeriveIden)] +enum HummockPinnedSnapshot { + Table, + ContextId, + MinPinnedSnapshot, +} + +#[derive(DeriveIden)] +enum HummockVersionDelta { + Table, + Id, + PrevId, + GroupDeltas, + MaxCommittedEpoch, + SafeEpoch, + TrivialMove, + GcObjectIds, +} + +#[derive(DeriveIden)] +enum HummockVersionStats { + Table, + Id, + Stats, +} diff --git a/src/meta/src/model_v2/mod.rs b/src/meta/src/model_v2/mod.rs index 8f496b56d129..dfc4dc43fc3f 100644 --- a/src/meta/src/model_v2/mod.rs +++ b/src/meta/src/model_v2/mod.rs @@ -19,12 +19,19 @@ pub mod prelude; pub mod actor; pub mod cluster; +pub mod compaction_config; +pub mod compaction_status; +pub mod compaction_task; pub mod connection; pub mod database; pub mod election_leader; pub mod election_member; pub mod fragment; pub mod function; +pub mod hummock_pinned_snapshot; +pub mod hummock_pinned_version; +pub mod hummock_version_delta; +pub mod hummock_version_stats; pub mod index; pub mod object; pub mod object_dependency; diff --git a/src/meta/src/model_v2/prelude.rs b/src/meta/src/model_v2/prelude.rs index d929fa2a4aec..37496e486afc 100644 --- a/src/meta/src/model_v2/prelude.rs +++ b/src/meta/src/model_v2/prelude.rs @@ -14,12 +14,19 @@ pub use super::actor::Entity as Actor; pub use super::cluster::Entity as Cluster; +pub use super::compaction_config::Entity as CompactionConfig; +pub use super::compaction_status::Entity as CompactionStatus; +pub use super::compaction_task::Entity as CompactionTask; pub use super::connection::Entity as Connection; pub use super::database::Entity as Database; pub use super::election_leader::Entity as ElectionLeader; pub use super::election_member::Entity as ElectionMember; pub use super::fragment::Entity as Fragment; pub use super::function::Entity as Function; +pub use super::hummock_pinned_snapshot::Entity as HummockPinnedSnapshot; +pub use super::hummock_pinned_version::Entity as HummockPinnedVersion; +pub use super::hummock_version_delta::Entity as HummockVersionDelta; +pub use super::hummock_version_stats::Entity as HummockVersionStats; pub use super::index::Entity as Index; pub use super::object::Entity as Object; pub use super::object_dependency::Entity as ObjectDependency;