Skip to content

Commit 48ac24a

Browse files
laurynas-biveinisinikep
authored andcommitted
Partially convert Rdb_cf_options class to use (#1461)
Upstream commit ID: facebook/mysql-5.6@68638be03ecd PS-9395: Merge percona-202404 (https://jira.percona.com/browse/PS-9395) Summary: - Partially convert Rdb_cf_options methods to take std::string_view parameters. Specifically, do not convert the ones that are passed as keys to m_name_map, which is a std::unordered_map<string, string>. This can be converted in C++20, where lookups through a different key type are supported. - Convert Rdb_cf_manager::is_cf_name_reverse and create_cf_flags_if_needed methods to take std::string_view arguments, update callers. - Convert pointer arguments for the touched methods to const reference and reference ones, where possible, remove redundant nullptr-checking asserts. Remove redundant const from pass-by-value arguments, add [[nodiscard]]. - Update ER_CF_DIFFERENT to print an std::string_view parameter. Pull Request resolved: facebook/mysql-5.6#1461 Differential Revision: D58594610 fbshipit-source-id: 90e90875051cad3221fb5c485c787ea09a18efb8
1 parent 7433fdd commit 48ac24a

File tree

7 files changed

+119
-130
lines changed

7 files changed

+119
-130
lines changed

share/messages_to_clients.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10136,7 +10136,7 @@ ER_SK_POPULATE_DURING_ALTER
1013610136
eng "MyRocks failed populating secondary key during alter."
1013710137

1013810138
ER_CF_DIFFERENT
10139-
eng "Column family ('%s') flag (%d) is different from an existing flag (%d). Assign a new CF flag, or do not change existing CF flag."
10139+
eng "Column family ('%.*s') flag (%d) is different from an existing flag (%d). Assign a new CF flag, or do not change existing CF flag."
1014010140

1014110141
ER_RDB_TTL_UNSUPPORTED
1014210142
eng "TTL support is currently disabled when table has a hidden PK."

storage/rocksdb/ha_rocksdb.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8532,7 +8532,7 @@ bool ha_rocksdb::create_cfs(
85328532
return true;
85338533
}
85348534

8535-
if (cf_manager.create_cf_flags_if_needed(local_dict_manager,
8535+
if (cf_manager.create_cf_flags_if_needed(*local_dict_manager,
85368536
cf_handle->GetID(), cf_name,
85378537
per_part_match_found)) {
85388538
return true;
@@ -8545,7 +8545,7 @@ bool ha_rocksdb::create_cfs(
85458545
auto &cf = cfs[i];
85468546

85478547
cf.cf_handle = cf_handle;
8548-
cf.is_reverse_cf = Rdb_cf_manager::is_cf_name_reverse(cf_name.c_str());
8548+
cf.is_reverse_cf = Rdb_cf_manager::is_cf_name_reverse(cf_name);
85498549
cf.is_per_partition_cf = per_part_match_found;
85508550
}
85518551

@@ -16876,7 +16876,7 @@ static int rocksdb_validate_update_cf_options(
1687616876

1687716877
// Basic sanity checking and parsing the options into a map. If this fails
1687816878
// then there's no point to proceed.
16879-
if (!Rdb_cf_options::parse_cf_options(str, &option_map, &output)) {
16879+
if (!Rdb_cf_options::parse_cf_options(str, option_map, &output)) {
1688016880
my_printf_error(ER_WRONG_VALUE_FOR_VAR, "%s", MYF(0), output.str().c_str());
1688116881
return HA_EXIT_FAILURE;
1688216882
}
@@ -16929,7 +16929,7 @@ static void rocksdb_set_update_cf_options(
1692916929
Rdb_cf_options::Name_to_config_t option_map;
1693016930

1693116931
// This should never fail, because of rocksdb_validate_update_cf_options
16932-
if (!Rdb_cf_options::parse_cf_options(val, &option_map)) {
16932+
if (!Rdb_cf_options::parse_cf_options(val, option_map)) {
1693316933
return;
1693416934
}
1693516935

storage/rocksdb/rdb_cf_manager.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
namespace myrocks {
4040

4141
/* Check if ColumnFamily name says it's a reverse-ordered CF */
42-
bool Rdb_cf_manager::is_cf_name_reverse(const char *const name) {
43-
/* nullptr means the default CF is used.. (TODO: can the default CF be
42+
bool Rdb_cf_manager::is_cf_name_reverse(std::string_view name) {
43+
/* Empty string means the default CF is used. (TODO: can the default CF be
4444
* reverse?) */
45-
return (name && !strncmp(name, "rev:", 4));
45+
return name.compare(0, 4, "rev:") == 0;
4646
}
4747

4848
bool Rdb_cf_manager::init(
@@ -456,33 +456,33 @@ int Rdb_cf_manager::drop_cf(Rdb_ddl_manager *const ddl_manager,
456456
}
457457

458458
int Rdb_cf_manager::create_cf_flags_if_needed(
459-
const Rdb_dict_manager *const dict_manager, const uint32 &cf_id,
460-
const std::string &cf_name, const bool is_per_partition_cf) {
459+
const Rdb_dict_manager &dict_manager, uint32_t cf_id,
460+
std::string_view cf_name, bool is_per_partition_cf) {
461461
assert(!cf_name.empty());
462462
uchar flags =
463-
(is_cf_name_reverse(cf_name.c_str()) ? Rdb_key_def::REVERSE_CF_FLAG : 0) |
463+
(is_cf_name_reverse(cf_name) ? Rdb_key_def::REVERSE_CF_FLAG : 0) |
464464
(is_per_partition_cf ? Rdb_key_def::PER_PARTITION_CF_FLAG : 0);
465465

466466
uint existing_cf_flags;
467-
if (dict_manager->get_cf_flags(cf_id, &existing_cf_flags)) {
467+
if (dict_manager.get_cf_flags(cf_id, &existing_cf_flags)) {
468468
// For the purposes of comparison we'll clear the partitioning bit. The
469469
// intent here is to make sure that both partitioned and non-partitioned
470470
// tables can refer to the same CF.
471471
existing_cf_flags &= ~Rdb_key_def::CF_FLAGS_TO_IGNORE;
472472
flags &= ~Rdb_key_def::CF_FLAGS_TO_IGNORE;
473473

474474
if (existing_cf_flags != flags) {
475-
my_error(ER_CF_DIFFERENT, MYF(0), cf_name.c_str(), flags,
476-
existing_cf_flags);
475+
my_error(ER_CF_DIFFERENT, MYF(0), static_cast<int>(cf_name.length()),
476+
cf_name.data(), flags, existing_cf_flags);
477477

478478
return HA_EXIT_FAILURE;
479479
}
480480
} else {
481-
const std::unique_ptr<rocksdb::WriteBatch> wb = dict_manager->begin();
481+
const auto wb = dict_manager.begin();
482482
rocksdb::WriteBatch *const batch = wb.get();
483483

484-
dict_manager->add_cf_flags(batch, cf_id, flags);
485-
dict_manager->commit(batch);
484+
dict_manager.add_cf_flags(batch, cf_id, flags);
485+
dict_manager.commit(batch);
486486
}
487487

488488
return HA_EXIT_SUCCESS;

storage/rocksdb/rdb_cf_manager.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/* C++ system header files */
2020
#include <map>
2121
#include <string>
22+
#include <string_view>
2223
#include <vector>
2324

2425
/* RocksDB header files */
@@ -61,7 +62,7 @@ class Rdb_cf_manager : public Ensure_initialized {
6162
Rdb_cf_manager &operator=(const Rdb_cf_manager &) = delete;
6263
Rdb_cf_manager() = default;
6364

64-
static bool is_cf_name_reverse(const char *const name);
65+
[[nodiscard]] static bool is_cf_name_reverse(std::string_view name);
6566

6667
/*
6768
This is called right after the DB::Open() call. The parameters describe
@@ -108,9 +109,9 @@ class Rdb_cf_manager : public Ensure_initialized {
108109
Rdb_dict_manager *const dict_manager, const std::string &cf_name);
109110

110111
/* Create cf flags if it does not exist */
111-
int create_cf_flags_if_needed(const Rdb_dict_manager *const dict_manager,
112-
const uint32 &cf_id, const std::string &cf_name,
113-
const bool is_per_partition_cf = false);
112+
[[nodiscard]] int create_cf_flags_if_needed(
113+
const Rdb_dict_manager &dict_manager, uint32_t cf_id,
114+
std::string_view cf_name, bool is_per_partition_cf = false);
114115

115116
/* return true when success */
116117
bool get_cf_options(const std::string &cf_name,

0 commit comments

Comments
 (0)