~ubuntu-branches/ubuntu/lucid/mysql-dfsg-5.1/lucid-security

« back to all changes in this revision

Viewing changes to sql/sql_repl.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 22:33:55 UTC
  • mto: (1.2.1) (37.1.1 lucid-security)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: package-import@ubuntu.com-20120222223355-ku1tb4r70osci6v2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB & Sasha
 
1
/*
 
2
   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
#include "mysql_priv.h"
17
19
#ifdef HAVE_REPLICATION
21
23
#include "log_event.h"
22
24
#include "rpl_filter.h"
23
25
#include <my_dir.h>
 
26
#include "debug_sync.h"
24
27
 
25
28
int max_binlog_dump_events = 0; // unlimited
26
29
my_bool opt_sporadic_binlog_dump_fail = 0;
218
221
    if ((linfo = tmp->current_linfo))
219
222
    {
220
223
      pthread_mutex_lock(&linfo->lock);
221
 
      result = !bcmp((uchar*) log_name, (uchar*) linfo->log_file_name,
222
 
                     log_name_len);
 
224
      result = !memcmp(log_name, linfo->log_file_name, log_name_len);
223
225
      pthread_mutex_unlock(&linfo->lock);
224
226
      if (result)
225
227
        break;
357
359
#ifndef DBUG_OFF
358
360
  int left_events = max_binlog_dump_events;
359
361
#endif
 
362
  int old_max_allowed_packet= thd->variables.max_allowed_packet;
360
363
  DBUG_ENTER("mysql_binlog_send");
361
364
  DBUG_PRINT("enter",("log_ident: '%s'  pos: %ld", log_ident, (long) pos));
362
365
 
544
547
 
545
548
  while (!net->error && net->vio != 0 && !thd->killed)
546
549
  {
 
550
    my_off_t prev_pos= pos;
547
551
    while (!(error = Log_event::read_log_event(&log, packet, log_lock)))
548
552
    {
 
553
      prev_pos= my_b_tell(&log);
549
554
#ifndef DBUG_OFF
550
555
      if (max_binlog_dump_events && !left_events--)
551
556
      {
556
561
      }
557
562
#endif
558
563
 
 
564
      DBUG_EXECUTE_IF("dump_thread_wait_before_send_xid",
 
565
                      {
 
566
                        if ((*packet)[EVENT_TYPE_OFFSET+1] == XID_EVENT)
 
567
                        {
 
568
                          net_flush(net);
 
569
                          const char act[]=
 
570
                            "now "
 
571
                            "wait_for signal.continue";
 
572
                          DBUG_ASSERT(opt_debug_sync_timeout > 0);
 
573
                          DBUG_ASSERT(!debug_sync_set_action(current_thd,
 
574
                                                             STRING_WITH_LEN(act)));
 
575
                        }
 
576
                      });
 
577
 
559
578
      if ((*packet)[EVENT_TYPE_OFFSET+1] == FORMAT_DESCRIPTION_EVENT)
560
579
      {
561
580
        binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+1] &
572
591
        goto err;
573
592
      }
574
593
 
 
594
      DBUG_EXECUTE_IF("dump_thread_wait_before_send_xid",
 
595
                      {
 
596
                        if ((*packet)[EVENT_TYPE_OFFSET+1] == XID_EVENT)
 
597
                        {
 
598
                          net_flush(net);
 
599
                        }
 
600
                      });
 
601
 
575
602
      DBUG_PRINT("info", ("log event code %d",
576
603
                          (*packet)[LOG_EVENT_OFFSET+1] ));
577
604
      if ((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT)
590
617
      here we were reading binlog that was not closed properly (as a result
591
618
      of a crash ?). treat any corruption as EOF
592
619
    */
593
 
    if (binlog_can_be_corrupted && error != LOG_READ_MEM)
 
620
    if (binlog_can_be_corrupted &&
 
621
        error != LOG_READ_MEM && error != LOG_READ_EOF)
 
622
    {
 
623
      my_b_seek(&log, prev_pos);
594
624
      error=LOG_READ_EOF;
 
625
    }
 
626
 
595
627
    /*
596
628
      TODO: now that we are logging the offset, check to make sure
597
629
      the recorded offset and the actual match.
711
743
 
712
744
      thd_proc_info(thd, "Finished reading one binlog; switching to next binlog");
713
745
      switch (mysql_bin_log.find_next_log(&linfo, 1)) {
 
746
      case 0:
 
747
        break;
714
748
      case LOG_INFO_EOF:
715
 
        loop_breaker = (flags & BINLOG_DUMP_NON_BLOCK);
716
 
        break;
717
 
      case 0:
718
 
        break;
 
749
        if (mysql_bin_log.is_active(log_file_name))
 
750
        {
 
751
          loop_breaker = (flags & BINLOG_DUMP_NON_BLOCK);
 
752
          break;
 
753
        }
719
754
      default:
720
755
        errmsg = "could not find next log";
721
756
        my_errno= ER_MASTER_FATAL_ERROR_READING_BINLOG;
759
794
  pthread_mutex_lock(&LOCK_thread_count);
760
795
  thd->current_linfo = 0;
761
796
  pthread_mutex_unlock(&LOCK_thread_count);
 
797
  thd->variables.max_allowed_packet= old_max_allowed_packet;
762
798
  DBUG_VOID_RETURN;
763
799
 
764
800
err:
776
812
  pthread_mutex_unlock(&LOCK_thread_count);
777
813
  if (file >= 0)
778
814
    (void) my_close(file, MYF(MY_WME));
 
815
  thd->variables.max_allowed_packet= old_max_allowed_packet;
779
816
 
780
817
  my_message(my_errno, errmsg, MYF(0));
781
818
  DBUG_VOID_RETURN;
1001
1038
  MY_STAT stat_area;
1002
1039
  char fname[FN_REFLEN];
1003
1040
  int thread_mask= 0, error= 0;
1004
 
  uint sql_errno=0;
1005
 
  const char* errmsg=0;
 
1041
  uint sql_errno=ER_UNKNOWN_ERROR;
 
1042
  const char* errmsg= "Unknown error occured while reseting slave";
1006
1043
  DBUG_ENTER("reset_slave");
1007
1044
 
1008
1045
  lock_slave_threads(mi);
1131
1168
  int thread_mask;
1132
1169
  const char* errmsg= 0;
1133
1170
  bool need_relay_log_purge= 1;
 
1171
  char saved_host[HOSTNAME_LENGTH + 1];
 
1172
  uint saved_port;
 
1173
  char saved_log_name[FN_REFLEN];
 
1174
  my_off_t saved_log_pos;
1134
1175
  DBUG_ENTER("change_master");
1135
1176
 
1136
1177
  lock_slave_threads(mi);
1160
1201
  */
1161
1202
 
1162
1203
  /*
 
1204
    Before processing the command, save the previous state.
 
1205
  */
 
1206
  strmake(saved_host, mi->host, HOSTNAME_LENGTH);
 
1207
  saved_port= mi->port;
 
1208
  strmake(saved_log_name, mi->master_log_name, FN_REFLEN - 1);
 
1209
  saved_log_pos= mi->master_log_pos;
 
1210
 
 
1211
  /*
1163
1212
    If the user specified host or port without binlog or position,
1164
1213
    reset binlog's name to FIRST and position to 4.
1165
1214
  */
1264
1313
    Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never
1265
1314
    a slave before).
1266
1315
  */
1267
 
  if (flush_master_info(mi, 0))
 
1316
  if (flush_master_info(mi, FALSE, FALSE))
1268
1317
  {
1269
1318
    my_error(ER_RELAY_LOG_INIT, MYF(0), "Failed to flush master info file");
1270
1319
    unlock_slave_threads(mi);
1322
1371
  /* Clear the errors, for a clean start */
1323
1372
  mi->rli.clear_error();
1324
1373
  mi->rli.clear_until_condition();
 
1374
 
 
1375
  sql_print_information("'CHANGE MASTER TO executed'. "
 
1376
    "Previous state master_host='%s', master_port='%u', master_log_file='%s', "
 
1377
    "master_log_pos='%ld'. "
 
1378
    "New state master_host='%s', master_port='%u', master_log_file='%s', "
 
1379
    "master_log_pos='%ld'.", saved_host, saved_port, saved_log_name,
 
1380
    (ulong) saved_log_pos, mi->host, mi->port, mi->master_log_name,
 
1381
    (ulong) mi->master_log_pos);
 
1382
 
1325
1383
  /*
1326
1384
    If we don't write new coordinates to disk now, then old will remain in
1327
1385
    relay-log.info until START SLAVE is issued; but if mysqld is shutdown
1395
1453
  bool ret = TRUE;
1396
1454
  IO_CACHE log;
1397
1455
  File file = -1;
 
1456
  int old_max_allowed_packet= thd->variables.max_allowed_packet;
1398
1457
  DBUG_ENTER("mysql_show_binlog_events");
1399
1458
 
1400
1459
  Log_event::init_show_field_list(&field_list);
1533
1592
  pthread_mutex_lock(&LOCK_thread_count);
1534
1593
  thd->current_linfo = 0;
1535
1594
  pthread_mutex_unlock(&LOCK_thread_count);
 
1595
  thd->variables.max_allowed_packet= old_max_allowed_packet;
1536
1596
  DBUG_RETURN(ret);
1537
1597
}
1538
1598
 
1603
1663
  if (!mysql_bin_log.is_open())
1604
1664
  {
1605
1665
    my_message(ER_NO_BINARY_LOGGING, ER(ER_NO_BINARY_LOGGING), MYF(0));
1606
 
    return 1;
 
1666
    DBUG_RETURN(TRUE);
1607
1667
  }
1608
1668
 
1609
1669
  field_list.push_back(new Item_empty_string("Log_name", 255));
1668
1728
   replication events along LOAD DATA processing.
1669
1729
   
1670
1730
   @param file  pointer to io-cache
1671
 
   @return 0
 
1731
   @retval 0 success
 
1732
   @retval 1 failure
1672
1733
*/
1673
1734
int log_loaded_block(IO_CACHE* file)
1674
1735
{
1695
1756
      Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer,
1696
1757
                               min(block_len, max_event_size),
1697
1758
                               lf_info->log_delayed);
1698
 
      mysql_bin_log.write(&a);
 
1759
      if (mysql_bin_log.write(&a))
 
1760
        DBUG_RETURN(1);
1699
1761
    }
1700
1762
    else
1701
1763
    {
1703
1765
                                   buffer,
1704
1766
                                   min(block_len, max_event_size),
1705
1767
                                   lf_info->log_delayed);
1706
 
      mysql_bin_log.write(&b);
 
1768
      if (mysql_bin_log.write(&b))
 
1769
        DBUG_RETURN(1);
1707
1770
      lf_info->wrote_create_file= 1;
1708
 
      DBUG_SYNC_POINT("debug_lock.created_file_event",10);
1709
1771
    }
1710
1772
  }
1711
1773
  DBUG_RETURN(0);