diff options
Diffstat (limited to 'storage/rocksdb/rdb_datadic.h')
-rw-r--r-- | storage/rocksdb/rdb_datadic.h | 518 |
1 files changed, 311 insertions, 207 deletions
diff --git a/storage/rocksdb/rdb_datadic.h b/storage/rocksdb/rdb_datadic.h index 27ca5ca980d..0a3a747c633 100644 --- a/storage/rocksdb/rdb_datadic.h +++ b/storage/rocksdb/rdb_datadic.h @@ -22,6 +22,7 @@ #include <map> #include <mutex> #include <string> +#include <unordered_map> #include <unordered_set> #include <utility> #include <vector> @@ -48,6 +49,27 @@ class Rdb_ddl_manager; const uint32_t GTID_BUF_LEN = 60; +class Rdb_convert_to_record_key_decoder { + public: + Rdb_convert_to_record_key_decoder() = default; + Rdb_convert_to_record_key_decoder( + const Rdb_convert_to_record_key_decoder &decoder) = delete; + Rdb_convert_to_record_key_decoder &operator=( + const Rdb_convert_to_record_key_decoder &decoder) = delete; + static int decode(uchar *const buf, uint *offset, Rdb_field_packing *fpi, + TABLE *table, Field *field, bool has_unpack_info, + Rdb_string_reader *reader, + Rdb_string_reader *unpack_reader); + static int skip(const Rdb_field_packing *fpi, const Field *field, + Rdb_string_reader *reader, Rdb_string_reader *unpack_reader); + + private: + static int decode_field(Rdb_field_packing *fpi, Field *field, + Rdb_string_reader *reader, + const uchar *const default_value, + Rdb_string_reader *unpack_reader); +}; + /* @brief Field packing context. @@ -63,7 +85,7 @@ const uint32_t GTID_BUF_LEN = 60; unpack_info is passed as context data between the two. */ class Rdb_pack_field_context { -public: + public: Rdb_pack_field_context(const Rdb_pack_field_context &) = delete; Rdb_pack_field_context &operator=(const Rdb_pack_field_context &) = delete; @@ -74,6 +96,45 @@ public: Rdb_string_writer *writer; }; +class Rdb_key_field_iterator { + private: + Rdb_field_packing *m_pack_info; + int m_iter_index; + int m_iter_end; + TABLE *m_table; + Rdb_string_reader *m_reader; + Rdb_string_reader *m_unp_reader; + uint m_curr_bitmap_pos; + const MY_BITMAP *m_covered_bitmap; + uchar *m_buf; + bool m_has_unpack_info; + const Rdb_key_def *m_key_def; + bool m_secondary_key; + bool m_hidden_pk_exists; + bool m_is_hidden_pk; + bool m_is_null; + Field *m_field; + uint m_offset; + Rdb_field_packing *m_fpi; + + public: + Rdb_key_field_iterator(const Rdb_key_field_iterator &) = delete; + Rdb_key_field_iterator &operator=(const Rdb_key_field_iterator &) = delete; + Rdb_key_field_iterator(const Rdb_key_def *key_def, + Rdb_field_packing *pack_info, + Rdb_string_reader *reader, + Rdb_string_reader *unp_reader, TABLE *table, + bool has_unpack_info, const MY_BITMAP *covered_bitmap, + uchar *buf); + + int next(); + bool has_next(); + bool get_is_null() const; + Field *get_field() const; + int get_field_index() const; + void *get_dst() const; +}; + struct Rdb_collation_codec; struct Rdb_index_info; @@ -81,18 +142,19 @@ struct Rdb_index_info; C-style "virtual table" allowing different handling of packing logic based on the field type. See Rdb_field_packing::setup() implementation. */ -using rdb_make_unpack_info_t = - void (Rdb_key_def::*)(const Rdb_collation_codec *codec, const Field *field, - Rdb_pack_field_context *pack_ctx) const; -using rdb_index_field_unpack_t = int (Rdb_key_def::*)( - Rdb_field_packing *fpi, Field *field, uchar *field_ptr, - Rdb_string_reader *reader, Rdb_string_reader *unpack_reader) const; -using rdb_index_field_skip_t = - int (Rdb_key_def::*)(const Rdb_field_packing *fpi, const Field *field, - Rdb_string_reader *reader) const; -using rdb_index_field_pack_t = - void (Rdb_key_def::*)(Rdb_field_packing *fpi, Field *field, uchar *buf, - uchar **dst, Rdb_pack_field_context *pack_ctx) const; +using rdb_make_unpack_info_t = void (*)(const Rdb_collation_codec *codec, + const Field *field, + Rdb_pack_field_context *pack_ctx); +using rdb_index_field_unpack_t = int (*)(Rdb_field_packing *fpi, Field *field, + uchar *field_ptr, + Rdb_string_reader *reader, + Rdb_string_reader *unpack_reader); +using rdb_index_field_skip_t = int (*)(const Rdb_field_packing *fpi, + const Field *field, + Rdb_string_reader *reader); +using rdb_index_field_pack_t = void (*)(Rdb_field_packing *fpi, Field *field, + uchar *buf, uchar **dst, + Rdb_pack_field_context *pack_ctx); const uint RDB_INVALID_KEY_LEN = uint(-1); @@ -187,7 +249,7 @@ enum { */ class Rdb_key_def { -public: + public: /* Convert a key from KeyTupleFormat to mem-comparable form */ uint pack_index_tuple(TABLE *const tbl, uchar *const pack_buffer, uchar *const packed_tuple, const uchar *const key_tuple, @@ -202,23 +264,17 @@ public: uint pack_record(const TABLE *const tbl, uchar *const pack_buffer, const uchar *const record, uchar *const packed_tuple, Rdb_string_writer *const unpack_info, - const bool &should_store_row_debug_checksums, - const longlong &hidden_pk_id = 0, uint n_key_parts = 0, + const bool should_store_row_debug_checksums, + const longlong hidden_pk_id = 0, uint n_key_parts = 0, uint *const n_null_fields = nullptr, - uint *const ttl_pk_offset = nullptr, const char *const ttl_bytes = nullptr) const; /* Pack the hidden primary key into mem-comparable form. */ - uint pack_hidden_pk(const longlong &hidden_pk_id, + uint pack_hidden_pk(const longlong hidden_pk_id, uchar *const packed_tuple) const; - int unpack_field(Rdb_field_packing *const fpi, - Field *const field, - Rdb_string_reader* reader, - const uchar *const default_value, - Rdb_string_reader* unp_reader) const; int unpack_record(TABLE *const table, uchar *const buf, const rocksdb::Slice *const packed_key, const rocksdb::Slice *const unpack_info, - const bool &verify_row_debug_checksums) const; + const bool verify_row_debug_checksums) const; static bool unpack_info_has_checksum(const rocksdb::Slice &unpack_info); int compare_keys(const rocksdb::Slice *key1, const rocksdb::Slice *key2, @@ -240,33 +296,67 @@ public: /* Get the first key that you need to position at to start iterating. - Stores into *key a "supremum" or "infimum" key value for the index. - + @parameters key OUT Big Endian, value is m_index_number or + m_index_number + 1 + @parameters size OUT key size, value is INDEX_NUMBER_SIZE @return Number of bytes in the key that are usable for bloom filter use. */ inline int get_first_key(uchar *const key, uint *const size) const { - if (m_is_reverse_cf) + if (m_is_reverse_cf) { get_supremum_key(key, size); - else + /* Find out how many bytes of infimum are the same as m_index_number */ + uchar unmodified_key[INDEX_NUMBER_SIZE]; + rdb_netbuf_store_index(unmodified_key, m_index_number); + int i; + for (i = 0; i < INDEX_NUMBER_SIZE; i++) { + if (key[i] != unmodified_key[i]) { + break; + } + } + return i; + } else { get_infimum_key(key, size); + // For infimum key, its value will be m_index_number + // Thus return its own size instead. + return INDEX_NUMBER_SIZE; + } + } + + /* + The same as get_first_key, but get the key for the last entry in the index + @parameters key OUT Big Endian, value is m_index_number or + m_index_number + 1 + @parameters size OUT key size, value is INDEX_NUMBER_SIZE - /* Find out how many bytes of infimum are the same as m_index_number */ - uchar unmodified_key[INDEX_NUMBER_SIZE]; - rdb_netbuf_store_index(unmodified_key, m_index_number); - int i; - for (i = 0; i < INDEX_NUMBER_SIZE; i++) { - if (key[i] != unmodified_key[i]) - break; + @return Number of bytes in the key that are usable for bloom filter use. + */ + inline int get_last_key(uchar *const key, uint *const size) const { + if (m_is_reverse_cf) { + get_infimum_key(key, size); + // For infimum key, its value will be m_index_number + // Thus return its own size instead. + return INDEX_NUMBER_SIZE; + } else { + get_supremum_key(key, size); + /* Find out how many bytes are the same as m_index_number */ + uchar unmodified_key[INDEX_NUMBER_SIZE]; + rdb_netbuf_store_index(unmodified_key, m_index_number); + int i; + for (i = 0; i < INDEX_NUMBER_SIZE; i++) { + if (key[i] != unmodified_key[i]) { + break; + } + } + return i; } - return i; } /* Make a key that is right after the given key. */ - static int successor(uchar *const packed_tuple, const uint &len); + static int successor(uchar *const packed_tuple, const uint len); /* Make a key that is right before the given key. */ - static int predecessor(uchar *const packed_tuple, const uint &len); + static int predecessor(uchar *const packed_tuple, const uint len); /* This can be used to compare prefixes. @@ -282,19 +372,18 @@ public: /* Check if given mem-comparable key belongs to this index */ bool covers_key(const rocksdb::Slice &slice) const { - if (slice.size() < INDEX_NUMBER_SIZE) - return false; + if (slice.size() < INDEX_NUMBER_SIZE) return false; - if (memcmp(slice.data(), m_index_number_storage_form, INDEX_NUMBER_SIZE)) + if (memcmp(slice.data(), m_index_number_storage_form, INDEX_NUMBER_SIZE)) { return false; + } return true; } void get_lookup_bitmap(const TABLE *table, MY_BITMAP *map) const; - bool covers_lookup(TABLE *const table, - const rocksdb::Slice *const unpack_info, + bool covers_lookup(const rocksdb::Slice *const unpack_info, const MY_BITMAP *const map) const; inline bool use_covered_bitmap_format() const { @@ -302,6 +391,9 @@ public: m_kv_format_version >= SECONDARY_FORMAT_VERSION_UPDATE3; } + /* Indicates that all key parts can be unpacked to cover a secondary lookup */ + bool can_cover_lookup() const; + /* Return true if the passed mem-comparable key - is from this index, and @@ -339,7 +431,7 @@ public: uint get_key_parts() const { return m_key_parts; } - uint get_ttl_field_offset() const { return m_ttl_field_offset; } + uint get_ttl_field_index() const { return m_ttl_field_index; } /* Get a field object for key part #part_no @@ -377,7 +469,7 @@ public: VERSION_SIZE = 2, CF_NUMBER_SIZE = 4, CF_FLAG_SIZE = 4, - PACKED_SIZE = 4, // one int + PACKED_SIZE = 4, // one int }; // bit flags for combining bools when writing to disk @@ -505,7 +597,7 @@ public: uint64 *ttl_duration); static uint extract_ttl_col(const TABLE *const table_arg, const Rdb_tbl_def *const tbl_def_arg, - std::string *ttl_column, uint *ttl_field_offset, + std::string *ttl_column, uint *ttl_field_index, bool skip_checks = false); inline bool has_ttl() const { return m_ttl_duration > 0; } @@ -517,15 +609,14 @@ public: const uchar *const val, enum INDEX_FLAG flag) const; - static const std::string - gen_qualifier_for_table(const char *const qualifier, - const std::string &partition_name = ""); - static const std::string - gen_cf_name_qualifier_for_partition(const std::string &s); - static const std::string - gen_ttl_duration_qualifier_for_partition(const std::string &s); - static const std::string - gen_ttl_col_qualifier_for_partition(const std::string &s); + static const std::string gen_qualifier_for_table( + const char *const qualifier, const std::string &partition_name = ""); + static const std::string gen_cf_name_qualifier_for_partition( + const std::string &s); + static const std::string gen_ttl_duration_qualifier_for_partition( + const std::string &s); + static const std::string gen_ttl_col_qualifier_for_partition( + const std::string &s); static const std::string parse_comment_for_qualifier( const std::string &comment, const TABLE *const table_arg, @@ -535,133 +626,133 @@ public: rocksdb::ColumnFamilyHandle *get_cf() const { return m_cf_handle; } /* Check if keypart #kp can be unpacked from index tuple */ - inline bool can_unpack(const uint &kp) const; + inline bool can_unpack(const uint kp) const; /* Check if keypart #kp needs unpack info */ - inline bool has_unpack_info(const uint &kp) const; + inline bool has_unpack_info(const uint kp) const; /* Check if given table has a primary key */ static bool table_has_hidden_pk(const TABLE *const table); - void report_checksum_mismatch(const bool &is_key, const char *const data, + void report_checksum_mismatch(const bool is_key, const char *const data, const size_t data_size) const; /* Check if index is at least pk_min if it is a PK, or at least sk_min if SK.*/ - bool index_format_min_check(const int &pk_min, const int &sk_min) const; + bool index_format_min_check(const int pk_min, const int sk_min) const; - void pack_with_make_sort_key( + static void pack_with_make_sort_key( Rdb_field_packing *const fpi, Field *const field, uchar *buf MY_ATTRIBUTE((__unused__)), uchar **dst, - Rdb_pack_field_context *const pack_ctx MY_ATTRIBUTE((__unused__))) const; + Rdb_pack_field_context *const pack_ctx MY_ATTRIBUTE((__unused__))); - void pack_with_varchar_encoding( + static void pack_with_varchar_encoding( Rdb_field_packing *const fpi, Field *const field, uchar *buf, uchar **dst, - Rdb_pack_field_context *const pack_ctx MY_ATTRIBUTE((__unused__))) const; - - void - pack_with_varchar_space_pad(Rdb_field_packing *const fpi, Field *const field, - uchar *buf, uchar **dst, - Rdb_pack_field_context *const pack_ctx) const; - - int unpack_integer(Rdb_field_packing *const fpi, Field *const field, - uchar *const to, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader - MY_ATTRIBUTE((__unused__))) const; - - int unpack_double(Rdb_field_packing *const fpi MY_ATTRIBUTE((__unused__)), - Field *const field MY_ATTRIBUTE((__unused__)), - uchar *const field_ptr, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader - MY_ATTRIBUTE((__unused__))) const; - - int unpack_float(Rdb_field_packing *const fpi, - Field *const field MY_ATTRIBUTE((__unused__)), - uchar *const field_ptr, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader - MY_ATTRIBUTE((__unused__))) const; - - int unpack_binary_str(Rdb_field_packing *const fpi, Field *const field, - uchar *const to, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader - MY_ATTRIBUTE((__unused__))) const; - - int unpack_binary_or_utf8_varchar( - Rdb_field_packing *const fpi, Field *const field, uchar *dst, + Rdb_pack_field_context *const pack_ctx MY_ATTRIBUTE((__unused__))); + + static void pack_with_varchar_space_pad( + Rdb_field_packing *const fpi, Field *const field, uchar *buf, uchar **dst, + Rdb_pack_field_context *const pack_ctx); + + static int unpack_integer(Rdb_field_packing *const fpi, Field *const field, + uchar *const to, Rdb_string_reader *const reader, + Rdb_string_reader *const unp_reader + MY_ATTRIBUTE((__unused__))); + + static int unpack_double( + Rdb_field_packing *const fpi MY_ATTRIBUTE((__unused__)), + Field *const field MY_ATTRIBUTE((__unused__)), uchar *const field_ptr, + Rdb_string_reader *const reader, + Rdb_string_reader *const unp_reader MY_ATTRIBUTE((__unused__))); + + static int unpack_float( + Rdb_field_packing *const fpi, + Field *const field MY_ATTRIBUTE((__unused__)), uchar *const field_ptr, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader MY_ATTRIBUTE((__unused__))) const; + Rdb_string_reader *const unp_reader MY_ATTRIBUTE((__unused__))); + + static int unpack_binary_str(Rdb_field_packing *const fpi, Field *const field, + uchar *const to, Rdb_string_reader *const reader, + Rdb_string_reader *const unp_reader + MY_ATTRIBUTE((__unused__))); - int unpack_binary_or_utf8_varchar_space_pad( + static int unpack_binary_or_utf8_varchar( Rdb_field_packing *const fpi, Field *const field, uchar *dst, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader) const; + Rdb_string_reader *const unp_reader MY_ATTRIBUTE((__unused__))); - int unpack_newdate(Rdb_field_packing *const fpi, - Field *const field MY_ATTRIBUTE((__unused__)), - uchar *const field_ptr, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader - MY_ATTRIBUTE((__unused__))) const; + static int unpack_binary_or_utf8_varchar_space_pad( + Rdb_field_packing *const fpi, Field *const field, uchar *dst, + Rdb_string_reader *const reader, Rdb_string_reader *const unp_reader); - int unpack_utf8_str(Rdb_field_packing *const fpi, Field *const field, - uchar *dst, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader - MY_ATTRIBUTE((__unused__))) const; + static int unpack_newdate( + Rdb_field_packing *const fpi, + Field *const field MY_ATTRIBUTE((__unused__)), uchar *const field_ptr, + Rdb_string_reader *const reader, + Rdb_string_reader *const unp_reader MY_ATTRIBUTE((__unused__))); - int unpack_unknown_varchar(Rdb_field_packing *const fpi, Field *const field, + static int unpack_utf8_str(Rdb_field_packing *const fpi, Field *const field, uchar *dst, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader) const; + Rdb_string_reader *const unp_reader + MY_ATTRIBUTE((__unused__))); - int unpack_simple_varchar_space_pad( + static int unpack_unknown_varchar(Rdb_field_packing *const fpi, + Field *const field, uchar *dst, + Rdb_string_reader *const reader, + Rdb_string_reader *const unp_reader); + + static int unpack_simple_varchar_space_pad( Rdb_field_packing *const fpi, Field *const field, uchar *dst, - Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader) const; + Rdb_string_reader *const reader, Rdb_string_reader *const unp_reader); - int unpack_simple(Rdb_field_packing *const fpi, - Field *const field MY_ATTRIBUTE((__unused__)), - uchar *const dst, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader) const; + static int unpack_simple(Rdb_field_packing *const fpi, + Field *const field MY_ATTRIBUTE((__unused__)), + uchar *const dst, Rdb_string_reader *const reader, + Rdb_string_reader *const unp_reader); - int unpack_unknown(Rdb_field_packing *const fpi, Field *const field, - uchar *const dst, Rdb_string_reader *const reader, - Rdb_string_reader *const unp_reader) const; + static int unpack_unknown(Rdb_field_packing *const fpi, Field *const field, + uchar *const dst, Rdb_string_reader *const reader, + Rdb_string_reader *const unp_reader); - int unpack_floating_point(uchar *const dst, Rdb_string_reader *const reader, - const size_t &size, const int &exp_digit, - const uchar *const zero_pattern, - const uchar *const zero_val, - void (*swap_func)(uchar *, const uchar *)) const; + static int unpack_floating_point(uchar *const dst, + Rdb_string_reader *const reader, + const size_t size, const int exp_digit, + const uchar *const zero_pattern, + const uchar *const zero_val, + void (*swap_func)(uchar *, const uchar *)); - void make_unpack_simple_varchar(const Rdb_collation_codec *const codec, - const Field *const field, - Rdb_pack_field_context *const pack_ctx) const; + static void make_unpack_simple_varchar( + const Rdb_collation_codec *const codec, const Field *const field, + Rdb_pack_field_context *const pack_ctx); - void make_unpack_simple(const Rdb_collation_codec *const codec, - const Field *const field, - Rdb_pack_field_context *const pack_ctx) const; + static void make_unpack_simple(const Rdb_collation_codec *const codec, + const Field *const field, + Rdb_pack_field_context *const pack_ctx); - void make_unpack_unknown( + static void make_unpack_unknown( const Rdb_collation_codec *codec MY_ATTRIBUTE((__unused__)), - const Field *const field, Rdb_pack_field_context *const pack_ctx) const; + const Field *const field, Rdb_pack_field_context *const pack_ctx); - void make_unpack_unknown_varchar( + static void make_unpack_unknown_varchar( const Rdb_collation_codec *const codec MY_ATTRIBUTE((__unused__)), - const Field *const field, Rdb_pack_field_context *const pack_ctx) const; + const Field *const field, Rdb_pack_field_context *const pack_ctx); - void dummy_make_unpack_info( + static void dummy_make_unpack_info( const Rdb_collation_codec *codec MY_ATTRIBUTE((__unused__)), const Field *field MY_ATTRIBUTE((__unused__)), - Rdb_pack_field_context *pack_ctx MY_ATTRIBUTE((__unused__))) const; + Rdb_pack_field_context *pack_ctx MY_ATTRIBUTE((__unused__))); - int skip_max_length(const Rdb_field_packing *const fpi, - const Field *const field MY_ATTRIBUTE((__unused__)), - Rdb_string_reader *const reader) const; + static int skip_max_length(const Rdb_field_packing *const fpi, + const Field *const field + MY_ATTRIBUTE((__unused__)), + Rdb_string_reader *const reader); - int skip_variable_length( - const Rdb_field_packing *const fpi MY_ATTRIBUTE((__unused__)), - const Field *const field, Rdb_string_reader *const reader) const; + static int skip_variable_length(const Rdb_field_packing *const fpi, + const Field *const field, + Rdb_string_reader *const reader); - int skip_variable_space_pad(const Rdb_field_packing *const fpi, - const Field *const field, - Rdb_string_reader *const reader) const; + static int skip_variable_space_pad(const Rdb_field_packing *const fpi, + const Field *const field, + Rdb_string_reader *const reader); inline bool use_legacy_varbinary_format() const { return !index_format_min_check(PRIMARY_FORMAT_VERSION_UPDATE2, @@ -674,7 +765,7 @@ public: private: #ifndef DBUG_OFF - inline bool is_storage_available(const int &offset, const int &needed) const { + inline bool is_storage_available(const int offset, const int needed) const { const int storage_length = static_cast<int>(max_storage_fmt_length()); return (storage_length - offset) >= needed; } @@ -682,7 +773,7 @@ public: inline bool is_storage_available(const int &offset, const int &needed) const { return 1; } -#endif // DBUG_OFF +#endif // DBUG_OFF /* Global number of this index (used as prefix in StorageFormat) */ const uint32 m_index_number; @@ -691,15 +782,15 @@ public: rocksdb::ColumnFamilyHandle *m_cf_handle; - void pack_legacy_variable_format(const uchar *src, size_t src_len, - uchar **dst) const; + static void pack_legacy_variable_format(const uchar *src, size_t src_len, + uchar **dst); - void pack_variable_format(const uchar *src, size_t src_len, - uchar **dst) const; + static void pack_variable_format(const uchar *src, size_t src_len, + uchar **dst); - uint calc_unpack_legacy_variable_format(uchar flag, bool *done) const; + static uint calc_unpack_legacy_variable_format(uchar flag, bool *done); - uint calc_unpack_variable_format(uchar flag, bool *done) const; + static uint calc_unpack_variable_format(uchar flag, bool *done); public: uint16_t m_index_dict_version; @@ -738,8 +829,6 @@ public: std::string m_ttl_column; private: - friend class Rdb_tbl_def; // for m_index_number above - /* Number of key parts in the primary key*/ uint m_pk_key_parts; @@ -770,7 +859,7 @@ public: Index of the TTL column in table->s->fields, if it exists. Default is UINT_MAX to denote that it does not exist. */ - uint m_ttl_field_offset; + uint m_ttl_field_index; /* Prefix extractor for the column family of the key definiton */ std::shared_ptr<const rocksdb::SliceTransform> m_prefix_extractor; @@ -818,7 +907,7 @@ extern std::array<const Rdb_collation_codec *, MY_ALL_CHARSETS_SIZE> rdb_collation_data; class Rdb_field_packing { -public: + public: Rdb_field_packing(const Rdb_field_packing &) = delete; Rdb_field_packing &operator=(const Rdb_field_packing &) = delete; Rdb_field_packing() = default; @@ -836,9 +925,10 @@ public: Valid only for VARCHAR fields. */ const CHARSET_INFO *m_varchar_charset; + bool m_use_legacy_varbinary_format; // (Valid when Variable Length Space Padded Encoding is used): - uint m_segment_size; // size of segment used + uint m_segment_size; // size of segment used // number of bytes used to store number of trimmed (or added) // spaces in the upack_info @@ -881,7 +971,7 @@ public: */ rdb_index_field_skip_t m_skip_func; -private: + private: /* Location of the field in the table (key number and key part number). @@ -907,12 +997,12 @@ private: uint m_keynr; uint m_key_part; -public: + public: bool setup(const Rdb_key_def *const key_descr, const Field *const field, - const uint &keynr_arg, const uint &key_part_arg, - const uint16 &key_length); + const uint keynr_arg, const uint key_part_arg, + const uint16 key_length); Field *get_field_in_table(const TABLE *const tbl) const; - void fill_hidden_pk_val(uchar **dst, const longlong &hidden_pk_id) const; + void fill_hidden_pk_val(uchar **dst, const longlong hidden_pk_id) const; }; /* @@ -923,7 +1013,7 @@ public: For encoding/decoding of index tuples, see Rdb_key_def. */ class Rdb_field_encoder { -public: + public: Rdb_field_encoder(const Rdb_field_encoder &) = delete; Rdb_field_encoder &operator=(const Rdb_field_encoder &) = delete; /* @@ -944,7 +1034,7 @@ public: uint m_null_offset; uint16 m_field_index; - uchar m_null_mask; // 0 means the field cannot be null + uchar m_null_mask; // 0 means the field cannot be null my_core::enum_field_types m_field_type; @@ -964,12 +1054,12 @@ inline Field *Rdb_key_def::get_table_field_for_part_no(TABLE *table, return m_pack_info[part_no].get_field_in_table(table); } -inline bool Rdb_key_def::can_unpack(const uint &kp) const { +inline bool Rdb_key_def::can_unpack(const uint kp) const { DBUG_ASSERT(kp < m_key_parts); return (m_pack_info[kp].m_unpack_func != nullptr); } -inline bool Rdb_key_def::has_unpack_info(const uint &kp) const { +inline bool Rdb_key_def::has_unpack_info(const uint kp) const { DBUG_ASSERT(kp < m_key_parts); return m_pack_info[kp].uses_unpack_info(); } @@ -984,7 +1074,7 @@ inline bool Rdb_key_def::has_unpack_info(const uint &kp) const { */ class Rdb_tbl_def { -private: + private: void check_if_is_mysql_system_table(); /* Stores 'dbname.tablename' */ @@ -997,7 +1087,7 @@ private: void set_name(const std::string &name); -public: + public: Rdb_tbl_def(const Rdb_tbl_def &) = delete; Rdb_tbl_def &operator=(const Rdb_tbl_def &) = delete; @@ -1006,18 +1096,20 @@ public: set_name(name); } - Rdb_tbl_def(const char *const name, const size_t &len) + Rdb_tbl_def(const char *const name, const size_t len) : m_key_descr_arr(nullptr), m_hidden_pk_val(0), m_auto_incr_val(0) { set_name(std::string(name, len)); } - explicit Rdb_tbl_def(const rocksdb::Slice &slice, const size_t &pos = 0) + explicit Rdb_tbl_def(const rocksdb::Slice &slice, const size_t pos = 0) : m_key_descr_arr(nullptr), m_hidden_pk_val(0), m_auto_incr_val(0) { set_name(std::string(slice.data() + pos, slice.size() - pos)); } ~Rdb_tbl_def(); + void check_and_set_read_free_rpl_table(); + /* Number of indexes */ uint m_key_count; @@ -1030,8 +1122,11 @@ public: /* Is this a system table */ bool m_is_mysql_system_table; + /* Is this table read free repl enabled */ + std::atomic_bool m_is_read_free_rpl_table{false}; + bool put_dict(Rdb_dict_manager *const dict, rocksdb::WriteBatch *const batch, - uchar *const key, const size_t &keylen); + const rocksdb::Slice &key); const std::string &full_tablename() const { return m_dbname_tablename; } const std::string &base_dbname() const { return m_dbname; } @@ -1050,12 +1145,12 @@ class Rdb_seq_generator { mysql_mutex_t m_mutex; -public: + public: Rdb_seq_generator(const Rdb_seq_generator &) = delete; Rdb_seq_generator &operator=(const Rdb_seq_generator &) = delete; Rdb_seq_generator() = default; - void init(const uint &initial_number) { + void init(const uint initial_number) { mysql_mutex_init(0, &m_mutex, MY_MUTEX_INIT_FAST); m_next_number = initial_number; } @@ -1080,14 +1175,17 @@ interface Rdb_tables_scanner { class Rdb_ddl_manager { Rdb_dict_manager *m_dict = nullptr; - my_core::HASH m_ddl_hash; // Contains Rdb_tbl_def elements + + // Contains Rdb_tbl_def elements + std::unordered_map<std::string, Rdb_tbl_def *> m_ddl_map; + // Maps index id to <table_name, index number> std::map<GL_INDEX_ID, std::pair<std::string, uint>> m_index_num_to_keydef; // Maps index id to key definitons not yet committed to data dictionary. // This is mainly used to store key definitions during ALTER TABLE. std::map<GL_INDEX_ID, std::shared_ptr<Rdb_key_def>> - m_index_num_to_uncommitted_keydef; + m_index_num_to_uncommitted_keydef; mysql_rwlock_t m_rwlock; Rdb_seq_generator m_sequence; @@ -1098,30 +1196,30 @@ class Rdb_ddl_manager { const std::shared_ptr<Rdb_key_def> &find(GL_INDEX_ID gl_index_id); -public: + public: Rdb_ddl_manager(const Rdb_ddl_manager &) = delete; Rdb_ddl_manager &operator=(const Rdb_ddl_manager &) = delete; Rdb_ddl_manager() {} /* Load the data dictionary from on-disk storage */ bool init(Rdb_dict_manager *const dict_arg, Rdb_cf_manager *const cf_manager, - const uint32_t &validate_tables); + const uint32_t validate_tables); void cleanup(); - Rdb_tbl_def *find(const std::string &table_name, const bool &lock = true); + Rdb_tbl_def *find(const std::string &table_name, const bool lock = true); std::shared_ptr<const Rdb_key_def> safe_find(GL_INDEX_ID gl_index_id); void set_stats(const std::unordered_map<GL_INDEX_ID, Rdb_index_stats> &stats); void adjust_stats(const std::vector<Rdb_index_stats> &new_data, const std::vector<Rdb_index_stats> &deleted_data = std::vector<Rdb_index_stats>()); - void persist_stats(const bool &sync = false); + void persist_stats(const bool sync = false); /* Modify the mapping and write it to on-disk storage */ int put_and_write(Rdb_tbl_def *const key_descr, rocksdb::WriteBatch *const batch); void remove(Rdb_tbl_def *const rec, rocksdb::WriteBatch *const batch, - const bool &lock = true); + const bool lock = true); bool rename(const std::string &from, const std::string &to, rocksdb::WriteBatch *const batch); @@ -1140,9 +1238,9 @@ public: void remove_uncommitted_keydefs( const std::unordered_set<std::shared_ptr<Rdb_key_def>> &indexes); -private: + private: /* Put the data into in-memory table (only) */ - int put(Rdb_tbl_def *const key_descr, const bool &lock = true); + int put(Rdb_tbl_def *const key_descr, const bool lock = true); /* Helper functions to be passed to my_core::HASH object */ static const uchar *get_hash_key(Rdb_tbl_def *const rec, size_t *const length, @@ -1170,7 +1268,7 @@ private: binlog_gtid */ class Rdb_binlog_manager { -public: + public: Rdb_binlog_manager(const Rdb_binlog_manager &) = delete; Rdb_binlog_manager &operator=(const Rdb_binlog_manager &) = delete; Rdb_binlog_manager() = default; @@ -1181,18 +1279,15 @@ public: rocksdb::WriteBatchBase *const batch); bool read(char *const binlog_name, my_off_t *const binlog_pos, char *const binlog_gtid) const; - void update_slave_gtid_info(const uint &id, const char *const db, + void update_slave_gtid_info(const uint id, const char *const db, const char *const gtid, rocksdb::WriteBatchBase *const write_batch); -private: + private: Rdb_dict_manager *m_dict = nullptr; - uchar m_key_buf[Rdb_key_def::INDEX_NUMBER_SIZE] = {0}; + Rdb_buf_writer<Rdb_key_def::INDEX_NUMBER_SIZE> m_key_writer; rocksdb::Slice m_key_slice; - rocksdb::Slice pack_value(uchar *const buf, const char *const binlog_name, - const my_off_t &binlog_pos, - const char *const binlog_gtid) const; bool unpack_value(const uchar *const value, size_t value_size, char *const binlog_name, my_off_t *const binlog_pos, char *const binlog_gtid) const; @@ -1259,7 +1354,7 @@ private: */ class Rdb_dict_manager { -private: + private: mysql_mutex_t m_mutex; rocksdb::TransactionDB *m_db = nullptr; rocksdb::ColumnFamilyHandle *m_system_cfh = nullptr; @@ -1271,18 +1366,27 @@ private: static void dump_index_id(uchar *const netbuf, Rdb_key_def::DATA_DICT_TYPE dict_type, const GL_INDEX_ID &gl_index_id); + template <size_t T> + static void dump_index_id(Rdb_buf_writer<T> *buf_writer, + Rdb_key_def::DATA_DICT_TYPE dict_type, + const GL_INDEX_ID &gl_index_id) { + buf_writer->write_uint32(dict_type); + buf_writer->write_uint32(gl_index_id.cf_id); + buf_writer->write_uint32(gl_index_id.index_id); + } + void delete_with_prefix(rocksdb::WriteBatch *const batch, Rdb_key_def::DATA_DICT_TYPE dict_type, const GL_INDEX_ID &gl_index_id) const; /* Functions for fast DROP TABLE/INDEX */ void resume_drop_indexes() const; void log_start_drop_table(const std::shared_ptr<Rdb_key_def> *const key_descr, - const uint32 &n_keys, + const uint32 n_keys, const char *const log_action) const; void log_start_drop_index(GL_INDEX_ID gl_index_id, const char *log_action) const; -public: + public: Rdb_dict_manager(const Rdb_dict_manager &) = delete; Rdb_dict_manager &operator=(const Rdb_dict_manager &) = delete; Rdb_dict_manager() = default; @@ -1302,7 +1406,7 @@ public: /* Raw RocksDB operations */ std::unique_ptr<rocksdb::WriteBatch> begin() const; - int commit(rocksdb::WriteBatch *const batch, const bool &sync = true) const; + int commit(rocksdb::WriteBatch *const batch, const bool sync = true) const; rocksdb::Status get_value(const rocksdb::Slice &key, std::string *const value) const; void put_key(rocksdb::WriteBatchBase *const batch, const rocksdb::Slice &key, @@ -1312,23 +1416,23 @@ public: rocksdb::Iterator *new_iterator() const; /* Internal Index id => CF */ - void - add_or_update_index_cf_mapping(rocksdb::WriteBatch *batch, - struct Rdb_index_info *const index_info) const; + void add_or_update_index_cf_mapping( + rocksdb::WriteBatch *batch, + struct Rdb_index_info *const index_info) const; void delete_index_info(rocksdb::WriteBatch *batch, const GL_INDEX_ID &index_id) const; bool get_index_info(const GL_INDEX_ID &gl_index_id, struct Rdb_index_info *const index_info) const; /* CF id => CF flags */ - void add_cf_flags(rocksdb::WriteBatch *const batch, const uint &cf_id, - const uint &cf_flags) const; - bool get_cf_flags(const uint &cf_id, uint *const cf_flags) const; + void add_cf_flags(rocksdb::WriteBatch *const batch, const uint cf_id, + const uint cf_flags) const; + bool get_cf_flags(const uint cf_id, uint *const cf_flags) const; /* Functions for fast CREATE/DROP TABLE/INDEX */ - void - get_ongoing_index_operation(std::unordered_set<GL_INDEX_ID> *gl_index_ids, - Rdb_key_def::DATA_DICT_TYPE dd_type) const; + void get_ongoing_index_operation( + std::unordered_set<GL_INDEX_ID> *gl_index_ids, + Rdb_key_def::DATA_DICT_TYPE dd_type) const; bool is_index_operation_ongoing(const GL_INDEX_ID &gl_index_id, Rdb_key_def::DATA_DICT_TYPE dd_type) const; void start_ongoing_index_operation(rocksdb::WriteBatch *batch, @@ -1339,15 +1443,15 @@ public: Rdb_key_def::DATA_DICT_TYPE dd_type) const; bool is_drop_index_empty() const; void add_drop_table(std::shared_ptr<Rdb_key_def> *const key_descr, - const uint32 &n_keys, + const uint32 n_keys, rocksdb::WriteBatch *const batch) const; void add_drop_index(const std::unordered_set<GL_INDEX_ID> &gl_index_ids, rocksdb::WriteBatch *const batch) const; void add_create_index(const std::unordered_set<GL_INDEX_ID> &gl_index_ids, rocksdb::WriteBatch *const batch) const; - void - finish_indexes_operation(const std::unordered_set<GL_INDEX_ID> &gl_index_ids, - Rdb_key_def::DATA_DICT_TYPE dd_type) const; + void finish_indexes_operation( + const std::unordered_set<GL_INDEX_ID> &gl_index_ids, + Rdb_key_def::DATA_DICT_TYPE dd_type) const; void rollback_ongoing_index_creation() const; inline void get_ongoing_drop_indexes( @@ -1390,7 +1494,7 @@ public: bool get_max_index_id(uint32_t *const index_id) const; bool update_max_index_id(rocksdb::WriteBatch *const batch, - const uint32_t &index_id) const; + const uint32_t index_id) const; void add_stats(rocksdb::WriteBatch *const batch, const std::vector<Rdb_index_stats> &stats) const; Rdb_index_stats get_stats(GL_INDEX_ID gl_index_id) const; @@ -1517,4 +1621,4 @@ class Rdb_system_merge_op : public rocksdb::AssociativeMergeOperator { bool rdb_is_collation_supported(const my_core::CHARSET_INFO *const cs); -} // namespace myrocks +} // namespace myrocks |