-
Notifications
You must be signed in to change notification settings - Fork 332
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
feat: initial implementation of AlterDatabaseProcedure #4808
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2023 Greptime Team | ||
// | ||
// 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 async_trait::async_trait; | ||
use common_procedure::error::{FromJsonSnafu, Result as ProcedureResult, ToJsonSnafu}; | ||
use common_procedure::{Context, LockKey, Procedure, Status}; | ||
use serde::{Deserialize, Serialize}; | ||
use snafu::ResultExt; | ||
|
||
use super::utils::handle_retry_error; | ||
use crate::ddl::DdlContext; | ||
use crate::error::Result; | ||
use crate::lock_key::{CatalogLock, SchemaLock}; | ||
use crate::ClusterId; | ||
|
||
pub struct AlterDatabaseProcedure { | ||
_context: DdlContext, | ||
data: AlterDatabaseData, | ||
} | ||
|
||
impl AlterDatabaseProcedure { | ||
pub const TYPE_NAME: &'static str = "metasrv-procedure::AlterDatabase"; | ||
|
||
pub fn new( | ||
_cluster_id: ClusterId, | ||
context: DdlContext, | ||
catalog: String, | ||
schema: String, | ||
) -> Self { | ||
AlterDatabaseProcedure { | ||
_context: context, | ||
data: AlterDatabaseData { | ||
state: AlterDatabaseState::Prepare, | ||
catalog, | ||
schema, | ||
}, | ||
} | ||
} | ||
|
||
pub fn from_json(json: &str, context: DdlContext) -> ProcedureResult<Self> { | ||
let data = serde_json::from_str(json).context(FromJsonSnafu)?; | ||
|
||
Ok(Self { | ||
_context: context, | ||
data, | ||
}) | ||
} | ||
|
||
async fn on_prepare(&mut self) -> Result<Status> { | ||
todo!(); | ||
} | ||
|
||
async fn on_update_metadata(&mut self) -> Result<Status> { | ||
todo!(); | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Procedure for AlterDatabaseProcedure { | ||
fn type_name(&self) -> &str { | ||
Self::TYPE_NAME | ||
} | ||
async fn execute(&mut self, _ctx: &Context) -> ProcedureResult<Status> { | ||
let state = &self.data.state; | ||
match state { | ||
AlterDatabaseState::Prepare => self.on_prepare().await, | ||
AlterDatabaseState::UpdateMetadata => self.on_update_metadata().await, | ||
} | ||
.map_err(handle_retry_error) | ||
} | ||
fn lock_key(&self) -> LockKey { | ||
let lock_key = vec![ | ||
CatalogLock::Read(&self.data.catalog).into(), | ||
SchemaLock::write(&self.data.catalog, &self.data.schema).into(), | ||
Comment on lines
+84
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent naming conventions for lock constructors There is an inconsistency in naming conventions between
To maintain consistency and adhere to Rust naming conventions:
Consider applying one of the following changes: - CatalogLock::Read(&self.data.catalog).into(),
+ CatalogLock::read(&self.data.catalog).into(), or - SchemaLock::write(&self.data.catalog, &self.data.schema).into(),
+ SchemaLock::Write(&self.data.catalog, &self.data.schema).into(), Ensure that the naming reflects their respective types appropriately.
|
||
]; | ||
LockKey::new(lock_key) | ||
} | ||
fn dump(&self) -> common_procedure::Result<String> { | ||
serde_json::to_string(&self.data).context(ToJsonSnafu) | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
enum AlterDatabaseState { | ||
Prepare, | ||
UpdateMetadata, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct AlterDatabaseData { | ||
state: AlterDatabaseState, | ||
catalog: String, | ||
schema: String, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Issue:
AlterDatabaseProcedure
is defined but not registered inDdlManager
.AlterDatabaseProcedure
is imported and used inddl_manager.rs
, but there is no registration found.🔗 Analysis chain
LGTM: New
alter_database
module added.The addition of the
alter_database
module aligns with the PR objectives and is consistent with the structure of other DDL-related modules in this file.To ensure proper integration, let's verify if the new module is being used in the codebase: