From b1fb095b4dd2ad44d1612c8413acc4d6e8c5cf43 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 22 May 2019 22:50:45 -0700 Subject: [PATCH] Fix AutoInitCopy #2 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: 0b1707313dc --- storage/rocksdb/event_listener.cc | 2 +- storage/rocksdb/ha_rocksdb.cc | 16 ++++++--------- storage/rocksdb/properties_collector.cc | 2 +- storage/rocksdb/rdb_cf_manager.cc | 8 ++++++-- 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, 34 insertions(+), 28 deletions(-) diff --git a/storage/rocksdb/event_listener.cc b/storage/rocksdb/event_listener.cc index 56be8719de87..59cb1b40c9dd 100644 --- a/storage/rocksdb/event_listener.cc +++ b/storage/rocksdb/event_listener.cc @@ -36,7 +36,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); DBUG_ASSERT(it != props.end()); std::vector stats; diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 95ea7e49731a..164c3dcd1bcf 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -3518,8 +3518,6 @@ static Rdb_transaction *&get_tx_from_thd(THD *const thd) { my_core::thd_ha_data(thd, rocksdb_hton)); } -namespace { - class Rdb_perf_context_guard { Rdb_io_perf m_io_perf; Rdb_io_perf *m_io_perf_ptr; @@ -3555,8 +3553,6 @@ class Rdb_perf_context_guard { } }; -} // anonymous namespace - /* TODO: maybe, call this in external_lock() and store in ha_rocksdb.. */ @@ -4665,12 +4661,12 @@ static bool rocksdb_rollback_to_savepoint_can_release_mdl( */ static void rocksdb_update_table_stats( /* per-table stats callback */ - void (*cb)(const char *db, const char *tbl, bool is_partition, - my_io_perf_t *r, my_io_perf_t *w, my_io_perf_t *r_blob, - my_io_perf_t *r_primary, my_io_perf_t *r_secondary, - page_stats_t *page_stats, comp_stats_t *comp_stats, - int n_lock_wait, int n_lock_wait_timeout, int n_lock_deadlock, - const char *engine)) { + void (*cb)(const char *_db, const char *_tbl, bool _is_partition, + my_io_perf_t *_r, my_io_perf_t *w, my_io_perf_t *_r_blob, + my_io_perf_t *_r_primary, my_io_perf_t *_r_secondary, + page_stats_t *_page_stats, comp_stats_t *_comp_stats, + int _n_lock_wait, int _n_lock_wait_timeout, int _n_lock_deadlock, + const char *_engine)) { my_io_perf_t io_perf_read; my_io_perf_t io_perf_write; my_io_perf_t io_perf; diff --git a/storage/rocksdb/properties_collector.cc b/storage/rocksdb/properties_collector.cc index 823b38de5bbe..08a07e547811 100644 --- a/storage/rocksdb/properties_collector.cc +++ b/storage/rocksdb/properties_collector.cc @@ -260,7 +260,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 ad00bb40b2f7..043647f5804c 100644 --- a/storage/rocksdb/rdb_cf_manager.cc +++ b/storage/rocksdb/rdb_cf_manager.cc @@ -57,7 +57,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); @@ -166,7 +166,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); @@ -190,6 +190,8 @@ std::vector Rdb_cf_manager::get_all_cf( return list; } +namespace { + struct Rdb_cf_scanner : public Rdb_tables_scanner { uint32_t m_cf_id; int m_is_cf_used; @@ -212,6 +214,8 @@ struct Rdb_cf_scanner : public Rdb_tables_scanner { } }; +} // namespace + int Rdb_cf_manager::drop_cf(const std::string &cf_name) { auto ddl_manager = rdb_get_ddl_manager(); uint32_t cf_id = 0; diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc index 8e151c770114..99ba9e12cd70 100644 --- a/storage/rocksdb/rdb_datadic.cc +++ b/storage/rocksdb/rdb_datadic.cc @@ -2969,6 +2969,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 { @@ -2989,6 +2991,8 @@ class Rdb_charset_space_info { size_t space_mb_len; }; +} // namespace + static std::array, MY_ALL_CHARSETS_SIZE> rdb_mem_comparable_space; @@ -4162,7 +4166,7 @@ std::shared_ptr Rdb_ddl_manager::safe_find( 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) { @@ -4172,9 +4176,10 @@ std::shared_ptr Rdb_ddl_manager::safe_find( } } } 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; } @@ -4189,18 +4194,19 @@ std::shared_ptr Rdb_ddl_manager::safe_find( // 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; } } @@ -4226,7 +4232,7 @@ const std::string Rdb_ddl_manager::safe_get_table_name( 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 a6f7475657d3..453f30c259f2 100644 --- a/storage/rocksdb/rdb_i_s.cc +++ b/storage/rocksdb/rdb_i_s.cc @@ -632,7 +632,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()); @@ -839,7 +839,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 64ba8d963bc1..03b68a66dea8 100644 --- a/storage/rocksdb/rdb_sst_info.cc +++ b/storage/rocksdb/rdb_sst_info.cc @@ -346,7 +346,7 @@ Rdb_sst_info::Rdb_sst_info(rocksdb::DB *const db, const std::string &tablename, Rdb_sst_info::~Rdb_sst_info() { DBUG_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 f6b13790c023..91772c6a9636 100644 --- a/storage/rocksdb/rdb_sst_info.h +++ b/storage/rocksdb/rdb_sst_info.h @@ -188,7 +188,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.