2121#include < cassert>
2222#include < map>
2323#include < memory>
24+ #include < mysqld_error.h>
2425#include < utility>
2526
2627#include " rocksdb/sst_partitioner.h"
2728
2829#include " ./rdb_cf_manager.h"
2930#include " ./rdb_datadic.h"
3031
32+
3133namespace myrocks {
3234/* *
3335 * get string with data written with index bytes
@@ -69,7 +71,7 @@ class Rdb_index_boundary_sst_partitioner : public rocksdb::SstPartitioner {
6971 */
7072 bool should_partition (const std::string &index_key,
7173 const rocksdb::Slice *previous_key,
72- const rocksdb::Slice *current_key) {
74+ const rocksdb::Slice *current_key) const {
7375 // for reverse cf, indexKey is upper limit of index data,
7476 // for normal cf, indexKey is lower limit of index data.
7577 // we want indexKey itself get partitioned with other keys in the index.
@@ -82,9 +84,9 @@ class Rdb_index_boundary_sst_partitioner : public rocksdb::SstPartitioner {
8284 }
8385
8486 public:
85- explicit Rdb_index_boundary_sst_partitioner (
86- const std::set<Index_id> &index_ids ,
87- const rocksdb::Comparator *comparator, const bool is_reverse_cf)
87+ Rdb_index_boundary_sst_partitioner (const std::set<Index_id> &index_ids,
88+ const rocksdb::Comparator *comparator ,
89+ const bool is_reverse_cf)
8890 : m_comparator(comparator), m_is_reverse_cf(is_reverse_cf) {
8991 assert (!index_ids.empty ());
9092 for (auto index_id : index_ids) {
@@ -112,7 +114,7 @@ class Rdb_index_boundary_sst_partitioner : public rocksdb::SstPartitioner {
112114 m_max_index_key = get_index_key (max_index);
113115 }
114116
115- virtual ~Rdb_index_boundary_sst_partitioner () override {}
117+ ~Rdb_index_boundary_sst_partitioner () override {}
116118
117119 const char *Name () const override {
118120 return " Rdb_index_boundary_sst_partitioner" ;
@@ -127,7 +129,7 @@ class Rdb_index_boundary_sst_partitioner : public rocksdb::SstPartitioner {
127129 m_comparator->Compare (*request.current_user_key , m_min_index_key) < 0 ) {
128130 return rocksdb::PartitionerResult::kNotRequired ;
129131 }
130- for (auto &index_key_range : m_index_key_ranges) {
132+ for (const auto &index_key_range : m_index_key_ranges) {
131133 // partition sst file when the request keys cross index boundary
132134 if (should_partition (index_key_range.first , request.prev_user_key ,
133135 request.current_user_key ) ||
@@ -155,25 +157,18 @@ class Rdb_sst_partitioner_factory : public rocksdb::SstPartitionerFactory {
155157 const rocksdb::Comparator *m_comparator;
156158 const int m_num_levels;
157159 const bool m_is_reverse_cf;
158- std::mutex m_index_ids_mutex;
160+ mutable std::mutex m_index_ids_mutex;
159161 std::set<Index_id> m_index_ids;
160162
161163 std::set<Index_id> get_index_ids () const {
162- // this method is marked const so we can call it
163- // in const CreatePartitioner method.
164- // and it is a real const method as it does not change
165- // the object's state. the const_cast here is needed
166- // to get a non-const reference to mutex, which is needed
167- // for lock_guard
168- const std::lock_guard<std::mutex> lock (
169- const_cast <Rdb_sst_partitioner_factory *>(this )->m_index_ids_mutex );
164+ const std::lock_guard<std::mutex> lock (m_index_ids_mutex);
170165 std::set<Index_id> result (m_index_ids);
171166 return result;
172167 };
173168
174169 public:
175- explicit Rdb_sst_partitioner_factory (const rocksdb::Comparator *comparator,
176- int num_levels, int is_reverse_cf)
170+ Rdb_sst_partitioner_factory (const rocksdb::Comparator *comparator,
171+ int num_levels, int is_reverse_cf)
177172 : m_comparator(comparator),
178173 m_num_levels (num_levels),
179174 m_is_reverse_cf(is_reverse_cf){};
@@ -309,7 +304,7 @@ class Rdb_bulk_load_index_registry {
309304 */
310305 bool clear () {
311306 bool success = true ;
312- for (auto entry : m_partitioner_factories) {
307+ for (auto & entry : m_partitioner_factories) {
313308 bool removed = entry.second ->remove_index (entry.first );
314309 if (!removed) {
315310 // unlikely
@@ -325,7 +320,7 @@ class Rdb_bulk_load_index_registry {
325320 * returns true when we have index registered in
326321 * sst partitioner factory
327322 */
328- bool index_registered_in_sst_partitioner () {
323+ bool index_registered_in_sst_partitioner () const {
329324 return !m_partitioner_factories.empty ();
330325 }
331326
@@ -337,7 +332,7 @@ class Rdb_bulk_load_index_registry {
337332 rocksdb::TransactionDB *rdb,
338333 const rocksdb::CompactRangeOptions compact_range_options) {
339334 rocksdb::Status status;
340- for (auto entry : m_cf_indexes) {
335+ for (auto & entry : m_cf_indexes) {
341336 auto cf = entry.first ;
342337 const auto is_reverse_cf =
343338 Rdb_cf_manager::is_cf_name_reverse (cf->GetName ().c_str ());
0 commit comments