Skip to content

Commit

Permalink
chore: make error message of conflicting transactions more user-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyFan2002 committed Jan 16, 2025
1 parent c89e4a3 commit e6a183f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
26 changes: 16 additions & 10 deletions src/query/catalog/src/catalog/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ use databend_common_meta_types::SeqV;
use databend_storages_common_session::SessionState;
use databend_storages_common_table_meta::table::OPT_KEY_TEMP_PREFIX;
use dyn_clone::DynClone;
use log::info;

use crate::database::Database;
use crate::table::Table;
Expand Down Expand Up @@ -388,16 +389,21 @@ pub trait Catalog: DynClone + Send + Sync + Debug {
&self,
req: UpdateMultiTableMetaReq,
) -> Result<UpdateTableMetaReply> {
self.retryable_update_multi_table_meta(req)
.await?
.map_err(|e| {
ErrorCode::TableVersionMismatched(format!(
"Fail to update table metas, conflict tables: {:?}",
e.iter()
.map(|(tid, seq, meta)| (tid, seq, &meta.engine))
.collect::<Vec<_>>()
))
})
let result = self.retryable_update_multi_table_meta(req).await?;
match result {
Ok(reply) => Ok(reply),
Err(failed_tables) => {
let err_msg = format!(
"Due to concurrent transactions, transaction commit failed. Conflicting table IDs: {:?}",
failed_tables.iter().map(|(tid, _, _)| tid).collect::<Vec<_>>()
);
info!(
"Due to concurrent transactions, transaction commit failed. Conflicting tables: {:?}",
failed_tables
);
Err(ErrorCode::TableVersionMismatched(err_msg))
}
}
}

// update stream metas, currently used by "copy into location form stream"
Expand Down
10 changes: 6 additions & 4 deletions src/query/sql/src/planner/binder/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,12 @@ pub async fn execute_commit_statement(ctx: Arc<dyn TableContext>) -> Result<()>
}
Err(e) => {
let err_msg = format!(
"COMMIT: Table versions mismatched in multi statement transaction, conflict tables: {:?}",
e.iter()
.map(|(tid, seq, meta)| (tid, seq, &meta.engine))
.collect::<Vec<_>>()
"Due to concurrent transactions, explicit transaction commit failed. Conflicting table IDs: {:?}",
e.iter().map(|(tid, _, _)| tid).collect::<Vec<_>>()
);
info!(
"Due to concurrent transactions, explicit transaction commit failed. Conflicting table IDs: {:?}",
e
);
return Err(ErrorCode::TableVersionMismatched(err_msg));
}
Expand Down

0 comments on commit e6a183f

Please sign in to comment.