diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index da3d824966f0..fe667277589e 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -4405,7 +4405,7 @@ class Rdb_transaction { rocksdb::Slice merge_val; auto &key_merges = ctx->key_merge(); for (auto it = key_merges.begin(); it != key_merges.end(); it++) { - GL_INDEX_ID index_id = it->first; + const auto index_id = it->first; Rdb_index_merge &rdb_merge = it->second; std::string table_name = rdb_merge.get_table_name(); // there was a race here between dropping the table @@ -4909,7 +4909,7 @@ class Rdb_transaction { return false; } - void set_auto_incr(const GL_INDEX_ID &gl_index_id, ulonglong curr_id) { + void set_auto_incr(GL_INDEX_ID gl_index_id, ulonglong curr_id) { assert(!is_ac_nl_ro_rc_transaction()); auto &existing = m_auto_incr_map[gl_index_id]; @@ -4917,14 +4917,10 @@ class Rdb_transaction { } #ifndef NDEBUG - ulonglong get_auto_incr(const GL_INDEX_ID &gl_index_id) { - assert(statement_snapshot_type != snapshot_type::NONE); - - auto iter = m_auto_incr_map.find(gl_index_id); - if (m_auto_incr_map.end() != iter) { - return iter->second; - } - return 0; + [[nodiscard]] ulonglong get_auto_incr(GL_INDEX_ID gl_index_id) const { + assert(statement_snapshot_type != snapshot_type::NONE); + const auto iter = m_auto_incr_map.find(gl_index_id); + return (iter != m_auto_incr_map.cend()) ? iter->second : 0; } #endif @@ -7404,8 +7400,8 @@ class Rdb_snapshot_status : public Rdb_tx_list_walker { "=========================================\n"; } - static Rdb_deadlock_info::Rdb_dl_trx_info get_dl_txn_info( - const rocksdb::DeadlockInfo &txn, const GL_INDEX_ID &gl_index_id) { + [[nodiscard]] static Rdb_deadlock_info::Rdb_dl_trx_info get_dl_txn_info( + const rocksdb::DeadlockInfo &txn, GL_INDEX_ID gl_index_id) { Rdb_deadlock_info::Rdb_dl_trx_info txn_data; txn_data.trx_id = txn.m_txn_id; @@ -7444,9 +7440,10 @@ class Rdb_snapshot_status : public Rdb_tx_list_walker { for (auto it = path_entry.path.begin(); it != path_entry.path.end(); it++) { const auto &txn = *it; - const GL_INDEX_ID gl_index_id = { - txn.m_cf_id, rdb_netbuf_to_uint32(reinterpret_cast( - txn.m_waiting_key.c_str()))}; + const auto gl_index_id = GL_INDEX_ID{ + .cf_id = txn.m_cf_id, + .index_id = rdb_netbuf_to_uint32( + reinterpret_cast(txn.m_waiting_key.c_str()))}; deadlock_info.path.push_back(get_dl_txn_info(txn, gl_index_id)); } assert_IFF(path_entry.limit_exceeded, path_entry.path.empty()); @@ -9756,7 +9753,7 @@ ulonglong ha_rocksdb::load_auto_incr_value_from_index() { #ifndef NDEBUG ulonglong dd_val; if (last_val <= max_val) { - const auto &gl_index_id = m_tbl_def->get_autoincr_gl_index_id(); + const auto gl_index_id = m_tbl_def->get_autoincr_gl_index_id(); if (dict_manager.get_dict_manager_selector_const(gl_index_id.cf_id) ->get_auto_incr_val(gl_index_id, &dd_val) && tx->get_auto_incr(gl_index_id) == 0) { @@ -10065,7 +10062,7 @@ bool rdb_should_hide_ttl_rec(const Rdb_key_def &kd, std::string buf; buf = rdb_hexdump(ttl_rec_val->data(), ttl_rec_val->size(), RDB_MAX_HEXDUMP_LEN); - const GL_INDEX_ID gl_index_id = kd.get_gl_index_id(); + const auto gl_index_id = kd.get_gl_index_id(); // NO_LINT_DEBUG LogPluginErrMsg(ERROR_LEVEL, ER_LOG_PRINTF_MSG, "Decoding ttl from PK value failed, " @@ -10904,7 +10901,7 @@ uint ha_rocksdb::create_inplace_key_defs( */ const Rdb_key_def &okd = *old_key_descr[it->second]; - const GL_INDEX_ID gl_index_id = okd.get_gl_index_id(); + const auto gl_index_id = okd.get_gl_index_id(); struct Rdb_index_info index_info; if (!dict_manager.get_dict_manager_selector_const(gl_index_id.cf_id) ->get_index_info(gl_index_id, &index_info)) { @@ -14792,7 +14789,7 @@ int ha_rocksdb::update_stats(ha_statistics *ha_stats, Rdb_tbl_def *tbl_def, // Unfortunately in this case we don't know if we actually have auto // increment without opening the table, so we'd have to load the value // always even if the table doesn't have auto increment - const GL_INDEX_ID &gl_index_id = tbl_def->get_autoincr_gl_index_id(); + const auto gl_index_id = tbl_def->get_autoincr_gl_index_id(); if (!dict_manager.get_dict_manager_selector_const(gl_index_id.cf_id) ->get_auto_incr_val(gl_index_id, &ha_stats->auto_increment_value)) { @@ -15452,7 +15449,7 @@ static int delete_range(const std::unordered_set &indices) { int ret = 0; size_t default_cf_ts_sz = rocksdb_enable_udt_in_mem ? ROCKSDB_SIZEOF_UDT : 0; rocksdb::WriteBatch batch = rocksdb::WriteBatch(0, 0, 0, default_cf_ts_sz); - for (const auto &d : indices) { + for (const auto d : indices) { auto local_dict_manager = dict_manager.get_dict_manager_selector_non_const(d.cf_id); uint32 cf_flags = 0; @@ -15770,6 +15767,7 @@ int ha_rocksdb::delete_table(Rdb_tbl_def *const tbl) { std::lock_guard dm_lock(*local_dict_manager); if (rocksdb_enable_delete_range_for_drop_index) { std::unordered_set dropped_index_ids; + dropped_index_ids.reserve(tbl->m_key_count); for (uint32 i = 0; i < tbl->m_key_count; i++) { dropped_index_ids.insert(tbl->m_key_descr_arr[i]->get_gl_index_id()); local_dict_manager->delete_index_info( @@ -16190,7 +16188,7 @@ static void init_stats( &to_recalc, std::unordered_map *stats) { for (const auto &it : to_recalc) { - const GL_INDEX_ID index_id = it.first; + const auto index_id = it.first; auto &kd = it.second; (*stats).emplace(index_id, Rdb_index_stats(index_id)); @@ -16232,7 +16230,7 @@ static int calculate_cardinality_table_scan( Rdb_tbl_card_coll cardinality_collector(rocksdb_table_stats_sampling_pct); for (const auto &it_kd : to_recalc) { - const GL_INDEX_ID index_id = it_kd.first; + const auto index_id = it_kd.first; if (!ddl_manager.safe_find(index_id)) { // If index id is not in ddl manager, then it has been dropped. @@ -16339,7 +16337,7 @@ static void merge_stats( assert(stats->size() == card_stats.size()); for (auto &src : *stats) { - auto index_id = src.first; + const auto index_id = src.first; Rdb_index_stats &stat = src.second; auto it = card_stats.find(index_id); assert(it != card_stats.end()); @@ -16423,7 +16421,7 @@ static int read_stats_from_ssts( continue; } - auto it_index = to_recalc.find(it1.m_gl_index_id); + const auto it_index = to_recalc.find(it1.m_gl_index_id); assert(it_index != to_recalc.end()); if (it_index == to_recalc.end()) { continue; @@ -16503,11 +16501,12 @@ static int calculate_stats_for_table( } std::unordered_map> to_recalc; - for (const auto &index : indexes) { + for (const auto index : indexes) { std::shared_ptr keydef = ddl_manager.safe_find(index); if (keydef) { - to_recalc.insert(std::make_pair(keydef->get_gl_index_id(), keydef)); + assert(index == keydef->get_gl_index_id()); + to_recalc.insert(std::make_pair(index, keydef)); } } @@ -17491,6 +17490,7 @@ int ha_rocksdb::inplace_populate_sk( /* Update the data dictionary */ std::unordered_set create_index_ids; + create_index_ids.reserve(indexes.size()); for (const auto &index : indexes) { create_index_ids.insert(index->get_gl_index_id()); } @@ -17801,6 +17801,7 @@ bool ha_rocksdb::commit_inplace_alter_table( local_dict_manager->add_drop_index(ctx->m_dropped_index_ids, batch); } + create_index_ids.reserve(ctx->m_added_indexes.size()); for (const auto &index : ctx->m_added_indexes) { create_index_ids.insert(index->get_gl_index_id()); } @@ -17856,7 +17857,6 @@ bool ha_rocksdb::commit_inplace_alter_table( auto local_dict_manager = dict_manager.get_dict_manager_selector_non_const(table_default_cf_id); auto batch = Rdb_dict_manager::begin(); - std::unordered_set create_index_ids; ulonglong auto_incr_val = ha_alter_info->create_info->auto_increment_value; @@ -17864,9 +17864,12 @@ bool ha_rocksdb::commit_inplace_alter_table( Rdb_inplace_alter_ctx *const ctx = static_cast(*pctx); auto_incr_val = std::max(auto_incr_val, ctx->m_max_auto_incr); - local_dict_manager->put_auto_incr_val( + const auto status = local_dict_manager->put_auto_incr_val( batch, ctx->m_new_tdef->get_autoincr_gl_index_id(), auto_incr_val, true /* overwrite */); + if (unlikely(!status.ok())) { + assert(0); + } ctx->m_new_tdef->m_auto_incr_val = auto_incr_val; } diff --git a/storage/rocksdb/ha_rocksdb.h b/storage/rocksdb/ha_rocksdb.h index 28ce89398ad4..538e9e2c1a57 100644 --- a/storage/rocksdb/ha_rocksdb.h +++ b/storage/rocksdb/ha_rocksdb.h @@ -106,7 +106,7 @@ struct Rdb_table_handler { namespace std { template <> struct hash { - std::size_t operator()(const myrocks::GL_INDEX_ID &gl_index_id) const { + std::size_t operator()(myrocks::GL_INDEX_ID gl_index_id) const noexcept { const uint64_t val = ((uint64_t)gl_index_id.cf_id << 32 | (uint64_t)gl_index_id.index_id); return std::hash()(val); @@ -392,9 +392,6 @@ class ha_rocksdb : public my_core::handler, public blob_buffer { ulonglong load_auto_incr_value_from_index(); void update_auto_incr_val(ulonglong val); void update_auto_incr_val_from_field(); - rocksdb::Status get_datadic_auto_incr(Rdb_transaction *const tx, - const GL_INDEX_ID &gl_index_id, - ulonglong *new_val) const; longlong update_hidden_pk_val(); int load_hidden_pk_value() MY_ATTRIBUTE((__warn_unused_result__)); int read_hidden_pk_id_from_rowkey(longlong *const hidden_pk_id) @@ -1120,7 +1117,7 @@ struct Rdb_inplace_alter_ctx : public my_core::inplace_alter_handler_ctx { m_old_n_keys(old_n_keys), m_new_n_keys(new_n_keys), m_added_indexes(added_indexes), - m_dropped_index_ids(dropped_index_ids), + m_dropped_index_ids(std::move(dropped_index_ids)), m_n_added_keys(n_added_keys), m_n_dropped_keys(n_dropped_keys), m_max_auto_incr(max_auto_incr) {} diff --git a/storage/rocksdb/properties_collector.cc b/storage/rocksdb/properties_collector.cc index 437b9f106afb..6256ba22e69d 100644 --- a/storage/rocksdb/properties_collector.cc +++ b/storage/rocksdb/properties_collector.cc @@ -109,9 +109,10 @@ void Rdb_tbl_prop_coll::AdjustDeletedRows(rocksdb::EntryType type) { } Rdb_index_stats *Rdb_tbl_prop_coll::AccessStats(const rocksdb::Slice &key) { - GL_INDEX_ID gl_index_id = {.cf_id = m_cf_id, - .index_id = rdb_netbuf_to_uint32( - reinterpret_cast(key.data()))}; + const auto gl_index_id = GL_INDEX_ID{ + .cf_id = m_cf_id, + .index_id = + rdb_netbuf_to_uint32(reinterpret_cast(key.data()))}; if (m_last_stats == nullptr || m_last_stats->m_gl_index_id != gl_index_id) { m_keydef = nullptr; @@ -418,7 +419,7 @@ int Rdb_index_stats::unmaterialize(const std::string &s, if (p + needed > p2) { return HA_EXIT_FAILURE; } - rdb_netbuf_read_gl_index(&p, &stats.m_gl_index_id); + stats.m_gl_index_id = rdb_netbuf_read_gl_index(&p); stats.m_data_size = rdb_netbuf_read_uint64(&p); stats.m_rows = rdb_netbuf_read_uint64(&p); stats.m_actual_disk_size = rdb_netbuf_read_uint64(&p); diff --git a/storage/rocksdb/rdb_buff.h b/storage/rocksdb/rdb_buff.h index d84e8daa7453..1662c872d3e3 100644 --- a/storage/rocksdb/rdb_buff.h +++ b/storage/rocksdb/rdb_buff.h @@ -216,13 +216,11 @@ inline uint16 rdb_netbuf_read_uint16(const uchar **netbuf_ptr) { return host_val; } -inline void rdb_netbuf_read_gl_index(const uchar **netbuf_ptr, - GL_INDEX_ID *const gl_index_id) { - assert(gl_index_id != nullptr); +[[nodiscard]] inline GL_INDEX_ID rdb_netbuf_read_gl_index( + const uchar **netbuf_ptr) { assert(netbuf_ptr != nullptr); - - gl_index_id->cf_id = rdb_netbuf_read_uint32(netbuf_ptr); - gl_index_id->index_id = rdb_netbuf_read_uint32(netbuf_ptr); + return {.cf_id = rdb_netbuf_read_uint32(netbuf_ptr), + .index_id = rdb_netbuf_read_uint32(netbuf_ptr)}; } /* diff --git a/storage/rocksdb/rdb_compact_filter.h b/storage/rocksdb/rdb_compact_filter.h index 244f4be4656b..115e90bfb01d 100644 --- a/storage/rocksdb/rdb_compact_filter.h +++ b/storage/rocksdb/rdb_compact_filter.h @@ -83,9 +83,10 @@ class Rdb_compact_filter : public rocksdb::CompactionFilter { bool *value_changed MY_ATTRIBUTE((unused))) const override { assert(key.size() >= sizeof(uint32)); - GL_INDEX_ID gl_index_id; - gl_index_id.cf_id = m_cf_id; - gl_index_id.index_id = rdb_netbuf_to_uint32((const uchar *)key.data()); + const auto gl_index_id = GL_INDEX_ID{ + .cf_id = m_cf_id, + .index_id = + rdb_netbuf_to_uint32(reinterpret_cast(key.data()))}; assert(gl_index_id.index_id >= 1); if (gl_index_id != m_prev_index) { @@ -125,7 +126,7 @@ class Rdb_compact_filter : public rocksdb::CompactionFilter { virtual const char *Name() const override { return "Rdb_compact_filter"; } - void get_ttl_duration_and_offset(const GL_INDEX_ID &gl_index_id, + void get_ttl_duration_and_offset(GL_INDEX_ID gl_index_id, uint64 *ttl_duration, uint32 *ttl_offset) const { assert(ttl_duration != nullptr); diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc index c1958e58bab5..608c132d2682 100644 --- a/storage/rocksdb/rdb_datadic.cc +++ b/storage/rocksdb/rdb_datadic.cc @@ -4444,10 +4444,10 @@ GL_INDEX_ID Rdb_tbl_def::get_autoincr_gl_index_id() { // Every table must have a primary key, even if it's hidden. abort(); - return GL_INDEX_ID(); + return {}; } -void Rdb_ddl_manager::erase_index_num(const GL_INDEX_ID &gl_index_id) { +void Rdb_ddl_manager::erase_index_num(GL_INDEX_ID gl_index_id) { m_index_num_to_keydef.erase(gl_index_id); } @@ -4633,7 +4633,6 @@ bool Rdb_ddl_manager::validate_auto_incr() const { for (it->Seek(auto_incr_entry_slice); it->Valid(); it->Next()) { const rocksdb::Slice key = it->key(); const rocksdb::Slice val = it->value(); - GL_INDEX_ID gl_index_id; if (key.size() >= Rdb_key_def::INDEX_NUMBER_SIZE && memcmp(key.data(), auto_incr_entry, Rdb_key_def::INDEX_NUMBER_SIZE)) { @@ -4652,7 +4651,7 @@ bool Rdb_ddl_manager::validate_auto_incr() const { // referencing ddl entries. auto ptr = reinterpret_cast(key.data()); ptr += Rdb_key_def::INDEX_NUMBER_SIZE; - rdb_netbuf_read_gl_index(&ptr, &gl_index_id); + const auto gl_index_id = rdb_netbuf_read_gl_index(&ptr); if (!dict_user_table->get_index_info(gl_index_id, nullptr)) { // NO_LINT_DEBUG LogPluginErrMsg(WARNING_LEVEL, ER_LOG_PRINTF_MSG, @@ -4755,8 +4754,7 @@ bool Rdb_ddl_manager::populate(uint32_t validate_tables, bool lock) { } ptr_end = ptr + real_val_size; for (uint keyno = 0; ptr < ptr_end; keyno++) { - GL_INDEX_ID gl_index_id; - rdb_netbuf_read_gl_index(&ptr, &gl_index_id); + const auto gl_index_id = rdb_netbuf_read_gl_index(&ptr); uint flags = 0; struct Rdb_index_info index_info; if (!dict_user_table->get_index_info(gl_index_id, &index_info)) { @@ -4938,6 +4936,7 @@ int Rdb_ddl_manager::find_indexes(const std::string &table_name, return HA_EXIT_FAILURE; } + indexes->reserve(tdef->m_key_count); for (uint i = 0; i < tdef->m_key_count; i++) { indexes->push_back(tdef->m_key_descr_arr[i]->get_gl_index_id()); } @@ -5610,9 +5609,9 @@ int Rdb_dict_manager::commit(rocksdb::WriteBatch &batch, bool sync) const { return res; } -void Rdb_dict_manager::dump_index_id(uchar *const netbuf, +void Rdb_dict_manager::dump_index_id(uchar *netbuf, Rdb_key_def::DATA_DICT_TYPE dict_type, - const GL_INDEX_ID &gl_index_id) { + GL_INDEX_ID gl_index_id) { rdb_netbuf_store_uint32(netbuf, dict_type); rdb_netbuf_store_uint32(netbuf + Rdb_key_def::INDEX_NUMBER_SIZE, gl_index_id.cf_id); @@ -5622,7 +5621,7 @@ void Rdb_dict_manager::dump_index_id(uchar *const netbuf, void Rdb_dict_manager::delete_with_prefix( rocksdb::WriteBatch &batch, Rdb_key_def::DATA_DICT_TYPE dict_type, - const GL_INDEX_ID &gl_index_id) const { + GL_INDEX_ID gl_index_id) const { Rdb_buf_writer key_writer; dump_index_id(&key_writer, dict_type, gl_index_id); @@ -5673,15 +5672,14 @@ void Rdb_dict_manager::delete_cf_flags(rocksdb::WriteBatch &batch, } void Rdb_dict_manager::delete_index_info(rocksdb::WriteBatch &batch, - const GL_INDEX_ID &gl_index_id) const { + GL_INDEX_ID gl_index_id) const { delete_with_prefix(batch, Rdb_key_def::INDEX_INFO, gl_index_id); delete_with_prefix(batch, Rdb_key_def::INDEX_STATISTICS, gl_index_id); delete_with_prefix(batch, Rdb_key_def::AUTO_INC, gl_index_id); } -bool Rdb_dict_manager::get_index_info( - const GL_INDEX_ID &gl_index_id, - struct Rdb_index_info *const index_info) const { +bool Rdb_dict_manager::get_index_info(GL_INDEX_ID gl_index_id, + Rdb_index_info *index_info) const { if (index_info) { index_info->m_gl_index_id = gl_index_id; } @@ -5893,11 +5891,10 @@ void Rdb_dict_manager::get_ongoing_index_operation( // We don't check version right now since currently we always store only // Rdb_key_def::DDL_DROP_INDEX_ONGOING_VERSION = 1 as a value. // If increasing version number, we need to add version check logic here. - GL_INDEX_ID gl_index_id; - gl_index_id.cf_id = - rdb_netbuf_to_uint32(ptr + Rdb_key_def::INDEX_NUMBER_SIZE); - gl_index_id.index_id = - rdb_netbuf_to_uint32(ptr + 2 * Rdb_key_def::INDEX_NUMBER_SIZE); + const auto gl_index_id = GL_INDEX_ID{ + .cf_id = rdb_netbuf_to_uint32(ptr + Rdb_key_def::INDEX_NUMBER_SIZE), + .index_id = + rdb_netbuf_to_uint32(ptr + 2 * Rdb_key_def::INDEX_NUMBER_SIZE)}; gl_index_ids->insert(gl_index_id); } delete it; @@ -5960,7 +5957,7 @@ int Rdb_dict_manager::remove_orphaned_dropped_cfs( or not. */ bool Rdb_dict_manager::is_index_operation_ongoing( - const GL_INDEX_ID &gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const { + GL_INDEX_ID gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const { assert(dd_type == Rdb_key_def::DDL_DROP_INDEX_ONGOING || dd_type == Rdb_key_def::DDL_CREATE_INDEX_ONGOING); @@ -5981,7 +5978,7 @@ bool Rdb_dict_manager::is_index_operation_ongoing( by drop_index_thread, or to track online index creation. */ void Rdb_dict_manager::start_ongoing_index_operation( - rocksdb::WriteBatch &batch, const GL_INDEX_ID &gl_index_id, + rocksdb::WriteBatch &batch, GL_INDEX_ID gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const { assert(dd_type == Rdb_key_def::DDL_DROP_INDEX_ONGOING || dd_type == Rdb_key_def::DDL_CREATE_INDEX_ONGOING); @@ -6006,7 +6003,7 @@ void Rdb_dict_manager::start_ongoing_index_operation( completed dropping entire key/values of the index_id */ void Rdb_dict_manager::end_ongoing_index_operation( - rocksdb::WriteBatch &batch, const GL_INDEX_ID &gl_index_id, + rocksdb::WriteBatch &batch, GL_INDEX_ID gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const { assert(dd_type == Rdb_key_def::DDL_DROP_INDEX_ONGOING || dd_type == Rdb_key_def::DDL_CREATE_INDEX_ONGOING); @@ -6033,6 +6030,7 @@ void Rdb_dict_manager::add_drop_table( std::shared_ptr *const key_descr, uint32 n_keys, rocksdb::WriteBatch &batch) const { std::unordered_set dropped_index_ids; + dropped_index_ids.reserve(n_keys); for (uint32 i = 0; i < n_keys; i++) { dropped_index_ids.insert(key_descr[i]->get_gl_index_id()); } @@ -6048,7 +6046,7 @@ void Rdb_dict_manager::add_drop_table( void Rdb_dict_manager::add_drop_index( const std::unordered_set &gl_index_ids, rocksdb::WriteBatch &batch) const { - for (const auto &gl_index_id : gl_index_ids) { + for (const auto gl_index_id : gl_index_ids) { log_start_drop_index(gl_index_id, "Begin"); start_drop_index(batch, gl_index_id); } @@ -6086,7 +6084,7 @@ void Rdb_dict_manager::finish_indexes_operation( std::unordered_set incomplete_create_indexes; get_ongoing_create_indexes(&incomplete_create_indexes); - for (const auto &gl_index_id : gl_index_ids) { + for (const auto gl_index_id : gl_index_ids) { if (is_index_operation_ongoing(gl_index_id, dd_type)) { end_ongoing_index_operation(batch, gl_index_id, dd_type); @@ -6121,7 +6119,7 @@ void Rdb_dict_manager::resume_drop_indexes() const { uint max_index_id_in_dict = 0; get_max_index_id(&max_index_id_in_dict); - for (const auto &gl_index_id : gl_index_ids) { + for (const auto gl_index_id : gl_index_ids) { log_start_drop_index(gl_index_id, "Resume"); if (max_index_id_in_dict < gl_index_id.index_id) { rdb_fatal_error( @@ -6145,7 +6143,7 @@ void Rdb_dict_manager::rollback_ongoing_index_creation( const std::unordered_set &gl_index_ids) const { auto batch = Rdb_dict_manager::begin(); - for (const auto &gl_index_id : gl_index_ids) { + for (const auto gl_index_id : gl_index_ids) { // NO_LINT_DEBUG LogPluginErrMsg(INFORMATION_LEVEL, ER_LOG_PRINTF_MSG, "RocksDB: Removing incomplete create index (%u,%u)", @@ -6313,8 +6311,8 @@ Rdb_index_stats Rdb_dict_manager::get_stats(GL_INDEX_ID gl_index_id) const { } rocksdb::Status Rdb_dict_manager::put_auto_incr_val( - rocksdb::WriteBatchBase &batch, const GL_INDEX_ID &gl_index_id, - ulonglong val, bool overwrite) const { + rocksdb::WriteBatchBase &batch, GL_INDEX_ID gl_index_id, ulonglong val, + bool overwrite) const { Rdb_buf_writer key_writer; dump_index_id(&key_writer, Rdb_key_def::AUTO_INC, gl_index_id); @@ -6333,7 +6331,7 @@ rocksdb::Status Rdb_dict_manager::put_auto_incr_val( value_writer.to_slice()); } -bool Rdb_dict_manager::get_auto_incr_val(const GL_INDEX_ID &gl_index_id, +bool Rdb_dict_manager::get_auto_incr_val(GL_INDEX_ID gl_index_id, ulonglong *new_val) const { Rdb_buf_writer key_writer; dump_index_id(&key_writer, Rdb_key_def::AUTO_INC, gl_index_id); diff --git a/storage/rocksdb/rdb_datadic.h b/storage/rocksdb/rdb_datadic.h index a67ff500d0a4..16651ec3fa63 100644 --- a/storage/rocksdb/rdb_datadic.h +++ b/storage/rocksdb/rdb_datadic.h @@ -384,9 +384,8 @@ class Rdb_key_def { return m_index_number; } - GL_INDEX_ID get_gl_index_id() const { - const GL_INDEX_ID gl_index_id = {m_cf_handle->GetID(), get_index_number()}; - return gl_index_id; + [[nodiscard]] GL_INDEX_ID get_gl_index_id() const { + return {.cf_id = m_cf_handle->GetID(), .index_id = get_index_number()}; } int read_memcmp_key_part(Rdb_string_reader *reader, @@ -1505,7 +1504,7 @@ class Rdb_ddl_manager : public Ensure_initialized { /* Walk the data dictionary */ int scan_for_tables(Rdb_tables_scanner *tables_scanner) const; - void erase_index_num(const GL_INDEX_ID &gl_index_id); + void erase_index_num(GL_INDEX_ID gl_index_id); void add_uncommitted_keydefs( const std::unordered_set> &indexes); void remove_uncommitted_keydefs( @@ -1659,13 +1658,13 @@ class Rdb_dict_manager : public Ensure_initialized { uchar m_key_buf_server_version[Rdb_key_def::INDEX_NUMBER_SIZE] = {0}; rocksdb::Slice m_key_slice_server_version; - static void dump_index_id(uchar *const netbuf, + static void dump_index_id(uchar *netbuf, Rdb_key_def::DATA_DICT_TYPE dict_type, - const GL_INDEX_ID &gl_index_id); + GL_INDEX_ID gl_index_id); template static void dump_index_id(Rdb_buf_writer *buf_writer, Rdb_key_def::DATA_DICT_TYPE dict_type, - const GL_INDEX_ID &gl_index_id) { + GL_INDEX_ID gl_index_id) { buf_writer->write_uint32(dict_type); buf_writer->write_uint32(gl_index_id.cf_id); buf_writer->write_uint32(gl_index_id.index_id); @@ -1673,7 +1672,7 @@ class Rdb_dict_manager : public Ensure_initialized { void delete_with_prefix(rocksdb::WriteBatch &batch, Rdb_key_def::DATA_DICT_TYPE dict_type, - const GL_INDEX_ID &gl_index_id) const; + GL_INDEX_ID gl_index_id) const; /* Functions for fast DROP TABLE/INDEX */ void resume_drop_indexes() const; void log_start_drop_table(const std::shared_ptr *const key_descr, @@ -1724,9 +1723,9 @@ class Rdb_dict_manager : public Ensure_initialized { rocksdb::WriteBatch &batch, struct Rdb_index_info *const index_info) const; void delete_index_info(rocksdb::WriteBatch &batch, - const GL_INDEX_ID &index_id) const; - bool get_index_info(const GL_INDEX_ID &gl_index_id, - struct Rdb_index_info *const index_info) const; + GL_INDEX_ID index_id) const; + [[nodiscard]] bool get_index_info(GL_INDEX_ID gl_index_id, + Rdb_index_info *index_info) const; /* CF id => CF flags */ void add_cf_flags(rocksdb::WriteBatch &batch, uint cf_id, @@ -1745,13 +1744,13 @@ class Rdb_dict_manager : public Ensure_initialized { void get_ongoing_index_operation( std::unordered_set *gl_index_ids, Rdb_key_def::DATA_DICT_TYPE dd_type) const; - bool is_index_operation_ongoing(const GL_INDEX_ID &gl_index_id, - Rdb_key_def::DATA_DICT_TYPE dd_type) const; + [[nodiscard]] bool is_index_operation_ongoing( + GL_INDEX_ID gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const; void start_ongoing_index_operation(rocksdb::WriteBatch &batch, - const GL_INDEX_ID &gl_index_id, + GL_INDEX_ID gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const; void end_ongoing_index_operation(rocksdb::WriteBatch &batch, - const GL_INDEX_ID &gl_index_id, + GL_INDEX_ID gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const; bool is_drop_index_empty() const; void add_drop_table(std::shared_ptr *const key_descr, @@ -1777,12 +1776,12 @@ class Rdb_dict_manager : public Ensure_initialized { Rdb_key_def::DDL_CREATE_INDEX_ONGOING); } inline void start_drop_index(rocksdb::WriteBatch &wb, - const GL_INDEX_ID &gl_index_id) const { + GL_INDEX_ID gl_index_id) const { start_ongoing_index_operation(wb, gl_index_id, Rdb_key_def::DDL_DROP_INDEX_ONGOING); } inline void start_create_index(rocksdb::WriteBatch &wb, - const GL_INDEX_ID &gl_index_id) const { + GL_INDEX_ID gl_index_id) const { start_ongoing_index_operation(wb, gl_index_id, Rdb_key_def::DDL_CREATE_INDEX_ONGOING); } @@ -1791,11 +1790,14 @@ class Rdb_dict_manager : public Ensure_initialized { finish_indexes_operation(gl_index_ids, Rdb_key_def::DDL_DROP_INDEX_ONGOING); } - inline bool is_drop_index_ongoing(const GL_INDEX_ID &gl_index_id) const { + [[nodiscard]] inline bool is_drop_index_ongoing( + GL_INDEX_ID gl_index_id) const { return is_index_operation_ongoing(gl_index_id, Rdb_key_def::DDL_DROP_INDEX_ONGOING); } - inline bool is_create_index_ongoing(const GL_INDEX_ID &gl_index_id) const { + + [[nodiscard]] inline bool is_create_index_ongoing( + GL_INDEX_ID gl_index_id) const { return is_index_operation_ongoing(gl_index_id, Rdb_key_def::DDL_CREATE_INDEX_ONGOING); } @@ -1823,12 +1825,12 @@ class Rdb_dict_manager : public Ensure_initialized { const std::vector &stats) const; Rdb_index_stats get_stats(GL_INDEX_ID gl_index_id) const; - rocksdb::Status put_auto_incr_val(rocksdb::WriteBatchBase &batch, - const GL_INDEX_ID &gl_index_id, - ulonglong val, - bool overwrite = false) const; - bool get_auto_incr_val(const GL_INDEX_ID &gl_index_id, - ulonglong *new_val) const; + [[nodiscard]] rocksdb::Status put_auto_incr_val( + rocksdb::WriteBatchBase &batch, GL_INDEX_ID gl_index_id, ulonglong val, + bool overwrite = false) const; + + [[nodiscard]] bool get_auto_incr_val(GL_INDEX_ID gl_index_id, + ulonglong *new_val) const; private: /* dropped cf flags */ @@ -1845,11 +1847,11 @@ class Rdb_dict_manager : public Ensure_initialized { struct Rdb_index_info { GL_INDEX_ID m_gl_index_id; + uint64 m_ttl_duration = 0; + uint32 m_index_flags = 0; uint16_t m_index_dict_version = 0; - uchar m_index_type = 0; uint16_t m_kv_version = 0; - uint32 m_index_flags = 0; - uint64 m_ttl_duration = 0; + uchar m_index_type = 0; }; /* diff --git a/storage/rocksdb/rdb_global.h b/storage/rocksdb/rdb_global.h index e26170713d76..083755d0f8ad 100644 --- a/storage/rocksdb/rdb_global.h +++ b/storage/rocksdb/rdb_global.h @@ -370,32 +370,35 @@ const char *const rocksdb_hton_name = "ROCKSDB"; using Index_id = uint32_t; constexpr size_t INDEX_NUMBER_SIZE = 4; -typedef struct _gl_index_id_s { +struct [[nodiscard]] GL_INDEX_ID { uint32_t cf_id; Index_id index_id; - bool operator==(const struct _gl_index_id_s &other) const { + + [[nodiscard]] bool operator==(GL_INDEX_ID other) const noexcept { return cf_id == other.cf_id && index_id == other.index_id; } - bool operator!=(const struct _gl_index_id_s &other) const { + [[nodiscard]] bool operator!=(GL_INDEX_ID other) const noexcept { return cf_id != other.cf_id || index_id != other.index_id; } - bool operator<(const struct _gl_index_id_s &other) const { + [[nodiscard]] bool operator<(GL_INDEX_ID other) const noexcept { return cf_id < other.cf_id || (cf_id == other.cf_id && index_id < other.index_id); } - bool operator<=(const struct _gl_index_id_s &other) const { + [[nodiscard]] bool operator<=(GL_INDEX_ID other) const noexcept { return cf_id < other.cf_id || (cf_id == other.cf_id && index_id <= other.index_id); } - bool operator>(const struct _gl_index_id_s &other) const { + [[nodiscard]] bool operator>(GL_INDEX_ID other) const noexcept { return cf_id > other.cf_id || (cf_id == other.cf_id && index_id > other.index_id); } - bool operator>=(const struct _gl_index_id_s &other) const { + [[nodiscard]] bool operator>=(GL_INDEX_ID other) const noexcept { return cf_id > other.cf_id || (cf_id == other.cf_id && index_id >= other.index_id); } -} GL_INDEX_ID; +}; +// Fits into a single word. Pass around by value. +static_assert(sizeof(GL_INDEX_ID) == 8); enum operation_type : int { ROWS_DELETED = 0, diff --git a/storage/rocksdb/rdb_i_s.cc b/storage/rocksdb/rdb_i_s.cc index acb947310619..9ec81aca8d6e 100644 --- a/storage/rocksdb/rdb_i_s.cc +++ b/storage/rocksdb/rdb_i_s.cc @@ -1485,7 +1485,7 @@ int Rdb_ddl_scanner::add_table(Rdb_tbl_def *tdef) { field[RDB_DDL_FIELD::INDEX_NAME]->store(kd.m_name.c_str(), kd.m_name.size(), system_charset_info); - GL_INDEX_ID gl_index_id = kd.get_gl_index_id(); + const auto gl_index_id = kd.get_gl_index_id(); field[RDB_DDL_FIELD::COLUMN_FAMILY]->store(gl_index_id.cf_id, true); field[RDB_DDL_FIELD::INDEX_NUMBER]->store(gl_index_id.index_id, true); field[RDB_DDL_FIELD::INDEX_TYPE]->store(kd.m_index_type, true); @@ -1728,7 +1728,7 @@ int Rdb_vector_index_scanner::add_table(Rdb_tbl_def *tdef) { field[RDB_VECTOR_INDEX_FIELD::INDEX_NAME]->store( kd.m_name.c_str(), kd.m_name.size(), system_charset_info); - GL_INDEX_ID gl_index_id = kd.get_gl_index_id(); + const auto gl_index_id = kd.get_gl_index_id(); field[RDB_VECTOR_INDEX_FIELD::INDEX_NUMBER]->store(gl_index_id.index_id, true);