Skip to content

Commit

Permalink
Adding and fixing asserts for preconditions to myrocks.
Browse files Browse the repository at this point in the history
Summary: Added and fixed asserts checking preconditions in /storage/rocksd for first half of ha_rocksdb.cc and various other small files.

Reviewed By: gunnarku

Differential Revision: D4329089
  • Loading branch information
ethanhjennings authored and inikep committed Jan 28, 2022
1 parent c1717b4 commit d96b987
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
22 changes: 22 additions & 0 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ rocksdb_compact_column_family(THD* thd,
char buff[STRING_BUFFER_USUAL_SIZE];
int len = sizeof(buff);

DBUG_ASSERT(value != nullptr);

if (const char* cf = value->val_str(value, buff, &len)) {
bool is_automatic;
auto cfh = cf_manager.get_cf(cf, "", nullptr, &is_automatic);
Expand Down Expand Up @@ -453,6 +455,8 @@ rocksdb_set_rocksdb_info_log_level(THD* thd,
void* var_ptr,
const void* save)
{
DBUG_ASSERT(save != nullptr);

mysql_mutex_lock(&rdb_sysvars_mutex);
rocksdb_info_log_level = *static_cast<const uint64_t*>(save);
rocksdb_db_options.info_log->SetInfoLogLevel(
Expand Down Expand Up @@ -1514,6 +1518,8 @@ class Rdb_transaction

static void walk_tx_list(Rdb_tx_list_walker* walker)
{
DBUG_ASSERT(walker != nullptr);

mysql_mutex_lock(&s_tx_list_mutex);
for (auto it : s_tx_list)
walker->process_tran(it);
Expand All @@ -1525,6 +1531,7 @@ class Rdb_transaction
Rdb_tbl_def *tbl_def)
{
DBUG_ASSERT(!s.ok());
DBUG_ASSERT(tbl_def != nullptr);

if (s.IsTimedOut())
{
Expand Down Expand Up @@ -1690,6 +1697,8 @@ class Rdb_transaction

void snapshot_created(const rocksdb::Snapshot *snapshot)
{
DBUG_ASSERT(snapshot != nullptr);

m_read_opts.snapshot = snapshot;
rdb->GetEnv()->GetCurrentTime(&m_snapshot_timestamp);
m_is_delayed_snapshot = false;
Expand Down Expand Up @@ -1736,6 +1745,8 @@ class Rdb_transaction
multiple bulk loads to occur on a partitioned table, but then closes
them all out when we switch to another table.
*/
DBUG_ASSERT(bulk_load != nullptr);

if (!m_curr_bulk_load.empty() &&
!bulk_load->same_table(*m_curr_bulk_load[0]))
{
Expand Down Expand Up @@ -1831,6 +1842,7 @@ class Rdb_transaction
// Make sure we are not doing both read_current (which implies we don't
// want a snapshot) and create_snapshot which makes sure we create
// a snapshot
DBUG_ASSERT(column_family != nullptr);
DBUG_ASSERT(!read_current || !create_snapshot);

if (create_snapshot)
Expand Down Expand Up @@ -2860,6 +2872,8 @@ static std::string format_string(
va_list args_copy;
char static_buff[256];

DBUG_ASSERT(format != nullptr);

va_start(args, format);
va_copy(args_copy, args);

Expand Down Expand Up @@ -2957,6 +2971,8 @@ class Rdb_snapshot_status : public Rdb_tx_list_walker
/* Create one row in the snapshot status table */
void process_tran(const Rdb_transaction *tx) override
{
DBUG_ASSERT(tx != nullptr);

/* Calculate the duration the snapshot has existed */
int64_t snapshot_timestamp = tx->m_snapshot_timestamp;
if (snapshot_timestamp != 0)
Expand Down Expand Up @@ -3003,6 +3019,8 @@ class Rdb_trx_info_aggregator : public Rdb_tx_list_walker
{rocksdb::Transaction::ROLLEDBACK, "ROLLEDBACK"},
};

DBUG_ASSERT(tx != nullptr);

THD* thd = tx->get_thd();
ulong thread_id = thd_thread_id(thd);

Expand Down Expand Up @@ -3203,6 +3221,8 @@ static bool rocksdb_show_status(handlerton* hton,
static inline void rocksdb_register_tx(handlerton *hton, THD *thd,
Rdb_transaction *tx)
{
DBUG_ASSERT(tx != nullptr);

trans_register_ha(thd, FALSE, rocksdb_hton);
if (my_core::thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
{
Expand Down Expand Up @@ -4125,6 +4145,7 @@ void Rdb_open_tables_map::release_table_handler(
{
mysql_mutex_lock(&m_mutex);

DBUG_ASSERT(table_handler != nullptr);
DBUG_ASSERT(table_handler->m_ref_count > 0);
if (!--table_handler->m_ref_count)
{
Expand Down Expand Up @@ -4810,6 +4831,7 @@ int ha_rocksdb::alloc_key_buffers(const TABLE* table_arg,
{
DBUG_ENTER("ha_rocksdb::alloc_key_buffers");
DBUG_ASSERT(m_pk_tuple == nullptr);
DBUG_ASSERT(tbl_def_arg != nullptr);

std::shared_ptr<Rdb_key_def>* kd_arr= tbl_def_arg->m_key_descr_arr;

Expand Down
6 changes: 6 additions & 0 deletions storage/rocksdb/properties_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Rdb_tbl_prop_coll::Rdb_tbl_prop_coll(
m_seed(time(nullptr)),
m_card_adj_extra(1.)
{
DBUG_ASSERT(ddl_manager != nullptr);

// We need to adjust the index cardinality numbers based on the sampling
// rate so that the output of "SHOW INDEX" command will reflect reality
// more closely. It will still be an approximation, just a better one.
Expand Down Expand Up @@ -249,6 +251,8 @@ Rdb_tbl_prop_coll::Finish(
uint64_t num_sst_entry_merge = 0;
uint64_t num_sst_entry_other = 0;

DBUG_ASSERT(properties != nullptr);

for (auto it = m_stats.begin(); it != m_stats.end(); it++)
{
num_sst_entry_put += it->m_rows;
Expand Down Expand Up @@ -507,6 +511,8 @@ void Rdb_index_stats::merge(
{
std::size_t i;

DBUG_ASSERT(estimated_data_len >= 0);

m_gl_index_id = s.m_gl_index_id;
if (m_distinct_keys_per_prefix.size() < s.m_distinct_keys_per_prefix.size())
{
Expand Down
3 changes: 3 additions & 0 deletions storage/rocksdb/rdb_buff.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ inline void rdb_netstr_append_uint16(my_core::String *out_netstr, uint16 val)

inline void rdb_netbuf_store_uint64(uchar *dst_netbuf, uint64 n)
{
DBUG_ASSERT(dst_netbuf != nullptr);

// Convert from host byte order (usually Little Endian) to network byte order
// (Big Endian).
uint64 net_val= htobe64(n);
Expand Down Expand Up @@ -362,6 +364,7 @@ class Rdb_string_writer

void write(uchar *new_data, size_t len)
{
DBUG_ASSERT(new_data != nullptr);
m_data.insert(m_data.end(), new_data, new_data + len);
}

Expand Down
1 change: 0 additions & 1 deletion storage/rocksdb/rdb_cf_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ Rdb_cf_manager::get_cf(const char *cf_name,
const char *index_name,
bool *is_automatic) const
{
DBUG_ASSERT(cf_name != nullptr);
DBUG_ASSERT(is_automatic != nullptr);

rocksdb::ColumnFamilyHandle* cf_handle;
Expand Down
3 changes: 3 additions & 0 deletions storage/rocksdb/rdb_cf_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ bool Rdb_cf_options::init(
const char * default_cf_options,
const char * override_cf_options)
{
DBUG_ASSERT(default_cf_options != nullptr);
DBUG_ASSERT(override_cf_options != nullptr);

m_default_cf_opts.comparator = &s_pk_comparator;
m_default_cf_opts.compaction_filter_factory.reset(
new Rdb_compact_filter_factory);
Expand Down

0 comments on commit d96b987

Please sign in to comment.