Skip to content

Commit 1a0f581

Browse files
sunshine-Chunfacebook-github-bot
authored andcommitted
Add dict_register_dd_table_id api support for rocksdb dd (#1298)
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
1 parent 35a178a commit 1a0f581

File tree

5 files changed

+134
-11
lines changed

5 files changed

+134
-11
lines changed

storage/rocksdb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ SET(ROCKSDB_SE_SOURCES
159159
rdb_cf_options.cc rdb_cf_options.h
160160
rdb_cf_manager.cc rdb_cf_manager.h
161161
rdb_converter.cc rdb_converter.h
162+
rdb_native_dd.cc rdb_native_dd.h
162163
properties_collector.cc properties_collector.h
163164
event_listener.cc event_listener.h
164165
rdb_i_s.cc rdb_i_s.h

storage/rocksdb/ha_rocksdb.cc

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#include "./rdb_index_merge.h"
102102
#include "./rdb_iterator.h"
103103
#include "./rdb_mutex_wrapper.h"
104+
#include "./rdb_native_dd.h"
104105
#include "./rdb_psi.h"
105106
#include "./rdb_sst_partitioner_factory.h"
106107
#include "./rdb_threads.h"
@@ -7432,6 +7433,8 @@ static int rocksdb_init_internal(void *const p) {
74327433
rocksdb_hton->clone_interface.clone_apply = rocksdb_clone_apply;
74337434
rocksdb_hton->clone_interface.clone_apply_end = rocksdb_clone_apply_end;
74347435

7436+
rocksdb_hton->dict_register_dd_table_id = rocksdb_dict_register_dd_table_id;
7437+
74357438
rocksdb_hton->flags = HTON_SUPPORTS_EXTENDED_KEYS | HTON_CAN_RECREATE;
74367439

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

10138+
int err = native_dd::reject_if_dd_table(table_def);
10139+
if (err != 0) DBUG_RETURN(err);
10140+
1013510141
/*
1013610142
Fast table truncation involves deleting the table and then recreating
1013710143
it. However, it is possible recreating the table fails. In this case, a
@@ -10155,8 +10161,8 @@ int ha_rocksdb::truncate_table(Rdb_tbl_def *tbl_def_arg,
1015510161
should be locked via MDL, no other process thread be able to access this
1015610162
table.
1015710163
*/
10158-
int err = rdb_split_normalized_tablename(orig_tablename, &dbname, &tblname,
10159-
&partition);
10164+
err = rdb_split_normalized_tablename(orig_tablename, &dbname, &tblname,
10165+
&partition);
1016010166
assert(err == 0);
1016110167
if (err != HA_EXIT_SUCCESS) DBUG_RETURN(err);
1016210168
tblname = std::string(TRUNCATE_TABLE_PREFIX) + tblname;
@@ -14065,12 +14071,14 @@ int ha_rocksdb::delete_table(Rdb_tbl_def *const tbl) {
1406514071
*/
1406614072

1406714073
int ha_rocksdb::delete_table(const char *const tablename,
14068-
const dd::Table *table_def
14069-
MY_ATTRIBUTE((__unused__))) {
14074+
const dd::Table *table_def) {
1407014075
DBUG_ENTER_FUNC();
1407114076

1407214077
assert(tablename != nullptr);
1407314078

14079+
int err = native_dd::reject_if_dd_table(table_def);
14080+
if (err != 0) DBUG_RETURN(err);
14081+
1407414082
/* Find the table in the hash */
1407514083
Rdb_tbl_def *const tbl = get_table_if_exists(tablename);
1407614084
if (!tbl) {
@@ -14085,17 +14093,19 @@ int ha_rocksdb::delete_table(const char *const tablename,
1408514093
HA_EXIT_SUCCESS OK
1408614094
other HA_ERR error code (cannot be SE-specific)
1408714095
*/
14088-
int ha_rocksdb::rename_table(
14089-
const char *const from, const char *const to,
14090-
const dd::Table *from_table_def MY_ATTRIBUTE((__unused__)),
14091-
dd::Table *to_table_def MY_ATTRIBUTE((__unused__))) {
14096+
int ha_rocksdb::rename_table(const char *const from, const char *const to,
14097+
const dd::Table *from_table_def,
14098+
[[maybe_unused]] dd::Table *to_table_def) {
1409214099
DBUG_ENTER_FUNC();
1409314100

14101+
int rc;
14102+
rc = native_dd::reject_if_dd_table(from_table_def);
14103+
if (rc != 0) DBUG_RETURN(rc);
14104+
1409414105
std::string from_str;
1409514106
std::string to_str;
1409614107
std::string from_db;
1409714108
std::string to_db;
14098-
int rc;
1409914109

1410014110
if (rdb_is_tablename_normalized(from)) {
1410114111
from_str = from;
@@ -19020,6 +19030,16 @@ static bool parse_fault_injection_params(
1902019030
return false;
1902119031
}
1902219032

19033+
bool ha_rocksdb::get_se_private_data(dd::Table *, bool reset) {
19034+
// TODO: Remove the assert once we fully migrate to using RocksDB DD API.
19035+
assert(false);
19036+
if (reset) {
19037+
native_dd::clear_dd_table_ids();
19038+
}
19039+
19040+
return false;
19041+
}
19042+
1902319043
} // namespace myrocks
1902419044

1902519045
/*

storage/rocksdb/ha_rocksdb.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ class ha_rocksdb : public my_core::handler, public blob_buffer {
493493
bool should_store_row_debug_checksums() const;
494494

495495
int rename_table(const char *const from, const char *const to,
496-
const dd::Table *from_table_def MY_ATTRIBUTE((__unused__)),
497-
dd::Table *to_table_def MY_ATTRIBUTE((__unused__))) override
496+
const dd::Table *from_table_def,
497+
dd::Table *to_table_def) override
498498
MY_ATTRIBUTE((__warn_unused_result__, __nonnull__(2, 3)));
499499

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

673+
bool get_se_private_data(dd::Table *, bool reset) override;
674+
673675
private:
674676
bool mrr_sorted_mode; // true <=> we are in ordered-keys, ordered-results
675677
// RANGE_SEQ_IF is stored in handler::mrr_funcs

storage/rocksdb/rdb_native_dd.cc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright (c) 2023 Meta, Inc
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16+
17+
/* This C++ file's header file */
18+
#include "rdb_native_dd.h"
19+
20+
/* MySQL header files */
21+
#include "sql/dd/types/table.h" // dd::Table
22+
23+
/* MyRocks header files */
24+
#include "ha_rocksdb.h"
25+
26+
namespace myrocks {
27+
std::unordered_set<dd::Object_id> native_dd::s_dd_table_ids = {};
28+
29+
bool native_dd::is_dd_table_id(dd::Object_id id) {
30+
return (native_dd::s_dd_table_ids.find(id) !=
31+
native_dd::s_dd_table_ids.end());
32+
}
33+
34+
int native_dd::reject_if_dd_table(const dd::Table *table_def) {
35+
if (table_def != nullptr && is_dd_table_id(table_def->se_private_id())) {
36+
my_error(ER_NOT_ALLOWED_COMMAND, MYF(0));
37+
return HA_ERR_UNSUPPORTED;
38+
}
39+
40+
return (0);
41+
}
42+
43+
void native_dd::insert_dd_table_ids(dd::Object_id dd_table_id) {
44+
s_dd_table_ids.insert(dd_table_id);
45+
}
46+
47+
void native_dd::clear_dd_table_ids() { s_dd_table_ids.clear(); }
48+
49+
void rocksdb_dict_register_dd_table_id(dd::Object_id dd_table_id) {
50+
native_dd::insert_dd_table_ids(dd_table_id);
51+
};
52+
53+
} // namespace myrocks

storage/rocksdb/rdb_native_dd.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright (c) 2023 Meta, Inc
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16+
#pragma once
17+
18+
/* C++ standard header files */
19+
#include <unordered_set>
20+
21+
/* MySQL header files */
22+
#include "sql/dd/object_id.h"
23+
24+
namespace dd {
25+
class Table;
26+
}
27+
28+
namespace myrocks {
29+
30+
void rocksdb_dict_register_dd_table_id(dd::Object_id dd_table_id);
31+
32+
class native_dd {
33+
private:
34+
/* Set of ids of DD tables */
35+
static std::unordered_set<dd::Object_id> s_dd_table_ids;
36+
37+
public:
38+
static bool is_dd_table_id(dd::Object_id id);
39+
40+
static void insert_dd_table_ids(dd::Object_id dd_table_id);
41+
42+
static void clear_dd_table_ids();
43+
44+
static int reject_if_dd_table(const dd::Table *table_def);
45+
};
46+
47+
} // namespace myrocks

0 commit comments

Comments
 (0)