Skip to content

fix: fix create or replace stage bug, only remove dir when success #14766

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

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
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
41 changes: 22 additions & 19 deletions src/query/service/src/interpreters/interpreter_user_stage_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,30 @@ impl Interpreter for CreateUserStageInterpreter {
)));
};

// when create or replace stage, if old stage is not External stage, remove stage files
if let CreateOption::CreateOrReplace = plan.create_option {
if let Ok(stage) = user_mgr
let old_stage = match plan.create_option {
CreateOption::CreateOrReplace => user_mgr
.get_stage(&plan.tenant, &user_stage.stage_name)
.await
{
if stage.stage_type != StageType::External {
let op = StageTable::get_op(&stage)?;
op.remove_all("/").await?;
info!(
"create or replace stage {:?} with all objects removed in stage",
user_stage.stage_name
);
}
.ok(),
_ => None,
};

let mut user_stage = user_stage;
user_stage.creator = Some(self.ctx.get_current_user()?.identity());
user_stage.created_on = Utc::now();
let _ = user_mgr
.add_stage(&plan.tenant, user_stage.clone(), &plan.create_option)
.await?;

// when create or replace stage success, if old stage is not External stage, remove stage files
if let Some(stage) = old_stage {
if stage.stage_type != StageType::External {
let op = StageTable::get_op(&stage)?;
op.remove_all("/").await?;
info!(
"create or replace stage {:?} with all objects removed in stage",
user_stage.stage_name
);
}
}

Expand All @@ -105,13 +115,6 @@ impl Interpreter for CreateUserStageInterpreter {
op.create_dir(&user_stage.stage_prefix()).await?
}

let mut user_stage = user_stage;
user_stage.creator = Some(self.ctx.get_current_user()?.identity());
user_stage.created_on = Utc::now();
let _ = user_mgr
.add_stage(&plan.tenant, user_stage, &plan.create_option)
.await?;

// Grant ownership as the current role
let tenant = self.ctx.get_tenant();
let role_api = UserApiProvider::instance().get_role_api_client(&tenant)?;
Expand Down