21
21
/* The C++ file's header */
22
22
#include " ./ha_rocksdb.h"
23
23
24
+ /* C++ standard header files */
25
+ #include < map>
26
+
24
27
/* MySQL includes */
25
28
#include " ./my_bit.h"
26
29
#include " ./my_stacktrace.h"
@@ -979,7 +982,7 @@ static bool stop_drop_index_thread;
979
982
class Rdb_CompactionFilter : public rocksdb ::CompactionFilter
980
983
{
981
984
public:
982
- Rdb_CompactionFilter () {}
985
+ explicit Rdb_CompactionFilter (uint32_t _cf_id) : cf_id(_cf_id ) {}
983
986
~Rdb_CompactionFilter ()
984
987
{
985
988
print_compaction_status ();
@@ -996,18 +999,21 @@ class Rdb_CompactionFilter : public rocksdb::CompactionFilter
996
999
bool * value_changed) const override {
997
1000
998
1001
DBUG_ASSERT (key.size () >= sizeof (uint32));
999
- uint32 index= read_big_uint4 ((const uchar*)key.data ());
1000
- DBUG_ASSERT (index >= 1 );
1001
1002
1002
- if (index != prev_index) // processing new index id
1003
+ GL_INDEX_ID gl_index_id;
1004
+ gl_index_id.cf_id = cf_id;
1005
+ gl_index_id.index_id = read_big_uint4 ((const uchar*)key.data ());
1006
+ DBUG_ASSERT (gl_index_id.index_id >= 1 );
1007
+
1008
+ if (gl_index_id != prev_index) // processing new index id
1003
1009
{
1004
1010
if (num_deleted > 0 )
1005
1011
{
1006
1012
print_compaction_status ();
1007
1013
num_deleted= 0 ;
1008
1014
}
1009
- should_delete= dict_manager.is_drop_index_ongoing (index );
1010
- prev_index= index ;
1015
+ should_delete= dict_manager.is_drop_index_ongoing (gl_index_id );
1016
+ prev_index= gl_index_id ;
1011
1017
}
1012
1018
1013
1019
if (should_delete)
@@ -1024,11 +1030,14 @@ class Rdb_CompactionFilter : public rocksdb::CompactionFilter
1024
1030
{
1025
1031
if (num_deleted > 0 )
1026
1032
sql_print_information (" RocksDB: Compacting away elements from dropped "
1027
- " index %u: %llu" , prev_index, num_deleted);
1033
+ " index (%u,%u): %llu" , prev_index.cf_id ,
1034
+ prev_index.index_id , num_deleted);
1028
1035
}
1029
1036
1037
+ // Column family for this compaction filter
1038
+ const uint32_t cf_id;
1030
1039
// Index id of the previous record
1031
- mutable uint32 prev_index= 0 ;
1040
+ mutable GL_INDEX_ID prev_index= { 0 , 0 } ;
1032
1041
// Number of rows deleted for the same index id
1033
1042
mutable uint64 num_deleted= 0 ;
1034
1043
// Current index id should be deleted or not (should be deleted if true)
@@ -1049,7 +1058,7 @@ class Rdb_CompactionFilterFactory : public rocksdb::CompactionFilterFactory
1049
1058
std::unique_ptr<rocksdb::CompactionFilter> CreateCompactionFilter (
1050
1059
const rocksdb::CompactionFilter::Context& context) {
1051
1060
return std::unique_ptr<rocksdb::CompactionFilter>(
1052
- new Rdb_CompactionFilter);
1061
+ new Rdb_CompactionFilter (context. column_family_id ) );
1053
1062
}
1054
1063
};
1055
1064
@@ -3041,18 +3050,16 @@ int ha_rocksdb::create_key_defs(TABLE *table_arg, const char *db_table,
3041
3050
for (i= 0 ; i < table_arg->s ->keys ; i++)
3042
3051
{
3043
3052
uint index_id= ddl_manager.get_and_update_next_number (&dict_manager);
3044
- uint16_t index_dict_version;
3053
+ uint16_t index_dict_version= RDBSE_KEYDEF::INDEX_INFO_VERSION_GLOBAL_ID ;
3045
3054
uchar index_type;
3046
3055
uint16_t kv_version;
3047
3056
if (i == table_arg->s ->primary_key )
3048
3057
{
3049
- index_dict_version= RDBSE_KEYDEF::INDEX_CF_MAPPING_VERSION_KV_FORMAT;
3050
3058
index_type= RDBSE_KEYDEF::INDEX_TYPE_PRIMARY;
3051
3059
kv_version= RDBSE_KEYDEF::PRIMARY_FORMAT_VERSION_INITIAL;
3052
3060
}
3053
3061
else
3054
3062
{
3055
- index_dict_version= RDBSE_KEYDEF::INDEX_CF_MAPPING_VERSION_KV_FORMAT;
3056
3063
index_type= RDBSE_KEYDEF::INDEX_TYPE_SECONDARY;
3057
3064
kv_version= RDBSE_KEYDEF::SECONDARY_FORMAT_VERSION_INITIAL;
3058
3065
}
@@ -5549,43 +5556,31 @@ void* drop_index_thread(void*)
5549
5556
assert (ret == 0 || ret == ETIMEDOUT);
5550
5557
mysql_mutex_unlock (&drop_index_interrupt_mutex);
5551
5558
5552
- std::vector<uint32 > indices;
5553
- dict_manager.get_drop_indexes_ongoing (indices);
5559
+ std::vector<GL_INDEX_ID > indices;
5560
+ dict_manager.get_drop_indexes_ongoing (& indices);
5554
5561
if (!indices.empty ()) {
5555
- std::unordered_set<uint32 > finished;
5562
+ std::unordered_set<GL_INDEX_ID > finished;
5556
5563
rocksdb::ReadOptions read_opts;
5557
5564
read_opts.total_order_seek = true ; // disable bloom filter
5558
5565
5559
5566
for (auto d : indices) {
5560
- uint16 index_dict_version=0 ;
5561
- uchar index_type= 0 ;
5562
- uint16 kv_version= 0 ;
5563
- uint32 cf_id= 0 ;
5564
5567
uint32 cf_flags= 0 ;
5565
- if (!dict_manager.get_cf_id (d, &index_dict_version, &index_type,
5566
- &kv_version, &cf_id))
5567
- {
5568
- sql_print_error (" RocksDB: Failed to get column family id "
5569
- " from index id %u. MyRocks data dictionary may "
5570
- " get corrupted." , d);
5571
- abort_with_stack_traces ();
5572
- }
5573
- if (!dict_manager.get_cf_flags (cf_id, &cf_flags))
5568
+ if (!dict_manager.get_cf_flags (d.cf_id , &cf_flags))
5574
5569
{
5575
5570
sql_print_error (" RocksDB: Failed to get column family flags "
5576
5571
" from cf id %u. MyRocks data dictionary may "
5577
- " get corrupted." , cf_id);
5572
+ " get corrupted." , d. cf_id );
5578
5573
abort_with_stack_traces ();
5579
5574
}
5580
- rocksdb::ColumnFamilyHandle* cfh= cf_manager.get_cf (cf_id);
5575
+ rocksdb::ColumnFamilyHandle* cfh= cf_manager.get_cf (d. cf_id );
5581
5576
DBUG_ASSERT (cfh);
5582
5577
bool is_reverse_cf= cf_flags & RDBSE_KEYDEF::REVERSE_CF_FLAG;
5583
5578
std::unique_ptr<rocksdb::Iterator> it (
5584
5579
rdb->NewIterator (read_opts, cfh));
5585
5580
5586
5581
bool index_removed= false ;
5587
5582
uchar key_buf[RDBSE_KEYDEF::INDEX_NUMBER_SIZE]= {0 };
5588
- store_big_uint4 (key_buf, d);
5583
+ store_big_uint4 (key_buf, d. index_id );
5589
5584
rocksdb::Slice key = rocksdb::Slice ((char *)key_buf, sizeof (key_buf));
5590
5585
it->Seek (key);
5591
5586
if (is_reverse_cf)
@@ -5938,7 +5933,7 @@ void compute_optimizer_stats()
5938
5933
}
5939
5934
}
5940
5935
5941
- std::map<uint32_t , MyRocksTablePropertiesCollector::IndexStats>
5936
+ std::map<GL_INDEX_ID , MyRocksTablePropertiesCollector::IndexStats>
5942
5937
statsFromProps;
5943
5938
for (auto cf : cfs) {
5944
5939
rocksdb::TablePropertiesCollection props;
@@ -5953,13 +5948,13 @@ void compute_optimizer_stats()
5953
5948
std::vector<MyRocksTablePropertiesCollector::IndexStats> stats;
5954
5949
for (auto & keydef : keydefs)
5955
5950
{
5956
- auto it = statsFromProps.find (keydef->get_index_number ());
5951
+ auto it = statsFromProps.find (keydef->get_gl_index_id ());
5957
5952
if (it != statsFromProps.end ()) {
5958
5953
stats.push_back (it->second );
5959
5954
} else {
5960
5955
// This index didn't have any associated stats in SST properties.
5961
5956
// It might be an empty table, for example.
5962
- stats.emplace_back (keydef->get_index_number ());
5957
+ stats.emplace_back (keydef->get_gl_index_id ());
5963
5958
}
5964
5959
5965
5960
uchar buf[2 *RDBSE_KEYDEF::INDEX_NUMBER_SIZE];
0 commit comments