Skip to content

Commit

Permalink
feat(tianmu): reorganize code in handler #11
Browse files Browse the repository at this point in the history
[summary]
1. rename file name in handler, just like innodb, myisam ... does.
2. reorganize code about tianmu_handler.cpp & tianmu_handler_com.cpp into one.
  • Loading branch information
hustjieke authored and mergify[bot] committed Nov 22, 2022
1 parent 88f4fb7 commit 72b1256
Show file tree
Hide file tree
Showing 10 changed files with 797 additions and 43 deletions.
1 change: 1 addition & 0 deletions sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ extern const char *opt_date_time_formats[];
extern handlerton *myisam_hton;
extern handlerton *heap_hton;
extern handlerton *innodb_hton;
extern handlerton *tianmu_hton;
extern uint opt_server_id_bits;
extern ulong opt_server_id_mask;
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
}
// TIANMU UPGRADE BEGIN
if (!Tianmu::handler::tianmu_load(thd, ex, table_list, (void*) &lf_info)) {
if (!Tianmu::handler::ha_my_tianmu_load(thd, ex, table_list, (void*) &lf_info)) {
DBUG_RETURN(FALSE);
}
//END
Expand Down
7 changes: 3 additions & 4 deletions storage/tianmu/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
#include <set>
#include <tuple>

#include "common/mysql_gate.h"

#include "common/data_format.h"
#include "common/exception.h"
#include "common/mysql_gate.h"
#include "core/rc_mem_table.h"
#include "core/table_share.h"
#include "core/task_executor.h"
Expand Down Expand Up @@ -836,7 +835,7 @@ std::vector<AttrInfo> Engine::GetTableAttributesInfo(const std::string &table_pa

void Engine::UpdateAndStoreColumnComment(TABLE *table, int field_id, Field *source_field, int source_field_id,
CHARSET_INFO *cs) {
if (source_field->orig_table->s->db_type() == rcbase_hton) { // do not use table (cont. default values)
if (source_field->orig_table->s->db_type() == tianmu_hton) { // do not use table (cont. default values)
char buf_size[256] = {0};
char buf_ratio[256] = {0};
uint buf_size_count = 0;
Expand Down Expand Up @@ -1628,7 +1627,7 @@ bool Engine::IsTIANMURoute(THD *thd, TABLE_LIST *table_list, SELECT_LEX *selects
}

bool Engine::IsTianmuTable(TABLE *table) {
return table && table->s->db_type() == rcbase_hton; // table->db_type is always nullptr
return table && table->s->db_type() == tianmu_hton; // table->db_type is always nullptr
}

const char *Engine::GetFilename(SELECT_LEX *selects_list, int &is_dumpfile) {
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "util/mapped_circular_buffer.h"
#include "util/thread_pool.h"

extern handlerton *rcbase_hton;
extern handlerton *tianmu_hton;
class Field;

namespace Tianmu {
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/rc_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "core/rc_table.h"
#include "core/table_share.h"
#include "core/transaction.h"
#include "handler/tianmu_handler.h"
#include "handler/ha_tianmu.h"
#include "loader/load_parser.h"
#include "log_event.h"
#include "system/channel.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,26 @@
namespace Tianmu {
namespace handler {

enum class TIANMUEngineReturnValues { LD_Successed = 100, LD_Failed = 101, LD_Continue = 102 };
enum class TianmuEngineReturnValues {
kLoadSuccessed = 0,
kLoadFailed,
kLoadContinue,
};

bool AtLeastOneTIANMUTableInvolved(LEX *lex) {
for (TABLE_LIST *table_list = lex->query_tables; table_list; table_list = table_list->next_global) {
TABLE *table = table_list->table;
if (core::Engine::IsTianmuTable(table))
return true;
}
return false;
}

bool ForbiddenMySQLQueryPath([[maybe_unused]] LEX *lex) {
// 0: not allowed route to mysql
// 1: allowed route to mysql if tianmu engine not support
return 0 == tianmu_sysvar_allowmysqlquerypath;
}

void ha_my_tianmu_update_and_store_col_comment(TABLE *table, int field_id, Field *source_field, int source_field_id,
CHARSET_INFO *cs) {
Expand All @@ -40,19 +59,7 @@ void ha_my_tianmu_update_and_store_col_comment(TABLE *table, int field_id, Field
}
}

namespace {
bool AtLeastOneTIANMUTableInvolved(LEX *lex) {
for (TABLE_LIST *table_list = lex->query_tables; table_list; table_list = table_list->next_global) {
TABLE *table = table_list->table;
if (core::Engine::IsTianmuTable(table))
return TRUE;
}
return FALSE;
}

bool ForbiddenMySQLQueryPath([[maybe_unused]] LEX *lex) { return (tianmu_sysvar_allowmysqlquerypath == 0); }
} // namespace

// used in stonedb 5.7, deleted in stonedb 8.0
bool ha_my_tianmu_set_statement_allowed(THD *thd, LEX *lex) {
if (AtLeastOneTIANMUTableInvolved(lex)) {
if (ForbiddenMySQLQueryPath(lex)) {
Expand Down Expand Up @@ -99,20 +106,20 @@ Either restructure the query with supported syntax, or enable the MySQL core::Qu
return ret;
}

int ha_my_tianmu_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg, char *errmsg, int len,
int &errcode) {
int tianmu_load_impl(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg, char *errmsg, int len,
int &errcode) {
common::TianmuError tianmu_error;
int ret = static_cast<int>(TIANMUEngineReturnValues::LD_Failed);
int ret = static_cast<int>(TianmuEngineReturnValues::kLoadFailed);

if (!core::Engine::IsTianmuTable(table_list->table))
return static_cast<int>(TIANMUEngineReturnValues::LD_Continue);
return static_cast<int>(TianmuEngineReturnValues::kLoadContinue);

try {
tianmu_error = ha_rcengine_->RunLoader(thd, ex, table_list, arg);
if (tianmu_error.GetErrorCode() != common::ErrorCode::SUCCESS) {
TIANMU_LOG(LogCtl_Level::ERROR, "RunLoader Error: %s", tianmu_error.Message().c_str());
} else {
ret = static_cast<int>(TIANMUEngineReturnValues::LD_Successed);
ret = static_cast<int>(TianmuEngineReturnValues::kLoadSuccessed);
}
} catch (std::exception &e) {
tianmu_error = common::TianmuError(common::ErrorCode::UNKNOWN_ERROR, e.what());
Expand All @@ -128,17 +135,17 @@ int ha_my_tianmu_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *
}

// returning true means 'to continue'
bool tianmu_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg) {
bool ha_my_tianmu_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg) {
char tianmu_msg[256] = {0};
int tianmu_errcode = 0;
switch (static_cast<TIANMUEngineReturnValues>(
ha_my_tianmu_load(thd, ex, table_list, arg, tianmu_msg, 256, tianmu_errcode))) {
case TIANMUEngineReturnValues::LD_Continue:
switch (static_cast<TianmuEngineReturnValues>(
tianmu_load_impl(thd, ex, table_list, arg, tianmu_msg, 256, tianmu_errcode))) {
case TianmuEngineReturnValues::kLoadContinue:
return true;
case TIANMUEngineReturnValues::LD_Failed:
case TianmuEngineReturnValues::kLoadFailed:
my_message(tianmu_errcode, tianmu_msg, MYF(0));
[[fallthrough]];
case TIANMUEngineReturnValues::LD_Successed:
case TianmuEngineReturnValues::kLoadSuccessed:
return false;
default:
my_message(tianmu_errcode, tianmu_msg, MYF(0));
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/handler/ha_my_tianmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void ha_my_tianmu_update_and_store_col_comment(TABLE *table, int field_id, Field
bool ha_my_tianmu_set_statement_allowed(THD *thd, LEX *lex);

// processing the load operation.
bool tianmu_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg);
bool ha_my_tianmu_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg);

} // namespace handler
} // namespace Tianmu
Expand Down
Loading

0 comments on commit 72b1256

Please sign in to comment.