~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/rpl_mi.cc

  • Committer: Brian Aker
  • Date: 2008-07-03 00:14:39 UTC
  • Revision ID: brian@tangent.org-20080703001439-pit0mcl0wk8elxlq
Cleanup of sql-common and mysqldump

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
 
16
#include <my_global.h> // For HAVE_REPLICATION
 
17
#include "mysql_priv.h"
 
18
#include <my_dir.h>
 
19
 
17
20
#include "rpl_mi.h"
18
21
 
 
22
#ifdef HAVE_REPLICATION
 
23
 
19
24
#define DEFAULT_CONNECT_RETRY 60
20
25
 
21
26
// Defined in slave.cc
26
31
 
27
32
Master_info::Master_info()
28
33
  :Slave_reporting_capability("I/O"),
29
 
   ssl(0), ssl_verify_server_cert(0), fd(-1),  io_thd(0), port(DRIZZLE_PORT),
 
34
   ssl(0), ssl_verify_server_cert(0), fd(-1),  io_thd(0), port(MYSQL_PORT),
30
35
   connect_retry(DEFAULT_CONNECT_RETRY), heartbeat_period(0),
31
36
   received_heartbeats(0), inited(0),
32
37
   abort_slave(0), slave_running(0), slave_run_id(0)
35
40
  ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;
36
41
  ssl_cipher[0]= 0; ssl_key[0]= 0;
37
42
 
38
 
  memset(&file, 0, sizeof(file));
 
43
  bzero((char*) &file, sizeof(file));
39
44
  pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST);
40
45
  pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST);
41
46
  pthread_cond_init(&data_cond, NULL);
55
60
 
56
61
void init_master_log_pos(Master_info* mi)
57
62
{
 
63
  DBUG_ENTER("init_master_log_pos");
 
64
 
58
65
  mi->master_log_name[0] = 0;
59
66
  mi->master_log_pos = BIN_LOG_HEADER_SIZE;             // skip magic number
60
67
  /* 
63
70
    if CHANGE MASTER did not specify it.  (no data loss in conversion
64
71
    as hb period has a max)
65
72
  */
66
 
  mi->heartbeat_period= (float) cmin((double)SLAVE_MAX_HEARTBEAT_PERIOD,
 
73
  mi->heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
67
74
                                    (slave_net_timeout/2.0));
68
 
  assert(mi->heartbeat_period > (float) 0.001
 
75
  DBUG_ASSERT(mi->heartbeat_period > (float) 0.001
69
76
              || mi->heartbeat_period == 0);
70
 
  return;
 
77
  DBUG_VOID_RETURN;
71
78
}
72
79
 
73
80
 
92
99
{
93
100
  int fd,error;
94
101
  char fname[FN_REFLEN+128];
 
102
  DBUG_ENTER("init_master_info");
95
103
 
96
104
  if (mi->inited)
97
105
  {
111
119
    {
112
120
      my_b_seek(mi->rli.cur_log, (my_off_t) 0);
113
121
    }
114
 
    return(0);
 
122
    DBUG_RETURN(0);
115
123
  }
116
124
 
117
 
  mi->drizzle=0;
 
125
  mi->mysql=0;
118
126
  mi->file_id=1;
119
127
  fn_format(fname, master_info_fname, mysql_data_home, "", 4+32);
120
128
 
133
141
    if (abort_if_no_master_info_file)
134
142
    {
135
143
      pthread_mutex_unlock(&mi->data_lock);
136
 
      return(0);
 
144
      DBUG_RETURN(0);
137
145
    }
138
146
    /*
139
147
      if someone removed the file from underneath our feet, just close
143
151
      my_close(fd, MYF(MY_WME));
144
152
    if ((fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0 )
145
153
    {
146
 
      sql_print_error(_("Failed to create a new master info file (file '%s', errno %d)"), fname, my_errno);
 
154
      sql_print_error("Failed to create a new master info file (file '%s', errno %d)", fname, my_errno);
147
155
      goto err;
148
156
    }
149
157
    if (init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,0,
150
158
                      MYF(MY_WME)))
151
159
    {
152
 
      sql_print_error(_("Failed to create a cache on master info file (file '%s')"), fname);
 
160
      sql_print_error("Failed to create a cache on master info file (file '%s')", fname);
153
161
      goto err;
154
162
    }
155
163
 
165
173
    {
166
174
      if ((fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0 )
167
175
      {
168
 
        sql_print_error(_("Failed to open the existing master info file (file '%s', errno %d)"), fname, my_errno);
 
176
        sql_print_error("Failed to open the existing master info file (file '%s', errno %d)", fname, my_errno);
169
177
        goto err;
170
178
      }
171
179
      if (init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,
172
180
                        0, MYF(MY_WME)))
173
181
      {
174
 
        sql_print_error(_("Failed to create a cache on master info file (file '%s')"), fname);
 
182
        sql_print_error("Failed to create a cache on master info file (file '%s')", fname);
175
183
        goto err;
176
184
      }
177
185
    }
229
237
        init_strvar_from_file(mi->user, sizeof(mi->user), &mi->file, "test") ||
230
238
        init_strvar_from_file(mi->password, SCRAMBLED_PASSWORD_CHAR_LENGTH+1,
231
239
                              &mi->file, 0 ) ||
232
 
        init_intvar_from_file(&port, &mi->file, DRIZZLE_PORT) ||
 
240
        init_intvar_from_file(&port, &mi->file, MYSQL_PORT) ||
233
241
        init_intvar_from_file(&connect_retry, &mi->file, DEFAULT_CONNECT_RETRY))
234
242
      goto errwithmsg;
235
243
 
271
279
    }
272
280
 
273
281
    if (ssl)
274
 
      sql_print_warning(_("SSL information in the master info file "
275
 
                          "('%s') are ignored because this MySQL slave was "
276
 
                          "compiled without SSL support."), fname);
 
282
      sql_print_warning("SSL information in the master info file "
 
283
                      "('%s') are ignored because this MySQL slave was "
 
284
                      "compiled without SSL support.", fname);
277
285
 
278
286
    /*
279
287
      This has to be handled here as init_intvar_from_file can't handle
282
290
    mi->master_log_pos= (my_off_t) master_log_pos;
283
291
    mi->port= (uint) port;
284
292
    mi->connect_retry= (uint) connect_retry;
285
 
    mi->ssl= (bool) ssl;
 
293
    mi->ssl= (my_bool) ssl;
286
294
    mi->ssl_verify_server_cert= ssl_verify_server_cert;
287
295
    mi->heartbeat_period= master_heartbeat_period;
288
296
  }
 
297
  DBUG_PRINT("master_info",("log_file_name: %s  position: %ld",
 
298
                            mi->master_log_name,
 
299
                            (ulong) mi->master_log_pos));
289
300
 
290
301
  mi->rli.mi = mi;
291
302
  if (init_relay_log_info(&mi->rli, slave_info_fname))
295
306
  // now change cache READ -> WRITE - must do this before flush_master_info
296
307
  reinit_io_cache(&mi->file, WRITE_CACHE, 0L, 0, 1);
297
308
  if ((error=test(flush_master_info(mi, 1))))
298
 
    sql_print_error(_("Failed to flush master info file"));
 
309
    sql_print_error("Failed to flush master info file");
299
310
  pthread_mutex_unlock(&mi->data_lock);
300
 
  return(error);
 
311
  DBUG_RETURN(error);
301
312
 
302
313
errwithmsg:
303
 
  sql_print_error(_("Error reading master configuration"));
 
314
  sql_print_error("Error reading master configuration");
304
315
 
305
316
err:
306
317
  if (fd >= 0)
310
321
  }
311
322
  mi->fd= -1;
312
323
  pthread_mutex_unlock(&mi->data_lock);
313
 
  return(1);
 
324
  DBUG_RETURN(1);
314
325
}
315
326
 
316
327
 
325
336
  IO_CACHE* file = &mi->file;
326
337
  char lbuf[22];
327
338
 
 
339
  DBUG_ENTER("flush_master_info");
 
340
  DBUG_PRINT("enter",("master_pos: %ld", (long) mi->master_log_pos));
 
341
 
328
342
  /*
329
343
    Flush the relay log to disk. If we don't do it, then the relay log while
330
344
    have some part (its last kilobytes) in memory only, so if the slave server
339
353
  */
340
354
  if (flush_relay_log_cache &&
341
355
      flush_io_cache(mi->rli.relay_log.get_log_file()))
342
 
    return(2);
 
356
    DBUG_RETURN(2);
343
357
 
344
358
  /*
345
359
    We flushed the relay log BEFORE the master.info file, because if we crash
358
372
     of file we don't care about this garbage.
359
373
  */
360
374
  char heartbeat_buf[sizeof(mi->heartbeat_period) * 4]; // buffer to suffice always
361
 
  sprintf(heartbeat_buf, "%.3f", mi->heartbeat_period);
 
375
  my_sprintf(heartbeat_buf, (heartbeat_buf, "%.3f", mi->heartbeat_period));
362
376
  my_b_seek(file, 0L);
363
377
  my_b_printf(file,
364
378
              "%u\n%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n%s\n%s\n%s\n%s\n%s\n%d\n%s\n",
369
383
              (int)(mi->ssl), mi->ssl_ca, mi->ssl_capath, mi->ssl_cert,
370
384
              mi->ssl_cipher, mi->ssl_key, mi->ssl_verify_server_cert,
371
385
              heartbeat_buf);
372
 
  return(-flush_io_cache(file));
 
386
  DBUG_RETURN(-flush_io_cache(file));
373
387
}
374
388
 
375
389
 
376
390
void end_master_info(Master_info* mi)
377
391
{
 
392
  DBUG_ENTER("end_master_info");
 
393
 
378
394
  if (!mi->inited)
379
 
    return;
 
395
    DBUG_VOID_RETURN;
380
396
  end_relay_log_info(&mi->rli);
381
397
  if (mi->fd >= 0)
382
398
  {
386
402
  }
387
403
  mi->inited = 0;
388
404
 
389
 
  return;
 
405
  DBUG_VOID_RETURN;
390
406
}
 
407
 
 
408
 
 
409
#endif /* HAVE_REPLICATION */