26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_GTID_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_GTID_H_
48 constexpr std::array<char, 16> hex_chars = {
49 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
50 '8',
'9',
'A',
'B',
'C',
'D',
'E',
'F',
54 out.reserve(
raw.size() * 2 + 4);
57 for (uint8_t ch :
raw) {
66 out += hex_chars[ch >> 4];
67 out += hex_chars[ch & 0xf];
74template <
typename ValueType>
75ValueType
abs(
const ValueType v1,
const ValueType v2) {
76 if (v1 < v2)
return v2 - v1;
77 if (v1 > v2)
return v1 - v2;
82template <
typename ValueType>
83ValueType
value(
const std::optional<ValueType> &v) {
87template <
typename ValueType>
88inline ValueType
value(
const ValueType &v) {
92template <
typename ValueType>
97template <
typename ValueType>
102template <
typename ValueType,
typename X>
107template <
typename ValueType,
typename X,
typename... Args>
108ValueType
max(
X &&first, Args &&...rest) {
109 ValueType rest_value = inner::max<ValueType>(rest...);
110 if (!
has_value(first))
return rest_value;
111 if (rest_value >
value(first))
return rest_value;
130 if (
end_.has_value() != other.
end_.has_value())
return false;
131 if (!
end_.has_value())
return true;
133 return end_.value() == other.
end_.value();
139 if (
end_.has_value()) {
140 if (
end_.value() < other.
start_)
return false;
142 if (!other.
end_.has_value())
return true;
144 return other.
end_.value() <=
end_.value();
147 if (other.
end_.has_value() && other.
end_.value() !=
start_)
return false;
156 switch (args.size()) {
167 if (0 ==
start_)
return false;
168 if (
end_.has_value() && 0 ==
end_.value())
return false;
187 }
else if (
end_.has_value() &&
end_.value() == (other.
start_ - 1)) {
220 if (1 ==
static_cast<int64_t
>(other.
start_ -
end_.value())) {
225 if (1 ==
static_cast<int64_t
>(
start_ - other.
end_.value())) {
236 if (
end_.has_value()) {
249 uint64_t
size()
const {
return 1; }
282 if (!other.
has(
r))
return false;
290 if (
r == other)
return true;
297 if (
r.contains(other))
return true;
309 bool parse(
const std::vector<std::string> &values) {
310 for (
const auto &v : values) {
312 if (!(*range).parse(v))
return false;
329 if (other.
get_start() < (*it).get_start()) {
348template <
typename Range>
351 template <
typename...
T>
355 if (
uid_ != other.
uid_)
return false;
360 template <
typename OtherRange>
362 if (
uid_ != other.
uid_)
return false;
364 bool all_matched =
false;
365 for (
const auto &orange : other.
range_) {
366 if (!
r.contains(orange))
break;
369 if (all_matched)
return true;
374 bool parse(
const std::string >id) {
376 helper::string::unhex<std::string, helper::string::get_unhex_character>(
392 if (
r.try_merge(
range))
return true;
397 template <
typename SomeRange>
399 if (
uid_ != gtid.
uid_)
return false;
404 template <
typename SomeRange>
406 if (!(other.
uid_ ==
uid_))
return false;
413 template <
typename SomeRange>
425 template <
typename SomeRange>
442 if (!
parse(v))
throw std::runtime_error(
"Invalid GTID");
448 if (gtid_parts.size() != 2)
return false;
461 if (!
parse(v))
throw std::runtime_error(
"Invalid GTID-set");
467 if (gtid_parts.size() < 2)
return false;
469 gtid_parts.erase(gtid_parts.begin());
GtidSet()
Definition: gtid.h:458
bool parse(const std::string &v)
Definition: gtid.h:465
Gtid< inner::GtidSetOfRanges > Parent
Definition: gtid.h:456
GtidSet(const std::string &v)
Definition: gtid.h:460
bool parse(const std::string &v)
Definition: gtid.h:446
Gtid(const GTIDuuid &uid, const inner::GtidRange &r)
Definition: gtid.h:440
Gtid(const std::string &v)
Definition: gtid.h:441
Gtid()
Definition: gtid.h:439
std::string to_string() const
Definition: gtid.h:47
bool try_merge(const GtidRange &other)
Definition: gtid.h:173
uint64_t get_start() const
Definition: gtid.h:242
std::optional< uint64_t > end_
Definition: gtid.h:259
GtidRange & operator=(const GtidRange &other)
Definition: gtid.h:122
bool parse(const std::string &value)
Definition: gtid.h:154
GtidRange * end()
Definition: gtid.h:246
std::string to_string() const
Definition: gtid.h:233
GtidRange(const GtidRange &other)
Definition: gtid.h:120
const std::optional< uint64_t > & get_end() const
Definition: gtid.h:243
bool contains(const GtidRange &other) const
Definition: gtid.h:136
GtidRange(uint64_t start=0, std::optional< uint64_t > end={})
Definition: gtid.h:117
GtidRange * begin()
Definition: gtid.h:245
uint64_t size() const
Definition: gtid.h:249
const GtidRange * begin() const
Definition: gtid.h:247
bool is_point() const
Definition: gtid.h:152
uint64_t start_
Definition: gtid.h:258
const GtidRange * end() const
Definition: gtid.h:248
bool operator==(const GtidRange &other) const
Definition: gtid.h:128
bool is_between(const uint64_t value) const
Definition: gtid.h:252
GtidSetOfRanges(const GtidSetOfRanges &other)
Definition: gtid.h:265
bool has(const GtidRange &other) const
Definition: gtid.h:288
GtidSetOfRanges()
Definition: gtid.h:264
auto end()
Definition: gtid.h:340
bool operator==(const GtidSetOfRanges &other) const
Definition: gtid.h:278
bool contains(const GtidSetOfRanges &other) const
Definition: gtid.h:302
GtidSetOfRanges & operator=(const GtidSetOfRanges &other)
Definition: gtid.h:273
bool contains(const GtidRange &other) const
Definition: gtid.h:295
bool parse(const std::vector< std::string > &values)
Definition: gtid.h:309
GtidSetOfRanges & operator=(const GtidRange &other)
Definition: gtid.h:267
uint64_t size() const
Definition: gtid.h:343
std::string to_string() const
Definition: gtid.h:317
auto begin() const
Definition: gtid.h:341
std::list< GtidRange > ranges_
Definition: gtid.h:345
void insert(const GtidRange &other)
Definition: gtid.h:325
auto end() const
Definition: gtid.h:342
auto begin()
Definition: gtid.h:339
const GTIDuuid & get_uid() const
Definition: gtid.h:421
bool insert(const Gtid< SomeRange > &other)
Definition: gtid.h:405
Range range_
Definition: gtid.h:428
bool operator==(const Gtid &other) const
Definition: gtid.h:354
GTIDuuid uid_
Definition: gtid.h:427
bool try_merge(const Gtid< SomeRange > >id)
Definition: gtid.h:398
const Range & get_range() const
Definition: gtid.h:422
uint64_t size() const
Definition: gtid.h:419
Gtid(const GTIDuuid &uid, T &&...v)
Definition: gtid.h:352
bool parse(const std::string >id)
Definition: gtid.h:374
void set(const Gtid< SomeRange > &other)
Definition: gtid.h:414
std::string to_string() const
Definition: gtid.h:384
bool contains(const Gtid< OtherRange > &other) const
Definition: gtid.h:361
bool try_merge(const GtidRange &range)
Definition: gtid.h:390
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:180
#define T
Definition: jit_executor_value.cc:373
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:51
std::pair< os_offset_t, os_offset_t > Range
Represents the chunk in bytes : first element represents the beginning offset of the chunk and,...
Definition: ddl0impl-file-reader.h:44
uint64_t to_uint64(const String &str)
Definition: from.h:36
ValueType abs(const ValueType v1, const ValueType v2)
Definition: gtid.h:75
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
bool has_value(const std::optional< ValueType > &v)
Definition: gtid.h:93
ValueType max(X &&first)
Definition: gtid.h:103
std::vector< Gtid > Gtids
Definition: gtid.h:474
inner::GTIDuuid GTIDuuid
Definition: gtid.h:433
std::vector< GtidSet > GtidSets
Definition: gtid.h:475
Definition: authorize_manager.h:48
mrs::database::entry::UniversalId UniversalId
Definition: universal_id.h:33
HARNESS_EXPORT std::vector< std::string > split_string(const std::string_view &data, const char delimiter, bool allow_empty=true)
Splits a string using a delimiter.
Definition: string_utils.cc:37
bool parse(MYSQL_THD thd, const string &query, bool is_prepared, Condition_handler *handler)
Definition: services.cc:81
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
struct result result
Definition: result.h:34
Array raw
Definition: universal_id.h:58
constexpr static uint64_t k_size
Definition: universal_id.h:46
static void from_raw(UniversalId *uid, const char *binray)
Definition: universal_id.h:97
Definition: gen_lex_token.cc:149
#define X(b)
Definition: xcom_base.cc:9207