@@ -713,6 +713,109 @@ static int i_s_rocksdb_cfoptions_init(void *p)
713
713
DBUG_RETURN (0 );
714
714
}
715
715
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
+
716
819
static int i_s_rocksdb_deinit (void *p)
717
820
{
718
821
DBUG_ENTER (" i_s_rocksdb_deinit" );
@@ -823,3 +926,20 @@ struct st_mysql_plugin i_s_rocksdb_ddl=
823
926
NULL , /* config options */
824
927
0 , /* flags */
825
928
};
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
+ };
0 commit comments