|
45 | 45 | */
|
46 | 46 | #define EXTRA_ROW_INFO_LEN_OFFSET 0
|
47 | 47 | #define EXTRA_ROW_INFO_FORMAT_OFFSET 1
|
48 |
| -#define EXTRA_ROW_INFO_HDR_BYTES 2 |
49 |
| -#define EXTRA_ROW_INFO_MAX_PAYLOAD (255 - EXTRA_ROW_INFO_HDR_BYTES) |
| 48 | +#define EXTRA_ROW_INFO_HEADER_LENGTH 2 |
| 49 | +#define EXTRA_ROW_INFO_MAX_PAYLOAD (255 - EXTRA_ROW_INFO_HEADER_LENGTH) |
50 | 50 |
|
51 | 51 | #define ROWS_MAPID_OFFSET 0
|
52 | 52 | #define ROWS_FLAGS_OFFSET 6
|
53 | 53 | #define ROWS_VHLEN_OFFSET 8
|
54 |
| -#define ROWS_V_TAG_LEN 1 |
55 |
| -#define ROWS_V_EXTRAINFO_TAG 0 |
| 54 | +#define EXTRA_ROW_INFO_TYPECODE_LENGTH 1 |
| 55 | +#define EXTRA_ROW_PART_INFO_VALUE_LENGTH 2 |
| 56 | + |
| 57 | +/** |
| 58 | + This is the typecode defined for the different elements present in |
| 59 | + the container Extra_row_info, this is different from the format information |
| 60 | + stored inside extra_row_ndb_info at EXTRA_ROW_INFO_FORMAT_OFFSET. |
| 61 | +*/ |
| 62 | +enum class enum_extra_row_info_typecode { NDB = 0, PART = 1 }; |
56 | 63 |
|
57 | 64 | namespace binary_log {
|
58 | 65 | /**
|
@@ -747,9 +754,47 @@ class Table_map_event : public Binary_log_event {
|
747 | 754 | </tr>
|
748 | 755 |
|
749 | 756 | <tr>
|
750 |
| - <td>extra_row_data</td> |
751 |
| - <td>unsigned char pointer</td> |
752 |
| - <td>Pointer to extra row data if any. If non null, first byte is length</td> |
| 757 | + <td>extra_row_info</td> |
| 758 | + <td>An object of class Extra_row_info</td> |
| 759 | + <td>The class Extra_row_info will be storing the information related |
| 760 | + to m_extra_row_ndb_info and partition info (partition_id and |
| 761 | + source_partition_id). At any given time a Rows_event can have both, one |
| 762 | + or none of ndb_info and partition_info present as part of Rows_event. |
| 763 | + In case both ndb_info and partition_info are present then below will |
| 764 | + be the order in which they will be stored. |
| 765 | +
|
| 766 | + @verbatim |
| 767 | + +----------+--------------------------------------+ |
| 768 | + |type_code | extra_row_ndb_info | |
| 769 | + +--- ------+--------------------------------------+ |
| 770 | + | NDB |Len of ndb_info |Format |ndb_data | |
| 771 | + | 1 byte |1 byte |1 byte |len - 2 byte | |
| 772 | + +----------+----------------+-------+-------------+ |
| 773 | +
|
| 774 | + In case of INSERT/DELETE |
| 775 | + +-----------+----------------+ |
| 776 | + | type_code | partition_info | |
| 777 | + +-----------+----------------+ |
| 778 | + | PART | partition_id | |
| 779 | + | (1 byte) | 2 byte | |
| 780 | + +-----------+----------------+ |
| 781 | +
|
| 782 | + In case of UPDATE |
| 783 | + +-----------+------------------------------------+ |
| 784 | + | type_code | partition_info | |
| 785 | + +-----------+--------------+---------------------+ |
| 786 | + | PART | partition_id | source_partition_id | |
| 787 | + | (1 byte) | 2 byte | 2 byte | |
| 788 | + +-----------+--------------+---------------------+ |
| 789 | +
|
| 790 | + source_partition_id is used only in the case of Update_event |
| 791 | + to log the partition_id of the source partition. |
| 792 | +
|
| 793 | + @endverbatim |
| 794 | + This is the format for any information stored as extra_row_info. |
| 795 | + type_code is not a part of the class Extra_row_info as it is a constant |
| 796 | + values used at the time of serializing and decoding the event. |
| 797 | + </td> |
753 | 798 | </tr>
|
754 | 799 |
|
755 | 800 | <tr>
|
@@ -848,11 +893,9 @@ class Rows_event : public Binary_log_event {
|
848 | 893 | : Binary_log_event(type_arg),
|
849 | 894 | m_table_id(0),
|
850 | 895 | m_width(0),
|
851 |
| - m_extra_row_data(0), |
852 | 896 | columns_before_image(0),
|
853 | 897 | columns_after_image(0),
|
854 | 898 | row(0) {}
|
855 |
| - |
856 | 899 | /**
|
857 | 900 | The constructor is responsible for decoding the event contained in
|
858 | 901 | the buffer.
|
@@ -890,13 +933,76 @@ class Rows_event : public Binary_log_event {
|
890 | 933 | uint32_t n_bits_len; /** value determined by (m_width + 7) / 8 */
|
891 | 934 | uint16_t var_header_len;
|
892 | 935 |
|
893 |
| - unsigned char *m_extra_row_data; |
894 |
| - |
895 | 936 | std::vector<uint8_t> columns_before_image;
|
896 | 937 | std::vector<uint8_t> columns_after_image;
|
897 | 938 | std::vector<uint8_t> row;
|
898 | 939 |
|
899 | 940 | public:
|
| 941 | + class Extra_row_info { |
| 942 | + private: |
| 943 | + /** partition_id for a row in a partitioned table */ |
| 944 | + int m_partition_id; |
| 945 | + /** |
| 946 | + It is the partition_id of the source partition in case |
| 947 | + of Update_event, the target's partition_id is m_partition_id. |
| 948 | + This variable is used only in case of Update_event. |
| 949 | + */ |
| 950 | + int m_source_partition_id; |
| 951 | + /** The extra row info provided by NDB */ |
| 952 | + unsigned char *m_extra_row_ndb_info; |
| 953 | + |
| 954 | + public: |
| 955 | + Extra_row_info() |
| 956 | + : m_partition_id(UNDEFINED), |
| 957 | + m_source_partition_id(UNDEFINED), |
| 958 | + m_extra_row_ndb_info(nullptr) {} |
| 959 | + |
| 960 | + Extra_row_info(const Extra_row_info &) = delete; |
| 961 | + |
| 962 | + int get_partition_id() const { return m_partition_id; } |
| 963 | + void set_partition_id(int partition_id) { |
| 964 | + BAPI_ASSERT(partition_id < 65535); |
| 965 | + m_partition_id = partition_id; |
| 966 | + } |
| 967 | + |
| 968 | + int get_source_partition_id() const { return m_source_partition_id; } |
| 969 | + void set_source_partition_id(int source_partition_id) { |
| 970 | + BAPI_ASSERT(source_partition_id < 65535); |
| 971 | + m_source_partition_id = source_partition_id; |
| 972 | + } |
| 973 | + |
| 974 | + unsigned char *get_ndb_info() const { return m_extra_row_ndb_info; } |
| 975 | + void set_ndb_info(const unsigned char *ndb_info, size_t len) { |
| 976 | + BAPI_ASSERT(!have_ndb_info()); |
| 977 | + m_extra_row_ndb_info = |
| 978 | + static_cast<unsigned char *>(bapi_malloc(len, 16 /* flags */)); |
| 979 | + std::copy(ndb_info, ndb_info + len, m_extra_row_ndb_info); |
| 980 | + } |
| 981 | + /** |
| 982 | + Compares the extra_row_info in a Row event, it checks three things |
| 983 | + 1. The m_extra_row_ndb_info pointers. It compares their significant bytes. |
| 984 | + 2. Partition_id |
| 985 | + 3. source_partition_id |
| 986 | +
|
| 987 | + @return |
| 988 | + true all the above variables are same in the event and the one passed |
| 989 | + in parameter. |
| 990 | + false Any of the above variable has a different value. |
| 991 | + */ |
| 992 | + bool compare_extra_row_info(const unsigned char *ndb_info_arg, |
| 993 | + int part_id_arg, int source_part_id); |
| 994 | + |
| 995 | + bool have_part() const { return m_partition_id != UNDEFINED; } |
| 996 | + |
| 997 | + bool have_ndb_info() const { return m_extra_row_ndb_info != nullptr; } |
| 998 | + size_t get_ndb_length(); |
| 999 | + size_t get_part_length(); |
| 1000 | + ~Extra_row_info(); |
| 1001 | + |
| 1002 | + static const int UNDEFINED{INT_MAX}; |
| 1003 | + }; |
| 1004 | + Extra_row_info m_extra_row_info; |
| 1005 | + |
900 | 1006 | unsigned long long get_table_id() const { return m_table_id.id(); }
|
901 | 1007 |
|
902 | 1008 | enum_flag get_flags() const { return static_cast<enum_flag>(m_flags); }
|
|
0 commit comments