Skip to content

Commit

Permalink
Add dict_register_dd_table_id api support for rocksdb dd (#1298)
Browse files Browse the repository at this point in the history
Summary:
We are adding support for data dictionary related rocksdb_hton functions. This will include the current diff and couple of following diffs. Each diff will add support for one or several rocksdb_hton function.

This current adds support for rocksdb_hton->dict_register_dd_table_id. It contains several part
1. Add a rdb_native_dd file. The file is dedicated to rocksdb data dictionary related function and objects.
2. Add dd table check in rename_table/delete_table/truncate_table. These table operations are not allowed for dd tables. Fail the operation if it's operated on dd tables.
3. Maintain a dd table id set.

Pull Request resolved: #1298

Reviewed By: luqun

Differential Revision: D45332365

Pulled By: sunshine-Chun

fbshipit-source-id: 95aebf8
  • Loading branch information
sunshine-Chun authored and facebook-github-bot committed Apr 28, 2023
1 parent 35a178a commit 1a0f581
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 11 deletions.
1 change: 1 addition & 0 deletions storage/rocksdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ SET(ROCKSDB_SE_SOURCES
rdb_cf_options.cc rdb_cf_options.h
rdb_cf_manager.cc rdb_cf_manager.h
rdb_converter.cc rdb_converter.h
rdb_native_dd.cc rdb_native_dd.h
properties_collector.cc properties_collector.h
event_listener.cc event_listener.h
rdb_i_s.cc rdb_i_s.h
Expand Down
38 changes: 29 additions & 9 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#include "./rdb_index_merge.h"
#include "./rdb_iterator.h"
#include "./rdb_mutex_wrapper.h"
#include "./rdb_native_dd.h"
#include "./rdb_psi.h"
#include "./rdb_sst_partitioner_factory.h"
#include "./rdb_threads.h"
Expand Down Expand Up @@ -7432,6 +7433,8 @@ static int rocksdb_init_internal(void *const p) {
rocksdb_hton->clone_interface.clone_apply = rocksdb_clone_apply;
rocksdb_hton->clone_interface.clone_apply_end = rocksdb_clone_apply_end;

rocksdb_hton->dict_register_dd_table_id = rocksdb_dict_register_dd_table_id;

rocksdb_hton->flags = HTON_SUPPORTS_EXTENDED_KEYS | HTON_CAN_RECREATE;

rocksdb_hton->partition_flags = rocksdb_partition_flags;
Expand Down Expand Up @@ -10132,6 +10135,9 @@ int ha_rocksdb::truncate_table(Rdb_tbl_def *tbl_def_arg,
dd::Table *table_def) {
DBUG_ENTER_FUNC();

int err = native_dd::reject_if_dd_table(table_def);
if (err != 0) DBUG_RETURN(err);

/*
Fast table truncation involves deleting the table and then recreating
it. However, it is possible recreating the table fails. In this case, a
Expand All @@ -10155,8 +10161,8 @@ int ha_rocksdb::truncate_table(Rdb_tbl_def *tbl_def_arg,
should be locked via MDL, no other process thread be able to access this
table.
*/
int err = rdb_split_normalized_tablename(orig_tablename, &dbname, &tblname,
&partition);
err = rdb_split_normalized_tablename(orig_tablename, &dbname, &tblname,
&partition);
assert(err == 0);
if (err != HA_EXIT_SUCCESS) DBUG_RETURN(err);
tblname = std::string(TRUNCATE_TABLE_PREFIX) + tblname;
Expand Down Expand Up @@ -14065,12 +14071,14 @@ int ha_rocksdb::delete_table(Rdb_tbl_def *const tbl) {
*/

int ha_rocksdb::delete_table(const char *const tablename,
const dd::Table *table_def
MY_ATTRIBUTE((__unused__))) {
const dd::Table *table_def) {
DBUG_ENTER_FUNC();

assert(tablename != nullptr);

int err = native_dd::reject_if_dd_table(table_def);
if (err != 0) DBUG_RETURN(err);

/* Find the table in the hash */
Rdb_tbl_def *const tbl = get_table_if_exists(tablename);
if (!tbl) {
Expand All @@ -14085,17 +14093,19 @@ int ha_rocksdb::delete_table(const char *const tablename,
HA_EXIT_SUCCESS OK
other HA_ERR error code (cannot be SE-specific)
*/
int ha_rocksdb::rename_table(
const char *const from, const char *const to,
const dd::Table *from_table_def MY_ATTRIBUTE((__unused__)),
dd::Table *to_table_def MY_ATTRIBUTE((__unused__))) {
int ha_rocksdb::rename_table(const char *const from, const char *const to,
const dd::Table *from_table_def,
[[maybe_unused]] dd::Table *to_table_def) {
DBUG_ENTER_FUNC();

int rc;
rc = native_dd::reject_if_dd_table(from_table_def);
if (rc != 0) DBUG_RETURN(rc);

std::string from_str;
std::string to_str;
std::string from_db;
std::string to_db;
int rc;

if (rdb_is_tablename_normalized(from)) {
from_str = from;
Expand Down Expand Up @@ -19020,6 +19030,16 @@ static bool parse_fault_injection_params(
return false;
}

bool ha_rocksdb::get_se_private_data(dd::Table *, bool reset) {
// TODO: Remove the assert once we fully migrate to using RocksDB DD API.
assert(false);
if (reset) {
native_dd::clear_dd_table_ids();
}

return false;
}

} // namespace myrocks

/*
Expand Down
6 changes: 4 additions & 2 deletions storage/rocksdb/ha_rocksdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ class ha_rocksdb : public my_core::handler, public blob_buffer {
bool should_store_row_debug_checksums() const;

int rename_table(const char *const from, const char *const to,
const dd::Table *from_table_def MY_ATTRIBUTE((__unused__)),
dd::Table *to_table_def MY_ATTRIBUTE((__unused__))) override
const dd::Table *from_table_def,
dd::Table *to_table_def) override
MY_ATTRIBUTE((__warn_unused_result__, __nonnull__(2, 3)));

int convert_record_from_storage_format(const rocksdb::Slice *const key,
Expand Down Expand Up @@ -670,6 +670,8 @@ class ha_rocksdb : public my_core::handler, public blob_buffer {
static bool can_use_bloom_filter(THD *thd, const Rdb_key_def &kd,
const rocksdb::Slice &eq_cond);

bool get_se_private_data(dd::Table *, bool reset) override;

private:
bool mrr_sorted_mode; // true <=> we are in ordered-keys, ordered-results
// RANGE_SEQ_IF is stored in handler::mrr_funcs
Expand Down
53 changes: 53 additions & 0 deletions storage/rocksdb/rdb_native_dd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright (c) 2023 Meta, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

/* This C++ file's header file */
#include "rdb_native_dd.h"

/* MySQL header files */
#include "sql/dd/types/table.h" // dd::Table

/* MyRocks header files */
#include "ha_rocksdb.h"

namespace myrocks {
std::unordered_set<dd::Object_id> native_dd::s_dd_table_ids = {};

bool native_dd::is_dd_table_id(dd::Object_id id) {
return (native_dd::s_dd_table_ids.find(id) !=
native_dd::s_dd_table_ids.end());
}

int native_dd::reject_if_dd_table(const dd::Table *table_def) {
if (table_def != nullptr && is_dd_table_id(table_def->se_private_id())) {
my_error(ER_NOT_ALLOWED_COMMAND, MYF(0));
return HA_ERR_UNSUPPORTED;
}

return (0);
}

void native_dd::insert_dd_table_ids(dd::Object_id dd_table_id) {
s_dd_table_ids.insert(dd_table_id);
}

void native_dd::clear_dd_table_ids() { s_dd_table_ids.clear(); }

void rocksdb_dict_register_dd_table_id(dd::Object_id dd_table_id) {
native_dd::insert_dd_table_ids(dd_table_id);
};

} // namespace myrocks
47 changes: 47 additions & 0 deletions storage/rocksdb/rdb_native_dd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright (c) 2023 Meta, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#pragma once

/* C++ standard header files */
#include <unordered_set>

/* MySQL header files */
#include "sql/dd/object_id.h"

namespace dd {
class Table;
}

namespace myrocks {

void rocksdb_dict_register_dd_table_id(dd::Object_id dd_table_id);

class native_dd {
private:
/* Set of ids of DD tables */
static std::unordered_set<dd::Object_id> s_dd_table_ids;

public:
static bool is_dd_table_id(dd::Object_id id);

static void insert_dd_table_ids(dd::Object_id dd_table_id);

static void clear_dd_table_ids();

static int reject_if_dd_table(const dd::Table *table_def);
};

} // namespace myrocks

0 comments on commit 1a0f581

Please sign in to comment.