1 /* 2 Copyright (c) 2013, 2021, Oracle and/or its affiliates. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 23 24 25 #ifndef TABLE_REPLICATION_APPLIER_STATUS_BY_WORKER_H 26 #define TABLE_REPLICATION_APPLIER_STATUS_BY_WORKER_H 27 28 /** 29 @file storage/perfschema/table_replication_applier_status_by_worker.h 30 Table replication_applier_status_by_worker (declarations). 31 */ 32 33 #include "pfs_column_types.h" 34 #include "pfs_engine_table.h" 35 #include "rpl_mi.h" 36 #include "mysql_com.h" 37 #include "rpl_rli_pdb.h" 38 #include "rpl_msr.h" 39 #include "rpl_info.h" /*CHANNEL_NAME_LENGTH*/ 40 41 class Slave_worker; 42 class Master_info; 43 44 /** 45 @addtogroup Performance_schema_tables 46 @{ 47 */ 48 49 #ifndef ENUM_RPL_YES_NO 50 #define ENUM_RPL_YES_NO 51 /** enumerated values for service_state of worker thread*/ 52 enum enum_rpl_yes_no { 53 PS_RPL_YES= 1, /* service_state= on */ 54 PS_RPL_NO /* service_state= off */ 55 }; 56 #endif 57 58 /* 59 A row in worker's table. The fields with string values have an additional 60 length field denoted by <field_name>_length. 61 */ 62 struct st_row_worker { 63 64 char channel_name[CHANNEL_NAME_LENGTH]; 65 uint channel_name_length; 66 /* 67 worker_id is added to the table because thread is killed at STOP SLAVE 68 but the status needs to show up, so worker_id is used as a permanent 69 identifier. 70 */ 71 ulonglong worker_id; 72 ulonglong thread_id; 73 uint thread_id_is_null; 74 enum_rpl_yes_no service_state; 75 char last_seen_transaction[Gtid::MAX_TEXT_LENGTH+1]; 76 uint last_seen_transaction_length; 77 uint last_error_number; 78 char last_error_message[MAX_SLAVE_ERRMSG]; 79 uint last_error_message_length; 80 ulonglong last_error_timestamp; 81 }; 82 83 /** 84 Position in table replication_applier_status_by_worker. 85 Index 1 for replication channel. 86 Index 2 for worker: 87 - position [0] is for Single Thread Slave (Master_info) 88 - position [1] .. [N] is for Multi Thread Slave (Slave_worker) 89 */ 90 struct pos_replication_applier_status_by_worker : public PFS_double_index 91 { 92 pos_replication_applier_status_by_workerpos_replication_applier_status_by_worker93 pos_replication_applier_status_by_worker() : PFS_double_index(0, 0) 94 {} 95 resetpos_replication_applier_status_by_worker96 inline void reset(void) 97 { 98 m_index_1= 0; 99 m_index_2= 0; 100 } 101 has_more_channelspos_replication_applier_status_by_worker102 inline bool has_more_channels(uint num) 103 { return (m_index_1 < num); } 104 next_channelpos_replication_applier_status_by_worker105 inline void next_channel(void) 106 { 107 m_index_1++; 108 m_index_2= 0; 109 } 110 next_workerpos_replication_applier_status_by_worker111 inline void next_worker() 112 { 113 m_index_2++; 114 } 115 116 inline void set_channel_afterpos_replication_applier_status_by_worker117 set_channel_after(const pos_replication_applier_status_by_worker *other) 118 { 119 m_index_1 = other->m_index_1 + 1; 120 m_index_2 = 0; 121 } 122 }; 123 124 125 /** Table PERFORMANCE_SCHEMA.replication_applier_status_by_worker */ 126 class table_replication_applier_status_by_worker: public PFS_engine_table 127 { 128 typedef pos_replication_applier_status_by_worker pos_t; 129 130 private: 131 void make_row(Slave_worker *); 132 /* 133 Master_info to construct a row to display SQL Thread's status 134 information in STS mode 135 */ 136 void make_row(Master_info *); 137 138 /** Table share lock. */ 139 static THR_LOCK m_table_lock; 140 /** Fields definition. */ 141 static TABLE_FIELD_DEF m_field_def; 142 /** current row*/ 143 st_row_worker m_row; 144 /** True is the current row exists. */ 145 bool m_row_exists; 146 /** Current position. */ 147 pos_t m_pos; 148 /** Next position. */ 149 pos_t m_next_pos; 150 151 protected: 152 /** 153 Read the current row values. 154 @param table Table handle 155 @param buf row buffer 156 @param fields Table fields 157 @param read_all true if all columns are read. 158 */ 159 160 virtual int read_row_values(TABLE *table, 161 unsigned char *buf, 162 Field **fields, 163 bool read_all); 164 165 table_replication_applier_status_by_worker(); 166 167 public: 168 ~table_replication_applier_status_by_worker(); 169 170 /** Table share. */ 171 static PFS_engine_table_share m_share; 172 static PFS_engine_table* create(); 173 static ha_rows get_row_count(); 174 virtual int rnd_next(); 175 virtual int rnd_pos(const void *pos); 176 virtual void reset_position(void); 177 178 }; 179 180 /** @} */ 181 #endif 182