From 46b1121d271b29382c548f3c8ae72056201475a9 Mon Sep 17 00:00:00 2001 From: leipeng Date: Mon, 15 Aug 2022 22:09:09 +0800 Subject: [PATCH 1/2] properties_collector: (un)materialize: add missing m_name use highest bit of m_rows for m_name existing flag, this is safe, because m_rows is 64 bits, m_rows will never reach 64 bits limit. --- storage/rocksdb/properties_collector.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/storage/rocksdb/properties_collector.cc b/storage/rocksdb/properties_collector.cc index bf51c73e95e3..f2159f72d212 100644 --- a/storage/rocksdb/properties_collector.cc +++ b/storage/rocksdb/properties_collector.cc @@ -370,7 +370,7 @@ std::string Rdb_index_stats::materialize( rdb_netstr_append_uint32(&ret, i.m_gl_index_id.index_id); assert(sizeof i.m_data_size <= 8); rdb_netstr_append_uint64(&ret, i.m_data_size); - rdb_netstr_append_uint64(&ret, i.m_rows); + rdb_netstr_append_uint64(&ret, i.m_rows | uint64_t(1) << 63); rdb_netstr_append_uint64(&ret, i.m_actual_disk_size); rdb_netstr_append_uint64(&ret, i.m_distinct_keys_per_prefix.size()); rdb_netstr_append_uint64(&ret, i.m_entry_deletes); @@ -380,6 +380,8 @@ std::string Rdb_index_stats::materialize( for (const auto &num_keys : i.m_distinct_keys_per_prefix) { rdb_netstr_append_uint64(&ret, num_keys); } + rdb_netstr_append_uint16(&ret, i.m_name.size()); + ret.append(i.m_name.data(), i.m_name.size()); } return std::string((char *)ret.ptr(), ret.length()); @@ -448,6 +450,12 @@ int Rdb_index_stats::unmaterialize(const std::string &s, for (std::size_t i = 0; i < stats.m_distinct_keys_per_prefix.size(); i++) { stats.m_distinct_keys_per_prefix[i] = rdb_netbuf_read_uint64(&p); } + if (stats.m_rows & uint64_t(1) << 63) { // flag m_name is materialized + stats.m_rows &= ~(uint64_t(1) << 63); + size_t namelen = rdb_netbuf_read_uint16(&p); + stats.m_name.assign((const char*)p, namelen); + p += namelen; + } ret->push_back(stats); } return HA_EXIT_SUCCESS; From 83413b847a5846bfa2df22393e5953a5a737ba55 Mon Sep 17 00:00:00 2001 From: leipeng Date: Tue, 16 Aug 2022 10:47:10 +0800 Subject: [PATCH 2/2] properties_collector: (un)materialize: add missing m_name: by INDEX_STATS_VERSION_WITH_NAME --- storage/rocksdb/properties_collector.cc | 9 ++++----- storage/rocksdb/properties_collector.h | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/storage/rocksdb/properties_collector.cc b/storage/rocksdb/properties_collector.cc index f2159f72d212..9b17a1cc8ec5 100644 --- a/storage/rocksdb/properties_collector.cc +++ b/storage/rocksdb/properties_collector.cc @@ -364,13 +364,13 @@ void Rdb_tbl_prop_coll::read_stats_from_tbl_props( std::string Rdb_index_stats::materialize( const std::vector &stats) { String ret; - rdb_netstr_append_uint16(&ret, INDEX_STATS_VERSION_ENTRY_TYPES); + rdb_netstr_append_uint16(&ret, INDEX_STATS_VERSION_WITH_NAME); for (const auto &i : stats) { rdb_netstr_append_uint32(&ret, i.m_gl_index_id.cf_id); rdb_netstr_append_uint32(&ret, i.m_gl_index_id.index_id); assert(sizeof i.m_data_size <= 8); rdb_netstr_append_uint64(&ret, i.m_data_size); - rdb_netstr_append_uint64(&ret, i.m_rows | uint64_t(1) << 63); + rdb_netstr_append_uint64(&ret, i.m_rows); rdb_netstr_append_uint64(&ret, i.m_actual_disk_size); rdb_netstr_append_uint64(&ret, i.m_distinct_keys_per_prefix.size()); rdb_netstr_append_uint64(&ret, i.m_entry_deletes); @@ -408,7 +408,7 @@ int Rdb_index_stats::unmaterialize(const std::string &s, Rdb_index_stats stats; // Make sure version is within supported range. if (version < INDEX_STATS_VERSION_INITIAL || - version > INDEX_STATS_VERSION_ENTRY_TYPES) { + version > INDEX_STATS_VERSION_WITH_NAME) { // NO_LINT_DEBUG sql_print_error( "Index stats version %d was outside of supported range. " @@ -450,8 +450,7 @@ int Rdb_index_stats::unmaterialize(const std::string &s, for (std::size_t i = 0; i < stats.m_distinct_keys_per_prefix.size(); i++) { stats.m_distinct_keys_per_prefix[i] = rdb_netbuf_read_uint64(&p); } - if (stats.m_rows & uint64_t(1) << 63) { // flag m_name is materialized - stats.m_rows &= ~(uint64_t(1) << 63); + if (version >= INDEX_STATS_VERSION_WITH_NAME) { size_t namelen = rdb_netbuf_read_uint16(&p); stats.m_name.assign((const char*)p, namelen); p += namelen; diff --git a/storage/rocksdb/properties_collector.h b/storage/rocksdb/properties_collector.h index 7eb901caec57..74ed4ca4f821 100644 --- a/storage/rocksdb/properties_collector.h +++ b/storage/rocksdb/properties_collector.h @@ -49,6 +49,7 @@ struct Rdb_index_stats { enum { INDEX_STATS_VERSION_INITIAL = 1, INDEX_STATS_VERSION_ENTRY_TYPES = 2, + INDEX_STATS_VERSION_WITH_NAME = 3, }; GL_INDEX_ID m_gl_index_id; int64_t m_data_size, m_rows, m_actual_disk_size;