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_CONNECTION_STATUS_H
26 #define TABLE_REPLICATION_CONNECTION_STATUS_H
27 
28 /**
29   @file storage/perfschema/table_replication_connection_status.h
30   Table replication_connection_status (declarations).
31 */
32 
33 #include "pfs_column_types.h"
34 #include "pfs_engine_table.h"
35 #include "rpl_mi.h"
36 #include "rpl_reporting.h" /* MAX_SLAVE_ERRMSG */
37 #include "mysql_com.h"
38 #include "rpl_msr.h"
39 #include "rpl_info.h"  /*CHANNEL_NAME_LENGTH */
40 
41 class Master_info;
42 
43 /**
44   @addtogroup Performance_schema_tables
45   @{
46 */
47 
48 #ifndef ENUM_RPL_YES_NO
49 #define ENUM_RPL_YES_NO
50 enum enum_rpl_yes_no {
51   PS_RPL_YES= 1,
52   PS_RPL_NO
53 };
54 #endif
55 
56 enum enum_rpl_connect_status_service_state {
57   PS_RPL_CONNECT_SERVICE_STATE_YES= 1,
58   PS_RPL_CONNECT_SERVICE_STATE_NO,
59   PS_RPL_CONNECT_SERVICE_STATE_CONNECTING
60 };
61 
62 /*
63   A row in the table. The fields with string values have an additional
64   length field denoted by <field_name>_length.
65 */
66 struct st_row_connect_status {
67   char group_name[UUID_LENGTH];
68   bool group_name_is_null;
69   char channel_name[CHANNEL_NAME_LENGTH];
70   uint channel_name_length;
71   char source_uuid[UUID_LENGTH];
72   bool source_uuid_is_null;
73   ulonglong thread_id;
74   bool thread_id_is_null;
75   enum_rpl_connect_status_service_state service_state;
76   ulonglong count_received_heartbeats;
77   ulonglong last_heartbeat_timestamp;
78   char* received_transaction_set;
79   int received_transaction_set_length;
80   uint last_error_number;
81   char last_error_message[MAX_SLAVE_ERRMSG];
82   uint last_error_message_length;
83   ulonglong last_error_timestamp;
84 
st_row_connect_statusst_row_connect_status85   st_row_connect_status() : received_transaction_set(NULL) {}
86 
cleanupst_row_connect_status87   void cleanup()
88   {
89     if (received_transaction_set != NULL)
90     {
91       my_free(received_transaction_set);
92       received_transaction_set= NULL;
93     }
94   }
95 };
96 
97 
98 /** Table PERFORMANCE_SCHEMA.REPLICATION_CONNECTION_STATUS. */
99 class table_replication_connection_status: public PFS_engine_table
100 {
101   typedef PFS_simple_index pos_t;
102 
103 private:
104   void make_row(Master_info *mi);
105 
106   /** Table share lock. */
107   static THR_LOCK m_table_lock;
108   /** Fields definition. */
109   static TABLE_FIELD_DEF m_field_def;
110   /** True if the current row exists. */
111   bool m_row_exists;
112   /** Current row */
113   st_row_connect_status m_row;
114   /** Current position. */
115   pos_t m_pos;
116   /** Next position. */
117   pos_t m_next_pos;
118 
119 protected:
120   /**
121     Read the current row values.
122     @param table            Table handle
123     @param buf              row buffer
124     @param fields           Table fields
125     @param read_all         true if all columns are read.
126   */
127 
128   virtual int read_row_values(TABLE *table,
129                               unsigned char *buf,
130                               Field **fields,
131                               bool read_all);
132 
133   table_replication_connection_status();
134 
135 public:
136   ~table_replication_connection_status();
137 
138   /** Table share. */
139   static PFS_engine_table_share m_share;
140   static PFS_engine_table* create();
141   static ha_rows get_row_count();
142   virtual int rnd_next();
143   virtual int rnd_pos(const void *pos);
144   virtual void reset_position(void);
145 
146 };
147 
148 /** @} */
149 #endif
150