~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/rpl_rli.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:
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 "mysql_priv.h"
17
17
 
18
18
#include "rpl_mi.h"
19
19
#include "rpl_rli.h"
 
20
#include <my_dir.h>
20
21
#include "sql_repl.h"  // For check_binlog_magic
21
22
#include "rpl_utility.h"
22
23
 
23
 
#include <libdrizzle/gettext.h>
24
 
 
25
 
static int32_t count_relay_log_space(Relay_log_info* rli);
 
24
static int count_relay_log_space(Relay_log_info* rli);
26
25
 
27
26
// Defined in slave.cc
28
 
int32_t init_intvar_from_file(int32_t* var, IO_CACHE* f, int32_t default_val);
29
 
int32_t init_strvar_from_file(char *var, int32_t max_size, IO_CACHE *f,
 
27
int init_intvar_from_file(int* var, IO_CACHE* f, int default_val);
 
28
int init_strvar_from_file(char *var, int max_size, IO_CACHE *f,
30
29
                          const char *default_val);
31
30
 
32
31
 
33
32
Relay_log_info::Relay_log_info()
34
33
  :Slave_reporting_capability("SQL"),
35
 
   no_storage(false), replicate_same_server_id(::replicate_same_server_id),
 
34
   no_storage(FALSE), replicate_same_server_id(::replicate_same_server_id),
36
35
   info_fd(-1), cur_log_fd(-1), save_temporary_tables(0),
37
 
#if defined(HAVE_purify) && HAVE_purify
38
 
   is_fake(false),
 
36
#if HAVE_purify
 
37
   is_fake(FALSE),
39
38
#endif
40
39
   cur_log_old_open_count(0), group_relay_log_pos(0), event_relay_log_pos(0),
41
40
   group_master_log_pos(0), log_space_total(0), ignore_log_space_limit(0),
46
45
   tables_to_lock(0), tables_to_lock_count(0),
47
46
   last_event_start_time(0), m_flags(0)
48
47
{
 
48
  DBUG_ENTER("Relay_log_info::Relay_log_info");
 
49
 
49
50
  group_relay_log_name[0]= event_relay_log_name[0]=
50
51
    group_master_log_name[0]= 0;
51
52
  until_log_name[0]= ign_master_log_name_end[0]= 0;
52
 
  memset(&info_file, 0, sizeof(info_file));
53
 
  memset(&cache_buf, 0, sizeof(cache_buf));
 
53
  bzero((char*) &info_file, sizeof(info_file));
 
54
  bzero((char*) &cache_buf, sizeof(cache_buf));
54
55
  cached_charset_invalidate();
55
56
  pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST);
56
57
  pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST);
60
61
  pthread_cond_init(&stop_cond, NULL);
61
62
  pthread_cond_init(&log_space_cond, NULL);
62
63
  relay_log.init_pthread_objects();
63
 
  return;
 
64
  DBUG_VOID_RETURN;
64
65
}
65
66
 
66
67
 
67
68
Relay_log_info::~Relay_log_info()
68
69
{
 
70
  DBUG_ENTER("Relay_log_info::~Relay_log_info");
 
71
 
69
72
  pthread_mutex_destroy(&run_lock);
70
73
  pthread_mutex_destroy(&data_lock);
71
74
  pthread_mutex_destroy(&log_space_lock);
74
77
  pthread_cond_destroy(&stop_cond);
75
78
  pthread_cond_destroy(&log_space_cond);
76
79
  relay_log.cleanup();
77
 
  return;
 
80
  DBUG_VOID_RETURN;
78
81
}
79
82
 
80
83
 
81
 
int32_t init_relay_log_info(Relay_log_info* rli,
 
84
int init_relay_log_info(Relay_log_info* rli,
82
85
                        const char* info_fname)
83
86
{
84
87
  char fname[FN_REFLEN+128];
85
 
  int32_t info_fd;
 
88
  int info_fd;
86
89
  const char* msg = 0;
87
 
  int32_t error = 0;
88
 
  assert(!rli->no_storage);         // Don't init if there is no storage
 
90
  int error = 0;
 
91
  DBUG_ENTER("init_relay_log_info");
 
92
  DBUG_ASSERT(!rli->no_storage);         // Don't init if there is no storage
89
93
 
90
94
  if (rli->inited)                       // Set if this function called
91
 
    return(0);
 
95
    DBUG_RETURN(0);
92
96
  fn_format(fname, info_fname, mysql_data_home, "", 4+32);
93
97
  pthread_mutex_lock(&rli->data_lock);
94
98
  info_fd = rli->info_fd;
131
135
        instead require a name. But as we don't want to break many existing
132
136
        setups, we only give warning, not error.
133
137
      */
134
 
      sql_print_warning(_("Neither --relay-log nor --relay-log-index were used;"
 
138
      sql_print_warning("Neither --relay-log nor --relay-log-index were used;"
135
139
                        " so replication "
136
140
                        "may break when this MySQL server acts as a "
137
141
                        "slave and has his hostname changed!! Please "
138
 
                        "use '--relay-log=%s' to avoid this problem."), ln);
 
142
                        "use '--relay-log=%s' to avoid this problem.", ln);
139
143
      name_warning_sent= 1;
140
144
    }
141
145
    /*
148
152
                            max_binlog_size), 1))
149
153
    {
150
154
      pthread_mutex_unlock(&rli->data_lock);
151
 
      sql_print_error(_("Failed in open_log() called from "
152
 
                        "init_relay_log_info()"));
153
 
      return(1);
 
155
      sql_print_error("Failed in open_log() called from init_relay_log_info()");
 
156
      DBUG_RETURN(1);
154
157
    }
155
158
  }
156
159
 
165
168
      my_close(info_fd, MYF(MY_WME));
166
169
    if ((info_fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
167
170
    {
168
 
      sql_print_error(_("Failed to create a new relay log info file "
169
 
                        "( file '%s', errno %d)"), fname, my_errno);
 
171
      sql_print_error("Failed to create a new relay log info file (\
 
172
file '%s', errno %d)", fname, my_errno);
170
173
      msg= current_thd->main_da.message();
171
174
      goto err;
172
175
    }
173
176
    if (init_io_cache(&rli->info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,
174
177
                      MYF(MY_WME)))
175
178
    {
176
 
      sql_print_error(_("Failed to create a cache on relay log info file '%s'"),
 
179
      sql_print_error("Failed to create a cache on relay log info file '%s'",
177
180
                      fname);
178
181
      msg= current_thd->main_da.message();
179
182
      goto err;
180
183
    }
181
184
 
182
185
    /* Init relay log with first entry in the relay index file */
183
 
    if (init_relay_log_pos(rli,NULL,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
 
186
    if (init_relay_log_pos(rli,NullS,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
184
187
                           &msg, 0))
185
188
    {
186
 
      sql_print_error(_("Failed to open the relay log 'FIRST' (relay_log_pos 4)"));
 
189
      sql_print_error("Failed to open the relay log 'FIRST' (relay_log_pos 4)");
187
190
      goto err;
188
191
    }
189
192
    rli->group_master_log_name[0]= 0;
196
199
      reinit_io_cache(&rli->info_file, READ_CACHE, 0L,0,0);
197
200
    else
198
201
    {
199
 
      int32_t error=0;
 
202
      int error=0;
200
203
      if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
201
204
      {
202
 
        sql_print_error(_("Failed to open the existing relay log info "
203
 
                          "file '%s' (errno %d)"),
 
205
        sql_print_error("\
 
206
Failed to open the existing relay log info file '%s' (errno %d)",
204
207
                        fname, my_errno);
205
208
        error= 1;
206
209
      }
207
210
      else if (init_io_cache(&rli->info_file, info_fd,
208
211
                             IO_SIZE*2, READ_CACHE, 0L, 0, MYF(MY_WME)))
209
212
      {
210
 
        sql_print_error(_("Failed to create a cache on relay log info "
211
 
                          "file '%s'"),
 
213
        sql_print_error("Failed to create a cache on relay log info file '%s'",
212
214
                        fname);
213
215
        error= 1;
214
216
      }
219
221
        rli->info_fd= -1;
220
222
        rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
221
223
        pthread_mutex_unlock(&rli->data_lock);
222
 
        return(1);
 
224
        DBUG_RETURN(1);
223
225
      }
224
226
    }
225
227
 
226
228
    rli->info_fd = info_fd;
227
 
    int32_t relay_log_pos, master_log_pos;
 
229
    int relay_log_pos, master_log_pos;
228
230
    if (init_strvar_from_file(rli->group_relay_log_name,
229
231
                              sizeof(rli->group_relay_log_name),
230
232
                              &rli->info_file, "") ||
250
252
                           &msg, 0))
251
253
    {
252
254
      char llbuf[22];
253
 
      sql_print_error(_("Failed to open the relay log '%s' (relay_log_pos %s)"),
 
255
      sql_print_error("Failed to open the relay log '%s' (relay_log_pos %s)",
254
256
                      rli->group_relay_log_name,
255
257
                      llstr(rli->group_relay_log_pos, llbuf));
256
258
      goto err;
257
259
    }
258
260
  }
259
 
  assert(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
260
 
  assert(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
 
261
 
 
262
#ifndef DBUG_OFF
 
263
  {
 
264
    char llbuf1[22], llbuf2[22];
 
265
    DBUG_PRINT("info", ("my_b_tell(rli->cur_log)=%s rli->event_relay_log_pos=%s",
 
266
                        llstr(my_b_tell(rli->cur_log),llbuf1),
 
267
                        llstr(rli->event_relay_log_pos,llbuf2)));
 
268
    DBUG_ASSERT(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
 
269
    DBUG_ASSERT(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
 
270
  }
 
271
#endif
261
272
 
262
273
  /*
263
274
    Now change the cache from READ to WRITE - must do this
265
276
  */
266
277
  reinit_io_cache(&rli->info_file, WRITE_CACHE,0L,0,1);
267
278
  if ((error= flush_relay_log_info(rli)))
268
 
    sql_print_error(_("Failed to flush relay log info file"));
 
279
    sql_print_error("Failed to flush relay log info file");
269
280
  if (count_relay_log_space(rli))
270
281
  {
271
 
    msg=_("Error counting relay log space");
 
282
    msg="Error counting relay log space";
272
283
    goto err;
273
284
  }
274
285
  rli->inited= 1;
275
286
  pthread_mutex_unlock(&rli->data_lock);
276
 
  return(error);
 
287
  DBUG_RETURN(error);
277
288
 
278
289
err:
279
290
  sql_print_error(msg);
283
294
  rli->info_fd= -1;
284
295
  rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
285
296
  pthread_mutex_unlock(&rli->data_lock);
286
 
  return(1);
 
297
  DBUG_RETURN(1);
287
298
}
288
299
 
289
300
 
290
 
static inline int32_t add_relay_log(Relay_log_info* rli,LOG_INFO* linfo)
 
301
static inline int add_relay_log(Relay_log_info* rli,LOG_INFO* linfo)
291
302
{
292
303
  struct stat s;
 
304
  DBUG_ENTER("add_relay_log");
293
305
  if (stat(linfo->log_file_name,&s))
294
306
  {
295
 
    sql_print_error(_("log %s listed in the index, but failed to stat"),
 
307
    sql_print_error("log %s listed in the index, but failed to stat",
296
308
                    linfo->log_file_name);
297
 
    return(1);
 
309
    DBUG_RETURN(1);
298
310
  }
299
311
  rli->log_space_total += s.st_size;
300
 
  return(0);
 
312
#ifndef DBUG_OFF
 
313
  char buf[22];
 
314
  DBUG_PRINT("info",("log_space_total: %s", llstr(rli->log_space_total,buf)));
 
315
#endif
 
316
  DBUG_RETURN(0);
301
317
}
302
318
 
303
319
 
304
 
static int32_t count_relay_log_space(Relay_log_info* rli)
 
320
static int count_relay_log_space(Relay_log_info* rli)
305
321
{
306
322
  LOG_INFO linfo;
 
323
  DBUG_ENTER("count_relay_log_space");
307
324
  rli->log_space_total= 0;
308
 
  if (rli->relay_log.find_log_pos(&linfo, NULL, 1))
 
325
  if (rli->relay_log.find_log_pos(&linfo, NullS, 1))
309
326
  {
310
 
    sql_print_error(_("Could not find first log while counting relay "
311
 
                      "log space"));
312
 
    return(1);
 
327
    sql_print_error("Could not find first log while counting relay log space");
 
328
    DBUG_RETURN(1);
313
329
  }
314
330
  do
315
331
  {
316
332
    if (add_relay_log(rli,&linfo))
317
 
      return(1);
 
333
      DBUG_RETURN(1);
318
334
  } while (!rli->relay_log.find_next_log(&linfo, 1));
319
335
  /*
320
336
     As we have counted everything, including what may have written in a
322
338
     twice.
323
339
  */
324
340
  rli->relay_log.reset_bytes_written();
325
 
  return(0);
 
341
  DBUG_RETURN(0);
326
342
}
327
343
 
328
344
 
336
352
 
337
353
void Relay_log_info::clear_until_condition()
338
354
{
 
355
  DBUG_ENTER("clear_until_condition");
 
356
 
339
357
  until_condition= Relay_log_info::UNTIL_NONE;
340
358
  until_log_name[0]= 0;
341
359
  until_log_pos= 0;
342
 
  return;
 
360
  DBUG_VOID_RETURN;
343
361
}
344
362
 
345
363
 
375
393
    1   error.  errmsg is set to point to the error message
376
394
*/
377
395
 
378
 
int32_t init_relay_log_pos(Relay_log_info* rli,const char* log,
379
 
                       uint64_t pos, bool need_data_lock,
 
396
int init_relay_log_pos(Relay_log_info* rli,const char* log,
 
397
                       ulonglong pos, bool need_data_lock,
380
398
                       const char** errmsg,
381
399
                       bool look_for_description_event)
382
400
{
 
401
  DBUG_ENTER("init_relay_log_pos");
 
402
  DBUG_PRINT("info", ("pos: %lu", (ulong) pos));
 
403
 
383
404
  *errmsg=0;
384
405
  pthread_mutex_t *log_lock=rli->relay_log.get_log_lock();
385
406
 
420
441
    Test to see if the previous run was with the skip of purging
421
442
    If yes, we do not purge when we restart
422
443
  */
423
 
  if (rli->relay_log.find_log_pos(&rli->linfo, NULL, 1))
 
444
  if (rli->relay_log.find_log_pos(&rli->linfo, NullS, 1))
424
445
  {
425
446
    *errmsg="Could not find first log during relay log initialization";
426
447
    goto err;
470
491
        Read the possible Format_description_log_event; if position
471
492
        was 4, no need, it will be read naturally.
472
493
      */
 
494
      DBUG_PRINT("info",("looking for a Format_description_log_event"));
 
495
 
473
496
      if (my_b_tell(rli->cur_log) >= pos)
474
497
        break;
475
498
 
480
503
      if (!(ev=Log_event::read_log_event(rli->cur_log,0,
481
504
                                         rli->relay_log.description_event_for_exec)))
482
505
      {
 
506
        DBUG_PRINT("info",("could not read event, rli->cur_log->error=%d",
 
507
                           rli->cur_log->error));
483
508
        if (rli->cur_log->error) /* not EOF */
484
509
        {
485
510
          *errmsg= "I/O error reading event at position 4";
489
514
      }
490
515
      else if (ev->get_type_code() == FORMAT_DESCRIPTION_EVENT)
491
516
      {
 
517
        DBUG_PRINT("info",("found Format_description_log_event"));
492
518
        delete rli->relay_log.description_event_for_exec;
493
519
        rli->relay_log.description_event_for_exec= (Format_description_log_event*) ev;
494
520
        /*
514
540
      }
515
541
      else
516
542
      {
 
543
        DBUG_PRINT("info",("found event of another type=%d",
 
544
                           ev->get_type_code()));
517
545
        look_for_description_event= (ev->get_type_code() == ROTATE_EVENT);
518
546
        delete ev;
519
547
      }
520
548
    }
521
549
    my_b_seek(rli->cur_log,(off_t)pos);
 
550
#ifndef DBUG_OFF
 
551
  {
 
552
    char llbuf1[22], llbuf2[22];
 
553
    DBUG_PRINT("info", ("my_b_tell(rli->cur_log)=%s rli->event_relay_log_pos=%s",
 
554
                        llstr(my_b_tell(rli->cur_log),llbuf1),
 
555
                        llstr(rli->event_relay_log_pos,llbuf2)));
 
556
  }
 
557
#endif
522
558
 
523
559
  }
524
560
 
538
574
  if (!rli->relay_log.description_event_for_exec->is_valid() && !*errmsg)
539
575
    *errmsg= "Invalid Format_description log event; could be out of memory";
540
576
 
541
 
  return ((*errmsg) ? 1 : 0);
 
577
  DBUG_RETURN ((*errmsg) ? 1 : 0);
542
578
}
543
579
 
544
580
 
554
590
    timeout         timeout in seconds before giving up waiting
555
591
 
556
592
  NOTES
557
 
    timeout is int64_t whereas it should be uint32_t ; but this is
 
593
    timeout is longlong whereas it should be ulong ; but this is
558
594
    to catch if the user submitted a negative timeout.
559
595
 
560
596
  RETURN VALUES
567
603
                before reaching the desired log/position
568
604
 */
569
605
 
570
 
int32_t Relay_log_info::wait_for_pos(THD* thd, String* log_name,
571
 
                                    int64_t log_pos,
572
 
                                    int64_t timeout)
 
606
int Relay_log_info::wait_for_pos(THD* thd, String* log_name,
 
607
                                    longlong log_pos,
 
608
                                    longlong timeout)
573
609
{
574
 
  int32_t event_count = 0;
575
 
  uint32_t init_abort_pos_wait;
576
 
  int32_t error=0;
 
610
  int event_count = 0;
 
611
  ulong init_abort_pos_wait;
 
612
  int error=0;
577
613
  struct timespec abstime; // for timeout checking
578
614
  const char *msg;
 
615
  DBUG_ENTER("Relay_log_info::wait_for_pos");
579
616
 
580
617
  if (!inited)
581
 
    return(-2);
 
618
    DBUG_RETURN(-2);
 
619
 
 
620
  DBUG_PRINT("enter",("log_name: '%s'  log_pos: %lu  timeout: %lu",
 
621
                      log_name->c_ptr(), (ulong) log_pos, (ulong) timeout));
582
622
 
583
623
  set_timespec(abstime,timeout);
584
624
  pthread_mutex_lock(&data_lock);
603
643
  /*
604
644
    We'll need to
605
645
    handle all possible log names comparisons (e.g. 999 vs 1000).
606
 
    We use uint32_t for string->number conversion ; this is no
 
646
    We use ulong for string->number conversion ; this is no
607
647
    stronger limitation than in find_uniq_filename in sql/log.cc
608
648
  */
609
 
  uint32_t log_name_extension;
 
649
  ulong log_name_extension;
610
650
  char log_name_tmp[FN_REFLEN]; //make a char[] from String
611
651
 
612
 
  strmake(log_name_tmp, log_name->ptr(), cmin(log_name->length(), (uint32_t)FN_REFLEN-1));
 
652
  strmake(log_name_tmp, log_name->ptr(), min(log_name->length(), FN_REFLEN-1));
613
653
 
614
654
  char *p= fn_ext(log_name_tmp);
615
655
  char *p_end;
619
659
    goto err;
620
660
  }
621
661
  // Convert 0-3 to 4
622
 
  log_pos= cmax(log_pos, (int64_t)BIN_LOG_HEADER_SIZE);
 
662
  log_pos= max(log_pos, BIN_LOG_HEADER_SIZE);
623
663
  /* p points to '.' */
624
664
  log_name_extension= strtoul(++p, &p_end, 10);
625
665
  /*
639
679
         slave_running)
640
680
  {
641
681
    bool pos_reached;
642
 
    int32_t cmp_result= 0;
 
682
    int cmp_result= 0;
 
683
 
 
684
    DBUG_PRINT("info",
 
685
               ("init_abort_pos_wait: %ld  abort_pos_wait: %ld",
 
686
                init_abort_pos_wait, abort_pos_wait));
 
687
    DBUG_PRINT("info",("group_master_log_name: '%s'  pos: %lu",
 
688
                       group_master_log_name, (ulong) group_master_log_pos));
643
689
 
644
690
    /*
645
691
      group_master_log_name can be "", if we are just after a fresh
665
711
        if the names do not match up to '.' included, return error
666
712
      */
667
713
      char *q= (char*)(fn_ext(basename)+1);
668
 
      if (strncmp(basename, log_name_tmp, (int32_t)(q-basename)))
 
714
      if (strncmp(basename, log_name_tmp, (int)(q-basename)))
669
715
      {
670
716
        error= -2;
671
717
        break;
672
718
      }
673
719
      // Now compare extensions.
674
720
      char *q_end;
675
 
      uint32_t group_master_log_name_extension= strtoul(q, &q_end, 10);
 
721
      ulong group_master_log_name_extension= strtoul(q, &q_end, 10);
676
722
      if (group_master_log_name_extension < log_name_extension)
677
723
        cmp_result= -1 ;
678
724
      else
679
725
        cmp_result= (group_master_log_name_extension > log_name_extension) ? 1 : 0 ;
680
726
 
681
 
      pos_reached= ((!cmp_result && group_master_log_pos >= (uint64_t)log_pos) ||
 
727
      pos_reached= ((!cmp_result && group_master_log_pos >= (ulonglong)log_pos) ||
682
728
                    cmp_result > 0);
683
729
      if (pos_reached || thd->killed)
684
730
        break;
686
732
 
687
733
    //wait for master update, with optional timeout.
688
734
 
 
735
    DBUG_PRINT("info",("Waiting for master update"));
689
736
    /*
690
737
      We are going to pthread_cond_(timed)wait(); if the SQL thread stops it
691
738
      will wake us up.
707
754
    }
708
755
    else
709
756
      pthread_cond_wait(&data_cond, &data_lock);
 
757
    DBUG_PRINT("info",("Got signal of master update or timed out"));
710
758
    if (error == ETIMEDOUT || error == ETIME)
711
759
    {
712
760
      error= -1;
714
762
    }
715
763
    error=0;
716
764
    event_count++;
 
765
    DBUG_PRINT("info",("Testing if killed or SQL thread not running"));
717
766
  }
718
767
 
719
768
err:
720
769
  thd->exit_cond(msg);
 
770
  DBUG_PRINT("exit",("killed: %d  abort: %d  slave_running: %d \
 
771
improper_arguments: %d  timed_out: %d",
 
772
                     thd->killed_errno(),
 
773
                     (int) (init_abort_pos_wait != abort_pos_wait),
 
774
                     (int) slave_running,
 
775
                     (int) (error == -2),
 
776
                     (int) (error == -1)));
721
777
  if (thd->killed || init_abort_pos_wait != abort_pos_wait ||
722
778
      !slave_running)
723
779
  {
724
780
    error= -2;
725
781
  }
726
 
  return( error ? error : event_count );
 
782
  DBUG_RETURN( error ? error : event_count );
727
783
}
728
784
 
729
785
 
730
 
void Relay_log_info::inc_group_relay_log_pos(uint64_t log_pos,
 
786
void Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos,
731
787
                                                bool skip_lock)
732
788
{
 
789
  DBUG_ENTER("Relay_log_info::inc_group_relay_log_pos");
 
790
 
733
791
  if (!skip_lock)
734
792
    pthread_mutex_lock(&data_lock);
735
793
  inc_event_relay_log_pos();
769
827
    the relay log is not "val".
770
828
    With the end_log_pos solution, we avoid computations involving lengthes.
771
829
  */
 
830
  DBUG_PRINT("info", ("log_pos: %lu  group_master_log_pos: %lu",
 
831
                      (long) log_pos, (long) group_master_log_pos));
772
832
  if (log_pos) // 3.23 binlogs don't have log_posx
773
833
  {
774
834
    group_master_log_pos= log_pos;
776
836
  pthread_cond_broadcast(&data_cond);
777
837
  if (!skip_lock)
778
838
    pthread_mutex_unlock(&data_lock);
779
 
  return;
 
839
  DBUG_VOID_RETURN;
780
840
}
781
841
 
782
842
 
783
843
void Relay_log_info::close_temporary_tables()
784
844
{
785
 
  Table *table,*next;
 
845
  TABLE *table,*next;
 
846
  DBUG_ENTER("Relay_log_info::close_temporary_tables");
786
847
 
787
848
  for (table=save_temporary_tables ; table ; table=next)
788
849
  {
791
852
      Don't ask for disk deletion. For now, anyway they will be deleted when
792
853
      slave restarts, but it is a better intention to not delete them.
793
854
    */
 
855
    DBUG_PRINT("info", ("table: 0x%lx", (long) table));
794
856
    close_temporary(table, 1, 0);
795
857
  }
796
858
  save_temporary_tables= 0;
797
859
  slave_open_temp_tables= 0;
798
 
  return;
 
860
  DBUG_VOID_RETURN;
799
861
}
800
862
 
801
863
/*
805
867
    Assumes to have a run lock on rli and that no slave thread are running.
806
868
*/
807
869
 
808
 
int32_t purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset,
 
870
int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset,
809
871
                     const char** errmsg)
810
872
{
811
 
  int32_t error=0;
 
873
  int error=0;
 
874
  DBUG_ENTER("purge_relay_logs");
812
875
 
813
876
  /*
814
877
    Even if rli->inited==0, we still try to empty rli->master_log_* variables.
833
896
 
834
897
  if (!rli->inited)
835
898
  {
836
 
    return(0);
 
899
    DBUG_PRINT("info", ("rli->inited == 0"));
 
900
    DBUG_RETURN(0);
837
901
  }
838
902
 
839
 
  assert(rli->slave_running == 0);
840
 
  assert(rli->mi->slave_running == 0);
 
903
  DBUG_ASSERT(rli->slave_running == 0);
 
904
  DBUG_ASSERT(rli->mi->slave_running == 0);
841
905
 
842
906
  rli->slave_skip_counter=0;
843
907
  pthread_mutex_lock(&rli->data_lock);
878
942
                              0 /* do not need data lock */, errmsg, 0);
879
943
 
880
944
err:
 
945
#ifndef DBUG_OFF
 
946
  char buf[22];
 
947
#endif
 
948
  DBUG_PRINT("info",("log_space_total: %s",llstr(rli->log_space_total,buf)));
881
949
  pthread_mutex_unlock(&rli->data_lock);
882
 
  return(error);
 
950
  DBUG_RETURN(error);
883
951
}
884
952
 
885
953
 
919
987
bool Relay_log_info::is_until_satisfied(my_off_t master_beg_pos)
920
988
{
921
989
  const char *log_name;
922
 
  uint64_t log_pos;
 
990
  ulonglong log_pos;
 
991
  DBUG_ENTER("Relay_log_info::is_until_satisfied");
923
992
 
924
 
  assert(until_condition != UNTIL_NONE);
 
993
  DBUG_ASSERT(until_condition != UNTIL_NONE);
925
994
 
926
995
  if (until_condition == UNTIL_MASTER_POS)
927
996
  {
934
1003
    log_pos= group_relay_log_pos;
935
1004
  }
936
1005
 
 
1006
#ifndef DBUG_OFF
 
1007
  {
 
1008
    char buf[32];
 
1009
    DBUG_PRINT("info", ("group_master_log_name='%s', group_master_log_pos=%s",
 
1010
                        group_master_log_name, llstr(group_master_log_pos, buf)));
 
1011
    DBUG_PRINT("info", ("group_relay_log_name='%s', group_relay_log_pos=%s",
 
1012
                        group_relay_log_name, llstr(group_relay_log_pos, buf)));
 
1013
    DBUG_PRINT("info", ("(%s) log_name='%s', log_pos=%s",
 
1014
                        until_condition == UNTIL_MASTER_POS ? "master" : "relay",
 
1015
                        log_name, llstr(log_pos, buf)));
 
1016
    DBUG_PRINT("info", ("(%s) until_log_name='%s', until_log_pos=%s",
 
1017
                        until_condition == UNTIL_MASTER_POS ? "master" : "relay",
 
1018
                        until_log_name, llstr(until_log_pos, buf)));
 
1019
  }
 
1020
#endif
 
1021
 
937
1022
  if (until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_UNKNOWN)
938
1023
  {
939
1024
    /*
949
1034
      const char *basename= log_name + dirname_length(log_name);
950
1035
 
951
1036
      const char *q= (const char*)(fn_ext(basename)+1);
952
 
      if (strncmp(basename, until_log_name, (int32_t)(q-basename)) == 0)
 
1037
      if (strncmp(basename, until_log_name, (int)(q-basename)) == 0)
953
1038
      {
954
1039
        /* Now compare extensions. */
955
1040
        char *q_end;
956
 
        uint32_t log_name_extension= strtoul(q, &q_end, 10);
 
1041
        ulong log_name_extension= strtoul(q, &q_end, 10);
957
1042
        if (log_name_extension < until_log_name_extension)
958
1043
          until_log_names_cmp_result= UNTIL_LOG_NAMES_CMP_LESS;
959
1044
        else
964
1049
      else
965
1050
      {
966
1051
        /* Probably error so we aborting */
967
 
        sql_print_error(_("Slave SQL thread is stopped because UNTIL "
968
 
                          "condition is bad."));
969
 
        return(true);
 
1052
        sql_print_error("Slave SQL thread is stopped because UNTIL "
 
1053
                        "condition is bad.");
 
1054
        DBUG_RETURN(TRUE);
970
1055
      }
971
1056
    }
972
1057
    else
973
 
      return(until_log_pos == 0);
 
1058
      DBUG_RETURN(until_log_pos == 0);
974
1059
  }
975
1060
 
976
 
  return(((until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_EQUAL &&
 
1061
  DBUG_RETURN(((until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_EQUAL &&
977
1062
           log_pos >= until_log_pos) ||
978
1063
          until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_GREATER));
979
1064
}
981
1066
 
982
1067
void Relay_log_info::cached_charset_invalidate()
983
1068
{
 
1069
  DBUG_ENTER("Relay_log_info::cached_charset_invalidate");
 
1070
 
984
1071
  /* Full of zeroes means uninitialized. */
985
 
  memset(cached_charset, 0, sizeof(cached_charset));
986
 
  return;
 
1072
  bzero(cached_charset, sizeof(cached_charset));
 
1073
  DBUG_VOID_RETURN;
987
1074
}
988
1075
 
989
1076
 
990
1077
bool Relay_log_info::cached_charset_compare(char *charset) const
991
1078
{
992
 
  if (memcmp(cached_charset, charset, sizeof(cached_charset)))
 
1079
  DBUG_ENTER("Relay_log_info::cached_charset_compare");
 
1080
 
 
1081
  if (bcmp((uchar*) cached_charset, (uchar*) charset,
 
1082
           sizeof(cached_charset)))
993
1083
  {
994
1084
    memcpy(const_cast<char*>(cached_charset), charset, sizeof(cached_charset));
995
 
    return(1);
 
1085
    DBUG_RETURN(1);
996
1086
  }
997
 
  return(0);
 
1087
  DBUG_RETURN(0);
998
1088
}
999
1089
 
1000
1090
 
1001
1091
void Relay_log_info::stmt_done(my_off_t event_master_log_pos,
1002
1092
                                  time_t event_creation_time)
1003
1093
{
1004
 
  extern uint32_t debug_not_change_ts_if_art_event;
 
1094
#ifndef DBUG_OFF
 
1095
  extern uint debug_not_change_ts_if_art_event;
 
1096
#endif
1005
1097
  clear_flag(IN_STMT);
1006
1098
 
1007
1099
  /*
1041
1133
      is that value may take some time to display in
1042
1134
      Seconds_Behind_Master - not critical).
1043
1135
    */
 
1136
#ifndef DBUG_OFF
1044
1137
    if (!(event_creation_time == 0 && debug_not_change_ts_if_art_event > 0))
1045
 
      last_master_timestamp= event_creation_time;
 
1138
#else
 
1139
      if (event_creation_time != 0)
 
1140
#endif
 
1141
        last_master_timestamp= event_creation_time;
1046
1142
  }
1047
1143
}
1048
1144
 
 
1145
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
1049
1146
void Relay_log_info::cleanup_context(THD *thd, bool error)
1050
1147
{
1051
 
  assert(sql_thd == thd);
 
1148
  DBUG_ENTER("Relay_log_info::cleanup_context");
 
1149
 
 
1150
  DBUG_ASSERT(sql_thd == thd);
1052
1151
  /*
1053
1152
    1) Instances of Table_map_log_event, if ::do_apply_event() was called on them,
1054
1153
    may have opened tables, which we cannot be sure have been closed (because
1076
1175
  thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
1077
1176
  thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
1078
1177
  last_event_start_time= 0;
1079
 
  return;
 
1178
  DBUG_VOID_RETURN;
1080
1179
}
1081
1180
 
1082
1181
void Relay_log_info::clear_tables_to_lock()
1083
1182
{
1084
1183
  while (tables_to_lock)
1085
1184
  {
1086
 
    unsigned char* to_free= reinterpret_cast<unsigned char*>(tables_to_lock);
 
1185
    uchar* to_free= reinterpret_cast<uchar*>(tables_to_lock);
1087
1186
    if (tables_to_lock->m_tabledef_valid)
1088
1187
    {
1089
1188
      tables_to_lock->m_tabledef.table_def::~table_def();
1090
 
      tables_to_lock->m_tabledef_valid= false;
 
1189
      tables_to_lock->m_tabledef_valid= FALSE;
1091
1190
    }
1092
1191
    tables_to_lock=
1093
 
      static_cast<RPL_TableList*>(tables_to_lock->next_global);
 
1192
      static_cast<RPL_TABLE_LIST*>(tables_to_lock->next_global);
1094
1193
    tables_to_lock_count--;
1095
 
    free(to_free);
 
1194
    my_free(to_free, MYF(MY_WME));
1096
1195
  }
1097
 
  assert(tables_to_lock == NULL && tables_to_lock_count == 0);
 
1196
  DBUG_ASSERT(tables_to_lock == NULL && tables_to_lock_count == 0);
1098
1197
}
 
1198
 
 
1199
#endif