~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/repl_failsafe.cc

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

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