Skip to content

Commit

Permalink
IB: 0.2 part I
Browse files Browse the repository at this point in the history
* SYS_VTQ internal InnoDB table;
* I_S.INNODB_SYS_VTQ table;
* vers_notify_vtq(): add record to SYS_VTQ on versioned DML;
* SYS_VTQ columns filled: TRX_ID, BEGIN_TS.
  • Loading branch information
midenok committed May 5, 2017
1 parent bd0b21d commit 84e1971
Show file tree
Hide file tree
Showing 20 changed files with 618 additions and 17 deletions.
1 change: 1 addition & 0 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ enum enum_alter_inplace_result {
#define HA_LEX_CREATE_TMP_TABLE 1U
#define HA_CREATE_TMP_ALTER 8U
#define HA_LEX_CREATE_SEQUENCE 16U
#define HA_VERSIONED_TABLE 32U

#define HA_MAX_REC_LENGTH 65535

Expand Down
6 changes: 6 additions & 0 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4627,6 +4627,12 @@ extern "C" int thd_rpl_is_parallel(const MYSQL_THD thd)
return thd->rgi_slave && thd->rgi_slave->is_parallel_exec;
}

/* Returns high resolution timestamp for the start
of the current query. */
extern "C" time_t thd_start_time(const MYSQL_THD thd)
{
return thd->start_time;
}

/* Returns high resolution timestamp for the start
of the current query. */
Expand Down
109 changes: 109 additions & 0 deletions storage/innobase/dict/dict0crea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,115 @@ dict_create_or_check_sys_virtual()
return(err);
}

UNIV_INTERN
dberr_t
dict_create_or_check_vtq_table(void)
/*================================================*/
{
trx_t* trx;
my_bool srv_file_per_table_backup;
dberr_t err;
dberr_t sys_vtq_err;

ut_a(srv_get_active_thread_type() == SRV_NONE);

/* Note: The master thread has not been started at this point. */


sys_vtq_err = dict_check_if_system_table_exists(
"SYS_VTQ", DICT_NUM_FIELDS__SYS_VTQ + 1, 3);

if (sys_vtq_err == DB_SUCCESS) {
mutex_enter(&dict_sys->mutex);
dict_sys->sys_vtq = dict_table_get_low("SYS_VTQ");
mutex_exit(&dict_sys->mutex);
return(DB_SUCCESS);
}

trx = trx_allocate_for_mysql();

trx_set_dict_operation(trx, TRX_DICT_OP_TABLE);

trx->op_info = "creating VTQ sys table";

row_mysql_lock_data_dictionary(trx);

/* Check which incomplete table definition to drop. */

if (sys_vtq_err == DB_CORRUPTION) {
ib::warn() <<
"Dropping incompletely created "
"SYS_VTQ table.";
row_drop_table_for_mysql("SYS_VTQ", trx, false, TRUE);
}

ib::warn() <<
"Creating VTQ system table.";

srv_file_per_table_backup = srv_file_per_table;

/* We always want SYSTEM tables to be created inside the system
tablespace. */

srv_file_per_table = 0;

err = que_eval_sql(
NULL,
"PROCEDURE CREATE_VTQ_SYS_TABLE_PROC () IS\n"
"BEGIN\n"
"CREATE TABLE\n"
"SYS_VTQ(TRX_ID BIGINT UNSIGNED, BEGIN_TS BIGINT UNSIGNED,"
" COMMIT_TS BIGINT UNSIGNED, CONCURR_TRX BLOB);\n"
"CREATE UNIQUE CLUSTERED INDEX TRX_ID_IND"
" ON SYS_VTQ (TRX_ID);\n"
"CREATE INDEX BEGIN_TS_IND"
" ON SYS_VTQ (BEGIN_TS);\n"
"CREATE INDEX COMMIT_TS_IND"
" ON SYS_VTQ (COMMIT_TS);\n"
"END;\n",
FALSE, trx);

if (err != DB_SUCCESS) {
ib::error() << "Creation of SYS_VTQ"
" failed: " << ut_strerr(err) << ". Tablespace is"
" full or too many transactions."
" Dropping incompletely created tables.";

ut_ad(err == DB_OUT_OF_FILE_SPACE
|| err == DB_TOO_MANY_CONCURRENT_TRXS);

row_drop_table_for_mysql("SYS_VTQ", trx, false, TRUE);

if (err == DB_OUT_OF_FILE_SPACE) {
err = DB_MUST_GET_MORE_FILE_SPACE;
}
}

trx_commit_for_mysql(trx);

row_mysql_unlock_data_dictionary(trx);

trx_free_for_mysql(trx);

srv_file_per_table = srv_file_per_table_backup;

if (err == DB_SUCCESS) {
ib::info() <<
"VTQ system table created";
}

/* Note: The master thread has not been started at this point. */
/* Confirm and move to the non-LRU part of the table LRU list. */
sys_vtq_err = dict_check_if_system_table_exists(
"SYS_VTQ", DICT_NUM_FIELDS__SYS_VTQ + 1, 3);
ut_a(sys_vtq_err == DB_SUCCESS);
mutex_enter(&dict_sys->mutex);
dict_sys->sys_vtq = dict_table_get_low("SYS_VTQ");
mutex_exit(&dict_sys->mutex);

return(err);
}

/****************************************************************//**
Evaluate the given foreign key SQL statement.
@return error code or DB_SUCCESS */
Expand Down
64 changes: 62 additions & 2 deletions storage/innobase/dict/dict0load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Created 4/24/1996 Heikki Tuuri
#include <set>

/** Following are the InnoDB system tables. The positions in
this array are referenced by enum dict_system_table_id. */
this array are referenced by enum dict_system_id_t. */
static const char* SYSTEM_TABLE_NAME[] = {
"SYS_TABLES",
"SYS_INDEXES",
Expand All @@ -60,7 +60,8 @@ static const char* SYSTEM_TABLE_NAME[] = {
"SYS_FOREIGN_COLS",
"SYS_TABLESPACES",
"SYS_DATAFILES",
"SYS_VIRTUAL"
"SYS_VIRTUAL",
"SYS_VTQ"
};

/** Loads a table definition and also all its index definitions.
Expand Down Expand Up @@ -821,6 +822,64 @@ dict_process_sys_datafiles(
return(NULL);
}

/********************************************************************//**
This function parses a SYS_VTQ record, extracts necessary
information from the record and returns it to the caller.
@return error message, or NULL on success */
UNIV_INTERN
const char*
dict_process_sys_vtq(
/*=======================*/
mem_heap_t* heap, /*!< in/out: heap memory */
const rec_t* rec, /*!< in: current rec */
ullong* col_trx_id, /*!< out: field values */
ullong* col_begin_ts,
ullong* col_commit_ts,
ullong* col_concurr_trx)
{
ulint len;
const byte* field;

if (rec_get_deleted_flag(rec, 0)) {
return("delete-marked record in SYS_VTQ");
}

if (rec_get_n_fields_old(rec) != DICT_NUM_FIELDS__SYS_VTQ) {
return("wrong number of columns in SYS_VTQ record");
}

field = rec_get_nth_field_old(
rec, DICT_FLD__SYS_VTQ__TRX_ID, &len);
if (len != sizeof(col_trx_id)) {
err_len:
return("incorrect column length in SYS_VTQ");
}
*col_trx_id = mach_read_from_8(field);

field = rec_get_nth_field_old(
rec, DICT_FLD__SYS_VTQ__BEGIN_TS, &len);
if (len != sizeof(col_begin_ts)) {
goto err_len;
}
*col_begin_ts = mach_read_from_8(field);

field = rec_get_nth_field_old(
rec, DICT_FLD__SYS_VTQ__COMMIT_TS, &len);
if (len != sizeof(col_commit_ts)) {
goto err_len;
}
*col_commit_ts = mach_read_from_8(field);

field = rec_get_nth_field_old(
rec, DICT_FLD__SYS_VTQ__CONCURR_TRX, &len);
if (len != sizeof(col_concurr_trx)) {
goto err_len;
}
*col_concurr_trx = mach_read_from_8(field);

return(NULL);
}

/** Get the first filepath from SYS_DATAFILES for a given space_id.
@param[in] space_id Tablespace ID
@return First filepath (caller must invoke ut_free() on it)
Expand Down Expand Up @@ -3714,3 +3773,4 @@ dict_table_open_on_index_id(
}
return table;
}

11 changes: 7 additions & 4 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,7 @@ thd_start_time_in_secs(
/*===================*/
THD* thd) /*!< in: thread handle, or NULL */
{
// FIXME: This function should be added to the server code.
//return(thd_start_time(thd));
return(ulint(ut_time()));
return(thd_start_time(thd));
}

/** Enter InnoDB engine after checking the max number of user threads
Expand Down Expand Up @@ -12855,6 +12853,10 @@ create_table_info_t::innobase_table_flags()
DBUG_EXECUTE_IF("innodb_test_wrong_fts_aux_table_name",
m_flags2 &= ~DICT_TF2_FTS_AUX_HEX_NAME;);

if (m_create_info->options & HA_VERSIONED_TABLE) {
m_flags2 |= DICT_TF2_VERSIONED;
}

DBUG_RETURN(true);
}

Expand Down Expand Up @@ -22000,7 +22002,8 @@ i_s_innodb_sys_virtual,
i_s_innodb_mutexes,
i_s_innodb_sys_semaphore_waits,
i_s_innodb_tablespaces_encryption,
i_s_innodb_tablespaces_scrubbing
i_s_innodb_tablespaces_scrubbing,
i_s_innodb_vtq
maria_declare_plugin_end;

/** @brief Initialize the default value of innodb_commit_concurrency.
Expand Down
Loading

0 comments on commit 84e1971

Please sign in to comment.