~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_repl.cc

Put errmsg.c in sql-common since it can be built only once and used twice.
Put client.c and net_serv.c in libmysql so that we can only have one
link_sources section. 
Got rid of just about all copying and other weirdness, other than some stuff
in client and client.c/net_serv.c, which need to be reworked.

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
#ifdef HAVE_REPLICATION
17
18
 
18
19
#include "rpl_mi.h"
19
20
#include "sql_repl.h"
20
21
#include "log_event.h"
21
22
#include "rpl_filter.h"
22
 
#include <drizzled/drizzled_error_messages.h>
 
23
#include <my_dir.h>
23
24
 
24
25
int max_binlog_dump_events = 0; // unlimited
 
26
my_bool opt_sporadic_binlog_dump_fail = 0;
 
27
#ifndef DBUG_OFF
 
28
static int binlog_dump_count = 0;
 
29
#endif
25
30
 
26
31
/*
27
32
    fake_rotate_event() builds a fake (=which does not exist physically in any
40
45
    well-placed zeros was not possible as Rotate events have a variable-length
41
46
    part.
42
47
*/
 
48
 
43
49
static int fake_rotate_event(NET* net, String* packet, char* log_file_name,
44
 
                             uint64_t position, const char** errmsg)
 
50
                             ulonglong position, const char** errmsg)
45
51
{
 
52
  DBUG_ENTER("fake_rotate_event");
46
53
  char header[LOG_EVENT_HEADER_LEN], buf[ROTATE_HEADER_LEN+100];
47
54
  /*
48
55
    'when' (the timestamp) is set to 0 so that slave could distinguish between
52
59
  header[EVENT_TYPE_OFFSET] = ROTATE_EVENT;
53
60
 
54
61
  char* p = log_file_name+dirname_length(log_file_name);
55
 
  uint32_t ident_len = (uint32_t) strlen(p);
56
 
  uint32_t event_len = ident_len + LOG_EVENT_HEADER_LEN + ROTATE_HEADER_LEN;
 
62
  uint ident_len = (uint) strlen(p);
 
63
  ulong event_len = ident_len + LOG_EVENT_HEADER_LEN + ROTATE_HEADER_LEN;
57
64
  int4store(header + SERVER_ID_OFFSET, server_id);
58
65
  int4store(header + EVENT_LEN_OFFSET, event_len);
59
66
  int2store(header + FLAGS_OFFSET, 0);
65
72
  int8store(buf+R_POS_OFFSET,position);
66
73
  packet->append(buf, ROTATE_HEADER_LEN);
67
74
  packet->append(p,ident_len);
68
 
  if (my_net_write(net, (unsigned char*) packet->ptr(), packet->length()))
 
75
  if (my_net_write(net, (uchar*) packet->ptr(), packet->length()))
69
76
  {
70
77
    *errmsg = "failed on my_net_write()";
71
 
    return(-1);
 
78
    DBUG_RETURN(-1);
72
79
  }
73
 
  return(0);
 
80
  DBUG_RETURN(0);
74
81
}
75
82
 
76
83
static int send_file(THD *thd)
82
89
  const char *errmsg = 0;
83
90
  int old_timeout;
84
91
  unsigned long packet_len;
85
 
  unsigned char buf[IO_SIZE];                           // It's safe to alloc this
 
92
  uchar buf[IO_SIZE];                           // It's safe to alloc this
 
93
  DBUG_ENTER("send_file");
86
94
 
87
95
  /*
88
96
    The client might be slow loading the data, give him wait_timeout to do
97
105
  */
98
106
  if (net_flush(net) || (packet_len = my_net_read(net)) == packet_error)
99
107
  {
100
 
    errmsg = _("Failed in send_file() while reading file name");
 
108
    errmsg = "while reading file name";
101
109
    goto err;
102
110
  }
103
111
 
110
118
 
111
119
  if ((fd = my_open(fname, O_RDONLY, MYF(0))) < 0)
112
120
  {
113
 
    errmsg = _("Failed in send_file() on open of file");
 
121
    errmsg = "on open of file";
114
122
    goto err;
115
123
  }
116
124
 
118
126
  {
119
127
    if (my_net_write(net, buf, bytes))
120
128
    {
121
 
      errmsg = _("Failed in send_file() while writing data to client");
 
129
      errmsg = "while writing data to client";
122
130
      goto err;
123
131
    }
124
132
  }
125
133
 
126
134
 end:
127
 
  if (my_net_write(net, (unsigned char*) "", 0) || net_flush(net) ||
 
135
  if (my_net_write(net, (uchar*) "", 0) || net_flush(net) ||
128
136
      (my_net_read(net) == packet_error))
129
137
  {
130
 
    errmsg = _("Failed in send_file() while negotiating file transfer close");
 
138
    errmsg = "while negotiating file transfer close";
131
139
    goto err;
132
140
  }
133
141
  error = 0;
138
146
    (void) my_close(fd, MYF(0));
139
147
  if (errmsg)
140
148
  {
141
 
    sql_print_error(errmsg);
 
149
    sql_print_error("Failed in send_file() %s", errmsg);
 
150
    DBUG_PRINT("error", (errmsg));
142
151
  }
143
 
  return(error);
 
152
  DBUG_RETURN(error);
144
153
}
145
154
 
146
155
 
209
218
    if ((linfo = tmp->current_linfo))
210
219
    {
211
220
      pthread_mutex_lock(&linfo->lock);
212
 
      result = !memcmp(log_name, linfo->log_file_name, log_name_len);
 
221
      result = !bcmp((uchar*) log_name, (uchar*) linfo->log_file_name,
 
222
                     log_name_len);
213
223
      pthread_mutex_unlock(&linfo->lock);
214
224
      if (result)
215
225
        break;
222
232
 
223
233
bool purge_error_message(THD* thd, int res)
224
234
{
225
 
  uint32_t errmsg= 0;
 
235
  uint errmsg= 0;
226
236
 
227
237
  switch (res)  {
228
238
  case 0: break;
240
250
  if (errmsg)
241
251
  {
242
252
    my_message(errmsg, ER(errmsg), MYF(0));
243
 
    return true;
 
253
    return TRUE;
244
254
  }
245
255
  my_ok(thd);
246
 
  return false;
 
256
  return FALSE;
247
257
}
248
258
 
249
259
 
253
263
  if (!mysql_bin_log.is_open())
254
264
  {
255
265
    my_ok(thd);
256
 
    return false;
 
266
    return FALSE;
257
267
  }
258
268
 
259
269
  mysql_bin_log.make_log_name(search_file_name, to_log);
310
320
 
311
321
  @param[in]    thd  THD to access a user variable
312
322
 
313
 
  @return        heartbeat period an uint64_t of nanoseconds
 
323
  @return        heartbeat period an ulonglong of nanoseconds
314
324
                 or zero if heartbeat was not demanded by slave
315
325
*/ 
316
 
static uint64_t get_heartbeat_period(THD * thd)
 
326
static ulonglong get_heartbeat_period(THD * thd)
317
327
{
318
 
  bool null_value;
 
328
  my_bool null_value;
319
329
  LEX_STRING name=  { C_STRING_WITH_LEN("master_heartbeat_period")};
320
330
  user_var_entry *entry= 
321
 
    (user_var_entry*) hash_search(&thd->user_vars, (unsigned char*) name.str,
 
331
    (user_var_entry*) hash_search(&thd->user_vars, (uchar*) name.str,
322
332
                                  name.length);
323
333
  return entry? entry->val_int(&null_value) : 0;
324
334
}
340
350
static int send_heartbeat_event(NET* net, String* packet,
341
351
                                const struct event_coordinates *coord)
342
352
{
 
353
  DBUG_ENTER("send_heartbeat_event");
343
354
  char header[LOG_EVENT_HEADER_LEN];
344
355
  /*
345
356
    'when' (the timestamp) is set to 0 so that slave could distinguish between
351
362
 
352
363
  char* p= coord->file_name + dirname_length(coord->file_name);
353
364
 
354
 
  uint32_t ident_len = strlen(p);
355
 
  uint32_t event_len = ident_len + LOG_EVENT_HEADER_LEN;
 
365
  uint ident_len = strlen(p);
 
366
  ulong event_len = ident_len + LOG_EVENT_HEADER_LEN;
356
367
  int4store(header + SERVER_ID_OFFSET, server_id);
357
368
  int4store(header + EVENT_LEN_OFFSET, event_len);
358
369
  int2store(header + FLAGS_OFFSET, 0);
362
373
  packet->append(header, sizeof(header));
363
374
  packet->append(p, ident_len);             // log_file_name
364
375
 
365
 
  if (my_net_write(net, (unsigned char*) packet->ptr(), packet->length()) ||
 
376
  if (my_net_write(net, (uchar*) packet->ptr(), packet->length()) ||
366
377
      net_flush(net))
367
378
  {
368
 
    return(-1);
 
379
    DBUG_RETURN(-1);
369
380
  }
370
381
  packet->set("\0", 1, &my_charset_bin);
371
 
  return(0);
 
382
  DBUG_RETURN(0);
372
383
}
373
384
 
374
385
/*
376
387
*/
377
388
 
378
389
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos,
379
 
                       uint16_t flags)
 
390
                       ushort flags)
380
391
{
381
392
  LOG_INFO linfo;
382
393
  char *log_file_name = linfo.log_file_name;
388
399
  const char *errmsg = "Unknown error";
389
400
  NET* net = &thd->net;
390
401
  pthread_mutex_t *log_lock;
391
 
  bool binlog_can_be_corrupted= false;
 
402
  bool binlog_can_be_corrupted= FALSE;
 
403
#ifndef DBUG_OFF
 
404
  int left_events = max_binlog_dump_events;
 
405
#endif
 
406
  DBUG_ENTER("mysql_binlog_send");
 
407
  DBUG_PRINT("enter",("log_ident: '%s'  pos: %ld", log_ident, (long) pos));
392
408
 
393
 
  memset(&log, 0, sizeof(log));
 
409
  bzero((char*) &log,sizeof(log));
394
410
  /* 
395
411
     heartbeat_period from @master_heartbeat_period user variable
396
412
  */
397
 
  uint64_t heartbeat_period= get_heartbeat_period(thd);
 
413
  ulonglong heartbeat_period= get_heartbeat_period(thd);
398
414
  struct timespec heartbeat_buf;
399
415
  struct event_coordinates coord_buf;
400
416
  struct timespec *heartbeat_ts= NULL;
401
417
  struct event_coordinates *coord= NULL;
402
 
  if (heartbeat_period != 0L)
 
418
  if (heartbeat_period != LL(0))
403
419
  {
404
420
    heartbeat_ts= &heartbeat_buf;
405
421
    set_timespec_nsec(*heartbeat_ts, 0);
407
423
    coord->file_name= log_file_name; // initialization basing on what slave remembers
408
424
    coord->pos= pos;
409
425
  }
 
426
#ifndef DBUG_OFF
 
427
  if (opt_sporadic_binlog_dump_fail && (binlog_dump_count++ % 2))
 
428
  {
 
429
    errmsg = "Master failed COM_BINLOG_DUMP to test if slave can recover";
 
430
    my_errno= ER_UNKNOWN_ERROR;
 
431
    goto err;
 
432
  }
 
433
#endif
410
434
 
411
435
  if (!mysql_bin_log.is_open())
412
436
  {
523
547
         The packet has offsets equal to the normal offsets in a binlog
524
548
         event +1 (the first character is \0).
525
549
       */
 
550
       DBUG_PRINT("info",
 
551
                  ("Looked for a Format_description_log_event, found event type %d",
 
552
                   (*packet)[EVENT_TYPE_OFFSET+1]));
526
553
       if ((*packet)[EVENT_TYPE_OFFSET+1] == FORMAT_DESCRIPTION_EVENT)
527
554
       {
528
555
         binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+1] &
539
566
           to avoid destroying temp tables.
540
567
          */
541
568
         int4store((char*) packet->ptr()+LOG_EVENT_MINIMAL_HEADER_LEN+
542
 
                   ST_CREATED_OFFSET+1, (uint32_t) 0);
 
569
                   ST_CREATED_OFFSET+1, (ulong) 0);
543
570
         /* send it */
544
 
         if (my_net_write(net, (unsigned char*) packet->ptr(), packet->length()))
 
571
         if (my_net_write(net, (uchar*) packet->ptr(), packet->length()))
545
572
         {
546
573
           errmsg = "Failed on my_net_write()";
547
574
           my_errno= ER_UNKNOWN_ERROR;
580
607
  {
581
608
    while (!(error = Log_event::read_log_event(&log, packet, log_lock)))
582
609
    {
 
610
#ifndef DBUG_OFF
 
611
      if (max_binlog_dump_events && !left_events--)
 
612
      {
 
613
        net_flush(net);
 
614
        errmsg = "Debugging binlog dump abort";
 
615
        my_errno= ER_UNKNOWN_ERROR;
 
616
        goto err;
 
617
      }
 
618
#endif
583
619
      /*
584
620
        log's filename does not change while it's active
585
621
      */
593
629
        (*packet)[FLAGS_OFFSET+1] &= ~LOG_EVENT_BINLOG_IN_USE_F;
594
630
      }
595
631
      else if ((*packet)[EVENT_TYPE_OFFSET+1] == STOP_EVENT)
596
 
        binlog_can_be_corrupted= false;
 
632
        binlog_can_be_corrupted= FALSE;
597
633
 
598
 
      if (my_net_write(net, (unsigned char*) packet->ptr(), packet->length()))
 
634
      if (my_net_write(net, (uchar*) packet->ptr(), packet->length()))
599
635
      {
600
636
        errmsg = "Failed on my_net_write()";
601
637
        my_errno= ER_UNKNOWN_ERROR;
602
638
        goto err;
603
639
      }
604
640
 
 
641
      DBUG_PRINT("info", ("log event code %d",
 
642
                          (*packet)[LOG_EVENT_OFFSET+1] ));
605
643
      if ((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT)
606
644
      {
607
645
        if (send_file(thd))
653
691
        log.error=0;
654
692
        bool read_packet = 0, fatal_error = 0;
655
693
 
 
694
#ifndef DBUG_OFF
 
695
        if (max_binlog_dump_events && !left_events--)
 
696
        {
 
697
          errmsg = "Debugging binlog dump abort";
 
698
          my_errno= ER_UNKNOWN_ERROR;
 
699
          goto err;
 
700
        }
 
701
#endif
 
702
 
656
703
        /*
657
704
          No one will update the log while we are reading
658
705
          now, but we'll be quick and just read one record
676
723
        case LOG_READ_EOF:
677
724
        {
678
725
          int ret;
 
726
          DBUG_PRINT("wait",("waiting for data in binary log"));
679
727
          if (thd->server_id==0) // for mysqlbinlog (mysqlbinlog.server_id==0)
680
728
          {
681
729
            pthread_mutex_unlock(log_lock);
682
730
            goto end;
683
731
          }
684
732
 
 
733
#ifndef DBUG_OFF
 
734
          ulong hb_info_counter= 0;
 
735
#endif
685
736
          do 
686
737
          {
687
738
            if (coord)
688
739
            {
689
 
              assert(heartbeat_ts && heartbeat_period != 0L);
 
740
              DBUG_ASSERT(heartbeat_ts && heartbeat_period != LL(0));
690
741
              set_timespec_nsec(*heartbeat_ts, heartbeat_period);
691
742
            }
692
743
            ret= mysql_bin_log.wait_for_update_bin_log(thd, heartbeat_ts);
693
 
            assert(ret == 0 || (heartbeat_period != 0L && coord != NULL));
 
744
            DBUG_ASSERT(ret == 0 || heartbeat_period != LL(0) && coord != NULL);
694
745
            if (ret == ETIMEDOUT || ret == ETIME)
695
746
            {
 
747
#ifndef DBUG_OFF
 
748
              if (hb_info_counter < 3)
 
749
              {
 
750
                sql_print_information("master sends heartbeat message");
 
751
                hb_info_counter++;
 
752
                if (hb_info_counter == 3)
 
753
                  sql_print_information("the rest of heartbeat info skipped ...");
 
754
              }
 
755
#endif
696
756
              if (send_heartbeat_event(net, packet, coord))
697
757
              {
698
758
                errmsg = "Failed on my_net_write()";
703
763
            }
704
764
            else
705
765
            {
706
 
              assert(ret == 0);
 
766
              DBUG_ASSERT(ret == 0);
 
767
              DBUG_PRINT("wait",("binary log received update"));
707
768
            }
708
769
          } while (ret != 0 && coord != NULL && !thd->killed);
709
770
          pthread_mutex_unlock(log_lock);
718
779
 
719
780
        if (read_packet)
720
781
        {
721
 
          thd->set_proc_info("Sending binlog event to slave");
722
 
          if (my_net_write(net, (unsigned char*) packet->ptr(), packet->length()) )
 
782
          thd_proc_info(thd, "Sending binlog event to slave");
 
783
          if (my_net_write(net, (uchar*) packet->ptr(), packet->length()) )
723
784
          {
724
785
            errmsg = "Failed on my_net_write()";
725
786
            my_errno= ER_UNKNOWN_ERROR;
756
817
      bool loop_breaker = 0;
757
818
      /* need this to break out of the for loop from switch */
758
819
 
759
 
      thd->set_proc_info("Finished reading one binlog; switching to next binlog");
 
820
      thd_proc_info(thd, "Finished reading one binlog; switching to next binlog");
760
821
      switch (mysql_bin_log.find_next_log(&linfo, 1)) {
761
822
      case LOG_INFO_EOF:
762
823
        loop_breaker = (flags & BINLOG_DUMP_NON_BLOCK);
804
865
  (void)my_close(file, MYF(MY_WME));
805
866
 
806
867
  my_eof(thd);
807
 
  thd->set_proc_info("Waiting to finalize termination");
 
868
  thd_proc_info(thd, "Waiting to finalize termination");
808
869
  pthread_mutex_lock(&LOCK_thread_count);
809
870
  thd->current_linfo = 0;
810
871
  pthread_mutex_unlock(&LOCK_thread_count);
811
 
  return;
 
872
  DBUG_VOID_RETURN;
812
873
 
813
874
err:
814
 
  thd->set_proc_info("Waiting to finalize termination");
 
875
  thd_proc_info(thd, "Waiting to finalize termination");
815
876
  end_io_cache(&log);
816
877
  /*
817
878
    Exclude  iteration through thread list
827
888
    (void) my_close(file, MYF(MY_WME));
828
889
 
829
890
  my_message(my_errno, errmsg, MYF(0));
830
 
  return;
 
891
  DBUG_VOID_RETURN;
831
892
}
832
893
 
833
894
int start_slave(THD* thd , Master_info* mi,  bool net_report)
834
895
{
835
896
  int slave_errno= 0;
836
897
  int thread_mask;
 
898
  DBUG_ENTER("start_slave");
837
899
 
838
900
  lock_slave_threads(mi);  // this allows us to cleanly read slave_running
839
901
  // Get a mask of _stopped_ threads
848
910
    thread_mask&= thd->lex->slave_thd_opt;
849
911
  if (thread_mask) //some threads are stopped, start them
850
912
  {
851
 
    if (mi->init_master_info(master_info_file, relay_log_info_file, thread_mask))
 
913
    if (init_master_info(mi,master_info_file,relay_log_info_file, 0,
 
914
                         thread_mask))
852
915
      slave_errno=ER_MASTER_INFO;
853
 
    else if (server_id_supplied && *mi->getHostname())
 
916
    else if (server_id_supplied && *mi->host)
854
917
    {
855
918
      /*
856
919
        If we will start SQL thread we will care about UNTIL options If
908
971
 
909
972
          /* Issuing warning then started without --skip-slave-start */
910
973
          if (!opt_skip_slave_start)
911
 
            push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
 
974
            push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
912
975
                         ER_MISSING_SKIP_SLAVE,
913
976
                         ER(ER_MISSING_SKIP_SLAVE));
914
977
        }
916
979
        pthread_mutex_unlock(&mi->rli.data_lock);
917
980
      }
918
981
      else if (thd->lex->mi.pos || thd->lex->mi.relay_log_pos)
919
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_UNTIL_COND_IGNORED,
 
982
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_UNTIL_COND_IGNORED,
920
983
                     ER(ER_UNTIL_COND_IGNORED));
921
984
 
922
985
      if (!slave_errno)
932
995
  else
933
996
  {
934
997
    /* no error if all threads are already started, only a warning */
935
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_SLAVE_WAS_RUNNING,
 
998
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_SLAVE_WAS_RUNNING,
936
999
                 ER(ER_SLAVE_WAS_RUNNING));
937
1000
  }
938
1001
 
942
1005
  {
943
1006
    if (net_report)
944
1007
      my_message(slave_errno, ER(slave_errno), MYF(0));
945
 
    return(1);
 
1008
    DBUG_RETURN(1);
946
1009
  }
947
1010
  else if (net_report)
948
1011
    my_ok(thd);
949
1012
 
950
 
  return(0);
 
1013
  DBUG_RETURN(0);
951
1014
}
952
1015
 
953
1016
 
954
1017
int stop_slave(THD* thd, Master_info* mi, bool net_report )
955
1018
{
 
1019
  DBUG_ENTER("stop_slave");
 
1020
  
956
1021
  int slave_errno;
957
1022
  if (!thd)
958
1023
    thd = current_thd;
959
1024
 
960
 
  thd->set_proc_info("Killing slave");
 
1025
  thd_proc_info(thd, "Killing slave");
961
1026
  int thread_mask;
962
1027
  lock_slave_threads(mi);
963
1028
  // Get a mask of _running_ threads
980
1045
  {
981
1046
    //no error if both threads are already stopped, only a warning
982
1047
    slave_errno= 0;
983
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE, ER_SLAVE_WAS_NOT_RUNNING,
 
1048
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_SLAVE_WAS_NOT_RUNNING,
984
1049
                 ER(ER_SLAVE_WAS_NOT_RUNNING));
985
1050
  }
986
1051
  unlock_slave_threads(mi);
987
 
  thd->set_proc_info(0);
 
1052
  thd_proc_info(thd, 0);
988
1053
 
989
1054
  if (slave_errno)
990
1055
  {
991
1056
    if (net_report)
992
1057
      my_message(slave_errno, ER(slave_errno), MYF(0));
993
 
    return(1);
 
1058
    DBUG_RETURN(1);
994
1059
  }
995
1060
  else if (net_report)
996
1061
    my_ok(thd);
997
1062
 
998
 
  return(0);
 
1063
  DBUG_RETURN(0);
999
1064
}
1000
1065
 
1001
1066
 
1018
1083
  struct stat stat_area;
1019
1084
  char fname[FN_REFLEN];
1020
1085
  int thread_mask= 0, error= 0;
1021
 
  uint32_t sql_errno=0;
 
1086
  uint sql_errno=0;
1022
1087
  const char* errmsg=0;
 
1088
  DBUG_ENTER("reset_slave");
1023
1089
 
1024
1090
  lock_slave_threads(mi);
1025
1091
  init_thread_mask(&thread_mask,mi,0 /* not inverse */);
1030
1096
    goto err;
1031
1097
  }
1032
1098
 
 
1099
  ha_reset_slave(thd);
 
1100
 
1033
1101
  // delete relay logs, clear relay log coordinates
1034
1102
  if ((error= purge_relay_logs(&mi->rli, thd,
1035
1103
                               1 /* just reset */,
1037
1105
    goto err;
1038
1106
 
1039
1107
  /* Clear master's log coordinates */
1040
 
  mi->reset();
 
1108
  init_master_log_pos(mi);
1041
1109
  /*
1042
1110
     Reset errors (the idea is that we forget about the
1043
1111
     old master).
1046
1114
  mi->rli.clear_until_condition();
1047
1115
 
1048
1116
  // close master_info_file, relay_log_info_file, set mi->inited=rli->inited=0
1049
 
  mi->end_master_info();
 
1117
  end_master_info(mi);
1050
1118
  // and delete these two files
1051
1119
  fn_format(fname, master_info_file, mysql_data_home, "", 4+32);
1052
1120
  if (!stat(fname, &stat_area) && my_delete(fname, MYF(MY_WME)))
1066
1134
  unlock_slave_threads(mi);
1067
1135
  if (error)
1068
1136
    my_error(sql_errno, MYF(0), errmsg);
1069
 
  return(error);
 
1137
  DBUG_RETURN(error);
1070
1138
}
1071
1139
 
1072
1140
/*
1089
1157
*/
1090
1158
 
1091
1159
 
1092
 
void kill_zombie_dump_threads(uint32_t slave_server_id)
 
1160
void kill_zombie_dump_threads(uint32 slave_server_id)
1093
1161
{
1094
1162
  pthread_mutex_lock(&LOCK_thread_count);
1095
1163
  I_List_iterator<THD> it(threads);
1123
1191
  int thread_mask;
1124
1192
  const char* errmsg= 0;
1125
1193
  bool need_relay_log_purge= 1;
 
1194
  DBUG_ENTER("change_master");
1126
1195
 
1127
1196
  lock_slave_threads(mi);
1128
1197
  init_thread_mask(&thread_mask,mi,0 /*not inverse*/);
1130
1199
  {
1131
1200
    my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
1132
1201
    unlock_slave_threads(mi);
1133
 
    return(true);
 
1202
    DBUG_RETURN(TRUE);
1134
1203
  }
1135
1204
 
1136
 
  thd->set_proc_info("Changing master");
 
1205
  thd_proc_info(thd, "Changing master");
1137
1206
  LEX_MASTER_INFO* lex_mi= &thd->lex->mi;
1138
1207
  // TODO: see if needs re-write
1139
 
  if (mi->init_master_info(master_info_file, relay_log_info_file, thread_mask))
 
1208
  if (init_master_info(mi, master_info_file, relay_log_info_file, 0,
 
1209
                       thread_mask))
1140
1210
  {
1141
1211
    my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0));
1142
1212
    unlock_slave_threads(mi);
1143
 
    return(true);
 
1213
    DBUG_RETURN(TRUE);
1144
1214
  }
1145
1215
 
1146
1216
  /*
1155
1225
  */
1156
1226
 
1157
1227
  if ((lex_mi->host || lex_mi->port) && !lex_mi->log_file_name && !lex_mi->pos)
1158
 
    mi->reset();
 
1228
  {
 
1229
    mi->master_log_name[0] = 0;
 
1230
    mi->master_log_pos= BIN_LOG_HEADER_SIZE;
 
1231
  }
1159
1232
 
1160
1233
  if (lex_mi->log_file_name)
1161
 
    mi->setLogName(lex_mi->log_file_name);
 
1234
    strmake(mi->master_log_name, lex_mi->log_file_name,
 
1235
            sizeof(mi->master_log_name)-1);
1162
1236
  if (lex_mi->pos)
1163
1237
  {
1164
 
    mi->setLogPosition(lex_mi->pos);
 
1238
    mi->master_log_pos= lex_mi->pos;
1165
1239
  }
 
1240
  DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos));
1166
1241
 
1167
1242
  if (lex_mi->host)
1168
 
    mi->setHost(lex_mi->host, lex_mi->port);
 
1243
    strmake(mi->host, lex_mi->host, sizeof(mi->host)-1);
1169
1244
  if (lex_mi->user)
1170
 
    mi->setUsername(lex_mi->user);
 
1245
    strmake(mi->user, lex_mi->user, sizeof(mi->user)-1);
1171
1246
  if (lex_mi->password)
1172
 
    mi->setPassword(lex_mi->password);
 
1247
    strmake(mi->password, lex_mi->password, sizeof(mi->password)-1);
 
1248
  if (lex_mi->port)
 
1249
    mi->port = lex_mi->port;
1173
1250
  if (lex_mi->connect_retry)
1174
1251
    mi->connect_retry = lex_mi->connect_retry;
1175
1252
  if (lex_mi->heartbeat_opt != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
1176
1253
    mi->heartbeat_period = lex_mi->heartbeat_period;
1177
1254
  else
1178
 
    mi->heartbeat_period= (float) cmin((double)SLAVE_MAX_HEARTBEAT_PERIOD,
 
1255
    mi->heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
1179
1256
                                      (slave_net_timeout/2.0));
1180
 
  mi->received_heartbeats= 0L; // counter lives until master is CHANGEd
 
1257
  mi->received_heartbeats= LL(0); // counter lives until master is CHANGEd
 
1258
  if (lex_mi->ssl != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
 
1259
    mi->ssl= (lex_mi->ssl == LEX_MASTER_INFO::LEX_MI_ENABLE);
 
1260
 
 
1261
  if (lex_mi->ssl_verify_server_cert != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
 
1262
    mi->ssl_verify_server_cert=
 
1263
      (lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::LEX_MI_ENABLE);
 
1264
 
 
1265
  if (lex_mi->ssl_ca)
 
1266
    strmake(mi->ssl_ca, lex_mi->ssl_ca, sizeof(mi->ssl_ca)-1);
 
1267
  if (lex_mi->ssl_capath)
 
1268
    strmake(mi->ssl_capath, lex_mi->ssl_capath, sizeof(mi->ssl_capath)-1);
 
1269
  if (lex_mi->ssl_cert)
 
1270
    strmake(mi->ssl_cert, lex_mi->ssl_cert, sizeof(mi->ssl_cert)-1);
 
1271
  if (lex_mi->ssl_cipher)
 
1272
    strmake(mi->ssl_cipher, lex_mi->ssl_cipher, sizeof(mi->ssl_cipher)-1);
 
1273
  if (lex_mi->ssl_key)
 
1274
    strmake(mi->ssl_key, lex_mi->ssl_key, sizeof(mi->ssl_key)-1);
 
1275
  if (lex_mi->ssl || lex_mi->ssl_ca || lex_mi->ssl_capath ||
 
1276
      lex_mi->ssl_cert || lex_mi->ssl_cipher || lex_mi->ssl_key ||
 
1277
      lex_mi->ssl_verify_server_cert )
 
1278
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
1279
                 ER_SLAVE_IGNORED_SSL_PARAMS, ER(ER_SLAVE_IGNORED_SSL_PARAMS));
1181
1280
 
1182
1281
  if (lex_mi->relay_log_name)
1183
1282
  {
1184
1283
    need_relay_log_purge= 0;
1185
 
    mi->rli.event_relay_log_name.assign(lex_mi->relay_log_name);
 
1284
    strmake(mi->rli.group_relay_log_name,lex_mi->relay_log_name,
 
1285
            sizeof(mi->rli.group_relay_log_name)-1);
 
1286
    strmake(mi->rli.event_relay_log_name,lex_mi->relay_log_name,
 
1287
            sizeof(mi->rli.event_relay_log_name)-1);
1186
1288
  }
1187
1289
 
1188
1290
  if (lex_mi->relay_log_pos)
1211
1313
   {
1212
1314
     /*
1213
1315
       Sometimes mi->rli.master_log_pos == 0 (it happens when the SQL thread is
1214
 
       not initialized), so we use a cmax().
 
1316
       not initialized), so we use a max().
1215
1317
       What happens to mi->rli.master_log_pos during the initialization stages
1216
1318
       of replication is not 100% clear, so we guard against problems using
1217
 
       cmax().
 
1319
       max().
1218
1320
      */
1219
 
     mi->setLogPosition(((BIN_LOG_HEADER_SIZE > mi->rli.group_master_log_pos)
1220
 
                         ? BIN_LOG_HEADER_SIZE
1221
 
                         : mi->rli.group_master_log_pos));
1222
 
     mi->setLogName(mi->rli.group_master_log_name.c_str());
 
1321
     mi->master_log_pos = max(BIN_LOG_HEADER_SIZE,
 
1322
                              mi->rli.group_master_log_pos);
 
1323
     strmake(mi->master_log_name, mi->rli.group_master_log_name,
 
1324
             sizeof(mi->master_log_name)-1);
1223
1325
  }
1224
1326
  /*
1225
1327
    Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never
1226
1328
    a slave before).
1227
1329
  */
1228
 
  if (mi->flush())
 
1330
  if (flush_master_info(mi, 0))
1229
1331
  {
1230
1332
    my_error(ER_RELAY_LOG_INIT, MYF(0), "Failed to flush master info file");
1231
1333
    unlock_slave_threads(mi);
1232
 
    return(true);
 
1334
    DBUG_RETURN(TRUE);
1233
1335
  }
1234
1336
  if (need_relay_log_purge)
1235
1337
  {
1236
1338
    relay_log_purge= 1;
1237
 
    thd->set_proc_info("Purging old relay logs");
 
1339
    thd_proc_info(thd, "Purging old relay logs");
1238
1340
    if (purge_relay_logs(&mi->rli, thd,
1239
1341
                         0 /* not only reset, but also reinit */,
1240
1342
                         &errmsg))
1241
1343
    {
1242
1344
      my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg);
1243
1345
      unlock_slave_threads(mi);
1244
 
      return(true);
 
1346
      DBUG_RETURN(TRUE);
1245
1347
    }
1246
1348
  }
1247
1349
  else
1250
1352
    relay_log_purge= 0;
1251
1353
    /* Relay log is already initialized */
1252
1354
    if (init_relay_log_pos(&mi->rli,
1253
 
                           mi->rli.group_relay_log_name.c_str(),
 
1355
                           mi->rli.group_relay_log_name,
1254
1356
                           mi->rli.group_relay_log_pos,
1255
1357
                           0 /*no data lock*/,
1256
1358
                           &msg, 0))
1257
1359
    {
1258
1360
      my_error(ER_RELAY_LOG_INIT, MYF(0), msg);
1259
1361
      unlock_slave_threads(mi);
1260
 
      return(true);
 
1362
      DBUG_RETURN(TRUE);
1261
1363
    }
1262
1364
  }
1263
1365
  /*
1270
1372
    ''/0: we have lost all copies of the original good coordinates.
1271
1373
    That's why we always save good coords in rli.
1272
1374
  */
1273
 
  mi->rli.group_master_log_pos= mi->getLogPosition();
1274
 
  mi->rli.group_master_log_name.assign(mi->getLogName());
 
1375
  mi->rli.group_master_log_pos= mi->master_log_pos;
 
1376
  DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos));
 
1377
  strmake(mi->rli.group_master_log_name,mi->master_log_name,
 
1378
          sizeof(mi->rli.group_master_log_name)-1);
1275
1379
 
1276
 
  if (mi->rli.group_master_log_name.size() == 0) // uninitialized case
1277
 
    mi->rli.group_master_log_pos= 0;
 
1380
  if (!mi->rli.group_master_log_name[0]) // uninitialized case
 
1381
    mi->rli.group_master_log_pos=0;
1278
1382
 
1279
1383
  pthread_mutex_lock(&mi->rli.data_lock);
1280
1384
  mi->rli.abort_pos_wait++; /* for MASTER_POS_WAIT() to abort */
1293
1397
  pthread_mutex_unlock(&mi->rli.data_lock);
1294
1398
 
1295
1399
  unlock_slave_threads(mi);
1296
 
  thd->set_proc_info(0);
 
1400
  thd_proc_info(thd, 0);
1297
1401
  my_ok(thd);
1298
 
  return(false);
 
1402
  DBUG_RETURN(FALSE);
1299
1403
}
1300
1404
 
1301
1405
int reset_master(THD* thd)
1309
1413
  return mysql_bin_log.reset_logs(thd);
1310
1414
}
1311
1415
 
1312
 
int cmp_master_pos(const char* log_file_name1, uint64_t log_pos1,
1313
 
                   const char* log_file_name2, uint64_t log_pos2)
 
1416
int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
 
1417
                   const char* log_file_name2, ulonglong log_pos2)
1314
1418
{
1315
1419
  int res;
1316
 
  uint32_t log_file_name1_len=  strlen(log_file_name1);
1317
 
  uint32_t log_file_name2_len=  strlen(log_file_name2);
 
1420
  uint log_file_name1_len=  strlen(log_file_name1);
 
1421
  uint log_file_name2_len=  strlen(log_file_name2);
1318
1422
 
1319
1423
  //  We assume that both log names match up to '.'
1320
1424
  if (log_file_name1_len == log_file_name2_len)
1327
1431
}
1328
1432
 
1329
1433
 
 
1434
bool mysql_show_binlog_events(THD* thd)
 
1435
{
 
1436
  Protocol *protocol= thd->protocol;
 
1437
  List<Item> field_list;
 
1438
  const char *errmsg = 0;
 
1439
  bool ret = TRUE;
 
1440
  IO_CACHE log;
 
1441
  File file = -1;
 
1442
  DBUG_ENTER("mysql_show_binlog_events");
 
1443
 
 
1444
  Log_event::init_show_field_list(&field_list);
 
1445
  if (protocol->send_fields(&field_list,
 
1446
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
 
1447
    DBUG_RETURN(TRUE);
 
1448
 
 
1449
  Format_description_log_event *description_event= new
 
1450
    Format_description_log_event(3); /* MySQL 4.0 by default */
 
1451
 
 
1452
  /*
 
1453
    Wait for handlers to insert any pending information
 
1454
    into the binlog.  For e.g. ndb which updates the binlog asynchronously
 
1455
    this is needed so that the uses sees all its own commands in the binlog
 
1456
  */
 
1457
  ha_binlog_wait(thd);
 
1458
 
 
1459
  if (mysql_bin_log.is_open())
 
1460
  {
 
1461
    LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
 
1462
    SELECT_LEX_UNIT *unit= &thd->lex->unit;
 
1463
    ha_rows event_count, limit_start, limit_end;
 
1464
    my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
 
1465
    char search_file_name[FN_REFLEN], *name;
 
1466
    const char *log_file_name = lex_mi->log_file_name;
 
1467
    pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
 
1468
    LOG_INFO linfo;
 
1469
    Log_event* ev;
 
1470
 
 
1471
    unit->set_limit(thd->lex->current_select);
 
1472
    limit_start= unit->offset_limit_cnt;
 
1473
    limit_end= unit->select_limit_cnt;
 
1474
 
 
1475
    name= search_file_name;
 
1476
    if (log_file_name)
 
1477
      mysql_bin_log.make_log_name(search_file_name, log_file_name);
 
1478
    else
 
1479
      name=0;                                   // Find first log
 
1480
 
 
1481
    linfo.index_file_offset = 0;
 
1482
 
 
1483
    if (mysql_bin_log.find_log_pos(&linfo, name, 1))
 
1484
    {
 
1485
      errmsg = "Could not find target log";
 
1486
      goto err;
 
1487
    }
 
1488
 
 
1489
    pthread_mutex_lock(&LOCK_thread_count);
 
1490
    thd->current_linfo = &linfo;
 
1491
    pthread_mutex_unlock(&LOCK_thread_count);
 
1492
 
 
1493
    if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0)
 
1494
      goto err;
 
1495
 
 
1496
    /*
 
1497
      to account binlog event header size
 
1498
    */
 
1499
    thd->variables.max_allowed_packet += MAX_LOG_EVENT_HEADER;
 
1500
 
 
1501
    pthread_mutex_lock(log_lock);
 
1502
 
 
1503
    /*
 
1504
      open_binlog() sought to position 4.
 
1505
      Read the first event in case it's a Format_description_log_event, to
 
1506
      know the format. If there's no such event, we are 3.23 or 4.x. This
 
1507
      code, like before, can't read 3.23 binlogs.
 
1508
      This code will fail on a mixed relay log (one which has Format_desc then
 
1509
      Rotate then Format_desc).
 
1510
    */
 
1511
    ev = Log_event::read_log_event(&log,(pthread_mutex_t*)0,description_event);
 
1512
    if (ev)
 
1513
    {
 
1514
      if (ev->get_type_code() == FORMAT_DESCRIPTION_EVENT)
 
1515
      {
 
1516
        delete description_event;
 
1517
        description_event= (Format_description_log_event*) ev;
 
1518
      }
 
1519
      else
 
1520
        delete ev;
 
1521
    }
 
1522
 
 
1523
    my_b_seek(&log, pos);
 
1524
 
 
1525
    if (!description_event->is_valid())
 
1526
    {
 
1527
      errmsg="Invalid Format_description event; could be out of memory";
 
1528
      goto err;
 
1529
    }
 
1530
 
 
1531
    for (event_count = 0;
 
1532
         (ev = Log_event::read_log_event(&log,(pthread_mutex_t*) 0,
 
1533
                                         description_event)); )
 
1534
    {
 
1535
      if (event_count >= limit_start &&
 
1536
          ev->net_send(protocol, linfo.log_file_name, pos))
 
1537
      {
 
1538
        errmsg = "Net error";
 
1539
        delete ev;
 
1540
        pthread_mutex_unlock(log_lock);
 
1541
        goto err;
 
1542
      }
 
1543
 
 
1544
      pos = my_b_tell(&log);
 
1545
      delete ev;
 
1546
 
 
1547
      if (++event_count >= limit_end)
 
1548
        break;
 
1549
    }
 
1550
 
 
1551
    if (event_count < limit_end && log.error)
 
1552
    {
 
1553
      errmsg = "Wrong offset or I/O error";
 
1554
      pthread_mutex_unlock(log_lock);
 
1555
      goto err;
 
1556
    }
 
1557
 
 
1558
    pthread_mutex_unlock(log_lock);
 
1559
  }
 
1560
 
 
1561
  ret= FALSE;
 
1562
 
 
1563
err:
 
1564
  delete description_event;
 
1565
  if (file >= 0)
 
1566
  {
 
1567
    end_io_cache(&log);
 
1568
    (void) my_close(file, MYF(MY_WME));
 
1569
  }
 
1570
 
 
1571
  if (errmsg)
 
1572
    my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0),
 
1573
             "SHOW BINLOG EVENTS", errmsg);
 
1574
  else
 
1575
    my_eof(thd);
 
1576
 
 
1577
  pthread_mutex_lock(&LOCK_thread_count);
 
1578
  thd->current_linfo = 0;
 
1579
  pthread_mutex_unlock(&LOCK_thread_count);
 
1580
  DBUG_RETURN(ret);
 
1581
}
 
1582
 
 
1583
 
1330
1584
bool show_binlog_info(THD* thd)
1331
1585
{
1332
1586
  Protocol *protocol= thd->protocol;
 
1587
  DBUG_ENTER("show_binlog_info");
1333
1588
  List<Item> field_list;
1334
1589
  field_list.push_back(new Item_empty_string("File", FN_REFLEN));
1335
1590
  field_list.push_back(new Item_return_int("Position",20,
1336
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1591
                                           MYSQL_TYPE_LONGLONG));
1337
1592
  field_list.push_back(new Item_empty_string("Binlog_Do_DB",255));
1338
1593
  field_list.push_back(new Item_empty_string("Binlog_Ignore_DB",255));
1339
1594
 
1340
1595
  if (protocol->send_fields(&field_list,
1341
1596
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1342
 
    return(true);
 
1597
    DBUG_RETURN(TRUE);
1343
1598
  protocol->prepare_for_resend();
1344
1599
 
1345
1600
  if (mysql_bin_log.is_open())
1348
1603
    mysql_bin_log.get_current_log(&li);
1349
1604
    int dir_len = dirname_length(li.log_file_name);
1350
1605
    protocol->store(li.log_file_name + dir_len, &my_charset_bin);
1351
 
    protocol->store((uint64_t) li.pos);
 
1606
    protocol->store((ulonglong) li.pos);
1352
1607
    protocol->store(binlog_filter->get_do_db());
1353
1608
    protocol->store(binlog_filter->get_ignore_db());
1354
1609
    if (protocol->write())
1355
 
      return(true);
 
1610
      DBUG_RETURN(TRUE);
1356
1611
  }
1357
1612
  my_eof(thd);
1358
 
  return(false);
 
1613
  DBUG_RETURN(FALSE);
1359
1614
}
1360
1615
 
1361
1616
 
1367
1622
    thd         Thread specific variable
1368
1623
 
1369
1624
  RETURN VALUES
1370
 
    false OK
1371
 
    true  error
 
1625
    FALSE OK
 
1626
    TRUE  error
1372
1627
*/
1373
1628
 
1374
1629
bool show_binlogs(THD* thd)
1378
1633
  File file;
1379
1634
  char fname[FN_REFLEN];
1380
1635
  List<Item> field_list;
1381
 
  uint32_t length;
 
1636
  uint length;
1382
1637
  int cur_dir_len;
1383
1638
  Protocol *protocol= thd->protocol;
 
1639
  DBUG_ENTER("show_binlogs");
1384
1640
 
1385
1641
  if (!mysql_bin_log.is_open())
1386
1642
  {
1390
1646
 
1391
1647
  field_list.push_back(new Item_empty_string("Log_name", 255));
1392
1648
  field_list.push_back(new Item_return_int("File_size", 20,
1393
 
                                           DRIZZLE_TYPE_LONGLONG));
 
1649
                                           MYSQL_TYPE_LONGLONG));
1394
1650
  if (protocol->send_fields(&field_list,
1395
1651
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1396
 
    return(true);
 
1652
    DBUG_RETURN(TRUE);
1397
1653
  
1398
1654
  pthread_mutex_lock(mysql_bin_log.get_log_lock());
1399
1655
  mysql_bin_log.lock_index();
1410
1666
  while ((length=my_b_gets(index_file, fname, sizeof(fname))) > 1)
1411
1667
  {
1412
1668
    int dir_len;
1413
 
    uint64_t file_length= 0;                   // Length if open fails
 
1669
    ulonglong file_length= 0;                   // Length if open fails
1414
1670
    fname[--length] = '\0';                     // remove the newline
1415
1671
 
1416
1672
    protocol->prepare_for_resend();
1423
1679
    else
1424
1680
    {
1425
1681
      /* this is an old log, open it and find the size */
1426
 
      if ((file= my_open(fname, O_RDONLY,
 
1682
      if ((file= my_open(fname, O_RDONLY | O_SHARE | O_BINARY,
1427
1683
                         MYF(0))) >= 0)
1428
1684
      {
1429
 
        file_length= (uint64_t) my_seek(file, 0L, MY_SEEK_END, MYF(0));
 
1685
        file_length= (ulonglong) my_seek(file, 0L, MY_SEEK_END, MYF(0));
1430
1686
        my_close(file, MYF(0));
1431
1687
      }
1432
1688
    }
1436
1692
  }
1437
1693
  mysql_bin_log.unlock_index();
1438
1694
  my_eof(thd);
1439
 
  return(false);
 
1695
  DBUG_RETURN(FALSE);
1440
1696
 
1441
1697
err:
1442
1698
  mysql_bin_log.unlock_index();
1443
 
  return(true);
 
1699
  DBUG_RETURN(TRUE);
1444
1700
}
1445
1701
 
1446
1702
/**
1454
1710
*/
1455
1711
int log_loaded_block(IO_CACHE* file)
1456
1712
{
 
1713
  DBUG_ENTER("log_loaded_block");
1457
1714
  LOAD_FILE_INFO *lf_info;
1458
 
  uint32_t block_len;
 
1715
  uint block_len;
1459
1716
  /* buffer contains position where we started last read */
1460
 
  unsigned char* buffer= (unsigned char*) my_b_get_buffer_start(file);
1461
 
  uint32_t max_event_size= current_thd->variables.max_allowed_packet;
 
1717
  uchar* buffer= (uchar*) my_b_get_buffer_start(file);
 
1718
  uint max_event_size= current_thd->variables.max_allowed_packet;
1462
1719
  lf_info= (LOAD_FILE_INFO*) file->arg;
1463
1720
  if (lf_info->thd->current_stmt_binlog_row_based)
1464
 
    return(0);
 
1721
    DBUG_RETURN(0);
1465
1722
  if (lf_info->last_pos_in_file != HA_POS_ERROR &&
1466
1723
      lf_info->last_pos_in_file >= my_b_get_pos_in_file(file))
1467
 
    return(0);
 
1724
    DBUG_RETURN(0);
1468
1725
  
1469
1726
  for (block_len= my_b_get_bytes_in_buffer(file); block_len > 0;
1470
 
       buffer += cmin(block_len, max_event_size),
1471
 
       block_len -= cmin(block_len, max_event_size))
 
1727
       buffer += min(block_len, max_event_size),
 
1728
       block_len -= min(block_len, max_event_size))
1472
1729
  {
1473
1730
    lf_info->last_pos_in_file= my_b_get_pos_in_file(file);
1474
1731
    if (lf_info->wrote_create_file)
1475
1732
    {
1476
1733
      Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer,
1477
 
                               cmin(block_len, max_event_size),
 
1734
                               min(block_len, max_event_size),
1478
1735
                               lf_info->log_delayed);
1479
1736
      mysql_bin_log.write(&a);
1480
1737
    }
1482
1739
    {
1483
1740
      Begin_load_query_log_event b(lf_info->thd, lf_info->thd->db,
1484
1741
                                   buffer,
1485
 
                                   cmin(block_len, max_event_size),
 
1742
                                   min(block_len, max_event_size),
1486
1743
                                   lf_info->log_delayed);
1487
1744
      mysql_bin_log.write(&b);
1488
1745
      lf_info->wrote_create_file= 1;
 
1746
      DBUG_SYNC_POINT("debug_lock.created_file_event",10);
1489
1747
    }
1490
1748
  }
1491
 
  return(0);
 
1749
  DBUG_RETURN(0);
1492
1750
}
1493
1751
 
1494
1752
/*
1513
1771
class sys_var_sync_binlog_period :public sys_var_long_ptr
1514
1772
{
1515
1773
public:
1516
 
  sys_var_sync_binlog_period(sys_var_chain *chain, const char *name_arg,
 
1774
  sys_var_sync_binlog_period(sys_var_chain *chain, const char *name_arg, 
1517
1775
                             ulong *value_ptr)
1518
1776
    :sys_var_long_ptr(chain, name_arg,value_ptr) {}
1519
1777
  bool update(THD *thd, set_var *var);
1520
1778
};
1521
1779
 
1522
 
static void fix_slave_net_timeout(THD *thd,
1523
 
                                  enum_var_type type __attribute__((unused)))
 
1780
static void fix_slave_net_timeout(THD *thd, enum_var_type type)
1524
1781
{
 
1782
  DBUG_ENTER("fix_slave_net_timeout");
 
1783
#ifdef HAVE_REPLICATION
1525
1784
  pthread_mutex_lock(&LOCK_active_mi);
 
1785
  DBUG_PRINT("info",("slave_net_timeout=%lu mi->heartbeat_period=%.3f",
 
1786
                     slave_net_timeout,
 
1787
                     (active_mi? active_mi->heartbeat_period : 0.0)));
1526
1788
  if (active_mi && slave_net_timeout < active_mi->heartbeat_period)
1527
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1789
    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1528
1790
                        ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1529
1791
                        "The currect value for master_heartbeat_period"
1530
1792
                        " exceeds the new value of `slave_net_timeout' sec."
1531
1793
                        " A sensible value for the period should be"
1532
1794
                        " less than the timeout.");
1533
1795
  pthread_mutex_unlock(&LOCK_active_mi);
1534
 
  return;
 
1796
#endif
 
1797
  DBUG_VOID_RETURN;
1535
1798
}
1536
1799
 
1537
1800
static sys_var_chain vars = { NULL, NULL };
1549
1812
static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff);
1550
1813
 
1551
1814
 
1552
 
static int show_slave_skip_errors(THD *thd __attribute__((unused)),
1553
 
                                  SHOW_VAR *var, char *buff)
 
1815
static SHOW_VAR fixed_vars[]= {
 
1816
  {"log_slave_updates",       (char*) &opt_log_slave_updates,       SHOW_MY_BOOL},
 
1817
  {"relay_log" , (char*) &opt_relay_logname, SHOW_CHAR_PTR},
 
1818
  {"relay_log_index", (char*) &opt_relaylog_index_name, SHOW_CHAR_PTR},
 
1819
  {"relay_log_info_file", (char*) &relay_log_info_file, SHOW_CHAR_PTR},
 
1820
  {"relay_log_space_limit",   (char*) &relay_log_space_limit,       SHOW_LONGLONG},
 
1821
  {"slave_load_tmpdir",       (char*) &slave_load_tmpdir,           SHOW_CHAR_PTR},
 
1822
  {"slave_skip_errors",       (char*) &show_slave_skip_errors,      SHOW_FUNC},
 
1823
};
 
1824
 
 
1825
static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff)
1554
1826
{
1555
1827
  var->type=SHOW_CHAR;
1556
1828
  var->value= buff;
1581
1853
    if (var->value != buff)
1582
1854
      buff--;                           // Remove last ','
1583
1855
    if (i < MAX_SLAVE_ERROR)
1584
 
      buff= my_stpcpy(buff, "...");  // Couldn't show all errors
 
1856
      buff= strmov(buff, "...");  // Couldn't show all errors
1585
1857
    *buff=0;
1586
1858
  }
1587
1859
  return 0;
1588
1860
}
1589
1861
 
1590
 
static st_show_var_func_container
1591
 
show_slave_skip_errors_cont = { &show_slave_skip_errors };
1592
 
 
1593
 
 
1594
 
static SHOW_VAR fixed_vars[]= {
1595
 
  {"log_slave_updates",       (char*) &opt_log_slave_updates,       SHOW_MY_BOOL},
1596
 
  {"relay_log" , (char*) &opt_relay_logname, SHOW_CHAR_PTR},
1597
 
  {"relay_log_index", (char*) &opt_relaylog_index_name, SHOW_CHAR_PTR},
1598
 
  {"relay_log_info_file", (char*) &relay_log_info_file, SHOW_CHAR_PTR},
1599
 
  {"relay_log_space_limit",   (char*) &relay_log_space_limit,       SHOW_LONGLONG},
1600
 
  {"slave_load_tmpdir",       (char*) &slave_load_tmpdir,           SHOW_CHAR_PTR},
1601
 
  {"slave_skip_errors",       (char*) &show_slave_skip_errors_cont,      SHOW_FUNC},
1602
 
};
1603
 
 
1604
 
bool sys_var_slave_skip_counter::check(THD *thd __attribute__((unused)),
1605
 
                                       set_var *var)
 
1862
bool sys_var_slave_skip_counter::check(THD *thd, set_var *var)
1606
1863
{
1607
1864
  int result= 0;
1608
1865
  pthread_mutex_lock(&LOCK_active_mi);
1619
1876
}
1620
1877
 
1621
1878
 
1622
 
bool sys_var_slave_skip_counter::update(THD *thd __attribute__((unused)),
1623
 
                                        set_var *var)
 
1879
bool sys_var_slave_skip_counter::update(THD *thd, set_var *var)
1624
1880
{
1625
1881
  pthread_mutex_lock(&LOCK_active_mi);
1626
1882
  pthread_mutex_lock(&active_mi->rli.run_lock);
1641
1897
}
1642
1898
 
1643
1899
 
1644
 
bool sys_var_sync_binlog_period::update(THD *thd __attribute__((unused)),
1645
 
                                        set_var *var)
 
1900
bool sys_var_sync_binlog_period::update(THD *thd, set_var *var)
1646
1901
{
1647
 
  sync_binlog_period= (uint32_t) var->save_result.uint64_t_value;
 
1902
  sync_binlog_period= (ulong) var->save_result.ulonglong_value;
1648
1903
  return 0;
1649
1904
}
1650
1905
 
1660
1915
  }
1661
1916
  return 0;
1662
1917
}
 
1918
 
 
1919
#endif /* HAVE_REPLICATION */
 
1920
 
 
1921