Skip to content

Commit 7b065e3

Browse files
jkedgarGunnar Kudrjavets
authored andcommitted
Add information_schema.rocksdb_index_file_map
Summary: It would be useful to know which SST files contain values for a particular index. Add a new information_schema table that will contain the relationships between index ids and SST files. Test Plan: MTR Reviewers: hermanlee4, yoshinorim, maykov, jtolmer Differential Revision: https://reviews.facebook.net/D46299
1 parent 00a0fa0 commit 7b065e3

File tree

7 files changed

+161
-1
lines changed

7 files changed

+161
-1
lines changed

storage/rocksdb/ha_rocksdb.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6084,7 +6084,8 @@ i_s_rocksdb_dbstats,
60846084
i_s_rocksdb_perf_context,
60856085
i_s_rocksdb_perf_context_global,
60866086
i_s_rocksdb_cfoptions,
6087-
i_s_rocksdb_ddl
6087+
i_s_rocksdb_ddl,
6088+
i_s_rocksdb_index_file_map
60886089
mysql_declare_plugin_end;
60896090

60906091

storage/rocksdb/properties_collector.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ MyRocksTablePropertiesCollector::GetReadableStats(
180180
return s;
181181
}
182182

183+
/*
184+
Given the properties of an SST file, reads the stats from it and returns it.
185+
*/
186+
std::vector<MyRocksTablePropertiesCollector::IndexStats>
187+
MyRocksTablePropertiesCollector::GetStatsFromTableProperties(
188+
const std::shared_ptr<const rocksdb::TableProperties>& table_props)
189+
{
190+
std::vector<MyRocksTablePropertiesCollector::IndexStats> ret;
191+
const auto& user_properties = table_props->user_collected_properties;
192+
auto it2 = user_properties.find(std::string(INDEXSTATS_KEY));
193+
if (it2 != user_properties.end()) {
194+
IndexStats::unmaterialize(it2->second, ret);
195+
}
196+
197+
return ret;
198+
}
199+
183200
/*
184201
Given properties stored on a bunch of SST files, reads the stats from them
185202
and returns one IndexStats struct per index

storage/rocksdb/properties_collector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class MyRocksTablePropertiesCollector
5151
GetReadableStats(const MyRocksTablePropertiesCollector::IndexStats& it);
5252
rocksdb::UserCollectedProperties GetReadableProperties() const override;
5353

54+
static std::vector<IndexStats> GetStatsFromTableProperties(
55+
const std::shared_ptr<const rocksdb::TableProperties>& table_props
56+
);
57+
5458
static void GetStats(
5559
const rocksdb::TablePropertiesCollection& collection,
5660
const std::unordered_set<uint32_t>& index_numbers,

storage/rocksdb/rdb_cf_manager.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,17 @@ Column_family_manager::get_cf_names(void)
204204
mysql_mutex_unlock(&cfm_mutex);
205205
return names;
206206
}
207+
208+
std::vector<rocksdb::ColumnFamilyHandle*>
209+
Column_family_manager::get_all_cf(void)
210+
{
211+
std::vector<rocksdb::ColumnFamilyHandle*> list;
212+
213+
mysql_mutex_lock(&cfm_mutex);
214+
for (auto it : cf_id_map) {
215+
list.push_back(it.second);
216+
}
217+
mysql_mutex_unlock(&cfm_mutex);
218+
219+
return list;
220+
}

storage/rocksdb/rdb_cf_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class Column_family_manager
7676
/* Used to iterate over column families for show status */
7777
std::vector<std::string> get_cf_names(void);
7878

79+
/* Used to iterate over column families */
80+
std::vector<rocksdb::ColumnFamilyHandle*> get_all_cf(void);
81+
7982
// void drop_cf(); -- not implemented so far.
8083
};
8184

storage/rocksdb/rdb_i_s.cc

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,109 @@ static int i_s_rocksdb_cfoptions_init(void *p)
713713
DBUG_RETURN(0);
714714
}
715715

716+
/* Given a path to a file return just the filename portion. */
717+
static std::string filename_without_path(
718+
const std::string& path)
719+
{
720+
/* Find last slash in path */
721+
size_t pos = path.rfind('/');
722+
723+
/* None found? Just return the original string */
724+
if (pos == std::string::npos) {
725+
return std::string(path);
726+
}
727+
728+
/* Return everything after the slash (or backslash) */
729+
return path.substr(pos + 1);
730+
}
731+
732+
/* Fill the information_schema.rocksdb_index_file_map virtual table */
733+
static int i_s_rocksdb_index_file_map_fill_table(
734+
THD *thd,
735+
TABLE_LIST *tables,
736+
Item *cond)
737+
{
738+
int ret = 0;
739+
Field **field = tables->table->field;
740+
741+
DBUG_ENTER("i_s_rocksdb_index_file_map_fill_table");
742+
743+
/* Iterate over all the column families */
744+
rocksdb::DB *rdb= rocksdb_get_rdb();
745+
Column_family_manager& cf_manager = rocksdb_get_cf_manager();
746+
for (auto cf_handle : cf_manager.get_all_cf()) {
747+
/* Grab the the properties of all the tables in the column family */
748+
rocksdb::TablePropertiesCollection table_props_collection;
749+
rocksdb::Status s = rdb->GetPropertiesOfAllTables(cf_handle,
750+
&table_props_collection);
751+
if (!s.ok()) {
752+
continue;
753+
}
754+
755+
/* Iterate over all the items in the collection, each of which contains a
756+
* name and the actual properties */
757+
for (auto props : table_props_collection) {
758+
/* Add the SST name into the output */
759+
std::string sst_name = filename_without_path(props.first);
760+
field[1]->store(sst_name.data(), sst_name.size(), system_charset_info);
761+
762+
/* Get the __indexstats__ data out of the table property */
763+
std::vector<MyRocksTablePropertiesCollector::IndexStats> stats =
764+
MyRocksTablePropertiesCollector::GetStatsFromTableProperties(props.second);
765+
if (stats.empty()) {
766+
field[0]->store(-1, true);
767+
field[2]->store(-1, true);
768+
field[3]->store(-1, true);
769+
}
770+
else {
771+
for (auto it : stats) {
772+
/* Add the index number, the number of rows, and data size to the output */
773+
field[0]->store(it.index_number, true);
774+
field[2]->store(it.rows, true);
775+
field[3]->store(it.data_size, true);
776+
777+
/* Tell MySQL about this row in the virtual table */
778+
ret= schema_table_store_record(thd, tables->table);
779+
if (ret != 0) {
780+
break;
781+
}
782+
}
783+
}
784+
}
785+
}
786+
787+
DBUG_RETURN(ret);
788+
}
789+
790+
static ST_FIELD_INFO i_s_rocksdb_index_file_map_fields_info[] =
791+
{
792+
/* The information_schema.rocksdb_index_file_map virtual table has four fields:
793+
* INDEX_NUMBER => the index id contained in the SST file
794+
* SST_NAME => the name of the SST file containing some indexes
795+
* NUM_ROWS => the number of entries of this index id in this SST file
796+
* DATA_SIZE => the data size stored in this SST file for this index id */
797+
ROCKSDB_FIELD_INFO("INDEX_NUMBER", sizeof(uint32_t), MYSQL_TYPE_LONG, 0),
798+
ROCKSDB_FIELD_INFO("SST_NAME", NAME_LEN+1, MYSQL_TYPE_STRING, 0),
799+
ROCKSDB_FIELD_INFO("NUM_ROWS", sizeof(int64_t), MYSQL_TYPE_LONGLONG, 0),
800+
ROCKSDB_FIELD_INFO("DATA_SIZE", sizeof(int64_t), MYSQL_TYPE_LONGLONG, 0),
801+
ROCKSDB_FIELD_INFO_END
802+
};
803+
804+
/* Initialize the information_schema.rocksdb_index_file_map virtual table */
805+
static int i_s_rocksdb_index_file_map_init(void *p)
806+
{
807+
ST_SCHEMA_TABLE *schema;
808+
809+
DBUG_ENTER("i_s_rocksdb_index_file_map_init");
810+
811+
schema= (ST_SCHEMA_TABLE*) p;
812+
813+
schema->fields_info=i_s_rocksdb_index_file_map_fields_info;
814+
schema->fill_table=i_s_rocksdb_index_file_map_fill_table;
815+
816+
DBUG_RETURN(0);
817+
}
818+
716819
static int i_s_rocksdb_deinit(void *p)
717820
{
718821
DBUG_ENTER("i_s_rocksdb_deinit");
@@ -823,3 +926,20 @@ struct st_mysql_plugin i_s_rocksdb_ddl=
823926
NULL, /* config options */
824927
0, /* flags */
825928
};
929+
930+
struct st_mysql_plugin i_s_rocksdb_index_file_map=
931+
{
932+
MYSQL_INFORMATION_SCHEMA_PLUGIN,
933+
&i_s_rocksdb_info,
934+
"ROCKSDB_INDEX_FILE_MAP",
935+
"Facebook",
936+
"RocksDB index file map",
937+
PLUGIN_LICENSE_GPL,
938+
i_s_rocksdb_index_file_map_init,
939+
i_s_rocksdb_deinit,
940+
0x0001, /* version number (0.1) */
941+
NULL, /* status variables */
942+
NULL, /* system variables */
943+
NULL, /* config options */
944+
0, /* flags */
945+
};

storage/rocksdb/rdb_i_s.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ extern struct st_mysql_plugin i_s_rocksdb_perf_context;
2323
extern struct st_mysql_plugin i_s_rocksdb_perf_context_global;
2424
extern struct st_mysql_plugin i_s_rocksdb_cfoptions;
2525
extern struct st_mysql_plugin i_s_rocksdb_ddl;
26+
extern struct st_mysql_plugin i_s_rocksdb_index_file_map;
2627

2728
#endif /* _rdb_i_s_h_ */

0 commit comments

Comments
 (0)