diff --git a/storage/tianmu/handler/tianmu_handler.cpp b/storage/tianmu/handler/tianmu_handler.cpp index 1da4294e49..bfabb2a4fd 100644 --- a/storage/tianmu/handler/tianmu_handler.cpp +++ b/storage/tianmu/handler/tianmu_handler.cpp @@ -1498,9 +1498,15 @@ int TianmuHandler::reset() { enum_alter_inplace_result TianmuHandler::check_if_supported_inplace_alter([[maybe_unused]] TABLE *altered_table, Alter_inplace_info *ha_alter_info) { DBUG_ENTER(__PRETTY_FUNCTION__); + + if ((ha_alter_info->handler_flags & TIANMU_SUPPORTED_ALTER_TABLE_OPTIONS) && + (ha_alter_info->create_info->used_fields & HA_CREATE_USED_CHARSET)) { + DBUG_RETURN(HA_ALTER_INPLACE_EXCLUSIVE_LOCK); + } + if ((ha_alter_info->handler_flags & ~TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER) && (ha_alter_info->handler_flags != TIANMU_SUPPORTED_ALTER_COLUMN_NAME)) { - // support alter table column type + // support alter table column type if (ha_alter_info->handler_flags & Alter_inplace_info::ALTER_STORED_COLUMN_TYPE) DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED); // support alter table column exceeded length @@ -1517,13 +1523,16 @@ enum_alter_inplace_result TianmuHandler::check_if_supported_inplace_alter([[mayb bool TianmuHandler::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info) { try { - if (!(ha_alter_info->handler_flags & ~TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER)) { + if ((ha_alter_info->handler_flags & TIANMU_SUPPORTED_ALTER_TABLE_OPTIONS) && + (ha_alter_info->create_info->used_fields & HA_CREATE_USED_CHARSET)) { + DBUG_RETURN(false); + } else if (!(ha_alter_info->handler_flags & ~TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER)) { std::vector v_old(table_share->field, table_share->field + table_share->fields); std::vector v_new(altered_table->s->field, altered_table->s->field + altered_table->s->fields); ha_rcengine_->PrepareAlterTable(table_name_, v_new, v_old, ha_thd()); - return false; + DBUG_RETURN(false); } else if (ha_alter_info->handler_flags == TIANMU_SUPPORTED_ALTER_COLUMN_NAME) { - return false; + DBUG_RETURN(false); } } catch (std::exception &e) { TIANMU_LOG(LogCtl_Level::ERROR, "An exception is caught: %s", e.what()); @@ -1533,21 +1542,25 @@ bool TianmuHandler::inplace_alter_table(TABLE *altered_table, Alter_inplace_info my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Unable to inplace alter table", MYF(0)); - return true; + DBUG_RETURN(true); } bool TianmuHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit) { if (!commit) { - TIANMU_LOG(LogCtl_Level::INFO, "Alter table failed : %s%s", table_name_.c_str(), " rollback"); - return true; + TIANMU_LOG(LogCtl_Level::INFO, "Alter table failed : %s%s", m_table_name.c_str(), " rollback"); + DBUG_RETURN(true); + } + if ((ha_alter_info->handler_flags & TIANMU_SUPPORTED_ALTER_TABLE_OPTIONS) && + (ha_alter_info->create_info->used_fields & HA_CREATE_USED_CHARSET)) { + DBUG_RETURN(false); } if (ha_alter_info->handler_flags == TIANMU_SUPPORTED_ALTER_COLUMN_NAME) { - return false; + DBUG_RETURN(false); } if ((ha_alter_info->handler_flags & ~TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER)) { TIANMU_LOG(LogCtl_Level::INFO, "Altered table not support type %lu", ha_alter_info->handler_flags); - return true; + DBUG_RETURN(true); } fs::path tmp_dir(table_name_ + ".tmp"); fs::path tab_dir(table_name_ + common::TIANMU_EXT); @@ -1561,12 +1574,14 @@ bool TianmuHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_t std::unordered_set s; for (auto &it : fs::directory_iterator(tab_dir / common::COLUMN_DIR)) { auto target = fs::read_symlink(it.path()).string(); - if (!target.empty()) s.insert(target); + if (!target.empty()) + s.insert(target); } for (auto &it : fs::directory_iterator(bak_dir / common::COLUMN_DIR)) { auto target = fs::read_symlink(it.path()).string(); - if (target.empty()) continue; + if (target.empty()) + continue; auto search = s.find(target); if (search == s.end()) { fs::remove_all(target); @@ -1578,9 +1593,9 @@ bool TianmuHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_t TIANMU_LOG(LogCtl_Level::ERROR, "file system error: %s %s|%s", e.what(), e.path1().string().c_str(), e.path2().string().c_str()); my_message(static_cast(common::ErrorCode::UNKNOWN_ERROR), "Failed to commit alter table", MYF(0)); - return true; + DBUG_RETURN(true); } - return false; + DBUG_RETURN(false); } /* key: mysql format, may be union key, need changed to kvstore key format diff --git a/storage/tianmu/handler/tianmu_handler.h b/storage/tianmu/handler/tianmu_handler.h index 76afbc6580..26cd3ab595 100644 --- a/storage/tianmu/handler/tianmu_handler.h +++ b/storage/tianmu/handler/tianmu_handler.h @@ -158,6 +158,7 @@ class TianmuHandler final : public handler { public: static const Alter_inplace_info::HA_ALTER_FLAGS TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER; static const Alter_inplace_info::HA_ALTER_FLAGS TIANMU_SUPPORTED_ALTER_COLUMN_NAME; + static const Alter_inplace_info::HA_ALTER_FLAGS TIANMU_SUPPORTED_ALTER_TABLE_OPTIONS; protected: int set_cond_iter();