From bf52ffbd433fc609225f81a9bb4af6c7c5ec7d1f Mon Sep 17 00:00:00 2001 From: DandreChen Date: Tue, 3 Jan 2023 11:12:34 +0800 Subject: [PATCH] fix(tianmu): ALTER TABLE prompt information is incorrect.(#1142) Print the specific information of known exceptions to better understand the cause of the problem --- storage/tianmu/core/tianmu_table.cpp | 18 +++++++++++------- storage/tianmu/handler/ha_tianmu.cpp | 5 +++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/storage/tianmu/core/tianmu_table.cpp b/storage/tianmu/core/tianmu_table.cpp index cc536bab91..01c33e4863 100644 --- a/storage/tianmu/core/tianmu_table.cpp +++ b/storage/tianmu/core/tianmu_table.cpp @@ -107,15 +107,19 @@ void TianmuTable::Alter(const std::string &table_path, std::vector &new for (auto &p : fs::directory_iterator(tmp_dir / common::COLUMN_DIR)) fs::remove(p); TABLE_META meta; - system::TianmuFile f; - f.OpenReadOnly(tab_dir / common::TABLE_DESC_FILE); - f.ReadExact(&meta, sizeof(meta)); + { + system::TianmuFile f; + f.OpenReadOnly(tab_dir / common::TABLE_DESC_FILE); + f.ReadExact(&meta, sizeof(meta)); + } meta.id = ha_tianmu_engine_->GetNextTableId(); // only table id is updated - system::TianmuFile tempf; - tempf.OpenReadWrite(tmp_dir / common::TABLE_DESC_FILE); - tempf.WriteExact(&meta, sizeof(meta)); - tempf.Flush(); + { + system::TianmuFile tempf; + tempf.OpenReadWrite(tmp_dir / common::TABLE_DESC_FILE); + tempf.WriteExact(&meta, sizeof(meta)); + tempf.Flush(); + } std::vector old_versions(old_cols.size()); { diff --git a/storage/tianmu/handler/ha_tianmu.cpp b/storage/tianmu/handler/ha_tianmu.cpp index 5e5b9724ca..de3be60b83 100644 --- a/storage/tianmu/handler/ha_tianmu.cpp +++ b/storage/tianmu/handler/ha_tianmu.cpp @@ -1642,16 +1642,17 @@ bool ha_tianmu::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha } } catch (std::exception &e) { TIANMU_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); + my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0)); } catch (...) { TIANMU_LOG(LogCtl_Level::ERROR, "An unknown system exception error caught."); + my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Unable to inplace alter table", MYF(0)); } + // if catch exception, remove tmp dir fs::path tmp_dir = table_name_ + ".tmp"; if (fs::exists(tmp_dir)) fs::remove_all(tmp_dir); - my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Unable to inplace alter table", MYF(0)); - DBUG_RETURN(true); }