From 11f9335eed8f423173181c456f5f2c168f4697dc Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 22 May 2019 22:50:45 -0700 Subject: [PATCH] Fix AutoInitCopy #2 Upstream commit ID : fb-mysql-5.6.35/911d1a387a0d80f3ba52b7432c1abdbd7e8cb220 PS-6867 : Merge fb-prod201905 Summary: Missed a few in earlier fixes for AutoInitCopy rule. Also added a few fixes for anoymous class rule and local shadowing rule. Reviewed By: luqun Differential Revision: D15467213 fbshipit-source-id: 9325852dbdd --- storage/rocksdb/event_listener.cc | 2 +- storage/rocksdb/ha_rocksdb.cc | 4 ---- storage/rocksdb/properties_collector.cc | 2 +- storage/rocksdb/rdb_cf_manager.cc | 4 ++-- storage/rocksdb/rdb_datadic.cc | 26 +++++++++++++++---------- storage/rocksdb/rdb_i_s.cc | 4 ++-- storage/rocksdb/rdb_sst_info.cc | 2 +- storage/rocksdb/rdb_sst_info.h | 2 +- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/storage/rocksdb/event_listener.cc b/storage/rocksdb/event_listener.cc index b6aa96b1e20e..3f824eeb61df 100644 --- a/storage/rocksdb/event_listener.cc +++ b/storage/rocksdb/event_listener.cc @@ -35,7 +35,7 @@ static std::vector extract_index_stats( const std::vector &files, const rocksdb::TablePropertiesCollection &props) { std::vector ret; - for (auto fn : files) { + for (const auto &fn : files) { const auto it = props.find(fn); assert(it != props.end()); std::vector stats; diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index e60bd6e46c4f..2acc131353a6 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -3424,8 +3424,6 @@ static void set_tx_on_thd(THD *const thd, Rdb_transaction *trx) { return get_ha_data(thd)->set_trx(trx); } -namespace { - class Rdb_perf_context_guard { Rdb_io_perf m_io_perf; Rdb_io_perf *m_io_perf_ptr; @@ -3461,8 +3459,6 @@ class Rdb_perf_context_guard { } }; -} // anonymous namespace - /* TODO: maybe, call this in external_lock() and store in ha_rocksdb.. */ diff --git a/storage/rocksdb/properties_collector.cc b/storage/rocksdb/properties_collector.cc index 4bbdc03f5200..c9260c0e9c1d 100644 --- a/storage/rocksdb/properties_collector.cc +++ b/storage/rocksdb/properties_collector.cc @@ -257,7 +257,7 @@ rocksdb::UserCollectedProperties Rdb_tbl_prop_coll::GetReadableProperties() s.append(" records...]"); #else bool first = true; - for (auto it : m_stats) { + for (const auto &it : m_stats) { if (first) { first = false; } else { diff --git a/storage/rocksdb/rdb_cf_manager.cc b/storage/rocksdb/rdb_cf_manager.cc index b937208f3c91..4c74a59f153b 100644 --- a/storage/rocksdb/rdb_cf_manager.cc +++ b/storage/rocksdb/rdb_cf_manager.cc @@ -58,7 +58,7 @@ void Rdb_cf_manager::init( } void Rdb_cf_manager::cleanup() { - for (auto it : m_cf_name_map) { + for (const auto &it : m_cf_name_map) { delete it.second; } mysql_mutex_destroy(&m_mutex); @@ -174,7 +174,7 @@ std::vector Rdb_cf_manager::get_cf_names(void) const { std::vector names; RDB_MUTEX_LOCK_CHECK(m_mutex); - for (auto it : m_cf_name_map) { + for (const auto &it : m_cf_name_map) { names.push_back(it.first); } RDB_MUTEX_UNLOCK_CHECK(m_mutex); diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc index a3195f786aeb..3674f871d798 100644 --- a/storage/rocksdb/rdb_datadic.cc +++ b/storage/rocksdb/rdb_datadic.cc @@ -3549,6 +3549,8 @@ int Rdb_key_def::unpack_simple(Rdb_field_packing *const fpi, // See Rdb_charset_space_info::spaces_xfrm const int RDB_SPACE_XFRM_SIZE = 32; +namespace { + // A class holding information about how space character is represented in a // charset. class Rdb_charset_space_info { @@ -3569,6 +3571,8 @@ class Rdb_charset_space_info { size_t space_mb_len; }; +} // namespace + static std::array, MY_ALL_CHARSETS_SIZE> rdb_mem_comparable_space; @@ -4805,7 +4809,7 @@ Rdb_ddl_manager::safe_find(GL_INDEX_ID gl_index_id) { mysql_rwlock_rdlock(&m_rwlock); - auto it = m_index_num_to_keydef.find(gl_index_id); + const auto it = m_index_num_to_keydef.find(gl_index_id); if (it != m_index_num_to_keydef.end()) { const auto table_def = find(it->second.first, false); if (table_def && it->second.second < table_def->m_key_count) { @@ -4815,9 +4819,10 @@ Rdb_ddl_manager::safe_find(GL_INDEX_ID gl_index_id) { } } } else { - auto it = m_index_num_to_uncommitted_keydef.find(gl_index_id); - if (it != m_index_num_to_uncommitted_keydef.end()) { - const auto &kd = it->second; + const auto uncommitted_it = + m_index_num_to_uncommitted_keydef.find(gl_index_id); + if (uncommitted_it != m_index_num_to_uncommitted_keydef.end()) { + const auto &kd = uncommitted_it->second; if (kd->max_storage_fmt_length() != 0) { ret = kd; } @@ -4832,18 +4837,19 @@ Rdb_ddl_manager::safe_find(GL_INDEX_ID gl_index_id) { // this method assumes at least read-only lock on m_rwlock const std::shared_ptr & Rdb_ddl_manager::find(GL_INDEX_ID gl_index_id) { - auto it = m_index_num_to_keydef.find(gl_index_id); + const auto it = m_index_num_to_keydef.find(gl_index_id); if (it != m_index_num_to_keydef.end()) { - auto table_def = find(it->second.first, false); + const auto table_def = find(it->second.first, false); if (table_def) { if (it->second.second < table_def->m_key_count) { return table_def->m_key_descr_arr[it->second.second]; } } } else { - auto it = m_index_num_to_uncommitted_keydef.find(gl_index_id); - if (it != m_index_num_to_uncommitted_keydef.end()) { - return it->second; + const auto uncommitted_it = + m_index_num_to_uncommitted_keydef.find(gl_index_id); + if (uncommitted_it != m_index_num_to_uncommitted_keydef.end()) { + return uncommitted_it->second; } } @@ -4869,7 +4875,7 @@ Rdb_ddl_manager::safe_get_table_name(const GL_INDEX_ID &gl_index_id) { void Rdb_ddl_manager::set_stats( const std::unordered_map &stats) { mysql_rwlock_wrlock(&m_rwlock); - for (auto src : stats) { + for (const auto &src : stats) { const auto &keydef = find(src.second.m_gl_index_id); if (keydef) { keydef->m_stats = src.second; diff --git a/storage/rocksdb/rdb_i_s.cc b/storage/rocksdb/rdb_i_s.cc index ae090016b983..cdc66af03ece 100644 --- a/storage/rocksdb/rdb_i_s.cc +++ b/storage/rocksdb/rdb_i_s.cc @@ -672,7 +672,7 @@ static int rdb_i_s_cfoptions_fill_table( std::vector table_options = split_into_vector(opts.table_factory->GetPrintableTableOptions(), '\n'); - for (auto option : table_options) { + for (std::string option : table_options) { option.erase(std::remove(option.begin(), option.end(), ' '), option.end()); @@ -868,7 +868,7 @@ static int rdb_i_s_compact_stats_fill_table( Rdb_cf_manager &cf_manager = rdb_get_cf_manager(); - for (auto cf_name : cf_manager.get_cf_names()) { + for (const auto &cf_name : cf_manager.get_cf_names()) { rocksdb::ColumnFamilyHandle *cfh = cf_manager.get_cf(cf_name); if (cfh == nullptr) { diff --git a/storage/rocksdb/rdb_sst_info.cc b/storage/rocksdb/rdb_sst_info.cc index a5b0e5488b88..0ecd4015a45a 100644 --- a/storage/rocksdb/rdb_sst_info.cc +++ b/storage/rocksdb/rdb_sst_info.cc @@ -342,7 +342,7 @@ Rdb_sst_info::Rdb_sst_info(rocksdb::DB *const db, const std::string &tablename, Rdb_sst_info::~Rdb_sst_info() { assert(m_sst_file == nullptr); - for (auto sst_file : m_committed_files) { + for (const auto &sst_file : m_committed_files) { // In case something went wrong attempt to delete the temporary file. // If everything went fine that file will have been renamed and this // function call will fail. diff --git a/storage/rocksdb/rdb_sst_info.h b/storage/rocksdb/rdb_sst_info.h index bfd631992fd1..9afe3d52953c 100644 --- a/storage/rocksdb/rdb_sst_info.h +++ b/storage/rocksdb/rdb_sst_info.h @@ -191,7 +191,7 @@ class Rdb_sst_info { void reset() { if (!m_committed) { - for (auto sst_file : m_committed_files) { + for (const auto &sst_file : m_committed_files) { // In case something went wrong attempt to delete the temporary file. // If everything went fine that file will have been renamed and this // function call will fail.