1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/* Copyright (C) 2014 MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef MYSQL_SERVER
#define MYSQL_SERVER
#endif
#include <my_config.h>
#include <mysql/plugin.h>
#include <table.h> /* ST_SCHEMA_TABLE */
#include <sql_show.h>
#include <sql_acl.h> /* check_global_access() */
#include <wsrep_mysqld.h>
#include <wsrep_utils.h>
/* WSREP_MEMBERSHIP table fields */
/* Node index */
#define COLUMN_WSREP_MEMB_INDEX 0
/* Unique member ID */
#define COLUMN_WSREP_MEMB_UUID 1
/* Human-readable name */
#define COLUMN_WSREP_MEMB_NAME 2
/* Incoming address */
#define COLUMN_WSREP_MEMB_ADDRESS 3
/* WSREP_STATUS table fields */
/* Node index */
#define COLUMN_WSREP_STATUS_NODE_INDEX 0
/* Node status */
#define COLUMN_WSREP_STATUS_NODE_STATUS 1
/* Cluster status */
#define COLUMN_WSREP_STATUS_CLUSTER_STATUS 2
/* Cluster size */
#define COLUMN_WSREP_STATUS_CLUSTER_SIZE 3
/* Global cluster state UUID */
#define COLUMN_WSREP_STATUS_CLUSTER_STATE_UUID 4
/* Global cluster state Sequence number */
#define COLUMN_WSREP_STATUS_CLUSTER_STATE_SEQNO 5
/* Cluster membership changes */
#define COLUMN_WSREP_STATUS_CLUSTER_CONF_ID 6
/* Gap between global and local states ? */
#define COLUMN_WSREP_STATUS_GAP 7
/* Application protocol version */
#define COLUMN_WSREP_STATUS_PROTO_VERSION 8
static const char* get_member_status(wsrep_member_status_t status)
{
switch (status)
{
case WSREP_MEMBER_UNDEFINED: return "Undefined";
case WSREP_MEMBER_JOINER: return "Joiner";
case WSREP_MEMBER_DONOR: return "Donor";
case WSREP_MEMBER_JOINED: return "Joined";
case WSREP_MEMBER_SYNCED: return "Synced";
case WSREP_MEMBER_ERROR: return "Error";
default: break;
}
return "UNKNOWN";
}
static const char* get_cluster_status(wsrep_view_status_t status)
{
switch (status)
{
case WSREP_VIEW_PRIMARY: return "Primary";
case WSREP_VIEW_NON_PRIMARY: return "Non-primary";
case WSREP_VIEW_DISCONNECTED: return "Disconnected";
default: break;
}
return "UNKNOWN";
}
static ST_FIELD_INFO wsrep_memb_fields[]=
{
{"INDEX", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Index", 0},
{"UUID", WSREP_UUID_STR_LEN, MYSQL_TYPE_STRING, 0, 0, "Uuid", 0},
{"NAME", WSREP_MEMBER_NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name", 0},
{"ADDRESS", WSREP_INCOMING_LEN, MYSQL_TYPE_STRING, 0, 0, "Address", 0},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
};
static ST_FIELD_INFO wsrep_status_fields[]=
{
{"NODE_INDEX", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG,
0, 0, "Node_Index", 0},
{"NODE_STATUS", 16, MYSQL_TYPE_STRING, 0, 0, "Node_Status", 0},
{"CLUSTER_STATUS", 16, MYSQL_TYPE_STRING, 0, 0, "Cluster_Status", 0},
{"CLUSTER_SIZE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG,
0, 0, "Cluster_Size", 0},
{"CLUSTER_STATE_UUID", WSREP_UUID_STR_LEN, MYSQL_TYPE_STRING,
0, 0, 0, 0},
{"CLUSTER_STATE_SEQNO", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG,
0, 0, 0, 0},
{"CLUSTER_CONF_ID", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG,
0, 0, 0, 0},
{"GAP", 10, MYSQL_TYPE_STRING, 0, 0, 0, 0},
{"PROTOCOL_VERSION", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG,
0, 0, 0, 0},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
};
static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
{
int rc= 0;
if (check_global_access(thd, SUPER_ACL, true))
return rc;
wsrep_config_state.lock();
Dynamic_array<wsrep_member_info_t> *memb_arr=
wsrep_config_state.get_member_info();
TABLE *table= tables->table;
for (unsigned int i= 0; i < memb_arr->elements(); i ++)
{
wsrep_member_info_t memb= memb_arr->at(i);
table->field[COLUMN_WSREP_MEMB_INDEX]->store(i, 0);
char uuid[40];
wsrep_uuid_print(&memb.id, uuid, sizeof(uuid));
table->field[COLUMN_WSREP_MEMB_UUID]->store(uuid, sizeof(uuid),
system_charset_info);
table->field[COLUMN_WSREP_MEMB_NAME]->store(memb.name, strlen(memb.name),
system_charset_info);
table->field[COLUMN_WSREP_MEMB_ADDRESS]->store(memb.incoming,
strlen(memb.incoming),
system_charset_info);
if (schema_table_store_record(thd, table))
{
rc= 1;
goto end;
}
}
end:
wsrep_config_state.unlock();
return rc;
}
static int wsrep_memb_plugin_init(void *p)
{
ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p;
schema->fields_info= wsrep_memb_fields;
schema->fill_table= wsrep_memb_fill_table;
return 0;
}
static struct st_mysql_information_schema wsrep_memb_plugin=
{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
static int wsrep_status_fill_table(THD *thd, TABLE_LIST *tables, COND *cond)
{
int rc= 0;
if (check_global_access(thd, SUPER_ACL, true))
return rc;
wsrep_config_state.lock();
wsrep_view_info_t view= wsrep_config_state.get_view_info();
wsrep_member_status_t status= wsrep_config_state.get_status();
TABLE *table= tables->table;
table->field[COLUMN_WSREP_STATUS_NODE_INDEX]
->store(view.my_idx, 0);
table->field[COLUMN_WSREP_STATUS_NODE_STATUS]
->store(get_member_status(status), strlen(get_member_status(status)),
system_charset_info);
table->field[COLUMN_WSREP_STATUS_CLUSTER_STATUS]
->store(get_cluster_status(view.status),
strlen(get_cluster_status(view.status)),
system_charset_info);
table->field[COLUMN_WSREP_STATUS_CLUSTER_SIZE]->store(view.memb_num, 0);
char uuid[40];
wsrep_uuid_print(&view.state_id.uuid, uuid, sizeof(uuid));
table->field[COLUMN_WSREP_STATUS_CLUSTER_STATE_UUID]
->store(uuid, sizeof(uuid), system_charset_info);
table->field[COLUMN_WSREP_STATUS_CLUSTER_STATE_SEQNO]
->store(view.state_id.seqno, 0);
table->field[COLUMN_WSREP_STATUS_CLUSTER_CONF_ID]->store(view.view, 0);
const char *gap= (view.state_gap == true) ? "YES" : "NO";
table->field[COLUMN_WSREP_STATUS_GAP]->store(gap, strlen(gap),
system_charset_info);
table->field[COLUMN_WSREP_STATUS_PROTO_VERSION]->store(view.proto_ver, 0);
if (schema_table_store_record(thd, table))
rc= 1;
wsrep_config_state.unlock();
return rc;
}
static int wsrep_status_plugin_init(void *p)
{
ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p;
schema->fields_info= wsrep_status_fields;
schema->fill_table= wsrep_status_fill_table;
return 0;
}
static struct st_mysql_information_schema wsrep_status_plugin=
{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION };
/*
Plugin library descriptor
*/
maria_declare_plugin(wsrep_info)
{
MYSQL_INFORMATION_SCHEMA_PLUGIN,
&wsrep_memb_plugin,
"WSREP_MEMBERSHIP", /* Plugin name */
"Nirbhay Choubey", /* Plugin author */
"Information about group members", /* Plugin description */
PLUGIN_LICENSE_GPL, /* License */
wsrep_memb_plugin_init, /* Plugin Init */
0, /* Plugin Deinit */
0x0100, /* Version (hex) */
NULL, /* Status variables */
NULL, /* System variables */
"1.0", /* Version (string) */
MariaDB_PLUGIN_MATURITY_STABLE /* Maturity */
},
{
MYSQL_INFORMATION_SCHEMA_PLUGIN,
&wsrep_status_plugin,
"WSREP_STATUS", /* Plugin name */
"Nirbhay Choubey", /* Plugin author */
"Group view information", /* Plugin description */
PLUGIN_LICENSE_GPL, /* License */
wsrep_status_plugin_init, /* Plugin Init */
0, /* Plugin Deinit */
0x0100, /* Version (hex) */
NULL, /* Status variables */
NULL, /* System variables */
"1.0", /* Version (string) */
MariaDB_PLUGIN_MATURITY_STABLE /* Maturity */
}
maria_declare_plugin_end;
|