~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log_event.cc

  • Committer: Monty Taylor
  • Date: 2008-10-20 08:48:34 UTC
  • mfrom: (520.1.22 drizzle)
  • Revision ID: monty@inaugust.com-20081020084834-xpb3w01vkcp55o02
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
   @param level     error, warning or info
98
98
   @param ha_error  HA_ERR_ code
99
99
   @param rli       pointer to the active Relay_log_info instance
100
 
   @param thd       pointer to the slave thread's thd
 
100
   @param session       pointer to the slave thread's session
101
101
   @param table     pointer to the event's table object
102
102
   @param type      the type of the event
103
103
   @param log_name  the master binlog file name
105
105
 
106
106
*/
107
107
static void inline slave_rows_error_report(enum loglevel level, int ha_error,
108
 
                                           Relay_log_info const *rli, THD *thd,
 
108
                                           Relay_log_info const *rli, Session *session,
109
109
                                           Table *table, const char * type,
110
110
                                           const char *log_name, ulong pos)
111
111
{
113
113
  char buff[MAX_SLAVE_ERRMSG], *slider;
114
114
  const char *buff_end= buff + sizeof(buff);
115
115
  uint32_t len;
116
 
  List_iterator_fast<DRIZZLE_ERROR> it(thd->warn_list);
 
116
  List_iterator_fast<DRIZZLE_ERROR> it(session->warn_list);
117
117
  DRIZZLE_ERROR *err;
118
118
  buff[0]= 0;
119
119
 
124
124
                  _(" %s, Error_code: %d;"), err->msg, err->code);
125
125
  }
126
126
  
127
 
  rli->report(level, thd->is_error()? thd->main_da.sql_errno() : 0,
 
127
  rli->report(level, session->is_error()? session->main_da.sql_errno() : 0,
128
128
              _("Could not execute %s event on table %s.%s;"
129
129
                "%s handler error %s; "
130
130
                "the event's master log %s, end_log_pos %lu"),
220
220
  pretty_print_str()
221
221
*/
222
222
 
223
 
static void clear_all_errors(THD *thd, Relay_log_info *rli)
 
223
static void clear_all_errors(Session *session, Relay_log_info *rli)
224
224
{
225
 
  thd->is_slave_error = 0;
226
 
  thd->clear_error();
 
225
  session->is_slave_error = 0;
 
226
  session->clear_error();
227
227
  rli->clear_error();
228
228
}
229
229
 
469
469
  Log_event::Log_event()
470
470
*/
471
471
 
472
 
Log_event::Log_event(THD* thd_arg, uint16_t flags_arg, bool using_trans)
473
 
  :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg)
 
472
Log_event::Log_event(Session* session_arg, uint16_t flags_arg, bool using_trans)
 
473
  :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), session(session_arg)
474
474
{
475
 
  server_id=    thd->server_id;
476
 
  when=         thd->start_time;
 
475
  server_id=    session->server_id;
 
476
  when=         session->start_time;
477
477
  cache_stmt=   using_trans;
478
478
}
479
479
 
480
480
 
481
481
/**
482
482
  This minimal constructor is for when you are not even sure that there
483
 
  is a valid THD. For example in the server when we are shutting down or
 
483
  is a valid Session. For example in the server when we are shutting down or
484
484
  flushing logs after receiving a SIGHUP (then we must write a Rotate to
485
 
  the binlog but we have no THD, so we need this minimal constructor).
 
485
  the binlog but we have no Session, so we need this minimal constructor).
486
486
*/
487
487
 
488
488
Log_event::Log_event()
489
489
  :temp_buf(0), exec_time(0), flags(0), cache_stmt(0),
490
 
   thd(0)
 
490
   session(0)
491
491
{
492
492
  server_id=    ::server_id;
493
493
  /*
507
507
                     const Format_description_log_event* description_event)
508
508
  :temp_buf(0), cache_stmt(0)
509
509
{
510
 
  thd= 0;
 
510
  session= 0;
511
511
  when= uint4korr(buf);
512
512
  server_id= uint4korr(buf + SERVER_ID_OFFSET);
513
513
  data_written= uint4korr(buf + EVENT_LEN_OFFSET);
752
752
  }
753
753
  data_len= uint4korr(buf + EVENT_LEN_OFFSET);
754
754
  if (data_len < LOG_EVENT_MINIMAL_HEADER_LEN ||
755
 
      data_len > current_thd->variables.max_allowed_packet)
 
755
      data_len > current_session->variables.max_allowed_packet)
756
756
  {
757
757
    result= ((data_len < LOG_EVENT_MINIMAL_HEADER_LEN) ? LOG_READ_BOGUS :
758
758
             LOG_READ_TOO_LARGE);
836
836
  const char *error= 0;
837
837
  Log_event *res=  0;
838
838
#ifndef max_allowed_packet
839
 
  THD *thd=current_thd;
840
 
  uint32_t max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0;
 
839
  Session *session=current_session;
 
840
  uint32_t max_allowed_packet= session ? session->variables.max_allowed_packet : ~(ulong)0;
841
841
#endif
842
842
 
843
843
  if (data_len > max_allowed_packet)
1281
1281
/*
1282
1282
  SYNOPSIS
1283
1283
    Query_log_event::Query_log_event()
1284
 
      thd_arg           - thread handle
 
1284
      session_arg           - thread handle
1285
1285
      query_arg         - array of char representing the query
1286
1286
      query_length      - size of the  `query_arg' array
1287
1287
      using_trans       - there is a modified transactional table
1288
1288
      suppress_use      - suppress the generation of 'USE' statements
1289
 
      killed_status_arg - an optional with default to THD::KILLED_NO_VALUE
 
1289
      killed_status_arg - an optional with default to Session::KILLED_NO_VALUE
1290
1290
                          if the value is different from the default, the arg
1291
 
                          is set to the current thd->killed value.
1292
 
                          A caller might need to masquerade thd->killed with
1293
 
                          THD::NOT_KILLED.
 
1291
                          is set to the current session->killed value.
 
1292
                          A caller might need to masquerade session->killed with
 
1293
                          Session::NOT_KILLED.
1294
1294
  DESCRIPTION
1295
1295
  Creates an event for binlogging
1296
1296
  The value for local `killed_status' can be supplied by caller.
1297
1297
*/
1298
 
Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
 
1298
Query_log_event::Query_log_event(Session* session_arg, const char* query_arg,
1299
1299
                                 ulong query_length, bool using_trans,
1300
1300
                                 bool suppress_use,
1301
 
                                 THD::killed_state killed_status_arg)
1302
 
  :Log_event(thd_arg,
1303
 
             (thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F :
 
1301
                                 Session::killed_state killed_status_arg)
 
1302
  :Log_event(session_arg,
 
1303
             (session_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F :
1304
1304
              0) |
1305
1305
             (suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0),
1306
1306
             using_trans),
1307
 
   data_buf(0), query(query_arg), catalog(thd_arg->catalog),
1308
 
   db(thd_arg->db), q_len((uint32_t) query_length),
1309
 
   thread_id(thd_arg->thread_id),
 
1307
   data_buf(0), query(query_arg), catalog(session_arg->catalog),
 
1308
   db(session_arg->db), q_len((uint32_t) query_length),
 
1309
   thread_id(session_arg->thread_id),
1310
1310
   /* save the original thread id; we already know the server id */
1311
 
   slave_proxy_id(thd_arg->variables.pseudo_thread_id),
 
1311
   slave_proxy_id(session_arg->variables.pseudo_thread_id),
1312
1312
   flags2_inited(1), sql_mode_inited(1), charset_inited(1),
1313
1313
   sql_mode(0),
1314
 
   auto_increment_increment(thd_arg->variables.auto_increment_increment),
1315
 
   auto_increment_offset(thd_arg->variables.auto_increment_offset),
1316
 
   lc_time_names_number(thd_arg->variables.lc_time_names->number),
 
1314
   auto_increment_increment(session_arg->variables.auto_increment_increment),
 
1315
   auto_increment_offset(session_arg->variables.auto_increment_offset),
 
1316
   lc_time_names_number(session_arg->variables.lc_time_names->number),
1317
1317
   charset_database_number(0)
1318
1318
{
1319
1319
  time_t end_time;
1320
1320
 
1321
 
  if (killed_status_arg == THD::KILLED_NO_VALUE)
1322
 
    killed_status_arg= thd_arg->killed;
 
1321
  if (killed_status_arg == Session::KILLED_NO_VALUE)
 
1322
    killed_status_arg= session_arg->killed;
1323
1323
 
1324
1324
  error_code=
1325
 
    (killed_status_arg == THD::NOT_KILLED) ?
1326
 
    (thd_arg->is_error() ? thd_arg->main_da.sql_errno() : 0) :
1327
 
    (thd_arg->killed_errno());
 
1325
    (killed_status_arg == Session::NOT_KILLED) ?
 
1326
    (session_arg->is_error() ? session_arg->main_da.sql_errno() : 0) :
 
1327
    (session_arg->killed_errno());
1328
1328
  
1329
1329
  time(&end_time);
1330
 
  exec_time = (ulong) (end_time  - thd_arg->start_time);
 
1330
  exec_time = (ulong) (end_time  - session_arg->start_time);
1331
1331
  /**
1332
1332
    @todo this means that if we have no catalog, then it is replicated
1333
1333
    as an existing catalog of length zero. is that safe? /sven
1335
1335
  catalog_len = (catalog) ? (uint32_t) strlen(catalog) : 0;
1336
1336
  /* status_vars_len is set just before writing the event */
1337
1337
  db_len = (db) ? (uint32_t) strlen(db) : 0;
1338
 
  if (thd_arg->variables.collation_database != thd_arg->db_charset)
1339
 
    charset_database_number= thd_arg->variables.collation_database->number;
 
1338
  if (session_arg->variables.collation_database != session_arg->db_charset)
 
1339
    charset_database_number= session_arg->variables.collation_database->number;
1340
1340
  
1341
1341
  /*
1342
1342
    If we don't use flags2 for anything else than options contained in
1343
 
    thd_arg->options, it would be more efficient to flags2=thd_arg->options
 
1343
    session_arg->options, it would be more efficient to flags2=session_arg->options
1344
1344
    (OPTIONS_WRITTEN_TO_BIN_LOG would be used only at reading time).
1345
1345
    But it's likely that we don't want to use 32 bits for 3 bits; in the future
1346
1346
    we will probably want to reclaim the 29 bits. So we need the &.
1347
1347
  */
1348
 
  flags2= (uint32_t) (thd_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG);
1349
 
  assert(thd_arg->variables.character_set_client->number < 256*256);
1350
 
  assert(thd_arg->variables.collation_connection->number < 256*256);
1351
 
  assert(thd_arg->variables.collation_server->number < 256*256);
1352
 
  assert(thd_arg->variables.character_set_client->mbminlen == 1);
1353
 
  int2store(charset, thd_arg->variables.character_set_client->number);
1354
 
  int2store(charset+2, thd_arg->variables.collation_connection->number);
1355
 
  int2store(charset+4, thd_arg->variables.collation_server->number);
1356
 
  if (thd_arg->time_zone_used)
 
1348
  flags2= (uint32_t) (session_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG);
 
1349
  assert(session_arg->variables.character_set_client->number < 256*256);
 
1350
  assert(session_arg->variables.collation_connection->number < 256*256);
 
1351
  assert(session_arg->variables.collation_server->number < 256*256);
 
1352
  assert(session_arg->variables.character_set_client->mbminlen == 1);
 
1353
  int2store(charset, session_arg->variables.character_set_client->number);
 
1354
  int2store(charset+2, session_arg->variables.collation_connection->number);
 
1355
  int2store(charset+4, session_arg->variables.collation_server->number);
 
1356
  if (session_arg->time_zone_used)
1357
1357
  {
1358
1358
    /*
1359
1359
      Note that our event becomes dependent on the Time_zone object
1360
1360
      representing the time zone. Fortunately such objects are never deleted
1361
1361
      or changed during mysqld's lifetime.
1362
1362
    */
1363
 
    time_zone_len= thd_arg->variables.time_zone->get_name()->length();
1364
 
    time_zone_str= thd_arg->variables.time_zone->get_name()->ptr();
 
1363
    time_zone_len= session_arg->variables.time_zone->get_name()->length();
 
1364
    time_zone_str= session_arg->variables.time_zone->get_name()->ptr();
1365
1365
  }
1366
1366
  else
1367
1367
    time_zone_len= 0;
1636
1636
     sql_print_error("Slave: did not get the expected number of affected \
1637
1637
     rows running query from master - expected %d, got %d (this numbers \
1638
1638
     should have matched modulo 4294967296).", 0, ...);
1639
 
     thd->query_error = 1;
 
1639
     session->query_error = 1;
1640
1640
     }
1641
1641
  @endcode
1642
1642
  We may also want an option to tell the slave to ignore "affected"
1649
1649
  LEX_STRING new_db;
1650
1650
  int expected_error,actual_error= 0;
1651
1651
  /*
1652
 
    Colleagues: please never free(thd->catalog) in MySQL. This would
1653
 
    lead to bugs as here thd->catalog is a part of an alloced block,
 
1652
    Colleagues: please never free(session->catalog) in MySQL. This would
 
1653
    lead to bugs as here session->catalog is a part of an alloced block,
1654
1654
    not an entire alloced block (see
1655
 
    Query_log_event::do_apply_event()). Same for thd->db.  Thank
 
1655
    Query_log_event::do_apply_event()). Same for session->db.  Thank
1656
1656
    you.
1657
1657
  */
1658
 
  thd->catalog= catalog_len ? (char *) catalog : (char *)"";
 
1658
  session->catalog= catalog_len ? (char *) catalog : (char *)"";
1659
1659
  new_db.length= db_len;
1660
1660
  new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length);
1661
 
  thd->set_db(new_db.str, new_db.length);       /* allocates a copy of 'db' */
1662
 
  thd->variables.auto_increment_increment= auto_increment_increment;
1663
 
  thd->variables.auto_increment_offset=    auto_increment_offset;
 
1661
  session->set_db(new_db.str, new_db.length);       /* allocates a copy of 'db' */
 
1662
  session->variables.auto_increment_increment= auto_increment_increment;
 
1663
  session->variables.auto_increment_offset=    auto_increment_offset;
1664
1664
 
1665
1665
  /*
1666
1666
    InnoDB internally stores the master log position it has executed so far,
1674
1674
  */
1675
1675
  const_cast<Relay_log_info*>(rli)->future_group_master_log_pos= log_pos;
1676
1676
 
1677
 
  clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
 
1677
  clear_all_errors(session, const_cast<Relay_log_info*>(rli));
1678
1678
  const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
1679
1679
 
1680
1680
  /*
1687
1687
            ::do_apply_event(), then the companion SET also have so
1688
1688
            we don't need to reset_one_shot_variables().
1689
1689
  */
1690
 
  if (rpl_filter->db_ok(thd->db))
 
1690
  if (rpl_filter->db_ok(session->db))
1691
1691
  {
1692
 
    thd->set_time((time_t)when);
1693
 
    thd->query_length= q_len_arg;
1694
 
    thd->query= (char*)query_arg;
 
1692
    session->set_time((time_t)when);
 
1693
    session->query_length= q_len_arg;
 
1694
    session->query= (char*)query_arg;
1695
1695
    pthread_mutex_lock(&LOCK_thread_count);
1696
 
    thd->query_id = next_query_id();
 
1696
    session->query_id = next_query_id();
1697
1697
    pthread_mutex_unlock(&LOCK_thread_count);
1698
 
    thd->variables.pseudo_thread_id= thread_id;         // for temp tables
 
1698
    session->variables.pseudo_thread_id= thread_id;             // for temp tables
1699
1699
 
1700
1700
    if (ignored_error_code((expected_error= error_code)) ||
1701
 
        !check_expected_error(thd,rli,expected_error))
 
1701
        !check_expected_error(session,rli,expected_error))
1702
1702
    {
1703
1703
      if (flags2_inited)
1704
1704
        /*
1705
 
          all bits of thd->options which are 1 in OPTIONS_WRITTEN_TO_BIN_LOG
 
1705
          all bits of session->options which are 1 in OPTIONS_WRITTEN_TO_BIN_LOG
1706
1706
          must take their value from flags2.
1707
1707
        */
1708
 
        thd->options= flags2|(thd->options & ~OPTIONS_WRITTEN_TO_BIN_LOG);
 
1708
        session->options= flags2|(session->options & ~OPTIONS_WRITTEN_TO_BIN_LOG);
1709
1709
      if (time_zone_len)
1710
1710
      {
1711
1711
        String tmp(time_zone_str, time_zone_len, &my_charset_bin);
1712
 
        if (!(thd->variables.time_zone= my_tz_find(thd, &tmp)))
 
1712
        if (!(session->variables.time_zone= my_tz_find(session, &tmp)))
1713
1713
        {
1714
1714
          my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), tmp.c_ptr());
1715
 
          thd->variables.time_zone= global_system_variables.time_zone;
 
1715
          session->variables.time_zone= global_system_variables.time_zone;
1716
1716
          goto compare_errors;
1717
1717
        }
1718
1718
      }
1719
1719
      if (lc_time_names_number)
1720
1720
      {
1721
 
        if (!(thd->variables.lc_time_names=
 
1721
        if (!(session->variables.lc_time_names=
1722
1722
              my_locale_by_number(lc_time_names_number)))
1723
1723
        {
1724
1724
          my_printf_error(ER_UNKNOWN_ERROR,
1725
1725
                      "Unknown locale: '%d'", MYF(0), lc_time_names_number);
1726
 
          thd->variables.lc_time_names= &my_locale_en_US;
 
1726
          session->variables.lc_time_names= &my_locale_en_US;
1727
1727
          goto compare_errors;
1728
1728
        }
1729
1729
      }
1730
1730
      else
1731
 
        thd->variables.lc_time_names= &my_locale_en_US;
 
1731
        session->variables.lc_time_names= &my_locale_en_US;
1732
1732
      if (charset_database_number)
1733
1733
      {
1734
1734
        const CHARSET_INFO *cs;
1739
1739
          my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
1740
1740
          goto compare_errors;
1741
1741
        }
1742
 
        thd->variables.collation_database= cs;
 
1742
        session->variables.collation_database= cs;
1743
1743
      }
1744
1744
      else
1745
 
        thd->variables.collation_database= thd->db_charset;
 
1745
        session->variables.collation_database= session->db_charset;
1746
1746
      
1747
1747
      /* Execute the query (note that we bypass dispatch_command()) */
1748
1748
      const char* found_semicolon= NULL;
1749
 
      mysql_parse(thd, thd->query, thd->query_length, &found_semicolon);
1750
 
      log_slow_statement(thd);
 
1749
      mysql_parse(session, session->query, session->query_length, &found_semicolon);
 
1750
      log_slow_statement(session);
1751
1751
    }
1752
1752
    else
1753
1753
    {
1758
1758
        we exit gracefully; otherwise we warn about the bad error and tell DBA
1759
1759
        to check/fix it.
1760
1760
      */
1761
 
      if (mysql_test_parse_for_slave(thd, thd->query, thd->query_length))
1762
 
        clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
 
1761
      if (mysql_test_parse_for_slave(session, session->query, session->query_length))
 
1762
        clear_all_errors(session, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
1763
1763
      else
1764
1764
      {
1765
1765
        rli->report(ERROR_LEVEL, expected_error,
1770
1770
                      "this query manually on the slave and then restart the "
1771
1771
                      "slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; "
1772
1772
                      "START SLAVE; . Query: '%s'"),
1773
 
                    expected_error, thd->query);
1774
 
        thd->is_slave_error= 1;
 
1773
                    expected_error, session->query);
 
1774
        session->is_slave_error= 1;
1775
1775
      }
1776
1776
      goto end;
1777
1777
    }
1782
1782
      If we expected a non-zero error code, and we don't get the same error
1783
1783
      code, and none of them should be ignored.
1784
1784
    */
1785
 
    actual_error= thd->is_error() ? thd->main_da.sql_errno() : 0;
 
1785
    actual_error= session->is_error() ? session->main_da.sql_errno() : 0;
1786
1786
    if ((expected_error != actual_error) &&
1787
1787
        expected_error &&
1788
1788
        !ignored_error_code(actual_error) &&
1794
1794
                    "Default database: '%s'. Query: '%s'"),
1795
1795
                  ER_SAFE(expected_error),
1796
1796
                  expected_error,
1797
 
                  actual_error ? thd->main_da.message() : _("no error"),
 
1797
                  actual_error ? session->main_da.message() : _("no error"),
1798
1798
                  actual_error,
1799
1799
                  print_slave_db_safe(db), query_arg);
1800
 
      thd->is_slave_error= 1;
 
1800
      session->is_slave_error= 1;
1801
1801
    }
1802
1802
    /*
1803
1803
      If we get the same error code as expected, or they should be ignored. 
1805
1805
    else if (expected_error == actual_error ||
1806
1806
             ignored_error_code(actual_error))
1807
1807
    {
1808
 
      clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
1809
 
      thd->killed= THD::NOT_KILLED;
 
1808
      clear_all_errors(session, const_cast<Relay_log_info*>(rli));
 
1809
      session->killed= Session::NOT_KILLED;
1810
1810
    }
1811
1811
    /*
1812
1812
      Other cases: mostly we expected no error and get one.
1813
1813
    */
1814
 
    else if (thd->is_slave_error || thd->is_fatal_error)
 
1814
    else if (session->is_slave_error || session->is_fatal_error)
1815
1815
    {
1816
1816
      rli->report(ERROR_LEVEL, actual_error,
1817
1817
                  _("Error '%s' on query. Default database: '%s'. Query: '%s'"),
1818
 
                  (actual_error ? thd->main_da.message() :
 
1818
                  (actual_error ? session->main_da.message() :
1819
1819
                   _("unexpected success or fatal error")),
1820
 
                      print_slave_db_safe(thd->db), query_arg);
1821
 
      thd->is_slave_error= 1;
 
1820
                      print_slave_db_safe(session->db), query_arg);
 
1821
      session->is_slave_error= 1;
1822
1822
    }
1823
1823
 
1824
1824
    /*
1829
1829
      sql_print_error("Slave: did not get the expected number of affected \
1830
1830
      rows running query from master - expected %d, got %d (this numbers \
1831
1831
      should have matched modulo 4294967296).", 0, ...);
1832
 
      thd->is_slave_error = 1;
 
1832
      session->is_slave_error = 1;
1833
1833
      }
1834
1834
      We may also want an option to tell the slave to ignore "affected"
1835
1835
      mismatch. This mismatch could be implemented with a new ER_ code, and
1847
1847
end:
1848
1848
  pthread_mutex_lock(&LOCK_thread_count);
1849
1849
  /*
1850
 
    Probably we have set thd->query, thd->db, thd->catalog to point to places
 
1850
    Probably we have set session->query, session->db, session->catalog to point to places
1851
1851
    in the data_buf of this event. Now the event is going to be deleted
1852
 
    probably, so data_buf will be freed, so the thd->... listed above will be
 
1852
    probably, so data_buf will be freed, so the session->... listed above will be
1853
1853
    pointers to freed memory. 
1854
1854
    So we must set them to 0, so that those bad pointers values are not later
1855
1855
    used. Note that "cleanup" queries like automatic DROP TEMPORARY Table
1856
1856
    don't suffer from these assignments to 0 as DROP TEMPORARY
1857
1857
    Table uses the db.table syntax.
1858
1858
  */
1859
 
  thd->catalog= 0;
1860
 
  thd->set_db(NULL, 0);                 /* will free the current database */
1861
 
  thd->query= 0;                        // just to be sure
1862
 
  thd->query_length= 0;
 
1859
  session->catalog= 0;
 
1860
  session->set_db(NULL, 0);                 /* will free the current database */
 
1861
  session->query= 0;                    // just to be sure
 
1862
  session->query_length= 0;
1863
1863
  pthread_mutex_unlock(&LOCK_thread_count);
1864
 
  close_thread_tables(thd);      
 
1864
  close_thread_tables(session);      
1865
1865
  /*
1866
1866
    As a disk space optimization, future masters will not log an event for
1867
1867
    LAST_INSERT_ID() if that function returned 0 (and thus they will be able
1868
 
    to replace the THD::stmt_depends_on_first_successful_insert_id_in_prev_stmt
1869
 
    variable by (THD->first_successful_insert_id_in_prev_stmt > 0) ; with the
 
1868
    to replace the Session::stmt_depends_on_first_successful_insert_id_in_prev_stmt
 
1869
    variable by (Session->first_successful_insert_id_in_prev_stmt > 0) ; with the
1870
1870
    resetting below we are ready to support that.
1871
1871
  */
1872
 
  thd->first_successful_insert_id_in_prev_stmt_for_binlog= 0;
1873
 
  thd->first_successful_insert_id_in_prev_stmt= 0;
1874
 
  thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
1875
 
  free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
1876
 
  return thd->is_slave_error;
 
1872
  session->first_successful_insert_id_in_prev_stmt_for_binlog= 0;
 
1873
  session->first_successful_insert_id_in_prev_stmt= 0;
 
1874
  session->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
 
1875
  free_root(session->mem_root,MYF(MY_KEEP_PREALLOC));
 
1876
  return session->is_slave_error;
1877
1877
}
1878
1878
 
1879
1879
int Query_log_event::do_update_pos(Relay_log_info *rli)
1883
1883
    after a SET ONE_SHOT, because SET ONE_SHOT should not be separated
1884
1884
    from its following updating query.
1885
1885
  */
1886
 
  if (thd->one_shot_set)
 
1886
  if (session->one_shot_set)
1887
1887
  {
1888
1888
    rli->inc_event_relay_log_pos();
1889
1889
    return 0;
1902
1902
  {
1903
1903
    if (strcmp("BEGIN", query) == 0)
1904
1904
    {
1905
 
      thd->options|= OPTION_BEGIN;
 
1905
      session->options|= OPTION_BEGIN;
1906
1906
      return(Log_event::continue_group(rli));
1907
1907
    }
1908
1908
 
1909
1909
    if (strcmp("COMMIT", query) == 0 || strcmp("ROLLBACK", query) == 0)
1910
1910
    {
1911
 
      thd->options&= ~OPTION_BEGIN;
 
1911
      session->options&= ~OPTION_BEGIN;
1912
1912
      return(Log_event::EVENT_SKIP_COUNT);
1913
1913
    }
1914
1914
  }
2013
2013
    */
2014
2014
    if (created)
2015
2015
    {
2016
 
      close_temporary_tables(thd);
 
2016
      close_temporary_tables(session);
2017
2017
      cleanup_load_tmpdir();
2018
2018
    }
2019
2019
    break;
2030
2030
        Can distinguish, based on the value of 'created': this event was
2031
2031
        generated at master startup.
2032
2032
      */
2033
 
      close_temporary_tables(thd);
 
2033
      close_temporary_tables(session);
2034
2034
    }
2035
2035
    /*
2036
2036
      Otherwise, can't distinguish a Start_log_event generated at
2328
2328
    original place when it comes to us; we'll know this by checking
2329
2329
    log_pos ("artificial" events have log_pos == 0).
2330
2330
  */
2331
 
  if (!artificial_event && created && thd->transaction.all.ha_list)
 
2331
  if (!artificial_event && created && session->transaction.all.ha_list)
2332
2332
  {
2333
2333
    /* This is not an error (XA is safe), just an information */
2334
2334
    rli->report(INFORMATION_LEVEL, 0,
2336
2336
                  "or ROLLBACK in relay log). A probable cause is that "
2337
2337
                  "the master died while writing the transaction to "
2338
2338
                  "its binary log, thus rolled back too."));
2339
 
    const_cast<Relay_log_info*>(rli)->cleanup_context(thd, 1);
 
2339
    const_cast<Relay_log_info*>(rli)->cleanup_context(session, 1);
2340
2340
  }
2341
2341
  /*
2342
2342
    If this event comes from ourselves, there is no cleaning task to
2600
2600
  Load_log_event::Load_log_event()
2601
2601
*/
2602
2602
 
2603
 
Load_log_event::Load_log_event(THD *thd_arg, sql_exchange *ex,
 
2603
Load_log_event::Load_log_event(Session *session_arg, sql_exchange *ex,
2604
2604
                               const char *db_arg, const char *table_name_arg,
2605
2605
                               List<Item> &fields_arg,
2606
2606
                               enum enum_duplicates handle_dup,
2607
2607
                               bool ignore, bool using_trans)
2608
 
  :Log_event(thd_arg,
2609
 
             thd_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0,
 
2608
  :Log_event(session_arg,
 
2609
             session_arg->thread_specific_used ? LOG_EVENT_THREAD_SPECIFIC_F : 0,
2610
2610
             using_trans),
2611
 
   thread_id(thd_arg->thread_id),
2612
 
   slave_proxy_id(thd_arg->variables.pseudo_thread_id),
 
2611
   thread_id(session_arg->thread_id),
 
2612
   slave_proxy_id(session_arg->variables.pseudo_thread_id),
2613
2613
   num_fields(0),fields(0),
2614
2614
   field_lens(0),field_block_len(0),
2615
2615
   table_name(table_name_arg ? table_name_arg : ""),
2617
2617
{
2618
2618
  time_t end_time;
2619
2619
  time(&end_time);
2620
 
  exec_time = (ulong) (end_time  - thd_arg->start_time);
 
2620
  exec_time = (ulong) (end_time  - session_arg->start_time);
2621
2621
  /* db can never be a zero pointer in 4.0 */
2622
2622
  db_len = (uint32_t) strlen(db);
2623
2623
  table_name_len = (uint32_t) strlen(table_name);
2818
2818
  LEX_STRING new_db;
2819
2819
  new_db.length= db_len;
2820
2820
  new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length);
2821
 
  thd->set_db(new_db.str, new_db.length);
2822
 
  assert(thd->query == 0);
2823
 
  thd->query_length= 0;                         // Should not be needed
2824
 
  thd->is_slave_error= 0;
2825
 
  clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
 
2821
  session->set_db(new_db.str, new_db.length);
 
2822
  assert(session->query == 0);
 
2823
  session->query_length= 0;                         // Should not be needed
 
2824
  session->is_slave_error= 0;
 
2825
  clear_all_errors(session, const_cast<Relay_log_info*>(rli));
2826
2826
 
2827
2827
  /* see Query_log_event::do_apply_event() and BUG#13360 */
2828
2828
  assert(!rli->m_table_map.count());
2830
2830
    Usually lex_start() is called by mysql_parse(), but we need it here
2831
2831
    as the present method does not call mysql_parse().
2832
2832
  */
2833
 
  lex_start(thd);
2834
 
  mysql_reset_thd_for_next_command(thd);
 
2833
  lex_start(session);
 
2834
  mysql_reset_session_for_next_command(session);
2835
2835
 
2836
2836
  if (!use_rli_only_for_errors)
2837
2837
  {
2865
2865
            ::do_apply_event(), then the companion SET also have so
2866
2866
            we don't need to reset_one_shot_variables().
2867
2867
  */
2868
 
  if (rpl_filter->db_ok(thd->db))
 
2868
  if (rpl_filter->db_ok(session->db))
2869
2869
  {
2870
 
    thd->set_time((time_t)when);
 
2870
    session->set_time((time_t)when);
2871
2871
    pthread_mutex_lock(&LOCK_thread_count);
2872
 
    thd->query_id = next_query_id();
 
2872
    session->query_id = next_query_id();
2873
2873
    pthread_mutex_unlock(&LOCK_thread_count);
2874
2874
    /*
2875
 
      Initing thd->row_count is not necessary in theory as this variable has no
 
2875
      Initing session->row_count is not necessary in theory as this variable has no
2876
2876
      influence in the case of the slave SQL thread (it is used to generate a
2877
2877
      "data truncated" warning but which is absorbed and never gets to the
2878
2878
      error log); still we init it to avoid a Valgrind message.
2879
2879
    */
2880
 
    drizzle_reset_errors(thd, 0);
 
2880
    drizzle_reset_errors(session, 0);
2881
2881
 
2882
2882
    TableList tables;
2883
2883
    memset(&tables, 0, sizeof(tables));
2884
 
    tables.db= thd->strmake(thd->db, thd->db_length);
 
2884
    tables.db= session->strmake(session->db, session->db_length);
2885
2885
    tables.alias = tables.table_name = (char*) table_name;
2886
2886
    tables.lock_type = TL_WRITE;
2887
2887
    tables.updating= 1;
2888
2888
 
2889
2889
    // the table will be opened in mysql_load    
2890
 
    if (rpl_filter->is_on() && !rpl_filter->tables_ok(thd->db, &tables))
 
2890
    if (rpl_filter->is_on() && !rpl_filter->tables_ok(session->db, &tables))
2891
2891
    {
2892
2892
      // TODO: this is a bug - this needs to be moved to the I/O thread
2893
2893
      if (net)
2905
2905
        Forge LOAD DATA INFILE query which will be used in SHOW PROCESS LIST
2906
2906
        and written to slave's binlog if binlogging is on.
2907
2907
      */
2908
 
      if (!(load_data_query= (char *)thd->alloc(get_query_buffer_length() + 1)))
 
2908
      if (!(load_data_query= (char *)session->alloc(get_query_buffer_length() + 1)))
2909
2909
      {
2910
2910
        /*
2911
 
          This will set thd->fatal_error in case of OOM. So we surely will notice
 
2911
          This will set session->fatal_error in case of OOM. So we surely will notice
2912
2912
          that something is wrong.
2913
2913
        */
2914
2914
        goto error;
2915
2915
      }
2916
2916
 
2917
 
      print_query(false, load_data_query, &end, (char **)&thd->lex->fname_start,
2918
 
                  (char **)&thd->lex->fname_end);
 
2917
      print_query(false, load_data_query, &end, (char **)&session->lex->fname_start,
 
2918
                  (char **)&session->lex->fname_end);
2919
2919
      *end= 0;
2920
 
      thd->query_length= end - load_data_query;
2921
 
      thd->query= load_data_query;
 
2920
      session->query_length= end - load_data_query;
 
2921
      session->query= load_data_query;
2922
2922
 
2923
2923
      if (sql_ex.opt_flags & REPLACE_FLAG)
2924
2924
      {
2947
2947
        handle_dup= DUP_ERROR;
2948
2948
      }
2949
2949
      /*
2950
 
        We need to set thd->lex->sql_command and thd->lex->duplicates
 
2950
        We need to set session->lex->sql_command and session->lex->duplicates
2951
2951
        since InnoDB tests these variables to decide if this is a LOAD
2952
2952
        DATA ... REPLACE INTO ... statement even though mysql_parse()
2953
2953
        is not called.  This is not needed in 5.0 since there the LOAD
2954
2954
        DATA ... statement is replicated using mysql_parse(), which
2955
 
        sets the thd->lex fields correctly.
 
2955
        sets the session->lex fields correctly.
2956
2956
      */
2957
 
      thd->lex->sql_command= SQLCOM_LOAD;
2958
 
      thd->lex->duplicates= handle_dup;
 
2957
      session->lex->sql_command= SQLCOM_LOAD;
 
2958
      session->lex->duplicates= handle_dup;
2959
2959
 
2960
2960
      sql_exchange ex((char*)fname, sql_ex.opt_flags & DUMPFILE_FLAG);
2961
2961
      String field_term(sql_ex.field_term,sql_ex.field_term_len,log_cs);
2975
2975
 
2976
2976
      ex.skip_lines = skip_lines;
2977
2977
      List<Item> field_list;
2978
 
      thd->lex->select_lex.context.resolve_in_table_list_only(&tables);
2979
 
      set_fields(tables.db, field_list, &thd->lex->select_lex.context);
2980
 
      thd->variables.pseudo_thread_id= thread_id;
 
2978
      session->lex->select_lex.context.resolve_in_table_list_only(&tables);
 
2979
      set_fields(tables.db, field_list, &session->lex->select_lex.context);
 
2980
      session->variables.pseudo_thread_id= thread_id;
2981
2981
      if (net)
2982
2982
      {
2983
 
        // mysql_load will use thd->net to read the file
2984
 
        thd->net.vio = net->vio;
 
2983
        // mysql_load will use session->net to read the file
 
2984
        session->net.vio = net->vio;
2985
2985
        /*
2986
2986
          Make sure the client does not get confused about the packet sequence
2987
2987
        */
2988
 
        thd->net.pkt_nr = net->pkt_nr;
 
2988
        session->net.pkt_nr = net->pkt_nr;
2989
2989
      }
2990
2990
      /*
2991
2991
        It is safe to use tmp_list twice because we are not going to
2992
2992
        update it inside mysql_load().
2993
2993
      */
2994
2994
      List<Item> tmp_list;
2995
 
      if (mysql_load(thd, &ex, &tables, field_list, tmp_list, tmp_list,
 
2995
      if (mysql_load(session, &ex, &tables, field_list, tmp_list, tmp_list,
2996
2996
                     handle_dup, ignore, net != 0))
2997
 
        thd->is_slave_error= 1;
2998
 
      if (thd->cuted_fields)
 
2997
        session->is_slave_error= 1;
 
2998
      if (session->cuted_fields)
2999
2999
      {
3000
3000
        /* log_pos is the position of the LOAD event in the master log */
3001
3001
        sql_print_warning(_("Slave: load data infile on table '%s' at "
3003
3003
                          "warning(s). Default database: '%s'"),
3004
3004
                          (char*) table_name,
3005
3005
                          llstr(log_pos,llbuff), RPL_LOG_NAME, 
3006
 
                          (ulong) thd->cuted_fields,
3007
 
                          print_slave_db_safe(thd->db));
 
3006
                          (ulong) session->cuted_fields,
 
3007
                          print_slave_db_safe(session->db));
3008
3008
      }
3009
3009
      if (net)
3010
 
        net->pkt_nr= thd->net.pkt_nr;
 
3010
        net->pkt_nr= session->net.pkt_nr;
3011
3011
    }
3012
3012
  }
3013
3013
  else
3022
3022
  }
3023
3023
 
3024
3024
error:
3025
 
  thd->net.vio = 0; 
3026
 
  const char *remember_db= thd->db;
 
3025
  session->net.vio = 0; 
 
3026
  const char *remember_db= session->db;
3027
3027
  pthread_mutex_lock(&LOCK_thread_count);
3028
 
  thd->catalog= 0;
3029
 
  thd->set_db(NULL, 0);                   /* will free the current database */
3030
 
  thd->query= 0;
3031
 
  thd->query_length= 0;
 
3028
  session->catalog= 0;
 
3029
  session->set_db(NULL, 0);                   /* will free the current database */
 
3030
  session->query= 0;
 
3031
  session->query_length= 0;
3032
3032
  pthread_mutex_unlock(&LOCK_thread_count);
3033
 
  close_thread_tables(thd);
 
3033
  close_thread_tables(session);
3034
3034
 
3035
 
  if (thd->is_slave_error)
 
3035
  if (session->is_slave_error)
3036
3036
  {
3037
3037
    /* this err/sql_errno code is copy-paste from net_send_error() */
3038
3038
    const char *err;
3039
3039
    int sql_errno;
3040
 
    if (thd->is_error())
 
3040
    if (session->is_error())
3041
3041
    {
3042
 
      err= thd->main_da.message();
3043
 
      sql_errno= thd->main_da.sql_errno();
 
3042
      err= session->main_da.message();
 
3043
      sql_errno= session->main_da.sql_errno();
3044
3044
    }
3045
3045
    else
3046
3046
    {
3051
3051
                _("Error '%s' running LOAD DATA INFILE on table '%s'. "
3052
3052
                  "Default database: '%s'"),
3053
3053
                err, (char*)table_name, print_slave_db_safe(remember_db));
3054
 
    free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
 
3054
    free_root(session->mem_root,MYF(MY_KEEP_PREALLOC));
3055
3055
    return 1;
3056
3056
  }
3057
 
  free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
 
3057
  free_root(session->mem_root,MYF(MY_KEEP_PREALLOC));
3058
3058
 
3059
 
  if (thd->is_fatal_error)
 
3059
  if (session->is_fatal_error)
3060
3060
  {
3061
3061
    char buf[256];
3062
3062
    snprintf(buf, sizeof(buf),
3190
3190
    rli->notify_group_relay_log_name_update();
3191
3191
    rli->group_relay_log_pos= rli->event_relay_log_pos;
3192
3192
    /*
3193
 
      Reset thd->options and sql_mode etc, because this could be the signal of
 
3193
      Reset session->options and sql_mode etc, because this could be the signal of
3194
3194
      a master's downgrade from 5.0 to 4.0.
3195
3195
      However, no need to reset description_event_for_exec: indeed, if the next
3196
3196
      master is 5.0 (even 5.0.1) we will soon get a Format_desc; if the next
3197
3197
      master is 4.0 then the events are in the slave's format (conversion).
3198
3198
    */
3199
 
    set_slave_thread_options(thd);
3200
 
    thd->variables.auto_increment_increment=
3201
 
      thd->variables.auto_increment_offset= 1;
 
3199
    set_slave_thread_options(session);
 
3200
    session->variables.auto_increment_increment=
 
3201
      session->variables.auto_increment_offset= 1;
3202
3202
  }
3203
3203
  pthread_mutex_unlock(&rli->data_lock);
3204
3204
  pthread_cond_broadcast(&rli->data_cond);
3304
3304
 
3305
3305
  switch (type) {
3306
3306
  case LAST_INSERT_ID_EVENT:
3307
 
    thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1;
3308
 
    thd->first_successful_insert_id_in_prev_stmt= val;
 
3307
    session->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 1;
 
3308
    session->first_successful_insert_id_in_prev_stmt= val;
3309
3309
    break;
3310
3310
  case INSERT_ID_EVENT:
3311
 
    thd->force_one_auto_inc_interval(val);
 
3311
    session->force_one_auto_inc_interval(val);
3312
3312
    break;
3313
3313
  }
3314
3314
  return 0;
3379
3379
   */
3380
3380
  const_cast<Relay_log_info*>(rli)->set_flag(Relay_log_info::IN_STMT);
3381
3381
 
3382
 
  thd->rand.seed1= (ulong) seed1;
3383
 
  thd->rand.seed2= (ulong) seed2;
 
3382
  session->rand.seed1= (ulong) seed1;
 
3383
  session->rand.seed2= (ulong) seed2;
3384
3384
  return 0;
3385
3385
}
3386
3386
 
3447
3447
 
3448
3448
int Xid_log_event::do_apply_event(Relay_log_info const *rli __attribute__((unused)))
3449
3449
{
3450
 
  return end_trans(thd, COMMIT);
 
3450
  return end_trans(session, COMMIT);
3451
3451
}
3452
3452
 
3453
3453
Log_event::enum_skip_reason
3454
3454
Xid_log_event::do_shall_skip(Relay_log_info *rli)
3455
3455
{
3456
3456
  if (rli->slave_skip_counter > 0) {
3457
 
    thd->options&= ~OPTION_BEGIN;
 
3457
    session->options&= ~OPTION_BEGIN;
3458
3458
    return(Log_event::EVENT_SKIP_COUNT);
3459
3459
  }
3460
3460
  return(Log_event::do_shall_skip(rli));
3698
3698
    Item_func_set_user_var can't substitute something else on its place =>
3699
3699
    0 can be passed as last argument (reference on item)
3700
3700
  */
3701
 
  e.fix_fields(thd, 0);
 
3701
  e.fix_fields(session, 0);
3702
3702
  /*
3703
3703
    A variable can just be considered as a table with
3704
3704
    a single record and with a single column. Thus, like
3705
3705
    a column value, it could always have IMPLICIT derivation.
3706
3706
   */
3707
3707
  e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0);
3708
 
  free_root(thd->mem_root,0);
 
3708
  free_root(session->mem_root,0);
3709
3709
 
3710
3710
  return 0;
3711
3711
}
3754
3754
  @todo
3755
3755
  re-write this better without holding both locks at the same time
3756
3756
*/
3757
 
Slave_log_event::Slave_log_event(THD* thd_arg,
 
3757
Slave_log_event::Slave_log_event(Session* session_arg,
3758
3758
                                 Relay_log_info* rli)
3759
 
  :Log_event(thd_arg, 0, 0) , mem_pool(0), master_host(0)
 
3759
  :Log_event(session_arg, 0, 0) , mem_pool(0), master_host(0)
3760
3760
{
3761
3761
  if (!rli->inited)                             // QQ When can this happen ?
3762
3762
    return;
3850
3850
    could give false triggers in MASTER_POS_WAIT() that we have reached
3851
3851
    the target position when in fact we have not.
3852
3852
  */
3853
 
  if (thd->options & OPTION_BEGIN)
 
3853
  if (session->options & OPTION_BEGIN)
3854
3854
    rli->inc_event_relay_log_pos();
3855
3855
  else
3856
3856
  {
3870
3870
*/
3871
3871
 
3872
3872
Create_file_log_event::
3873
 
Create_file_log_event(THD* thd_arg, sql_exchange* ex,
 
3873
Create_file_log_event(Session* session_arg, sql_exchange* ex,
3874
3874
                      const char* db_arg, const char* table_name_arg,
3875
3875
                      List<Item>& fields_arg, enum enum_duplicates handle_dup,
3876
3876
                      bool ignore,
3877
3877
                      unsigned char* block_arg, uint32_t block_len_arg, bool using_trans)
3878
 
  :Load_log_event(thd_arg,ex,db_arg,table_name_arg,fields_arg,handle_dup, ignore,
 
3878
  :Load_log_event(session_arg,ex,db_arg,table_name_arg,fields_arg,handle_dup, ignore,
3879
3879
                  using_trans),
3880
3880
   fake_base(0), block(block_arg), event_buf(0), block_len(block_len_arg),
3881
 
   file_id(thd_arg->file_id = mysql_bin_log.next_file_id())
 
3881
   file_id(session_arg->file_id = mysql_bin_log.next_file_id())
3882
3882
{
3883
3883
  sql_ex.force_new_format();
3884
3884
  return;
4015
4015
  memset(&file, 0, sizeof(file));
4016
4016
  fname_buf= my_stpcpy(proc_info, "Making temp file ");
4017
4017
  ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info");
4018
 
  thd->set_proc_info(proc_info);
 
4018
  session->set_proc_info(proc_info);
4019
4019
  my_delete(fname_buf, MYF(0)); // old copy may exist already
4020
4020
  if ((fd= my_create(fname_buf, CREATE_MODE,
4021
4021
                     O_WRONLY | O_EXCL,
4068
4068
    end_io_cache(&file);
4069
4069
  if (fd >= 0)
4070
4070
    my_close(fd, MYF(0));
4071
 
  thd->set_proc_info(0);
 
4071
  session->set_proc_info(0);
4072
4072
  return error == 0;
4073
4073
}
4074
4074
 
4081
4081
  Append_block_log_event ctor
4082
4082
*/
4083
4083
 
4084
 
Append_block_log_event::Append_block_log_event(THD *thd_arg,
 
4084
Append_block_log_event::Append_block_log_event(Session *session_arg,
4085
4085
                                               const char *db_arg,
4086
4086
                                               unsigned char *block_arg,
4087
4087
                                               uint32_t block_len_arg,
4088
4088
                                               bool using_trans)
4089
 
  :Log_event(thd_arg,0, using_trans), block(block_arg),
4090
 
   block_len(block_len_arg), file_id(thd_arg->file_id), db(db_arg)
 
4089
  :Log_event(session_arg,0, using_trans), block(block_arg),
 
4090
   block_len(block_len_arg), file_id(session_arg->file_id), db(db_arg)
4091
4091
{
4092
4092
}
4093
4093
 
4162
4162
 
4163
4163
  fname= my_stpcpy(proc_info, "Making temp file ");
4164
4164
  slave_load_file_stem(fname, file_id, server_id, ".data");
4165
 
  thd->set_proc_info(proc_info);
 
4165
  session->set_proc_info(proc_info);
4166
4166
  if (get_create_or_append())
4167
4167
  {
4168
4168
    my_delete(fname, MYF(0)); // old copy may exist already
4196
4196
err:
4197
4197
  if (fd >= 0)
4198
4198
    my_close(fd, MYF(0));
4199
 
  thd->set_proc_info(0);
 
4199
  session->set_proc_info(0);
4200
4200
  return(error);
4201
4201
}
4202
4202
 
4209
4209
  Delete_file_log_event ctor
4210
4210
*/
4211
4211
 
4212
 
Delete_file_log_event::Delete_file_log_event(THD *thd_arg, const char* db_arg,
 
4212
Delete_file_log_event::Delete_file_log_event(Session *session_arg, const char* db_arg,
4213
4213
                                             bool using_trans)
4214
 
  :Log_event(thd_arg, 0, using_trans), file_id(thd_arg->file_id), db(db_arg)
 
4214
  :Log_event(session_arg, 0, using_trans), file_id(session_arg->file_id), db(db_arg)
4215
4215
{
4216
4216
}
4217
4217
 
4279
4279
  Execute_load_log_event ctor
4280
4280
*/
4281
4281
 
4282
 
Execute_load_log_event::Execute_load_log_event(THD *thd_arg,
 
4282
Execute_load_log_event::Execute_load_log_event(Session *session_arg,
4283
4283
                                               const char* db_arg,
4284
4284
                                               bool using_trans)
4285
 
  :Log_event(thd_arg, 0, using_trans), file_id(thd_arg->file_id), db(db_arg)
 
4285
  :Log_event(session_arg, 0, using_trans), file_id(session_arg->file_id), db(db_arg)
4286
4286
{
4287
4287
}
4288
4288
  
4365
4365
    goto err;
4366
4366
  }
4367
4367
 
4368
 
  lev->thd = thd;
 
4368
  lev->session = session;
4369
4369
  /*
4370
4370
    lev->do_apply_event should use rli only for errors i.e. should
4371
4371
    not advance rli's position.
4426
4426
**************************************************************************/
4427
4427
 
4428
4428
Begin_load_query_log_event::
4429
 
Begin_load_query_log_event(THD* thd_arg, const char* db_arg, unsigned char* block_arg,
 
4429
Begin_load_query_log_event(Session* session_arg, const char* db_arg, unsigned char* block_arg,
4430
4430
                           uint32_t block_len_arg, bool using_trans)
4431
 
  :Append_block_log_event(thd_arg, db_arg, block_arg, block_len_arg,
 
4431
  :Append_block_log_event(session_arg, db_arg, block_arg, block_len_arg,
4432
4432
                          using_trans)
4433
4433
{
4434
 
   file_id= thd_arg->file_id= mysql_bin_log.next_file_id();
 
4434
   file_id= session_arg->file_id= mysql_bin_log.next_file_id();
4435
4435
}
4436
4436
 
4437
4437
 
4466
4466
 
4467
4467
 
4468
4468
Execute_load_query_log_event::
4469
 
Execute_load_query_log_event(THD *thd_arg, const char* query_arg,
 
4469
Execute_load_query_log_event(Session *session_arg, const char* query_arg,
4470
4470
                             ulong query_length_arg, uint32_t fn_pos_start_arg,
4471
4471
                             uint32_t fn_pos_end_arg,
4472
4472
                             enum_load_dup_handling dup_handling_arg,
4473
4473
                             bool using_trans, bool suppress_use,
4474
 
                             THD::killed_state killed_err_arg):
4475
 
  Query_log_event(thd_arg, query_arg, query_length_arg, using_trans,
 
4474
                             Session::killed_state killed_err_arg):
 
4475
  Query_log_event(session_arg, query_arg, query_length_arg, using_trans,
4476
4476
                  suppress_use, killed_err_arg),
4477
 
  file_id(thd_arg->file_id), fn_pos_start(fn_pos_start_arg),
 
4477
  file_id(session_arg->file_id), fn_pos_start(fn_pos_start_arg),
4478
4478
  fn_pos_end(fn_pos_end_arg), dup_handling(dup_handling_arg)
4479
4479
{
4480
4480
}
4697
4697
        Rows_log_event member functions
4698
4698
**************************************************************************/
4699
4699
 
4700
 
Rows_log_event::Rows_log_event(THD *thd_arg, Table *tbl_arg, ulong tid,
 
4700
Rows_log_event::Rows_log_event(Session *session_arg, Table *tbl_arg, ulong tid,
4701
4701
                               MY_BITMAP const *cols, bool is_transactional)
4702
 
  : Log_event(thd_arg, 0, is_transactional),
 
4702
  : Log_event(session_arg, 0, is_transactional),
4703
4703
    m_row_count(0),
4704
4704
    m_table(tbl_arg),
4705
4705
    m_table_id(tid),
4715
4715
   */
4716
4716
  assert((tbl_arg && tbl_arg->s && tid != UINT32_MAX) || (!tbl_arg && !cols && tid == UINT32_MAX));
4717
4717
 
4718
 
  if (thd_arg->options & OPTION_NO_FOREIGN_KEY_CHECKS)
 
4718
  if (session_arg->options & OPTION_NO_FOREIGN_KEY_CHECKS)
4719
4719
      set_flags(NO_FOREIGN_KEY_CHECKS_F);
4720
 
  if (thd_arg->options & OPTION_RELAXED_UNIQUE_CHECKS)
 
4720
  if (session_arg->options & OPTION_RELAXED_UNIQUE_CHECKS)
4721
4721
      set_flags(RELAXED_UNIQUE_CHECKS_F);
4722
4722
  /* if bitmap_init fails, caught in is_valid() */
4723
4723
  if (likely(!bitmap_init(&m_cols,
4933
4933
    assert(get_flags(STMT_END_F));
4934
4934
 
4935
4935
    const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
4936
 
    close_thread_tables(thd);
4937
 
    thd->clear_error();
 
4936
    close_thread_tables(session);
 
4937
    session->clear_error();
4938
4938
    return(0);
4939
4939
  }
4940
4940
 
4941
4941
  /*
4942
 
    'thd' has been set by exec_relay_log_event(), just before calling
 
4942
    'session' has been set by exec_relay_log_event(), just before calling
4943
4943
    do_apply_event(). We still check here to prevent future coding
4944
4944
    errors.
4945
4945
  */
4946
 
  assert(rli->sql_thd == thd);
 
4946
  assert(rli->sql_session == session);
4947
4947
 
4948
4948
  /*
4949
4949
    If there is no locks taken, this is the first binrow event seen
4951
4951
    used in the transaction and proceed with execution of the actual
4952
4952
    event.
4953
4953
  */
4954
 
  if (!thd->lock)
 
4954
  if (!session->lock)
4955
4955
  {
4956
4956
    bool need_reopen= 1; /* To execute the first lap of the loop below */
4957
4957
 
4958
4958
    /*
4959
 
      lock_tables() reads the contents of thd->lex, so they must be
 
4959
      lock_tables() reads the contents of session->lex, so they must be
4960
4960
      initialized. Contrary to in
4961
4961
      Table_map_log_event::do_apply_event() we don't call
4962
4962
      mysql_init_query() as that may reset the binlog format.
4963
4963
    */
4964
 
    lex_start(thd);
 
4964
    lex_start(session);
4965
4965
 
4966
4966
    /*
4967
4967
      There are a few flags that are replicated with each row event.
4969
4969
      the event.
4970
4970
    */
4971
4971
    if (get_flags(NO_FOREIGN_KEY_CHECKS_F))
4972
 
        thd->options|= OPTION_NO_FOREIGN_KEY_CHECKS;
 
4972
        session->options|= OPTION_NO_FOREIGN_KEY_CHECKS;
4973
4973
    else
4974
 
        thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
 
4974
        session->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
4975
4975
 
4976
4976
    if (get_flags(RELAXED_UNIQUE_CHECKS_F))
4977
 
        thd->options|= OPTION_RELAXED_UNIQUE_CHECKS;
 
4977
        session->options|= OPTION_RELAXED_UNIQUE_CHECKS;
4978
4978
    else
4979
 
        thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
 
4979
        session->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
4980
4980
    /* A small test to verify that objects have consistent types */
4981
 
    assert(sizeof(thd->options) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
4982
 
 
4983
 
 
4984
 
    while ((error= lock_tables(thd, rli->tables_to_lock,
 
4981
    assert(sizeof(session->options) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
 
4982
 
 
4983
 
 
4984
    while ((error= lock_tables(session, rli->tables_to_lock,
4985
4985
                               rli->tables_to_lock_count, &need_reopen)))
4986
4986
    {
4987
4987
      if (!need_reopen)
4988
4988
      {
4989
 
        if (thd->is_slave_error || thd->is_fatal_error)
 
4989
        if (session->is_slave_error || session->is_fatal_error)
4990
4990
        {
4991
4991
          /*
4992
4992
            Error reporting borrowed from Query_log_event with many excessive
4993
4993
            simplifications (we don't honour --slave-skip-errors)
4994
4994
          */
4995
 
          uint32_t actual_error= thd->main_da.sql_errno();
 
4995
          uint32_t actual_error= session->main_da.sql_errno();
4996
4996
          rli->report(ERROR_LEVEL, actual_error,
4997
4997
                      _("Error '%s' in %s event: when locking tables"),
4998
4998
                      (actual_error
4999
 
                       ? thd->main_da.message()
 
4999
                       ? session->main_da.message()
5000
5000
                       : _("unexpected success or fatal error")),
5001
5001
                      get_type_str());
5002
 
          thd->is_fatal_error= 1;
 
5002
          session->is_fatal_error= 1;
5003
5003
        }
5004
5004
        else
5005
5005
        {
5024
5024
        NOTE: For this new scheme there should be no pending event:
5025
5025
        need to add code to assert that is the case.
5026
5026
       */
5027
 
      thd->binlog_flush_pending_rows_event(false);
 
5027
      session->binlog_flush_pending_rows_event(false);
5028
5028
      TableList *tables= rli->tables_to_lock;
5029
 
      close_tables_for_reopen(thd, &tables);
 
5029
      close_tables_for_reopen(session, &tables);
5030
5030
 
5031
5031
      uint32_t tables_count= rli->tables_to_lock_count;
5032
 
      if ((error= open_tables(thd, &tables, &tables_count, 0)))
 
5032
      if ((error= open_tables(session, &tables, &tables_count, 0)))
5033
5033
      {
5034
 
        if (thd->is_slave_error || thd->is_fatal_error)
 
5034
        if (session->is_slave_error || session->is_fatal_error)
5035
5035
        {
5036
5036
          /*
5037
5037
            Error reporting borrowed from Query_log_event with many excessive
5038
5038
            simplifications (we don't honour --slave-skip-errors)
5039
5039
          */
5040
 
          uint32_t actual_error= thd->main_da.sql_errno();
 
5040
          uint32_t actual_error= session->main_da.sql_errno();
5041
5041
          rli->report(ERROR_LEVEL, actual_error,
5042
5042
                      _("Error '%s' on reopening tables"),
5043
5043
                      (actual_error
5044
 
                       ? thd->main_da.message()
 
5044
                       ? session->main_da.message()
5045
5045
                       : _("unexpected success or fatal error")));
5046
 
          thd->is_slave_error= 1;
 
5046
          session->is_slave_error= 1;
5047
5047
        }
5048
5048
        const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
5049
5049
        return(error);
5064
5064
      {
5065
5065
        if (ptr->m_tabledef.compatible_with(rli, ptr->table))
5066
5066
        {
5067
 
          mysql_unlock_tables(thd, thd->lock);
5068
 
          thd->lock= 0;
5069
 
          thd->is_slave_error= 1;
 
5067
          mysql_unlock_tables(session, session->lock);
 
5068
          session->lock= 0;
 
5069
          session->is_slave_error= 1;
5070
5070
          const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
5071
5071
          return(ERR_BAD_TABLE_DEF);
5072
5072
        }
5113
5113
      TIMESTAMP column to a table with one.
5114
5114
      So we call set_time(), like in SBR. Presently it changes nothing.
5115
5115
    */
5116
 
    thd->set_time((time_t)when);
 
5116
    session->set_time((time_t)when);
5117
5117
    /*
5118
5118
      There are a few flags that are replicated with each row event.
5119
5119
      Make sure to set/clear them before executing the main body of
5120
5120
      the event.
5121
5121
    */
5122
5122
    if (get_flags(NO_FOREIGN_KEY_CHECKS_F))
5123
 
        thd->options|= OPTION_NO_FOREIGN_KEY_CHECKS;
 
5123
        session->options|= OPTION_NO_FOREIGN_KEY_CHECKS;
5124
5124
    else
5125
 
        thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
 
5125
        session->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
5126
5126
 
5127
5127
    if (get_flags(RELAXED_UNIQUE_CHECKS_F))
5128
 
        thd->options|= OPTION_RELAXED_UNIQUE_CHECKS;
 
5128
        session->options|= OPTION_RELAXED_UNIQUE_CHECKS;
5129
5129
    else
5130
 
        thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
 
5130
        session->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
5131
5131
    
5132
5132
    if (slave_allow_batching)
5133
 
      thd->options|= OPTION_ALLOW_BATCH;
 
5133
      session->options|= OPTION_ALLOW_BATCH;
5134
5134
    else
5135
 
      thd->options&= ~OPTION_ALLOW_BATCH;
 
5135
      session->options&= ~OPTION_ALLOW_BATCH;
5136
5136
    
5137
5137
    /* A small test to verify that objects have consistent types */
5138
 
    assert(sizeof(thd->options) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
 
5138
    assert(sizeof(session->options) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
5139
5139
 
5140
5140
    /*
5141
5141
      Now we are in a statement and will stay in a statement until we
5176
5176
    while (error == 0 && m_curr_row < m_rows_end)
5177
5177
    {
5178
5178
      /* in_use can have been set to NULL in close_tables_for_reopen */
5179
 
      THD* old_thd= table->in_use;
 
5179
      Session* old_session= table->in_use;
5180
5180
      if (!table->in_use)
5181
 
        table->in_use= thd;
 
5181
        table->in_use= session;
5182
5182
 
5183
5183
      error= do_exec_row(rli);
5184
5184
 
5185
 
      table->in_use = old_thd;
 
5185
      table->in_use = old_session;
5186
5186
      switch (error)
5187
5187
      {
5188
5188
      case 0:
5212
5212
        if (bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
5213
5213
        {
5214
5214
          if (global_system_variables.log_warnings)
5215
 
            slave_rows_error_report(WARNING_LEVEL, error, rli, thd, table,
 
5215
            slave_rows_error_report(WARNING_LEVEL, error, rli, session, table,
5216
5216
                                    get_type_str(),
5217
5217
                                    RPL_LOG_NAME, (ulong) log_pos);
5218
5218
          error= 0;
5220
5220
        break;
5221
5221
        
5222
5222
      default:
5223
 
        thd->is_slave_error= 1;
 
5223
        session->is_slave_error= 1;
5224
5224
        break;
5225
5225
      }
5226
5226
 
5245
5245
    error= do_after_row_operations(rli, error);
5246
5246
    if (!cache_stmt)
5247
5247
    {
5248
 
      thd->options|= OPTION_KEEP_LOG;
 
5248
      session->options|= OPTION_KEEP_LOG;
5249
5249
    }
5250
5250
  } // if (table)
5251
5251
 
5256
5256
  if (rli->tables_to_lock && get_flags(STMT_END_F))
5257
5257
    const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
5258
5258
  /* reset OPTION_ALLOW_BATCH as not affect later events */
5259
 
  thd->options&= ~OPTION_ALLOW_BATCH;
 
5259
  session->options&= ~OPTION_ALLOW_BATCH;
5260
5260
  
5261
5261
  if (error)
5262
5262
  {                     /* error has occured during the transaction */
5263
 
    slave_rows_error_report(ERROR_LEVEL, error, rli, thd, table,
 
5263
    slave_rows_error_report(ERROR_LEVEL, error, rli, session, table,
5264
5264
                            get_type_str(), RPL_LOG_NAME, (ulong) log_pos);
5265
5265
  }
5266
5266
  if (error)
5276
5276
      thread is certainly going to stop.
5277
5277
      rollback at the caller along with sbr.
5278
5278
    */
5279
 
    thd->reset_current_stmt_binlog_row_based();
5280
 
    const_cast<Relay_log_info*>(rli)->cleanup_context(thd, error);
5281
 
    thd->is_slave_error= 1;
 
5279
    session->reset_current_stmt_binlog_row_based();
 
5280
    const_cast<Relay_log_info*>(rli)->cleanup_context(session, error);
 
5281
    session->is_slave_error= 1;
5282
5282
    return(error);
5283
5283
  }
5284
5284
 
5348
5348
      (assume the last master's transaction is ignored by the slave because of
5349
5349
      replicate-ignore rules).
5350
5350
    */
5351
 
    thd->binlog_flush_pending_rows_event(true);
 
5351
    session->binlog_flush_pending_rows_event(true);
5352
5352
 
5353
5353
    /*
5354
5354
      If this event is not in a transaction, the call below will, if some
5359
5359
      are involved, commit the transaction and flush the pending event to the
5360
5360
      binlog.
5361
5361
    */
5362
 
    error= ha_autocommit_or_rollback(thd, 0);
 
5362
    error= ha_autocommit_or_rollback(session, 0);
5363
5363
 
5364
5364
    /*
5365
5365
      Now what if this is not a transactional engine? we still need to
5366
5366
      flush the pending event to the binlog; we did it with
5367
 
      thd->binlog_flush_pending_rows_event(). Note that we imitate
 
5367
      session->binlog_flush_pending_rows_event(). Note that we imitate
5368
5368
      what is done for real queries: a call to
5369
5369
      ha_autocommit_or_rollback() (sometimes only if involves a
5370
5370
      transactional engine), and a call to be sure to have the pending
5371
5371
      event flushed.
5372
5372
    */
5373
5373
 
5374
 
    thd->reset_current_stmt_binlog_row_based();
 
5374
    session->reset_current_stmt_binlog_row_based();
5375
5375
 
5376
 
    rli->cleanup_context(thd, 0);
 
5376
    rli->cleanup_context(session, 0);
5377
5377
    if (error == 0)
5378
5378
    {
5379
5379
      /*
5384
5384
      rli->stmt_done(log_pos, when);
5385
5385
 
5386
5386
      /*
5387
 
        Clear any errors pushed in thd->net.last_err* if for example "no key
 
5387
        Clear any errors pushed in session->net.last_err* if for example "no key
5388
5388
        found" (as this is allowed). This is a safety measure; apparently
5389
5389
        those errors (e.g. when executing a Delete_rows_log_event of a
5390
5390
        non-existing row, like in rpl_row_mystery22.test,
5391
 
        thd->net.last_error = "Can't find record in 't1'" and last_errno=1032)
 
5391
        session->net.last_error = "Can't find record in 't1'" and last_errno=1032)
5392
5392
        do not become visible. We still prefer to wipe them out.
5393
5393
      */
5394
 
      thd->clear_error();
 
5394
      session->clear_error();
5395
5395
    }
5396
5396
    else
5397
5397
      rli->report(ERROR_LEVEL, error,
5532
5532
  Mats says tbl->s lives longer than this event so it's ok to copy pointers
5533
5533
  (tbl->s->db etc) and not pointer content.
5534
5534
 */
5535
 
Table_map_log_event::Table_map_log_event(THD *thd, Table *tbl, ulong tid,
 
5535
Table_map_log_event::Table_map_log_event(Session *session, Table *tbl, ulong tid,
5536
5536
                                         bool is_transactional __attribute__((unused)),
5537
5537
                                         uint16_t flags)
5538
 
  : Log_event(thd, 0, true),
 
5538
  : Log_event(session, 0, true),
5539
5539
    m_table(tbl),
5540
5540
    m_dbnam(tbl->s->db.str),
5541
5541
    m_dblen(m_dbnam ? tbl->s->db.length : 0),
5728
5728
  char *db_mem, *tname_mem;
5729
5729
  size_t dummy_len;
5730
5730
  void *memory;
5731
 
  assert(rli->sql_thd == thd);
 
5731
  assert(rli->sql_session == session);
5732
5732
 
5733
5733
  /* Step the query id to mark what columns that are actually used. */
5734
5734
  pthread_mutex_lock(&LOCK_thread_count);
5735
 
  thd->query_id= next_query_id();
 
5735
  session->query_id= next_query_id();
5736
5736
  pthread_mutex_unlock(&LOCK_thread_count);
5737
5737
 
5738
5738
  if (!(memory= my_multi_malloc(MYF(MY_WME),
5762
5762
  else
5763
5763
  {
5764
5764
    /*
5765
 
      open_tables() reads the contents of thd->lex, so they must be
 
5765
      open_tables() reads the contents of session->lex, so they must be
5766
5766
      initialized, so we should call lex_start(); to be even safer, we
5767
5767
      call mysql_init_query() which does a more complete set of inits.
5768
5768
    */
5769
 
    lex_start(thd);
5770
 
    mysql_reset_thd_for_next_command(thd);
 
5769
    lex_start(session);
 
5770
    mysql_reset_session_for_next_command(session);
5771
5771
    /*
5772
5772
      Check if the slave is set to use SBR.  If so, it should switch
5773
5773
      to using RBR until the end of the "statement", i.e., next
5774
5774
      STMT_END_F or next error.
5775
5775
    */
5776
 
    if (!thd->current_stmt_binlog_row_based &&
5777
 
        mysql_bin_log.is_open() && (thd->options & OPTION_BIN_LOG))
 
5776
    if (!session->current_stmt_binlog_row_based &&
 
5777
        mysql_bin_log.is_open() && (session->options & OPTION_BIN_LOG))
5778
5778
    {
5779
 
      thd->set_current_stmt_binlog_row_based();
 
5779
      session->set_current_stmt_binlog_row_based();
5780
5780
    }
5781
5781
 
5782
5782
    /*
5787
5787
      The creation of a new TableList is used to up-cast the
5788
5788
      table_list consisting of RPL_TableList items. This will work
5789
5789
      since the only case where the argument to open_tables() is
5790
 
      changed, is when thd->lex->query_tables == table_list, i.e.,
 
5790
      changed, is when session->lex->query_tables == table_list, i.e.,
5791
5791
      when the statement requires prelocking. Since this is not
5792
5792
      executed when a statement is executed, this case will not occur.
5793
5793
      As a precaution, an assertion is added to ensure that the bad
5798
5798
      of the pointer to make sure that it's not lost.
5799
5799
    */
5800
5800
    uint32_t count;
5801
 
    assert(thd->lex->query_tables != table_list);
 
5801
    assert(session->lex->query_tables != table_list);
5802
5802
    TableList *tmp_table_list= table_list;
5803
 
    if ((error= open_tables(thd, &tmp_table_list, &count, 0)))
 
5803
    if ((error= open_tables(session, &tmp_table_list, &count, 0)))
5804
5804
    {
5805
 
      if (thd->is_slave_error || thd->is_fatal_error)
 
5805
      if (session->is_slave_error || session->is_fatal_error)
5806
5806
      {
5807
5807
        /*
5808
5808
          Error reporting borrowed from Query_log_event with many excessive
5809
5809
          simplifications (we don't honour --slave-skip-errors)
5810
5810
        */
5811
 
        uint32_t actual_error= thd->main_da.sql_errno();
 
5811
        uint32_t actual_error= session->main_da.sql_errno();
5812
5812
        rli->report(ERROR_LEVEL, actual_error,
5813
5813
                    _("Error '%s' on opening table `%s`.`%s`"),
5814
5814
                    (actual_error
5815
 
                     ? thd->main_da.message()
 
5815
                     ? session->main_da.message()
5816
5816
                     : _("unexpected success or fatal error")),
5817
5817
                    table_list->db, table_list->table_name);
5818
 
        thd->is_slave_error= 1;
 
5818
        session->is_slave_error= 1;
5819
5819
      }
5820
5820
      goto err;
5821
5821
    }
5939
5939
/*
5940
5940
  Constructor used to build an event for writing to the binary log.
5941
5941
 */
5942
 
Write_rows_log_event::Write_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
5942
Write_rows_log_event::Write_rows_log_event(Session *session_arg, Table *tbl_arg,
5943
5943
                                           ulong tid_arg,
5944
5944
                                           bool is_transactional)
5945
 
  : Rows_log_event(thd_arg, tbl_arg, tid_arg, tbl_arg->write_set, is_transactional)
 
5945
  : Rows_log_event(session_arg, tbl_arg, tid_arg, tbl_arg->write_set, is_transactional)
5946
5946
{
5947
5947
}
5948
5948
 
5974
5974
    */
5975
5975
    
5976
5976
    /* Tell the storage engine that we are using REPLACE semantics. */
5977
 
    thd->lex->duplicates= DUP_REPLACE;
 
5977
    session->lex->duplicates= DUP_REPLACE;
5978
5978
    
5979
5979
    /*
5980
5980
      Pretend we're executing a REPLACE command: this is needed for
5981
5981
      InnoDB since it is not (properly) checking the
5982
5982
      lex->duplicates flag.
5983
5983
    */
5984
 
    thd->lex->sql_command= SQLCOM_REPLACE;
 
5984
    session->lex->sql_command= SQLCOM_REPLACE;
5985
5985
    /* 
5986
5986
       Do not raise the error flag in case of hitting to an unique attribute
5987
5987
    */
6110
6110
Rows_log_event::write_row(const Relay_log_info *const rli,
6111
6111
                          const bool overwrite)
6112
6112
{
6113
 
  assert(m_table != NULL && thd != NULL);
 
6113
  assert(m_table != NULL && session != NULL);
6114
6114
 
6115
6115
  Table *table= m_table;  // pointer to event's table
6116
6116
  int error;
6290
6290
    write_row(rli,        /* if 1 then overwrite */
6291
6291
              bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1);
6292
6292
    
6293
 
  if (error && !thd->is_error())
 
6293
  if (error && !session->is_error())
6294
6294
  {
6295
6295
    assert(0);
6296
6296
    my_error(ER_UNKNOWN_ERROR, MYF(0));
6605
6605
  Constructor used to build an event for writing to the binary log.
6606
6606
 */
6607
6607
 
6608
 
Delete_rows_log_event::Delete_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
6608
Delete_rows_log_event::Delete_rows_log_event(Session *session_arg, Table *tbl_arg,
6609
6609
                                             ulong tid,
6610
6610
                                             bool is_transactional)
6611
 
  : Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
 
6611
  : Rows_log_event(session_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
6612
6612
{
6613
6613
}
6614
6614
 
6681
6681
/*
6682
6682
  Constructor used to build an event for writing to the binary log.
6683
6683
 */
6684
 
Update_rows_log_event::Update_rows_log_event(THD *thd_arg, Table *tbl_arg,
 
6684
Update_rows_log_event::Update_rows_log_event(Session *session_arg, Table *tbl_arg,
6685
6685
                                             ulong tid,
6686
6686
                                             bool is_transactional)
6687
 
: Rows_log_event(thd_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
 
6687
: Rows_log_event(session_arg, tbl_arg, tid, tbl_arg->read_set, is_transactional)
6688
6688
{
6689
6689
  init(tbl_arg->write_set);
6690
6690
}