commit d1bb19b8f751875472211312c8e810143a7ba4b6
Author: Manuel Ung <mung@fb.com>
Date:   Fri Feb 3 11:50:34 2017 -0800

    Add cardinality stats to information schema

    Summary: This adds cardinality stats to the INFORMATION_SCHEMA.ROCKSDB_INDEX_FILE_MAP table. This is the only missing user collected properties from SST files that we don't expose, which is useful for debugging cardinality bugs.

    Reviewed By: hermanlee

    Differential Revision: D4509156

    fbshipit-source-id: 2d3918a
This commit is contained in:
Sergei Petrunia 2017-02-06 17:39:08 +00:00
commit 7468ccfadf
82 changed files with 9307 additions and 10589 deletions

View file

@ -17,43 +17,35 @@
/* This C++ file's header file */
#include "./rdb_mutex_wrapper.h"
/* MySQL header files */
#include "../sql/sql_class.h"
#include "../sql/replication.h"
/* MyRocks header files */
#include "./ha_rocksdb.h"
#include "./rdb_utils.h"
// Internal MySQL APIs not exposed in any header.
extern "C"
{
void thd_enter_cond(MYSQL_THD thd, mysql_cond_t *cond, mysql_mutex_t *mutex,
const PSI_stage_info *stage, PSI_stage_info *old_stage);
void thd_exit_cond(MYSQL_THD thd, const PSI_stage_info *stage);
}
using namespace rocksdb;
namespace myrocks {
static
PSI_stage_info stage_waiting_on_row_lock2= { 0, "Waiting for row lock", 0};
static PSI_stage_info stage_waiting_on_row_lock2 = {0, "Waiting for row lock",
0};
static const int64_t MICROSECS= 1000*1000;
static const int64_t ONE_SECOND_IN_MICROSECS = 1000 * 1000;
// A timeout as long as one full non-leap year worth of microseconds is as
// good as infinite timeout.
static const int64_t BIG_TIMEOUT= MICROSECS * 60 * 60 * 24 * 365;
static const int64_t ONE_YEAR_IN_MICROSECS =
ONE_SECOND_IN_MICROSECS * 60 * 60 * 24 * 365;
Rdb_cond_var::Rdb_cond_var() {
mysql_cond_init(0, &m_cond, nullptr);
}
Rdb_cond_var::Rdb_cond_var() { mysql_cond_init(0, &m_cond, nullptr); }
Rdb_cond_var::~Rdb_cond_var() {
mysql_cond_destroy(&m_cond);
}
Rdb_cond_var::~Rdb_cond_var() { mysql_cond_destroy(&m_cond); }
Status Rdb_cond_var::Wait(const std::shared_ptr<TransactionDBMutex> mutex_arg) {
return WaitFor(mutex_arg, BIG_TIMEOUT);
return WaitFor(mutex_arg, ONE_YEAR_IN_MICROSECS);
}
/*
@brief
Wait on condition variable. The caller must make sure that we own
@ -70,32 +62,30 @@ Status Rdb_cond_var::Wait(const std::shared_ptr<TransactionDBMutex> mutex_arg) {
Status
Rdb_cond_var::WaitFor(const std::shared_ptr<TransactionDBMutex> mutex_arg,
int64_t timeout_micros)
{
auto *mutex_obj= reinterpret_cast<Rdb_mutex*>(mutex_arg.get());
int64_t timeout_micros) {
auto *mutex_obj = reinterpret_cast<Rdb_mutex *>(mutex_arg.get());
DBUG_ASSERT(mutex_obj != nullptr);
mysql_mutex_t * const mutex_ptr= &mutex_obj->m_mutex;
mysql_mutex_t *const mutex_ptr = &mutex_obj->m_mutex;
int res= 0;
int res = 0;
struct timespec wait_timeout;
if (timeout_micros < 0)
timeout_micros= BIG_TIMEOUT;
set_timespec_nsec(wait_timeout, timeout_micros*1000);
timeout_micros = ONE_YEAR_IN_MICROSECS;
set_timespec_nsec(wait_timeout, timeout_micros * 1000);
#ifndef STANDALONE_UNITTEST
PSI_stage_info old_stage;
mysql_mutex_assert_owner(mutex_ptr);
if (current_thd && mutex_obj->m_old_stage_info.count(current_thd) == 0)
{
my_core::thd_enter_cond(current_thd, &m_cond, mutex_ptr,
&stage_waiting_on_row_lock2, &old_stage);
if (current_thd && mutex_obj->m_old_stage_info.count(current_thd) == 0) {
THD_ENTER_COND(current_thd, &m_cond, mutex_ptr, &stage_waiting_on_row_lock2,
&old_stage);
/*
After the mysql_cond_timedwait we need make this call
my_core::thd_exit_cond(thd, &old_stage);
THD_EXIT_COND(thd, &old_stage);
to inform the SQL layer that KILLable wait has ended. However,
that will cause mutex to be released. Defer the release until the mutex
@ -105,15 +95,14 @@ Rdb_cond_var::WaitFor(const std::shared_ptr<TransactionDBMutex> mutex_arg,
}
#endif
bool killed= false;
bool killed = false;
do
{
res= mysql_cond_timedwait(&m_cond, mutex_ptr, &wait_timeout);
do {
res = mysql_cond_timedwait(&m_cond, mutex_ptr, &wait_timeout);
#ifndef STANDALONE_UNITTEST
if (current_thd)
killed= my_core::thd_killed(current_thd);
killed = my_core::thd_killed(current_thd);
#endif
} while (!killed && res == EINTR);
@ -123,7 +112,6 @@ Rdb_cond_var::WaitFor(const std::shared_ptr<TransactionDBMutex> mutex_arg,
return Status::OK();
}
/*
@note
@ -154,32 +142,21 @@ Rdb_cond_var::WaitFor(const std::shared_ptr<TransactionDBMutex> mutex_arg,
None of this looks like a problem for our use case.
*/
void Rdb_cond_var::Notify()
{
mysql_cond_signal(&m_cond);
}
void Rdb_cond_var::Notify() { mysql_cond_signal(&m_cond); }
/*
@note
This is called without holding the mutex that's used for waiting on the
condition. See ::Notify().
*/
void Rdb_cond_var::NotifyAll()
{
mysql_cond_broadcast(&m_cond);
}
void Rdb_cond_var::NotifyAll() { mysql_cond_broadcast(&m_cond); }
Rdb_mutex::Rdb_mutex()
{
Rdb_mutex::Rdb_mutex() {
mysql_mutex_init(0 /* Don't register in P_S. */, &m_mutex,
MY_MUTEX_INIT_FAST);
}
Rdb_mutex::~Rdb_mutex() {
mysql_mutex_destroy(&m_mutex);
}
Rdb_mutex::~Rdb_mutex() { mysql_mutex_destroy(&m_mutex); }
Status Rdb_mutex::Lock() {
mysql_mutex_lock(&m_mutex);
@ -192,8 +169,7 @@ Status Rdb_mutex::Lock() {
// If implementing a custom version of this class, the implementation may
// choose to ignore the timeout.
// Return OK on success, or other Status on failure.
Status Rdb_mutex::TryLockFor(int64_t timeout_time __attribute__((__unused__)))
{
Status Rdb_mutex::TryLockFor(int64_t timeout_time MY_ATTRIBUTE((__unused__))) {
/*
Note: PThreads API has pthread_mutex_timedlock(), but mysql's
mysql_mutex_* wrappers do not wrap that function.
@ -202,10 +178,8 @@ Status Rdb_mutex::TryLockFor(int64_t timeout_time __attribute__((__unused__)))
return Status::OK();
}
#ifndef STANDALONE_UNITTEST
void Rdb_mutex::set_unlock_action(const PSI_stage_info* const old_stage_arg)
{
void Rdb_mutex::set_unlock_action(const PSI_stage_info *const old_stage_arg) {
DBUG_ASSERT(old_stage_arg != nullptr);
mysql_mutex_assert_owner(&m_mutex);
@ -219,17 +193,16 @@ void Rdb_mutex::set_unlock_action(const PSI_stage_info* const old_stage_arg)
// Unlock Mutex that was successfully locked by Lock() or TryLockUntil()
void Rdb_mutex::UnLock() {
#ifndef STANDALONE_UNITTEST
if (m_old_stage_info.count(current_thd) > 0)
{
if (m_old_stage_info.count(current_thd) > 0) {
const std::shared_ptr<PSI_stage_info> old_stage =
m_old_stage_info[current_thd];
m_old_stage_info[current_thd];
m_old_stage_info.erase(current_thd);
/* The following will call mysql_mutex_unlock */
my_core::thd_exit_cond(current_thd, old_stage.get());
THD_EXIT_COND(current_thd, old_stage.get());
return;
}
#endif
mysql_mutex_unlock(&m_mutex);
}
} // namespace myrocks
} // namespace myrocks