Skip to content

Commit

Permalink
feat: ensure procedure_state and migrate_region can be only called un…
Browse files Browse the repository at this point in the history
…der greptime catalog
  • Loading branch information
killme2008 committed Feb 21, 2024
1 parent 0518471 commit 83cc11f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/common/function/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ api.workspace = true
arc-swap = "1.0"
async-trait.workspace = true
chrono-tz = "0.6"
common-catalog.workspace = true
common-error.workspace = true
common-macro.workspace = true
common-meta.workspace = true
Expand Down
1 change: 1 addition & 0 deletions src/common/function/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod macros;
pub mod scalars;
mod system;
mod table;
Expand Down
13 changes: 13 additions & 0 deletions src/common/function/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Ensure current function is invokded under `greptime` catalog.
#[macro_export]
macro_rules! ensure_greptime {
($func_ctx: expr) => {{
use common_catalog::consts::DEFAULT_CATALOG_NAME;
snafu::ensure!(
$func_ctx.query_ctx.current_catalog() == DEFAULT_CATALOG_NAME,
common_query::error::PermissionDeniedSnafu {
err_msg: format!("current catalog is not {DEFAULT_CATALOG_NAME}")
}
);
}};
}
2 changes: 2 additions & 0 deletions src/common/function/src/system/procedure_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ impl Function for ProcedureStateFunction {
}

fn eval(&self, func_ctx: FunctionContext, columns: &[VectorRef]) -> Result<VectorRef> {
crate::ensure_greptime!(func_ctx);

ensure!(
columns.len() == 1,
InvalidFuncArgsSnafu {
Expand Down
2 changes: 2 additions & 0 deletions src/common/function/src/table/migrate_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ impl Function for MigrateRegionFunction {
}

fn eval(&self, func_ctx: FunctionContext, columns: &[VectorRef]) -> Result<VectorRef> {
crate::ensure_greptime!(func_ctx);

let (region_ids, from_peers, to_peers, replay_timeouts) = match columns.len() {
3 => {
let region_ids = cast_u64_vector(&columns[0])?;
Expand Down
5 changes: 5 additions & 0 deletions src/common/query/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ pub enum Error {

#[snafu(display("Invalid function args: {}", err_msg))]
InvalidFuncArgs { err_msg: String, location: Location },

#[snafu(display("Permission denied: {}", err_msg))]
PermissionDenied { err_msg: String, location: Location },
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -234,6 +237,8 @@ impl ErrorExt for Error {
Error::ProcedureService { source, .. } | Error::TableMutation { source, .. } => {
source.status_code()
}

Error::PermissionDenied { .. } => StatusCode::PermissionDenied,
}
}

Expand Down

0 comments on commit 83cc11f

Please sign in to comment.