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

refactor: allocate table id in the procedure #3271

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8bc802f
refactor: replace TableMetadataManager with TableNameManager
WenyXu Jan 31, 2024
1c43763
refactor: allocate table id in the procedure
WenyXu Jan 31, 2024
d9be8ea
refactor: refactor client logical of handling retries
WenyXu Feb 3, 2024
22f8313
feat(test_util): add TestCreateTableExprBuilder
WenyXu Feb 6, 2024
ccfc3a8
feat(test_util): add MockDatanodeManager
WenyXu Feb 6, 2024
d666a8b
feat(test_util): add new_ddl_context
WenyXu Feb 6, 2024
68c67ea
feat(test_util): add build_raw_table_info_from_expr
WenyXu Feb 6, 2024
342994f
feat(test_util): add MockDatanodeManager::new
WenyXu Feb 6, 2024
ab037d4
feat(procedure): add downcast_output_ref to Status
WenyXu Feb 6, 2024
b1639f0
test(create_table): add tests for CreateTableProcedure on_prepare
WenyXu Feb 6, 2024
b9c1b30
refactor(ddl): rename handle_operate_region_error to add_peer_context…
WenyXu Feb 6, 2024
69f9106
test(create_table): add tests for CreateTableProcedure on_datanode_cr…
WenyXu Feb 6, 2024
ccfd186
test(create_table): add tests for CreateTableProcedure on_create_meta…
WenyXu Feb 6, 2024
1388a0f
refactor(meta): use CreateTableExprBuilder
WenyXu Feb 6, 2024
1ea7d64
feat(create_table): ensure number of partitions is greater than 0
WenyXu Feb 6, 2024
b508041
refactor: rename to add_peer_context_if_needed
WenyXu Feb 18, 2024
f8c4b1f
feat: add context for panic
WenyXu Feb 18, 2024
5a592fe
refactor: simplify the should_retry
WenyXu Feb 20, 2024
18d0ccb
refactor: use Option<&T> instead of &Option<T>
WenyXu Feb 20, 2024
7cd1c62
refactor: move downcast_output_ref under cfg(test)
WenyXu Feb 20, 2024
3bcb4f6
chore: fmt toml
WenyXu Feb 20, 2024
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
Prev Previous commit
Next Next commit
feat(create_table): ensure number of partitions is greater than 0
  • Loading branch information
WenyXu committed Feb 20, 2024
commit 1ea7d640778c9f50e2e732f99075adbcc5fe3302
8 changes: 7 additions & 1 deletion src/common/meta/src/ddl/table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use store_api::metric_engine_consts::LOGICAL_TABLE_METADATA_KEY;
use store_api::storage::{RegionId, RegionNumber, TableId};

use crate::ddl::{TableMetadata, TableMetadataAllocatorContext};
use crate::error::{Result, TableNotFoundSnafu, UnsupportedSnafu};
use crate::error::{self, Result, TableNotFoundSnafu, UnsupportedSnafu};
use crate::key::table_name::{TableNameKey, TableNameManager};
use crate::key::table_route::{LogicalTableRouteValue, PhysicalTableRouteValue, TableRouteValue};
use crate::peer::Peer;
Expand Down Expand Up @@ -124,6 +124,12 @@ impl TableMetadataAllocator {
task: &CreateTableTask,
) -> Result<TableRouteValue> {
let regions = task.partitions.len();
ensure!(
regions > 0,
error::UnexpectedSnafu {
err_msg: "The number of partitions must be greater than 0"
}
);

let table_route = if task.create_table.engine == METRIC_ENGINE
&& let Some(physical_table_name) = task
Expand Down
16 changes: 16 additions & 0 deletions src/common/meta/src/ddl/tests/create_table.rs
MichaelScofield marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ async fn test_on_prepare_without_create_if_table_exists() {
assert_eq!(procedure.table_id(), 1024);
}

#[tokio::test]
async fn test_on_prepare_with_no_partition_err() {
let datanode_manager = Arc::new(MockDatanodeManager::new(()));
let ddl_context = new_ddl_context(datanode_manager);
let cluster_id = 1;
let mut task = test_create_table_task("foo");
task.partitions = vec![];
task.create_table.create_if_not_exists = true;
let mut procedure = CreateTableProcedure::new(cluster_id, task, ddl_context);
let err = procedure.on_prepare().await.unwrap_err();
assert_matches!(err, Error::Unexpected { .. });
assert!(err
.to_string()
.contains("The number of partitions must be greater than 0"),);
}

#[derive(Clone)]
pub struct RetryErrorDatanodeHandler;

Expand Down