diff options
author | Will DeVries <wdevries@clustrix.com> | 2020-02-28 00:58:16 -0800 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2020-03-10 11:22:33 +0300 |
commit | 9062b02365c4b5cee5ce21b97a9161691934609c (patch) | |
tree | 5c3a646d8f457726dfd1cef44d229d55afe3ffee | |
parent | 366fd6523d9cf250584e401bd45baf84aabe7556 (diff) | |
download | mariadb-git-9062b02365c4b5cee5ce21b97a9161691934609c.tar.gz |
Fix table discovery.
-rw-r--r-- | storage/xpand/ha_xpand.cc | 29 | ||||
-rw-r--r-- | storage/xpand/ha_xpand.h | 4 | ||||
-rw-r--r-- | storage/xpand/xpand_connection.cc | 17 |
3 files changed, 26 insertions, 24 deletions
diff --git a/storage/xpand/ha_xpand.cc b/storage/xpand/ha_xpand.cc index 8ee01467124..bf8119ed464 100644 --- a/storage/xpand/ha_xpand.cc +++ b/storage/xpand/ha_xpand.cc @@ -429,16 +429,7 @@ int ha_xpand::create(const char *name, TABLE *form, HA_CREATE_INFO *info) trx->run_query(createdb_stmt); } - error_code = trx->run_query(create_table_stmt); - if (error_code) - return error_code; - - // Load the oid of the created table - error_code= trx->get_table_oid(norm_db.c_str(), strlen(norm_db.c_str()), - norm_table.c_str(), strlen(norm_table.c_str()), - &xpand_table_oid, table_share); - - return error_code; + return trx->run_query(create_table_stmt); } int ha_xpand::delete_table(const char *path) @@ -502,10 +493,10 @@ int ha_xpand::rename_table(const char* from, const char* to) static void xpand_mark_table_for_discovery(TABLE *table) { - table->m_needs_reopen = TRUE; + table->m_needs_reopen = true; Xpand_share *xs; - if ((xs= (Xpand_share*)table->s->ha_share)) - xs->xpand_table_oid= 0; + if ((xs= static_cast<Xpand_share*>(table->s->ha_share))) + xs->rediscover_table = true; } void @@ -544,13 +535,18 @@ int ha_xpand::open(const char *name, int mode, uint test_if_locked) THD *thd= ha_thd(); DBUG_ENTER("ha_xpand::open"); + Xpand_share *share; if (!(share = get_share())) DBUG_RETURN(1); + int error_code; xpand_connection *trx = get_trx(thd, &error_code); if (!trx) DBUG_RETURN(error_code); + if (share->rediscover_table) + DBUG_RETURN(HA_ERR_TABLE_DEF_CHANGED); + if (!share->xpand_table_oid) { // We may end up with two threads executing this piece concurrently but // it's ok @@ -559,14 +555,19 @@ int ha_xpand::open(const char *name, int mode, uint test_if_locked) if ((error_code= normalize_tablename(name, &norm_db, &norm_table))) DBUG_RETURN(error_code); + ulonglong oid = 0; error_code= trx->get_table_oid(norm_db.c_str(), strlen(norm_db.c_str()), norm_table.c_str(), - strlen(norm_table.c_str()), &xpand_table_oid, + strlen(norm_table.c_str()), &oid, table_share); if (error_code) DBUG_RETURN(error_code); + + share->xpand_table_oid = oid; } + xpand_table_oid = share->xpand_table_oid; + // Surrogate key marker has_hidden_key = table->s->primary_key == MAX_KEY; if (has_hidden_key) { diff --git a/storage/xpand/ha_xpand.h b/storage/xpand/ha_xpand.h index bc3206f2f5f..06dca73f15b 100644 --- a/storage/xpand/ha_xpand.h +++ b/storage/xpand/ha_xpand.h @@ -35,9 +35,10 @@ ulonglong *xpand_extract_table_oids(THD *thd, LEX *lex); class Xpand_share : public Handler_share { public: - Xpand_share(): xpand_table_oid(0) {} + Xpand_share(): xpand_table_oid(0), rediscover_table(false) {} std::atomic<ulonglong> xpand_table_oid; + std::atomic<bool> rediscover_table; }; class ha_xpand : public handler @@ -67,7 +68,6 @@ private: } xpd_upsert_flags_t; int upsert_flag; - Xpand_share *share; Xpand_share *get_share(); ///< Get the share public: diff --git a/storage/xpand/xpand_connection.cc b/storage/xpand/xpand_connection.cc index ed251ba1da3..299679f989b 100644 --- a/storage/xpand/xpand_connection.cc +++ b/storage/xpand/xpand_connection.cc @@ -1024,8 +1024,7 @@ error: int xpand_connection::get_table_oid(const char *db, size_t db_len, const char *name, size_t name_len, - ulonglong *oid, - TABLE_SHARE *share) + ulonglong *oid, TABLE_SHARE *share) { MYSQL_ROW row; int error_code = 0; @@ -1063,12 +1062,7 @@ int xpand_connection::get_table_oid(const char *db, size_t db_len, if ((row = mysql_fetch_row(results_oid))) { DBUG_PRINT("row", ("%s", row[0])); - *oid = strtoull((const char *)row[0], NULL, 10); - if (share->ha_share) { - Xpand_share *cs= (Xpand_share*)share->ha_share; - cs->xpand_table_oid = *oid; - } } else { error_code = HA_ERR_NO_SUCH_TABLE; goto error; @@ -1094,13 +1088,19 @@ int xpand_connection::discover_table_details(LEX_CSTRING *db, LEX_CSTRING *name, MYSQL_RES *results_create = NULL; MYSQL_ROW row; String show; - ulonglong oid; + ulonglong oid = 0; + Xpand_share *cs; if ((error_code = xpand_connection::get_table_oid(db->str, db->length, name->str, name->length, &oid, share))) goto error; + if (!share->ha_share) + share->ha_share= new Xpand_share; + cs= static_cast<Xpand_share*>(share->ha_share); + cs->xpand_table_oid = oid; + /* get show create statement */ show.append("show simple create table "); show.append(db); @@ -1137,6 +1137,7 @@ int xpand_connection::discover_table_details(LEX_CSTRING *db, LEX_CSTRING *name, strlen(row[1])); } + cs->rediscover_table = false; error: if (results_create) mysql_free_result(results_create); |