From fa79f6ac86c700c23041dd0f314a71bbfb1f4bdf Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Sun, 5 Nov 2017 19:47:06 +0300 Subject: [PATCH] IB: style changes [closes #306] --- storage/innobase/handler/ha_innodb.h | 5 +--- storage/innobase/include/dict0load.h | 17 ++++++----- storage/innobase/include/row0merge.h | 1 + storage/innobase/include/row0mysql.h | 12 ++++---- storage/innobase/include/row0upd.h | 6 ++-- storage/innobase/include/sync0policy.h | 6 +--- storage/innobase/include/trx0trx.h | 31 ++++++++++++++++++-- storage/innobase/include/trx0vtq.h | 40 -------------------------- storage/innobase/row/row0ins.cc | 22 ++++++++------ storage/innobase/row/row0merge.cc | 1 + storage/innobase/row/row0mysql.cc | 1 + storage/innobase/vers/vers0vtq.cc | 21 +++++++++----- 12 files changed, 82 insertions(+), 81 deletions(-) delete mode 100644 storage/innobase/include/trx0vtq.h diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 064015812e9..d7f5d36a680 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -223,9 +223,6 @@ public: ha_rows estimate_rows_upper_bound(); - // JAN: TODO: MySQL 5.7 - ha_rows records_new(); // FIXME: rename to records(), fix main.bug39022 - void update_create_info(HA_CREATE_INFO* create_info); int create( @@ -458,7 +455,7 @@ protected: void reset_template(); protected: - void update_thd(THD* thd); + inline void update_thd(THD* thd); void update_thd(); int general_fetch(uchar* buf, uint direction, uint match_mode); diff --git a/storage/innobase/include/dict0load.h b/storage/innobase/include/dict0load.h index a32aebc6743..d2d8b0d9271 100644 --- a/storage/innobase/include/dict0load.h +++ b/storage/innobase/include/dict0load.h @@ -31,7 +31,6 @@ Created 4/24/1996 Heikki Tuuri #include "univ.i" #include "dict0types.h" #include "trx0types.h" -#include "trx0vtq.h" #include "ut0byte.h" #include "mem0mem.h" #include "btr0types.h" @@ -39,6 +38,8 @@ Created 4/24/1996 Heikki Tuuri #include +struct vtq_record_t; + /** A stack of table names related through foreign key constraints */ typedef std::deque > dict_names_t; @@ -317,17 +318,19 @@ dict_process_sys_datafiles( const rec_t* rec, /*!< in: current SYS_DATAFILES rec */ ulint* space, /*!< out: pace id */ const char** path); /*!< out: datafile path */ -/********************************************************************//** -This function parses a SYS_VTQ record, extracts necessary + +/** This function parses a SYS_VTQ record, extracts necessary information from the record and returns it to the caller. +@param[in,out] heap Heap memory +@param[in] rec Current record +@param[out] fields Field values @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 */ -vtq_record_t& fields /*!< out: field values */ + mem_heap_t* heap, /*!< in/out: heap memory */ + const rec_t* rec, /*!< in: current rec */ + vtq_record_t& fields /*!< out: field values */ ); /** Update the record for space_id in SYS_TABLESPACES to this filepath. diff --git a/storage/innobase/include/row0merge.h b/storage/innobase/include/row0merge.h index 85a3e8d2e50..327efb50578 100644 --- a/storage/innobase/include/row0merge.h +++ b/storage/innobase/include/row0merge.h @@ -325,6 +325,7 @@ this function and it will be passed to other functions for further accounting. @param[in] add_v new virtual columns added along with indexes @param[in] eval_table mysql table used to evaluate virtual column value, see innobase_get_computed_value(). +@param[in] drop_historical whether to drop historical system rows @return DB_SUCCESS or error code */ dberr_t row_merge_build_indexes( diff --git a/storage/innobase/include/row0mysql.h b/storage/innobase/include/row0mysql.h index 9f8be316c1c..5f3489e413a 100644 --- a/storage/innobase/include/row0mysql.h +++ b/storage/innobase/include/row0mysql.h @@ -235,18 +235,17 @@ row_lock_table_for_mysql( (ignored if table==NULL) */ MY_ATTRIBUTE((nonnull(1))); -/* System Versioning: row_insert_for_mysql() modes */ +/** System Versioning: row_insert_for_mysql() modes */ enum ins_mode_t { - ROW_INS_NORMAL = 0, - // insert versioned row: sys_trx_start = TRX_ID, sys_trx_end = MAX - ROW_INS_VERSIONED, - // insert historical row: sys_trx_end = TRX_ID - ROW_INS_HISTORICAL + ROW_INS_NORMAL = 0, ///< plain row (without versioning) + ROW_INS_VERSIONED, ///< sys_trx_start = TRX_ID, sys_trx_end = MAX + ROW_INS_HISTORICAL ///< sys_trx_end = TRX_ID }; /** Does an insert for MySQL. @param[in] mysql_rec row in the MySQL format @param[in,out] prebuilt prebuilt struct in MySQL handle +@param[in] ins_mode what row type we're inserting @return error code or DB_SUCCESS*/ dberr_t row_insert_for_mysql( @@ -274,6 +273,7 @@ row_get_prebuilt_update_vector( handle */ /** Does an update or delete of a row for MySQL. @param[in,out] prebuilt prebuilt struct in MySQL handle +@param[in] vers_set_fields working with system versioned table @return error code or DB_SUCCESS */ dberr_t row_update_for_mysql( diff --git a/storage/innobase/include/row0upd.h b/storage/innobase/include/row0upd.h index 97c0b0d4202..1d10156b634 100644 --- a/storage/innobase/include/row0upd.h +++ b/storage/innobase/include/row0upd.h @@ -573,8 +573,10 @@ struct upd_node_t{ compilation; speeds up execution: UPD_NODE_NO_ORD_CHANGE and UPD_NODE_NO_SIZE_CHANGE, ORed */ - bool versioned;/* update is versioned */ - bool vers_delete;/* versioned delete */ + /** working with system versioned table */ + bool versioned; + /** set sys_trx_end = CUR_TRX_ID */ + bool vers_delete; /*----------------------*/ /* Local storage for this graph node */ ulint state; /*!< node execution state */ diff --git a/storage/innobase/include/sync0policy.h b/storage/innobase/include/sync0policy.h index 21ae18aac82..a91270bde58 100644 --- a/storage/innobase/include/sync0policy.h +++ b/storage/innobase/include/sync0policy.h @@ -59,11 +59,7 @@ public: @param[in] id ID of the latch to track */ Context(latch_id_t id) : - latch_t(id), - m_mutex(), - m_filename(), - m_line(), - m_thread_id(os_thread_id_t(ULINT_UNDEFINED)) + latch_t(id) { ut_ad(id != LATCH_ID_NONE); } diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 3b6a2d9fe37..aa419c4d15b 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -42,7 +42,6 @@ Created 3/26/1996 Heikki Tuuri #include "que0types.h" #include "mem0mem.h" #include "trx0xa.h" -#include "trx0vtq.h" #include "ut0vec.h" #include "fts0fts.h" #include "srv0srv.h" @@ -884,6 +883,33 @@ struct TrxVersion { ulint m_version; }; +/** Class which is used to query VTQ and also serves as a cache to VTQ of size 1 + */ +class vtq_query_t +{ +public: + /** VTQ used to translate timestamps to nearest trx_id and this is + a timestamp for a row we're caching now */ + timeval prev_query; + /** We search for nearest trx_id on the left or on the right and + we search forwards or backwards */ + bool backwards; + + /** Cached row from VTQ */ + vtq_record_t result; + + /** Parses record and stores its value in a result field + but disables a cache */ + const char * cache_result(mem_heap_t* heap, const rec_t* rec); + /** Parses record and stores its value in a result field and enables + cache (prev_query, backward) */ + const char * cache_result( + mem_heap_t* heap, + const rec_t* rec, + const timeval &_ts_query, + bool _backwards); +}; + typedef std::list > hit_list_t; struct trx_t { @@ -1272,7 +1298,8 @@ struct trx_t { /* System Versioning */ bool vtq_notify_on_commit; /*!< Notify VTQ for System Versioned update */ - vtq_query_t vtq_query; + vtq_query_t vtq_query; /*!< Structure to query VTQ and store + one row result */ ulint magic_n; /** @return whether any persistent undo log has been generated */ diff --git a/storage/innobase/include/trx0vtq.h b/storage/innobase/include/trx0vtq.h deleted file mode 100644 index 5767dfeb5a0..00000000000 --- a/storage/innobase/include/trx0vtq.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef trx0vtq_h -#define trx0vtq_h - -/* Copyright (c) 2016, MariaDB Corporation. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - -#include -#include "trx0types.h" -#include "mem0mem.h" -#include "rem0types.h" - -class vtq_query_t -{ -public: - timeval prev_query; - bool backwards; - - vtq_record_t result; - - const char * cache_result(mem_heap_t* heap, const rec_t* rec); - const char * cache_result( - mem_heap_t* heap, - const rec_t* rec, - const timeval &_ts_query, - bool _backwards); -}; - -#endif // trx0vtq_h diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 91ace884727..4889af373b7 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1594,17 +1594,21 @@ row_ins_get_sys_trx_end( return(mach_read_from_8(field)); } -/*********************************************************************//** +/** Performs search at clustered index and returns sys_trx_end if row was found. +@param[in] index secondary index of record +@param[in] rec record in a secondary index +@param[out] end_trx_id value from clustered index @return DB_SUCCESS, DB_NO_REFERENCED_ROW */ static dberr_t row_ins_search_sys_trx_end( -/*=======================*/ - dict_index_t *index, /*!< in: index of record */ - const rec_t *rec, /*!< in: record */ - trx_id_t *end_trx_id) /*!< out: end_trx_id */ + dict_index_t *index, + const rec_t *rec, + trx_id_t *end_trx_id) { + ut_ad(!index->is_clust()); + bool found = false; mem_heap_t *heap = mem_heap_create(256); dict_index_t *clust_index = NULL; @@ -1629,7 +1633,8 @@ not_found: mtr_commit(&mtr); mem_heap_free(heap); if (!found) { - fprintf(stderr, "InnoDB: foreign constraints: secondary index is out of sync\n"); + ib::error() << "foreign constraints: secondary index is out of " + "sync"; ut_ad(false && "secondary index is out of sync"); return(DB_NO_REFERENCED_ROW); } @@ -4014,7 +4019,7 @@ vers_row_ins_vtq_low(trx_t* trx, mem_heap_t* heap, dtuple_t* tuple) break; case DB_SUCCESS_LOCKED_REC: /* The row had already been copied to the table. */ - fprintf(stderr, "InnoDB: duplicate VTQ record!\n"); + ib::info() << "InnoDB: duplicate VTQ record!"; return DB_SUCCESS; default: return err; @@ -4068,7 +4073,8 @@ void vers_notify_vtq(trx_t* trx) err = vers_row_ins_vtq_low(trx, heap, tuple); if (DB_SUCCESS != err) - fprintf(stderr, "InnoDB: failed to insert VTQ record (error %d)\n", err); + ib::error() + << "failed to insert VTQ record (error " << err << ")"; mem_heap_free(heap); } diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index f57f9accedd..1ca2aef5b69 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -4603,6 +4603,7 @@ this function and it will be passed to other functions for further accounting. @param[in] add_v new virtual columns added along with indexes @param[in] eval_table mysql table used to evaluate virtual column value, see innobase_get_computed_value(). +@param[in] drop_historical whether to drop historical system rows @return DB_SUCCESS or error code */ dberr_t row_merge_build_indexes( diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 007c3bf5ce6..7df0974c2f1 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1863,6 +1863,7 @@ public: /** Does an update or delete of a row for MySQL. @param[in,out] prebuilt prebuilt struct in MySQL handle +@param[in] vers_set_fields working with system versioned table @return error code or DB_SUCCESS */ dberr_t row_update_for_mysql( diff --git a/storage/innobase/vers/vers0vtq.cc b/storage/innobase/vers/vers0vtq.cc index 7fb63847316..f2eed3a254d 100644 --- a/storage/innobase/vers/vers0vtq.cc +++ b/storage/innobase/vers/vers0vtq.cc @@ -23,7 +23,6 @@ #include "row0row.h" #include "trx0trx.h" #include "trx0types.h" -#include "trx0vtq.h" /** Field or record selector. @@ -145,7 +144,9 @@ vtq_query_trx_id(THD* thd, void *out, ulonglong _in_trx_id, vtq_field_t field) { const char *err = trx->vtq_query.cache_result(heap, rec); if (err) { - fprintf(stderr, "InnoDB: vtq_query_trx_id: get VTQ field failed: %s\n", err); + ib::error() + << "vtq_query_trx_id: get VTQ field failed: " + << err; ut_ad(false && "get VTQ field failed"); goto not_found; } @@ -378,7 +379,8 @@ vtq_query_commit_ts( found: clust_rec = row_get_clust_rec(BTR_SEARCH_LEAF, rec, index, &clust_index, &mtr); if (!clust_rec) { - fprintf(stderr, "InnoDB: vtq_query_commit_ts: secondary index is out of sync\n"); + ib::error() << "vtq_query_commit_ts: secondary index is out of " + "sync"; ut_ad(false && "secondary index is out of sync"); goto not_found; } @@ -391,7 +393,9 @@ found: rec_ts, backwards); if (err) { - fprintf(stderr, "InnoDB: vtq_query_commit_ts: get VTQ field failed: %s\n", err); + ib::error() + << "vtq_query_commit_ts: get VTQ field failed: " + << err; ut_ad(false && "get VTQ field failed"); goto not_found; } @@ -438,10 +442,11 @@ vtq_trx_sees( DBUG_RETURN(true); } - static const char* msg_cant_find = "InnoDB: vtq_trx_sees: can't find COMMIT_ID%c by TRX_ID: %llu\n"; if (!commit_id1) { if (!vtq_query_trx_id(thd, NULL, trx_id1, VTQ_ALL)) { - fprintf(stderr, msg_cant_find, '1', trx_id1); + ib::info() << "vtq_trx_sees: can't find COMMIT_ID0 by " + "TRX_ID: " + << trx_id1; DBUG_RETURN(false); } trx_t* trx = thd_to_trx(thd); @@ -452,7 +457,9 @@ vtq_trx_sees( if (!commit_id0) { if (!vtq_query_trx_id(thd, &commit_id0, trx_id0, VTQ_COMMIT_ID)) { - fprintf(stderr, msg_cant_find, '0', trx_id0); + ib::info() << "vtq_trx_sees: can't find COMMIT_ID1 by " + "TRX_ID: " + << trx_id0; DBUG_RETURN(false); } }