Skip to content

Commit 0c67f42

Browse files
sunshine-ChunHerman Lee
authored andcommitted
Add set/get server version api (facebook#1296)
Summary: This diff added support for set/get server version api in rocksdb Pull Request resolved: facebook#1296 Test Plan: Test it locally Reviewed By: luqun Differential Revision: D45332426 Pulled By: sunshine-Chun ------------------------------------------------------------------------ Add rocksdb_is_supported_system_table api support for rocksdb dd (facebook#1299) Summary: We are adding support for data dictionary related rocksdb_hton handler functions. This will include the current diff and couple of following diffs. Each diff will add support for one or several rocksdb_hton handler function. This diff adds support for rocksdb_is_supported_system_table. Return false for now. More logic may need to be added once we have more prototype for dd bootstraping. Pull Request resolved: facebook#1299 Test Plan: The diff will unblock the test failure in D44598701 Imported from GitHub, without a `Test Plan:` line. Reviewed By: luqun Differential Revision: D45723276 Pulled By: sunshine-Chun
1 parent 07738fd commit 0c67f42

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

storage/rocksdb/ha_rocksdb.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7435,6 +7435,9 @@ static int rocksdb_init_internal(void *const p) {
74357435
rocksdb_hton->clone_interface.clone_apply_end = rocksdb_clone_apply_end;
74367436

74377437
rocksdb_hton->dict_register_dd_table_id = rocksdb_dict_register_dd_table_id;
7438+
rocksdb_hton->dict_get_server_version = rocksdb_dict_get_server_version;
7439+
rocksdb_hton->dict_set_server_version = rocksdb_dict_set_server_version;
7440+
rocksdb_hton->is_supported_system_table = rocksdb_is_supported_system_table;
74387441

74397442
rocksdb_hton->flags = HTON_SUPPORTS_EXTENDED_KEYS | HTON_CAN_RECREATE;
74407443

storage/rocksdb/rdb_datadic.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5309,6 +5309,11 @@ bool Rdb_dict_manager::init(rocksdb::TransactionDB *const rdb_dict,
53095309
rocksdb::Slice(reinterpret_cast<char *>(m_key_buf_max_index_id),
53105310
Rdb_key_def::INDEX_NUMBER_SIZE);
53115311

5312+
rdb_netbuf_store_index(m_key_buf_server_version, Rdb_key_def::SERVER_VERSION);
5313+
m_key_slice_server_version =
5314+
rocksdb::Slice(reinterpret_cast<char *>(m_key_buf_server_version),
5315+
Rdb_key_def::INDEX_NUMBER_SIZE);
5316+
53125317
resume_drop_indexes();
53135318
rollback_ongoing_index_creation();
53145319

@@ -6033,6 +6038,39 @@ bool Rdb_dict_manager::update_max_index_id(rocksdb::WriteBatch *const batch,
60336038
return false;
60346039
}
60356040

6041+
bool Rdb_dict_manager::get_server_version(uint *const ser_version) const {
6042+
std::string value;
6043+
6044+
const rocksdb::Status status = get_value(m_key_slice_server_version, &value);
6045+
if (status.ok()) {
6046+
Rdb_string_reader reader(value);
6047+
uint version = 0;
6048+
reader.read_uint16(&version);
6049+
if (version == Rdb_key_def::SERVER_VERSION_VERSION) {
6050+
return reader.read_uint32(ser_version);
6051+
}
6052+
}
6053+
6054+
return true;
6055+
}
6056+
6057+
bool Rdb_dict_manager::set_server_version() const {
6058+
const std::unique_ptr<rocksdb::WriteBatch> batch = begin();
6059+
6060+
Rdb_buf_writer<Rdb_key_def::VERSION_SIZE + Rdb_key_def::SERVER_VERSION_SIZE>
6061+
value_writer;
6062+
6063+
uint32 server_ver = MYSQL_VERSION_ID;
6064+
value_writer.write_uint16(Rdb_key_def::SERVER_VERSION_VERSION);
6065+
value_writer.write_uint32(server_ver);
6066+
const rocksdb::Status status = batch.get()->Put(
6067+
m_system_cfh, m_key_slice_server_version, value_writer.to_slice());
6068+
6069+
commit(batch.get());
6070+
6071+
return !status.ok();
6072+
}
6073+
60366074
void Rdb_dict_manager::add_stats(
60376075
rocksdb::WriteBatch *const batch,
60386076
const std::vector<Rdb_index_stats> &stats) const {

storage/rocksdb/rdb_datadic.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class Rdb_key_def {
421421
CF_NUMBER_SIZE = 4,
422422
CF_FLAG_SIZE = 4,
423423
PACKED_SIZE = 4, // one int
424+
SERVER_VERSION_SIZE = 4,
424425
};
425426

426427
// bit flags for combining bools when writing to disk
@@ -457,6 +458,7 @@ class Rdb_key_def {
457458
AUTO_INC = 9,
458459
DROPPED_CF = 10,
459460
MAX_DD_INDEX_ID = 11,
461+
SERVER_VERSION = 12,
460462
END_DICT_INDEX_ID = 255
461463
};
462464

@@ -472,6 +474,7 @@ class Rdb_key_def {
472474
DDL_CREATE_INDEX_ONGOING_VERSION = 1,
473475
AUTO_INCREMENT_VERSION = 1,
474476
DROPPED_CF_VERSION = 1,
477+
SERVER_VERSION_VERSION = 1,
475478
// Version for index stats is stored in IndexStats struct
476479
};
477480

@@ -1559,6 +1562,11 @@ class Rdb_binlog_manager {
15591562
value: version, index_id
15601563
index_id is 4 bytes
15611564
1565+
12. server version
1566+
key: Rdb_key_def::SERVER_VERSION(0xc)
1567+
value: version, {server version}
1568+
server version is 4 bytes
1569+
15621570
Data dictionary operations are atomic inside RocksDB. For example,
15631571
when creating a table with two indexes, it is necessary to call Put
15641572
three times. They have to be atomic. Rdb_dict_manager has a wrapper function
@@ -1578,6 +1586,9 @@ class Rdb_dict_manager : public Ensure_initialized {
15781586
uchar m_key_buf_max_dd_index_id[Rdb_key_def::INDEX_NUMBER_SIZE] = {0};
15791587
rocksdb::Slice m_key_slice_max_dd_index_id;
15801588

1589+
uchar m_key_buf_server_version[Rdb_key_def::INDEX_NUMBER_SIZE] = {0};
1590+
rocksdb::Slice m_key_slice_server_version;
1591+
15811592
static void dump_index_id(uchar *const netbuf,
15821593
Rdb_key_def::DATA_DICT_TYPE dict_type,
15831594
const GL_INDEX_ID &gl_index_id);
@@ -1725,6 +1736,22 @@ class Rdb_dict_manager : public Ensure_initialized {
17251736
bool update_max_index_id(rocksdb::WriteBatch *const batch,
17261737
const uint32_t index_id,
17271738
bool is_dd_tbl = false) const;
1739+
1740+
/**
1741+
Get the server version from the private data dictionary table
1742+
@param version out parameter
1743+
@retval false ok
1744+
@retval true error
1745+
*/
1746+
bool get_server_version(uint *const version) const;
1747+
1748+
/**
1749+
Set the server version to the private data dictionary table
1750+
@retval false ok
1751+
@retval true error
1752+
*/
1753+
bool set_server_version() const;
1754+
17281755
void add_stats(rocksdb::WriteBatch *const batch,
17291756
const std::vector<Rdb_index_stats> &stats) const;
17301757
Rdb_index_stats get_stats(GL_INDEX_ID gl_index_id) const;

storage/rocksdb/rdb_native_dd.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
/* MyRocks header files */
2424
#include "ha_rocksdb.h"
25+
#include "storage/rocksdb/ha_rocksdb_proto.h"
26+
#include "storage/rocksdb/rdb_datadic.h"
2527

2628
namespace myrocks {
2729
std::unordered_set<dd::Object_id> native_dd::s_dd_table_ids = {};
@@ -50,4 +52,20 @@ void rocksdb_dict_register_dd_table_id(dd::Object_id dd_table_id) {
5052
native_dd::insert_dd_table_ids(dd_table_id);
5153
};
5254

55+
bool rocksdb_dict_get_server_version(uint *version) {
56+
return rdb_get_dict_manager()
57+
->get_dict_manager_selector_non_const(false /*is_tmp_table*/)
58+
->get_server_version(version);
59+
};
60+
61+
bool rocksdb_dict_set_server_version() {
62+
return rdb_get_dict_manager()
63+
->get_dict_manager_selector_non_const(false /*is_tmp_table*/)
64+
->set_server_version();
65+
};
66+
67+
bool rocksdb_is_supported_system_table(const char *, const char *, bool) {
68+
return false;
69+
}
70+
5371
} // namespace myrocks

storage/rocksdb/rdb_native_dd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma once
1717

1818
/* C++ standard header files */
19+
#include <sys/types.h>
1920
#include <unordered_set>
2021

2122
/* MySQL header files */
@@ -28,6 +29,9 @@ class Table;
2829
namespace myrocks {
2930

3031
void rocksdb_dict_register_dd_table_id(dd::Object_id dd_table_id);
32+
bool rocksdb_dict_get_server_version(uint *version);
33+
bool rocksdb_dict_set_server_version();
34+
bool rocksdb_is_supported_system_table(const char *, const char *, bool);
3135

3236
class native_dd {
3337
private:

0 commit comments

Comments
 (0)