Skip to content

Commit

Permalink
fix: fix create or replace stage bug, only remove dir when success (#โ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆ14766)

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

* fix: fix create or replace stage bug, only remove dir when success
  • Loading branch information
lichuang authored Feb 27, 2024
1 parent e88992f commit ea87365
Showing 1 changed file with 22 additions and 19 deletions.
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

0 comments on commit ea87365

Please sign in to comment.