~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/repl_failsafe.cc

  • Committer: Toru Maesaka
  • Date: 2008-07-17 05:59:20 UTC
  • mto: (202.1.1 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: dev@torum.net-20080717055920-10okif50x6nh7b1d
forgot to bzr-add new files in the previous push

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
  it. The used functions (to handle LOAD DATA FROM MASTER, plus some small
23
23
  functions like register_slave()) are working.
24
24
*/
25
 
#include <drizzled/server_includes.h>
 
25
 
 
26
#include "mysql_priv.h"
 
27
#ifdef HAVE_REPLICATION
26
28
 
27
29
#include "repl_failsafe.h"
28
30
#include "sql_repl.h"
 
31
#include "slave.h"
29
32
#include "rpl_mi.h"
30
33
#include "rpl_filter.h"
31
34
#include "log_event.h"
39
42
pthread_cond_t COND_rpl_status;
40
43
HASH slave_list;
41
44
 
42
 
const char *rpl_role_type[] = {"MASTER","SLAVE",NULL};
 
45
const char *rpl_role_type[] = {"MASTER","SLAVE",NullS};
43
46
TYPELIB rpl_role_typelib = {array_elements(rpl_role_type)-1,"",
44
47
                            rpl_role_type, NULL};
45
48
 
46
49
const char* rpl_status_type[]=
47
50
{
48
51
  "AUTH_MASTER","ACTIVE_SLAVE","IDLE_SLAVE", "LOST_SOLDIER","TROOP_SOLDIER",
49
 
  "RECOVERY_CAPTAIN","NULL",NULL
 
52
  "RECOVERY_CAPTAIN","NULL",NullS
50
53
};
51
54
TYPELIB rpl_status_typelib= {array_elements(rpl_status_type)-1,"",
52
55
                             rpl_status_type, NULL};
64
67
 
65
68
#define get_object(p, obj, msg) \
66
69
{\
67
 
  uint32_t len = (uint)*p++;  \
 
70
  uint len = (uint)*p++;  \
68
71
  if (p + len > p_end || len >= sizeof(obj)) \
69
72
  {\
70
73
    errmsg= msg;\
91
94
 
92
95
    SLAVE_INFO* old_si;
93
96
    if ((old_si = (SLAVE_INFO*)hash_search(&slave_list,
94
 
                                           (unsigned char*)&thd->server_id, 4)) &&
 
97
                                           (uchar*)&thd->server_id, 4)) &&
95
98
        (!only_mine || old_si->thd == thd))
96
 
    hash_delete(&slave_list, (unsigned char*)old_si);
 
99
    hash_delete(&slave_list, (uchar*)old_si);
97
100
 
98
101
    if (need_mutex)
99
102
      pthread_mutex_unlock(&LOCK_slave_list);
110
113
    1   Error.   Error message sent to client
111
114
*/
112
115
 
113
 
int register_slave(THD* thd, unsigned char* packet, uint32_t packet_length)
 
116
int register_slave(THD* thd, uchar* packet, uint packet_length)
114
117
{
115
118
  int res;
116
119
  SLAVE_INFO *si;
117
 
  unsigned char *p= packet, *p_end= packet + packet_length;
 
120
  uchar *p= packet, *p_end= packet + packet_length;
118
121
  const char *errmsg= "Wrong parameters to function register_slave";
119
122
 
120
123
  if (!(si = (SLAVE_INFO*)my_malloc(sizeof(SLAVE_INFO), MYF(MY_WME))))
137
140
 
138
141
  pthread_mutex_lock(&LOCK_slave_list);
139
142
  unregister_slave(thd,0,0);
140
 
  res= my_hash_insert(&slave_list, (unsigned char*) si);
 
143
  res= my_hash_insert(&slave_list, (uchar*) si);
141
144
  pthread_mutex_unlock(&LOCK_slave_list);
142
145
  return res;
143
146
 
144
147
err:
145
 
  free(si);
 
148
  my_free(si, MYF(MY_WME));
146
149
  my_message(ER_UNKNOWN_ERROR, errmsg, MYF(0)); /* purecov: inspected */
147
150
err2:
148
151
  return 1;
149
152
}
150
153
 
151
 
extern "C" uint32_t
 
154
extern "C" uint32
152
155
*slave_list_key(SLAVE_INFO* si, size_t *len,
153
156
                bool not_used __attribute__((unused)))
154
157
{
158
161
 
159
162
extern "C" void slave_info_free(void *s)
160
163
{
161
 
  free(s);
 
164
  my_free(s, MYF(MY_WME));
162
165
}
163
166
 
164
167
void init_slave_list()
185
188
  Protocol *protocol= thd->protocol;
186
189
 
187
190
  field_list.push_back(new Item_return_int("Server_id", 10,
188
 
                                           DRIZZLE_TYPE_LONG));
 
191
                                           MYSQL_TYPE_LONG));
189
192
  field_list.push_back(new Item_empty_string("Host", 20));
190
193
  if (opt_show_slave_auth_info)
191
194
  {
192
195
    field_list.push_back(new Item_empty_string("User",20));
193
196
    field_list.push_back(new Item_empty_string("Password",20));
194
197
  }
195
 
  field_list.push_back(new Item_return_int("Port", 7, DRIZZLE_TYPE_LONG));
 
198
  field_list.push_back(new Item_return_int("Port", 7, MYSQL_TYPE_LONG));
196
199
  field_list.push_back(new Item_return_int("Rpl_recovery_rank", 7,
197
 
                                           DRIZZLE_TYPE_LONG));
 
200
                                           MYSQL_TYPE_LONG));
198
201
  field_list.push_back(new Item_return_int("Master_id", 10,
199
 
                                           DRIZZLE_TYPE_LONG));
 
202
                                           MYSQL_TYPE_LONG));
200
203
 
201
204
  if (protocol->send_fields(&field_list,
202
205
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
204
207
 
205
208
  pthread_mutex_lock(&LOCK_slave_list);
206
209
 
207
 
  for (uint32_t i = 0; i < slave_list.records; ++i)
 
210
  for (uint i = 0; i < slave_list.records; ++i)
208
211
  {
209
212
    SLAVE_INFO* si = (SLAVE_INFO*) hash_element(&slave_list, i);
210
213
    protocol->prepare_for_resend();
211
 
    protocol->store((uint32_t) si->server_id);
 
214
    protocol->store((uint32) si->server_id);
212
215
    protocol->store(si->host, &my_charset_bin);
213
216
    if (opt_show_slave_auth_info)
214
217
    {
215
218
      protocol->store(si->user, &my_charset_bin);
216
219
      protocol->store(si->password, &my_charset_bin);
217
220
    }
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
    protocol->store((uint32) si->port);
 
222
    protocol->store((uint32) si->rpl_recovery_rank);
 
223
    protocol->store((uint32) si->master_id);
221
224
    if (protocol->write())
222
225
    {
223
226
      pthread_mutex_unlock(&LOCK_slave_list);
228
231
  my_eof(thd);
229
232
  return(false);
230
233
}
 
234
 
 
235
#endif /* HAVE_REPLICATION */
 
236