Skip to content

Commit

Permalink
fix(tianmu): add file extension of tianmu into hton to fix drop datab…
Browse files Browse the repository at this point in the history
…ase error stoneatom#662

[summary]
When drop database, mysqld cannot find tianmu file extension and drop failed.
1. change all `rcbase_hton` to `tianmu_hton`, just like innodb, myisam,
csv ... does.
2. rm function bas_ext(), it used in 5.7, but removed in 8.0 and changed
to a variable instead.
3. Add tianmu file extension to tianmu_hton->file_extensions.
  • Loading branch information
hustjieke committed Oct 11, 2022
1 parent a49fecb commit 1c64c71
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 34 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ int ha_initialize_handlerton(st_plugin_int *plugin) {
case DB_TYPE_INNODB:
innodb_hton = hton;
break;
case DB_TYPE_TIANMU: // stonedb8
tianmu_hton = hton; // stonedb8
case DB_TYPE_TIANMU:
tianmu_hton = hton;
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ handlerton *heap_hton;
handlerton *temptable_hton;
handlerton *myisam_hton;
handlerton *innodb_hton;
handlerton *tianmu_hton; // stonedb8
handlerton *tianmu_hton;

char *opt_disabled_storage_engines;
uint opt_server_id_bits = 0;
Expand Down
2 changes: 1 addition & 1 deletion sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ extern handlerton *myisam_hton;
extern handlerton *heap_hton;
extern handlerton *temptable_hton;
extern handlerton *innodb_hton;
extern handlerton *tianmu_hton; // stonedb8
extern handlerton *tianmu_hton;

extern uint opt_server_id_bits;
extern ulong opt_server_id_mask;
Expand Down
4 changes: 2 additions & 2 deletions storage/tianmu/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ void Engine::UpdateAndStoreColumnComment(TABLE *table, int field_id, Field *sour
CHARSET_INFO *cs) {
// stonedb8 start convert orig_table to table, MySQL 8.0 don't have orig_table, idea from
// ha_innodb.cc:create_table_def
if (source_field->table->s->db_type() == rcbase_hton) { // do not use table (cont. default values)
if (source_field->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 @@ -1609,7 +1609,7 @@ Query_Route_To Engine::RouteTo(THD *thd, TABLE_LIST *table_list, Query_block *se
}

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

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

extern handlerton *rcbase_hton;
class Field;

namespace Tianmu {
Expand Down
32 changes: 20 additions & 12 deletions storage/tianmu/handler/ha_rcengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "mm/initializer.h"
#include "system/file_out.h"

handlerton *rcbase_hton;

struct SYS_VAR {
MYSQL_PLUGIN_VAR_HEADER;
Expand Down Expand Up @@ -184,23 +183,32 @@ static int init_variables() {
return 0;
}

// Gives the file extension of an Tianmu single-table tablespace.
static const char *ha_tianmu_exts[] = {common::TIANMU_EXT, NullS};

int rcbase_init_func(void *p) {
DBUG_ENTER(__PRETTY_FUNCTION__);
rcbase_hton = (handlerton *)p;

// move hton here, just like other storate like innodb, myisam, csv... does.
// handlerton is a singleton structure - one instance per storage engine.
// defined in sql/handler.h
handlerton *tianmu_hton;
tianmu_hton = (handlerton *)p;

if (init_variables()) {
DBUG_RETURN(1);
}

rcbase_hton->state = SHOW_OPTION_YES;
rcbase_hton->db_type = DB_TYPE_TIANMU;
rcbase_hton->create = rcbase_create_handler;
rcbase_hton->flags = HTON_NO_FLAGS;
rcbase_hton->panic = rcbase_panic_func;
rcbase_hton->close_connection = rcbase_close_connection;
rcbase_hton->commit = rcbase_commit;
rcbase_hton->rollback = rcbase_rollback;
rcbase_hton->show_status = rcbase_show_status;
tianmu_hton->state = SHOW_OPTION_YES;
tianmu_hton->db_type = DB_TYPE_TIANMU;
tianmu_hton->create = rcbase_create_handler;
tianmu_hton->flags = HTON_NO_FLAGS;
tianmu_hton->panic = rcbase_panic_func;
tianmu_hton->close_connection = rcbase_close_connection;
tianmu_hton->commit = rcbase_commit;
tianmu_hton->rollback = rcbase_rollback;
tianmu_hton->show_status = rcbase_show_status;
tianmu_hton->file_extensions = ha_tianmu_exts;

// When mysqld runs as bootstrap mode, we do not need to initialize
// memmanager.
Expand All @@ -222,7 +230,7 @@ int rcbase_init_func(void *p) {
ha_kvstore_ = new index::KVStore();
ha_kvstore_->Init();
ha_rcengine_ = new core::Engine();
ret = ha_rcengine_->Init(rcbase_hton->slot); // stonedb8
ret = ha_rcengine_->Init(tianmu_hton->slot);
{
TIANMU_LOG(LogCtl_Level::INFO,
"\n"
Expand Down
20 changes: 6 additions & 14 deletions storage/tianmu/handler/ha_tianmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,6 @@ TianmuHandler::TianmuHandler(handlerton *hton, TABLE_SHARE *table_arg, bool part
ref_length = sizeof(uint64_t);
}

// stonedb8
/*
const char **TianmuHandler::bas_ext() const {
static const char *ha_rcbase_exts[] = {common::TIANMU_EXT, 0};
return ha_rcbase_exts;
}
*/

namespace {
std::vector<bool> GetAttrsUseIndicator(TABLE *table) {
int col_id = 0;
Expand Down Expand Up @@ -272,9 +264,9 @@ int TianmuHandler::external_lock(THD *thd, int lock_type) {
tx->AddTableRD(share);
} else {
tx->AddTableWR(share);
trans_register_ha(thd, false, rcbase_hton, NULL);
trans_register_ha(thd, false, tianmu_hton, NULL);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
trans_register_ha(thd, true, rcbase_hton, NULL);
trans_register_ha(thd, true, tianmu_hton, NULL);
}
}
ret = 0;
Expand Down Expand Up @@ -1106,9 +1098,9 @@ int TianmuHandler::extra([[maybe_unused]] enum ha_extra_function operation) {
int TianmuHandler::start_stmt(THD *thd, thr_lock_type lock_type) {
try {
if (lock_type == TL_WRITE_CONCURRENT_INSERT || lock_type == TL_WRITE_DEFAULT || lock_type == TL_WRITE) {
trans_register_ha(thd, false, rcbase_hton, NULL);
trans_register_ha(thd, false, tianmu_hton, NULL);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
trans_register_ha(thd, true, rcbase_hton, NULL);
trans_register_ha(thd, true, tianmu_hton, NULL);
}
current_txn_ = ha_rcengine_->GetTx(thd);
current_txn_->AddTableWRIfNeeded(share);
Expand Down Expand Up @@ -1146,7 +1138,7 @@ bool TianmuHandler::register_query_cache_table(THD *thd, char *table_key, size_t
If you do not implement this, the default delete_table() is called from
handler.cc and it will delete all files with the file extentions returned
by bas_ext().
by bas_ext(). // stonedb8 TODO bas_ext() has been deleted in mysql8.0
Called from handler.cc by delete_table and ha_create_table(). Only used
during create if the table_flag HA_DROP_BEFORE_CREATE was specified for
Expand Down Expand Up @@ -1687,4 +1679,4 @@ void TianmuHandler::key_convert(const uchar *key, uint key_len, std::vector<uint
}

} // namespace DBHandler
} // namespace Tianmu
} // namespace Tianmu
2 changes: 1 addition & 1 deletion storage/tianmu/handler/ha_tianmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TianmuHandler final : public handler {
/* The name that will be used for display purposes */
const char *table_type() const override { return "TIANMU"; }
/*
Get the row type from the storage engine. If this method returns
Get the row type from the storage engine. If this method returns
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
*/
// enum row_type get_row_type() const override { return ROW_TYPE_COMPRESSED; } // stonedb8 get_row_type() is
Expand Down

0 comments on commit 1c64c71

Please sign in to comment.