1
/* Copyright (C) 2001-2006 MySQL AB & Sasha
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
All of the functions defined in this file which are not used (the ones to
20
handle failsafe) are not used; their code has not been updated for more
21
than one year now so should be considered as BADLY BROKEN. Do not enable
22
it. The used functions (to handle LOAD DATA FROM MASTER, plus some small
23
functions like register_slave()) are working.
25
#include <drizzled/server_includes.h>
27
#include "repl_failsafe.h"
30
#include "rpl_filter.h"
31
#include "log_event.h"
33
#define SLAVE_LIST_CHUNK 128
34
#define SLAVE_ERRMSG_SIZE (FN_REFLEN+64)
37
RPL_STATUS rpl_status=RPL_NULL;
38
pthread_mutex_t LOCK_rpl_status;
39
pthread_cond_t COND_rpl_status;
42
const char *rpl_role_type[] = {"MASTER","SLAVE",NULL};
43
TYPELIB rpl_role_typelib = {array_elements(rpl_role_type)-1,"",
46
const char* rpl_status_type[]=
48
"AUTH_MASTER","ACTIVE_SLAVE","IDLE_SLAVE", "LOST_SOLDIER","TROOP_SOLDIER",
49
"RECOVERY_CAPTAIN","NULL",NULL
51
TYPELIB rpl_status_typelib= {array_elements(rpl_status_type)-1,"",
52
rpl_status_type, NULL};
55
void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status)
57
pthread_mutex_lock(&LOCK_rpl_status);
58
if (rpl_status == from_status || rpl_status == RPL_ANY)
59
rpl_status = to_status;
60
pthread_cond_signal(&COND_rpl_status);
61
pthread_mutex_unlock(&LOCK_rpl_status);
65
#define get_object(p, obj, msg) \
67
uint32_t len = (uint)*p++; \
68
if (p + len > p_end || len >= sizeof(obj)) \
73
strmake(obj,(char*) p,len); \
78
static inline int cmp_master_pos(Slave_log_event* sev, LEX_MASTER_INFO* mi)
80
return cmp_master_pos(sev->master_log, sev->master_pos, mi->log_file_name,
85
void unregister_slave(THD* thd, bool only_mine, bool need_mutex)
90
pthread_mutex_lock(&LOCK_slave_list);
93
if ((old_si = (SLAVE_INFO*)hash_search(&slave_list,
94
(unsigned char*)&thd->server_id, 4)) &&
95
(!only_mine || old_si->thd == thd))
96
hash_delete(&slave_list, (unsigned char*)old_si);
99
pthread_mutex_unlock(&LOCK_slave_list);
105
Register slave in 'slave_list' hash table.
110
1 Error. Error message sent to client
113
int register_slave(THD* thd, unsigned char* packet, uint32_t packet_length)
117
unsigned char *p= packet, *p_end= packet + packet_length;
118
const char *errmsg= "Wrong parameters to function register_slave";
120
if (!(si = (SLAVE_INFO*)my_malloc(sizeof(SLAVE_INFO), MYF(MY_WME))))
123
thd->server_id= si->server_id= uint4korr(p);
125
get_object(p,si->host, "Failed to register slave: too long 'report-host'");
126
get_object(p,si->user, "Failed to register slave: too long 'report-user'");
127
get_object(p,si->password, "Failed to register slave; too long 'report-password'");
130
si->port= uint2korr(p);
132
si->rpl_recovery_rank= uint4korr(p);
134
if (!(si->master_id= uint4korr(p)))
135
si->master_id= server_id;
138
pthread_mutex_lock(&LOCK_slave_list);
139
unregister_slave(thd,0,0);
140
res= my_hash_insert(&slave_list, (unsigned char*) si);
141
pthread_mutex_unlock(&LOCK_slave_list);
146
my_message(ER_UNKNOWN_ERROR, errmsg, MYF(0)); /* purecov: inspected */
152
*slave_list_key(SLAVE_INFO* si, size_t *len,
153
bool not_used __attribute__((unused)))
156
return &si->server_id;
159
extern "C" void slave_info_free(void *s)
164
void init_slave_list()
166
hash_init(&slave_list, system_charset_info, SLAVE_LIST_CHUNK, 0, 0,
167
(hash_get_key) slave_list_key, (hash_free_key) slave_info_free, 0);
168
pthread_mutex_init(&LOCK_slave_list, MY_MUTEX_INIT_FAST);
171
void end_slave_list()
173
/* No protection by a mutex needed as we are only called at shutdown */
174
if (hash_inited(&slave_list))
176
hash_free(&slave_list);
177
pthread_mutex_destroy(&LOCK_slave_list);
182
bool show_slave_hosts(THD* thd)
184
List<Item> field_list;
185
Protocol *protocol= thd->protocol;
187
field_list.push_back(new Item_return_int("Server_id", 10,
189
field_list.push_back(new Item_empty_string("Host", 20));
190
if (opt_show_slave_auth_info)
192
field_list.push_back(new Item_empty_string("User",20));
193
field_list.push_back(new Item_empty_string("Password",20));
195
field_list.push_back(new Item_return_int("Port", 7, DRIZZLE_TYPE_LONG));
196
field_list.push_back(new Item_return_int("Rpl_recovery_rank", 7,
198
field_list.push_back(new Item_return_int("Master_id", 10,
201
if (protocol->send_fields(&field_list,
202
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
205
pthread_mutex_lock(&LOCK_slave_list);
207
for (uint32_t i = 0; i < slave_list.records; ++i)
209
SLAVE_INFO* si = (SLAVE_INFO*) hash_element(&slave_list, i);
210
protocol->prepare_for_resend();
211
protocol->store((uint32_t) si->server_id);
212
protocol->store(si->host, &my_charset_bin);
213
if (opt_show_slave_auth_info)
215
protocol->store(si->user, &my_charset_bin);
216
protocol->store(si->password, &my_charset_bin);
218
protocol->store((uint32_t) si->port);
219
protocol->store((uint32_t) si->rpl_recovery_rank);
220
protocol->store((uint32_t) si->master_id);
221
if (protocol->write())
223
pthread_mutex_unlock(&LOCK_slave_list);
227
pthread_mutex_unlock(&LOCK_slave_list);