[Commits] 3dcf732: Expose a few RocksDB tickers as status variables.

Sergei Petrunia psergey at askmonty.org
Thu Jul 24 23:04:39 EEST 2014


revision-id: 3dcf732135ed5865c3561d86465c0b4879788782
parent(s): e11e7d11aa515b36119f8915198f6a5674340ae2
committer: Sergei Petrunia
branch nick: webscalesql-5.6
timestamp: 2014-07-25 00:04:39 +0400
message:

Expose a few RocksDB tickers as status variables.

-----------------------

 mysql-test/r/rocksdb.result   |   26 ++++++++++++++++++
 mysql-test/t/rocksdb.test     |   11 ++++++++
 storage/rocksdb/ha_rocksdb.cc |   60 ++++++++++++++++++++++++++++++++++++-----
 storage/rocksdb/ha_rocksdb.h  |    1 +
 4 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/mysql-test/r/rocksdb.result b/mysql-test/r/rocksdb.result
index 9541aab..5ec571e 100644
--- a/mysql-test/r/rocksdb.result
+++ b/mysql-test/r/rocksdb.result
@@ -1282,3 +1282,29 @@ count(*)
 0
 set autocommit=1;
 drop table t0, t1;
+#
+# Check status variables
+#
+show status like 'rocksdb%';
+Variable_name	Value
+rocksdb_bytes_written	#
+rocksdb_bytes_read	#
+rocksdb_number_keys_written	#
+rocksdb_number_keys_read	#
+rocksdb_number_keys_updated	#
+select VARIABLE_NAME from INFORMATION_SCHEMA.global_status where VARIABLE_NAME LIKE 'rocksdb%';
+VARIABLE_NAME
+ROCKSDB_BYTES_WRITTEN
+ROCKSDB_BYTES_READ
+ROCKSDB_NUMBER_KEYS_WRITTEN
+ROCKSDB_NUMBER_KEYS_READ
+ROCKSDB_NUMBER_KEYS_UPDATED
+# RocksDB-SE's status variables are global internally 
+#  but they are shown as both session and global, like InnoDB's status vars.
+select VARIABLE_NAME from INFORMATION_SCHEMA.session_status where VARIABLE_NAME LIKE 'rocksdb%';
+VARIABLE_NAME
+ROCKSDB_BYTES_WRITTEN
+ROCKSDB_BYTES_READ
+ROCKSDB_NUMBER_KEYS_WRITTEN
+ROCKSDB_NUMBER_KEYS_READ
+ROCKSDB_NUMBER_KEYS_UPDATED
diff --git a/mysql-test/t/rocksdb.test b/mysql-test/t/rocksdb.test
index 0d11fe5..1bfb0b0 100644
--- a/mysql-test/t/rocksdb.test
+++ b/mysql-test/t/rocksdb.test
@@ -1139,3 +1139,14 @@ select count(*) from t1;
 set autocommit=1;
 drop table t0, t1;
 
+--echo #
+--echo # Check status variables
+--echo #
+--replace_column 2 #
+show status like 'rocksdb%';
+
+select VARIABLE_NAME from INFORMATION_SCHEMA.global_status where VARIABLE_NAME LIKE 'rocksdb%';
+--echo # RocksDB-SE's status variables are global internally 
+--echo #  but they are shown as both session and global, like InnoDB's status vars.
+select VARIABLE_NAME from INFORMATION_SCHEMA.session_status where VARIABLE_NAME LIKE 'rocksdb%';
+
diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc
index 4ebec6f..4ac3649 100644
--- a/storage/rocksdb/ha_rocksdb.cc
+++ b/storage/rocksdb/ha_rocksdb.cc
@@ -434,6 +434,7 @@ static int rocksdb_rollback(handlerton* hton, THD* thd, bool rollback_trx)
   return 0;
 }
 
+static std::shared_ptr<rocksdb::Statistics> rocksdb_stats;
 
 static int rocksdb_init_func(void *p)
 {
@@ -471,10 +472,12 @@ static int rocksdb_init_func(void *p)
   
   row_locks.init(compare_mem_comparable_keys, 
                  Primary_key_comparator::get_hashnr);
-
+  
+  rocksdb_stats= rocksdb::CreateDBStatistics();
   rocksdb::Options main_opts;
   main_opts.create_if_missing = true;
   main_opts.comparator= &primary_key_comparator;
+  main_opts.statistics= rocksdb_stats;
   rocksdb::Status status;
   status= rocksdb::DB::Open(main_opts, "./rocksdb", &rdb);
 
@@ -2470,15 +2473,58 @@ static int show_rocksdb_vars(THD *thd, SHOW_VAR *var, char *buff)
 }
 #endif
 
-struct st_mysql_storage_engine rocksdb_storage_engine=
-{ MYSQL_HANDLERTON_INTERFACE_VERSION };
+typedef struct {
+  long bytes_written;
+  long bytes_read;
+  long number_keys_written;
+  long number_keys_read;
+  long number_keys_updated;
+} ROCKSDBSE_STATUS_VARS;
+
+static ROCKSDBSE_STATUS_VARS rocksdb_counters;
+
+static SHOW_VAR rocksdb_status_variables[]= {
+  {"bytes_written",        (char*) &rocksdb_counters.bytes_written, SHOW_LONG},
+  {"bytes_read",           (char*) &rocksdb_counters.bytes_read, SHOW_LONG},
+  {"number_keys_written",  (char*) &rocksdb_counters.number_keys_written, SHOW_LONG},
+  {"number_keys_read",     (char*) &rocksdb_counters.number_keys_read, SHOW_LONG},
+  {"number_keys_updated",  (char*) &rocksdb_counters.number_keys_updated, SHOW_LONG},
+  {NullS, NullS, SHOW_LONG}
+};
 
-static struct st_mysql_show_var func_status[]=
+
+void rocksdb_export_status()
 {
- // {"Cassandra",  (char *)show_rocksdb_vars, SHOW_FUNC},
-  {0,0,SHOW_UNDEF}
+  ROCKSDBSE_STATUS_VARS &r= rocksdb_counters;
+  // TODO: should we protect the below with taking/releasing a mutex, like
+  // innodb does?
+  r.bytes_written=       rocksdb_stats->getTickerCount(rocksdb::BYTES_WRITTEN);
+  r.bytes_read=          rocksdb_stats->getTickerCount(rocksdb::BYTES_READ);
+  r.number_keys_written= rocksdb_stats->getTickerCount(rocksdb::NUMBER_KEYS_WRITTEN);
+  r.number_keys_read=    rocksdb_stats->getTickerCount(rocksdb::NUMBER_KEYS_READ);
+  r.number_keys_updated= rocksdb_stats->getTickerCount(rocksdb::NUMBER_KEYS_UPDATED);
+}
+
+
+static int show_rocksdb_status_vars(THD* thd, SHOW_VAR *var, char* buff)
+{
+  rocksdb_export_status();
+  var->type = SHOW_ARRAY;
+  var->value = (char*) &rocksdb_status_variables;
+  return(0);
+}
+
+
+static SHOW_VAR rocksdb_status_vars[]= 
+{
+  {"rocksdb", (char*) &show_rocksdb_status_vars, SHOW_FUNC},
+  {NullS, NullS, SHOW_LONG}
 };
 
+
+struct st_mysql_storage_engine rocksdb_storage_engine=
+{ MYSQL_HANDLERTON_INTERFACE_VERSION };
+
 mysql_declare_plugin(rocksdb_se)
 {
   MYSQL_STORAGE_ENGINE_PLUGIN,
@@ -2490,7 +2536,7 @@ mysql_declare_plugin(rocksdb_se)
   rocksdb_init_func,                            /* Plugin Init */
   rocksdb_done_func,                            /* Plugin Deinit */
   0x0001,                                       /* version number (0.1) */
-  func_status,                                  /* status variables */
+  rocksdb_status_vars,                          /* status variables */
   rocksdb_system_variables,                     /* system variables */
   NULL,                                         /* config options */
   0,                                            /* flags */
diff --git a/storage/rocksdb/ha_rocksdb.h b/storage/rocksdb/ha_rocksdb.h
index b43efd8..b58ff04 100644
--- a/storage/rocksdb/ha_rocksdb.h
+++ b/storage/rocksdb/ha_rocksdb.h
@@ -26,6 +26,7 @@
 #include "rocksdb/db.h"
 #include "rocksdb/comparator.h"
 #include "rocksdb/write_batch.h"
+#include "rocksdb/statistics.h"
 
 #include "sql_string.h"
 


More information about the commits mailing list