From bafa4592ba625538deab3f195efcb42de5dca1e6 Mon Sep 17 00:00:00 2001
From: AntiTopQuark
Date: Wed, 27 Dec 2023 23:38:34 +0800
Subject: [PATCH 1/3] refactor(TableRouteValue): add panic notes and type
checks
---
src/common/meta/src/key/table_route.rs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/common/meta/src/key/table_route.rs b/src/common/meta/src/key/table_route.rs
index d767d098a79f..7f6ed8c79680 100644
--- a/src/common/meta/src/key/table_route.rs
+++ b/src/common/meta/src/key/table_route.rs
@@ -62,7 +62,13 @@ impl TableRouteValue {
}
/// Returns a new version [TableRouteValue] with `region_routes`.
+ ///
+ /// # Panics
+ /// The route type is not the [TableRouteValue::Physical].
pub fn update(&self, region_routes: Vec) -> Self {
+ if (!self.is_physical()) {
+ panic!("Mistakenly been treated as a Physical TableRoute: {self:?}");
+ }
let version = self.physical_table_route().version;
Self::Physical(PhysicalTableRouteValue {
region_routes,
@@ -73,13 +79,25 @@ impl TableRouteValue {
/// Returns the version.
///
/// For test purpose.
+ ///
+ /// # Panics
+ /// The route type is not the [TableRouteValue::Physical].
#[cfg(any(test, feature = "testing"))]
pub fn version(&self) -> u64 {
+ if (!self.is_physical()) {
+ panic!("Mistakenly been treated as a Physical TableRoute: {self:?}");
+ }
self.physical_table_route().version
}
/// Returns the corresponding [RegionRoute].
+ ///
+ /// # Panics
+ /// The route type is not the [TableRouteValue::Physical].
pub fn region_route(&self, region_id: RegionId) -> Option {
+ if (!self.is_physical()) {
+ panic!("Mistakenly been treated as a Physical TableRoute: {self:?}");
+ }
self.physical_table_route()
.region_routes
.iter()
@@ -97,6 +115,9 @@ impl TableRouteValue {
/// # Panics
/// The route type is not the [TableRouteValue::Physical].
pub fn region_routes(&self) -> &Vec {
+ if (!self.is_physical()) {
+ panic!("Mistakenly been treated as a Physical TableRoute: {self:?}");
+ }
&self.physical_table_route().region_routes
}
From 262d903f3cabcdc4205159206081bfd287c40957 Mon Sep 17 00:00:00 2001
From: Ruihang Xia
Date: Thu, 28 Dec 2023 11:47:19 +0800
Subject: [PATCH 2/3] chore: add deprecate develop branch warning
Signed-off-by: Ruihang Xia
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index a9156560eb2a..bbb794764aef 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,9 @@
+> [!WARNING]
+> Our default branch has changed from `develop` to main. Please update your local repository to use the `main` branch.
+
## What is GreptimeDB
GreptimeDB is an open-source time-series database with a special focus on
From 25316e979886fd831645b0b0703af031b7c4f770 Mon Sep 17 00:00:00 2001
From: AntiTopQuark
Date: Thu, 28 Dec 2023 11:55:43 +0800
Subject: [PATCH 3/3] add error defines and checks
---
src/common/meta/src/ddl/alter_table.rs | 2 +-
src/common/meta/src/ddl/create_table.rs | 2 +-
src/common/meta/src/ddl/drop_table.rs | 6 +-
src/common/meta/src/ddl_manager.rs | 2 +-
src/common/meta/src/error.rs | 9 ++-
src/common/meta/src/key.rs | 10 +--
src/common/meta/src/key/table_route.rs | 62 +++++++++++--------
src/meta-srv/src/error.rs | 10 ++-
.../region_failover/update_metadata.rs | 6 +-
.../src/procedure/region_migration/manager.rs | 3 +
.../region_migration/migration_start.rs | 4 ++
.../upgrade_candidate_region.rs | 12 +++-
src/meta-srv/src/region/lease_keeper.rs | 2 +-
src/meta-srv/src/selector/load_based.rs | 2 +-
src/partition/src/error.rs | 8 +++
src/partition/src/manager.rs | 12 +++-
16 files changed, 106 insertions(+), 46 deletions(-)
diff --git a/src/common/meta/src/ddl/alter_table.rs b/src/common/meta/src/ddl/alter_table.rs
index 092d4dd24263..c3b1f7c31121 100644
--- a/src/common/meta/src/ddl/alter_table.rs
+++ b/src/common/meta/src/ddl/alter_table.rs
@@ -191,7 +191,7 @@ impl AlterTableProcedure {
.await?
.context(TableRouteNotFoundSnafu { table_id })?
.into_inner();
- let region_routes = table_route.region_routes();
+ let region_routes = table_route.region_routes()?;
let leaders = find_leaders(region_routes);
let mut alter_region_tasks = Vec::with_capacity(leaders.len());
diff --git a/src/common/meta/src/ddl/create_table.rs b/src/common/meta/src/ddl/create_table.rs
index c73844fc8337..c6e09006b470 100644
--- a/src/common/meta/src/ddl/create_table.rs
+++ b/src/common/meta/src/ddl/create_table.rs
@@ -217,7 +217,7 @@ impl CreateTableProcedure {
.context(TableRouteNotFoundSnafu {
table_id: physical_table_id,
})?;
- let region_routes = physical_table_route.region_routes();
+ let region_routes = physical_table_route.region_routes()?;
let request_builder = self.new_region_request_builder(Some(physical_table_id))?;
diff --git a/src/common/meta/src/ddl/drop_table.rs b/src/common/meta/src/ddl/drop_table.rs
index 94c6cdf0a06a..7fac47e62cb1 100644
--- a/src/common/meta/src/ddl/drop_table.rs
+++ b/src/common/meta/src/ddl/drop_table.rs
@@ -116,7 +116,7 @@ impl DropTableProcedure {
/// Register dropping regions if doesn't exist.
fn register_dropping_regions(&mut self) -> Result<()> {
- let region_routes = self.data.region_routes();
+ let region_routes = self.data.region_routes()?;
let dropping_regions = operating_leader_regions(region_routes);
@@ -190,7 +190,7 @@ impl DropTableProcedure {
pub async fn on_datanode_drop_regions(&self) -> Result {
let table_id = self.data.table_id();
- let region_routes = &self.data.region_routes();
+ let region_routes = &self.data.region_routes()?;
let leaders = find_leaders(region_routes);
let mut drop_region_tasks = Vec::with_capacity(leaders.len());
@@ -306,7 +306,7 @@ impl DropTableData {
self.task.table_ref()
}
- fn region_routes(&self) -> &Vec {
+ fn region_routes(&self) -> Result<&Vec> {
self.table_route_value.region_routes()
}
diff --git a/src/common/meta/src/ddl_manager.rs b/src/common/meta/src/ddl_manager.rs
index 6b1e4bf94f38..d0b5c6d12504 100644
--- a/src/common/meta/src/ddl_manager.rs
+++ b/src/common/meta/src/ddl_manager.rs
@@ -278,7 +278,7 @@ async fn handle_truncate_table_task(
let table_route_value =
table_route_value.context(error::TableRouteNotFoundSnafu { table_id })?;
- let table_route = table_route_value.into_inner().region_routes().clone();
+ let table_route = table_route_value.into_inner().region_routes()?.clone();
let id = ddl_manager
.submit_truncate_table_task(
diff --git a/src/common/meta/src/error.rs b/src/common/meta/src/error.rs
index c120c8ba939d..6a0a385e3e38 100644
--- a/src/common/meta/src/error.rs
+++ b/src/common/meta/src/error.rs
@@ -330,6 +330,12 @@ pub enum Error {
#[snafu(display("The topic pool is empty"))]
EmptyTopicPool { location: Location },
+
+ #[snafu(display("Unexpected table route type: {}", err_msg))]
+ UnexpectedTableRouteType {
+ location: Location,
+ err_msg: String,
+ },
}
pub type Result = std::result::Result;
@@ -369,7 +375,8 @@ impl ErrorExt for Error {
| BuildKafkaClient { .. }
| BuildKafkaCtrlClient { .. }
| CreateKafkaWalTopic { .. }
- | EmptyTopicPool { .. } => StatusCode::Unexpected,
+ | EmptyTopicPool { .. }
+ | UnexpectedTableRouteType { .. } => StatusCode::Unexpected,
SendMessage { .. }
| GetKvCache { .. }
diff --git a/src/common/meta/src/key.rs b/src/common/meta/src/key.rs
index bb2b87a973f5..eda184322874 100644
--- a/src/common/meta/src/key.rs
+++ b/src/common/meta/src/key.rs
@@ -483,7 +483,7 @@ impl TableMetadataManager {
.build_delete_txn(table_id, table_info_value)?;
// Deletes datanode table key value pairs.
- let distribution = region_distribution(table_route_value.region_routes())?;
+ let distribution = region_distribution(table_route_value.region_routes()?)?;
let delete_datanode_txn = self
.datanode_table_manager()
.build_delete_txn(table_id, distribution)?;
@@ -608,7 +608,7 @@ impl TableMetadataManager {
) -> Result<()> {
// Updates the datanode table key value pairs.
let current_region_distribution =
- region_distribution(current_table_route_value.region_routes())?;
+ region_distribution(current_table_route_value.region_routes()?)?;
let new_region_distribution = region_distribution(&new_region_routes)?;
let update_datanode_table_txn = self.datanode_table_manager().build_update_txn(
@@ -621,7 +621,7 @@ impl TableMetadataManager {
)?;
// Updates the table_route.
- let new_table_route_value = current_table_route_value.update(new_region_routes);
+ let new_table_route_value = current_table_route_value.update(new_region_routes)?;
let (update_table_route_txn, on_update_table_route_failure) = self
.table_route_manager()
@@ -656,7 +656,7 @@ impl TableMetadataManager {
where
F: Fn(&RegionRoute) -> Option