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