~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/log_event.h

  • Committer: Monty Taylor
  • Date: 2008-10-23 23:53:49 UTC
  • mto: This revision was merged to the branch mainline in revision 557.
  • Revision ID: monty@inaugust.com-20081023235349-317wgwqwgccuacmq
SplitĀ outĀ nested_join.h.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*/
30
30
 
31
31
 
32
 
#ifndef _log_event_h
33
 
#define _log_event_h
34
 
 
35
 
#if defined(USE_PRAGMA_INTERFACE)
36
 
#pragma interface                       /* gcc class implementation */
37
 
#endif
38
 
 
 
32
#ifndef DRIZZLED_LOG_EVENT_H
 
33
#define DRIZZLED_LOG_EVENT_H
 
34
 
 
35
 
 
36
#include <string>
39
37
#include <mysys/my_bitmap.h>
40
38
#include "rpl_constants.h"
41
39
#include "rpl_record.h"
161
159
  char opt_flags;
162
160
  char empty_flags;
163
161
 
164
 
  // store in new format even if old is possible
 
162
  /* store in new format even if old is possible */
165
163
  void force_new_format() { cached_new_format = 1;}
166
164
  int data_size()
167
165
  {
431
429
/**
432
430
  @def OPTIONS_WRITTEN_TO_BIN_LOG
433
431
 
434
 
  OPTIONS_WRITTEN_TO_BIN_LOG are the bits of thd->options which must
 
432
  OPTIONS_WRITTEN_TO_BIN_LOG are the bits of session->options which must
435
433
  be written to the binlog. OPTIONS_WRITTEN_TO_BIN_LOG could be
436
434
  written into the Format_description_log_event, so that if later we
437
435
  don't want to replicate a variable we did replicate, or the
438
436
  contrary, it's doable. But it should not be too hard to decide once
439
437
  for all of what we replicate and what we don't, among the fixed 32
440
 
  bits of thd->options.
 
438
  bits of session->options.
441
439
 
442
440
  I (Guilhem) have read through every option's usage, and it looks
443
441
  like OPTION_AUTO_IS_NULL and OPTION_NO_FOREIGN_KEYS are the only
549
547
 
550
548
class String;
551
549
class DRIZZLE_BIN_LOG;
552
 
class THD;
 
550
class Session;
553
551
 
554
552
class Format_description_log_event;
555
553
class Relay_log_info;
746
744
    sees the offset of the BEGIN, which is logical as rollback may
747
745
    occur), except the COMMIT query which has its real offset.
748
746
  */
749
 
  my_off_t log_pos;
 
747
  off_t log_pos;
750
748
  /*
751
749
     A temp buffer for read_log_event; it is later analysed according to the
752
750
     event's type, and its content is distributed in the event-specific fields.
787
785
  */
788
786
  ulong slave_exec_mode;
789
787
 
790
 
  THD* thd;
 
788
  Session* session;
791
789
 
792
790
  Log_event();
793
 
  Log_event(THD* thd_arg, uint16_t flags_arg, bool cache_stmt);
 
791
  Log_event(Session* session_arg, uint16_t flags_arg, bool cache_stmt);
794
792
  /*
795
793
    read_log_event() functions read an event from a binlog or relay
796
794
    log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the
825
823
 
826
824
  virtual const char* get_db()
827
825
  {
828
 
    return thd ? thd->db : 0;
 
826
    return session ? session->db : 0;
829
827
  }
830
828
 
831
829
  static void *operator new(size_t size)
856
854
  { return 0; }
857
855
  inline time_t get_time()
858
856
  {
859
 
    THD *tmp_thd;
 
857
    Session *tmp_session;
860
858
    if (when)
861
859
      return when;
862
 
    if (thd)
863
 
      return thd->start_time;
864
 
    if ((tmp_thd= current_thd))
865
 
      return tmp_thd->start_time;
 
860
    if (session)
 
861
      return session->start_time;
 
862
    if ((tmp_session= current_session))
 
863
      return tmp_session->start_time;
866
864
    return my_time(0);
867
865
  }
868
866
  virtual Log_event_type get_type_code() = 0;
1181
1179
    <td>flags2</td>
1182
1180
    <td>Q_FLAGS2_CODE == 0</td>
1183
1181
    <td>4 byte bitfield</td>
1184
 
    <td>The flags in @c thd->options, binary AND-ed with @c
1185
 
    OPTIONS_WRITTEN_TO_BIN_LOG.  The @c thd->options bitfield contains
 
1182
    <td>The flags in @c session->options, binary AND-ed with @c
 
1183
    OPTIONS_WRITTEN_TO_BIN_LOG.  The @c session->options bitfield contains
1186
1184
    options for "SELECT".  @c OPTIONS_WRITTEN identifies those options
1187
1185
    that need to be written to the binlog (not all do).  Specifically,
1188
1186
    @c OPTIONS_WRITTEN_TO_BIN_LOG equals (@c OPTION_AUTO_IS_NULL | @c
1339
1337
    <td>2 byte integer</td>
1340
1338
 
1341
1339
    <td>The value of the collation_database system variable (in the
1342
 
    source code stored in @c thd->variables.collation_database), which
 
1340
    source code stored in @c session->variables.collation_database), which
1343
1341
    holds the code for a (character set, collation) pair as described
1344
1342
    above (see Q_CHARSET_CODE).
1345
1343
 
1432
1430
 
1433
1431
  /*
1434
1432
    'flags2' is a second set of flags (on top of those in Log_event), for
1435
 
    session variables. These are thd->options which is & against a mask
 
1433
    session variables. These are session->options which is & against a mask
1436
1434
    (OPTIONS_WRITTEN_TO_BIN_LOG).
1437
1435
    flags2_inited helps make a difference between flags2==0 (3.23 or 4.x
1438
1436
    master, we don't know flags2, so use the slave server's global options) and
1454
1452
  uint32_t charset_database_number;
1455
1453
 
1456
1454
 
1457
 
  Query_log_event(THD* thd_arg, const char* query_arg, ulong query_length,
 
1455
  Query_log_event(Session* session_arg, const char* query_arg, ulong query_length,
1458
1456
                  bool using_trans, bool suppress_use,
1459
 
                  THD::killed_state killed_err_arg= THD::KILLED_NO_VALUE);
 
1457
                  Session::killed_state killed_err_arg= Session::KILLED_NO_VALUE);
1460
1458
  const char* get_db() { return db; }
1461
1459
  void pack_info(Protocol* protocol);
1462
1460
 
1541
1539
  </tr>
1542
1540
  </table>
1543
1541
*/
 
1542
 
1544
1543
class Slave_log_event: public Log_event
1545
1544
{
1546
1545
protected:
1547
1546
  char* mem_pool;
1548
 
  void init_from_mem_pool(int data_size);
 
1547
  void init_from_mem_pool();
1549
1548
public:
1550
 
  my_off_t master_pos;
1551
 
  char* master_host;
1552
 
  char* master_log;
1553
 
  int master_host_len;
1554
 
  int master_log_len;
 
1549
  off_t master_pos;
 
1550
  std::string master_host;
 
1551
  std::string master_log;
1555
1552
  uint16_t master_port;
1556
1553
 
1557
 
  Slave_log_event(THD* thd_arg, Relay_log_info* rli);
 
1554
  Slave_log_event(Session* session_arg, Relay_log_info* rli);
1558
1555
  void pack_info(Protocol* protocol);
1559
1556
 
1560
1557
  Slave_log_event(const char* buf, uint32_t event_len);
1561
1558
  ~Slave_log_event();
1562
1559
  int get_data_size();
1563
 
  bool is_valid() const { return master_host != 0; }
 
1560
  bool is_valid() const { return master_host.length() != 0; }
1564
1561
  Log_event_type get_type_code() { return SLAVE_EVENT; }
1565
1562
  bool write(IO_CACHE* file);
1566
1563
 
1818
1815
  String field_lens_buf;
1819
1816
  String fields_buf;
1820
1817
 
1821
 
  Load_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
 
1818
  Load_log_event(Session* session, sql_exchange* ex, const char* db_arg,
1822
1819
                 const char* table_name_arg,
1823
1820
                 List<Item>& fields_arg, enum enum_duplicates handle_dup, bool ignore,
1824
1821
                 bool using_trans);
1854
1851
public:        /* !!! Public in this patch to allow old usage */
1855
1852
  virtual int do_apply_event(Relay_log_info const* rli)
1856
1853
  {
1857
 
    return do_apply_event(thd->slave_net,rli,0);
 
1854
    return do_apply_event(session->slave_net,rli,0);
1858
1855
  }
1859
1856
 
1860
1857
  int do_apply_event(NET *net, Relay_log_info const *rli,
2053
2050
  uint64_t val;
2054
2051
  unsigned char type;
2055
2052
 
2056
 
  Intvar_log_event(THD* thd_arg,unsigned char type_arg, uint64_t val_arg)
2057
 
    :Log_event(thd_arg,0,0),val(val_arg),type(type_arg)
 
2053
  Intvar_log_event(Session* session_arg,unsigned char type_arg, uint64_t val_arg)
 
2054
    :Log_event(session_arg,0,0),val(val_arg),type(type_arg)
2058
2055
  {}
2059
2056
  void pack_info(Protocol* protocol);
2060
2057
 
2118
2115
  uint64_t seed1;
2119
2116
  uint64_t seed2;
2120
2117
 
2121
 
  Rand_log_event(THD* thd_arg, uint64_t seed1_arg, uint64_t seed2_arg)
2122
 
    :Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
 
2118
  Rand_log_event(Session* session_arg, uint64_t seed1_arg, uint64_t seed2_arg)
 
2119
    :Log_event(session_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
2123
2120
  {}
2124
2121
  void pack_info(Protocol* protocol);
2125
2122
 
2150
2147
 public:
2151
2148
   my_xid xid;
2152
2149
 
2153
 
  Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
 
2150
  Xid_log_event(Session* session_arg, my_xid x): Log_event(session_arg,0,0), xid(x) {}
2154
2151
  void pack_info(Protocol* protocol);
2155
2152
 
2156
2153
  Xid_log_event(const char* buf,
2185
2182
  Item_result type;
2186
2183
  uint32_t charset_number;
2187
2184
  bool is_null;
2188
 
  User_var_log_event(THD* thd_arg __attribute__((unused)),
 
2185
  User_var_log_event(Session* session_arg __attribute__((unused)),
2189
2186
                     char *name_arg, uint32_t name_len_arg,
2190
2187
                     char *val_arg, ulong val_len_arg, Item_result type_arg,
2191
2188
                     uint32_t charset_number_arg)
2351
2348
  uint32_t file_id;
2352
2349
  bool inited_from_old;
2353
2350
 
2354
 
  Create_file_log_event(THD* thd, sql_exchange* ex, const char* db_arg,
 
2351
  Create_file_log_event(Session* session, sql_exchange* ex, const char* db_arg,
2355
2352
                        const char* table_name_arg,
2356
2353
                        List<Item>& fields_arg,
2357
2354
                        enum enum_duplicates handle_dup, bool ignore,
2415
2412
  */
2416
2413
  const char* db;
2417
2414
 
2418
 
  Append_block_log_event(THD* thd, const char* db_arg, unsigned char* block_arg,
 
2415
  Append_block_log_event(Session* session, const char* db_arg, unsigned char* block_arg,
2419
2416
                         uint32_t block_len_arg, bool using_trans);
2420
2417
  void pack_info(Protocol* protocol);
2421
2418
  virtual int get_create_or_append() const;
2447
2444
  uint32_t file_id;
2448
2445
  const char* db; /* see comment in Append_block_log_event */
2449
2446
 
2450
 
  Delete_file_log_event(THD* thd, const char* db_arg, bool using_trans);
 
2447
  Delete_file_log_event(Session* session, const char* db_arg, bool using_trans);
2451
2448
  void pack_info(Protocol* protocol);
2452
2449
 
2453
2450
  Delete_file_log_event(const char* buf, uint32_t event_len,
2476
2473
  uint32_t file_id;
2477
2474
  const char* db; /* see comment in Append_block_log_event */
2478
2475
 
2479
 
  Execute_load_log_event(THD* thd, const char* db_arg, bool using_trans);
 
2476
  Execute_load_log_event(Session* session, const char* db_arg, bool using_trans);
2480
2477
  void pack_info(Protocol* protocol);
2481
2478
 
2482
2479
  Execute_load_log_event(const char* buf, uint32_t event_len,
2506
2503
class Begin_load_query_log_event: public Append_block_log_event
2507
2504
{
2508
2505
public:
2509
 
  Begin_load_query_log_event(THD* thd_arg, const char *db_arg,
 
2506
  Begin_load_query_log_event(Session* session_arg, const char *db_arg,
2510
2507
                             unsigned char* block_arg, uint32_t block_len_arg,
2511
2508
                             bool using_trans);
2512
 
  Begin_load_query_log_event(THD* thd);
 
2509
  Begin_load_query_log_event(Session* session);
2513
2510
  int get_create_or_append() const;
2514
2511
  Begin_load_query_log_event(const char* buf, uint32_t event_len,
2515
2512
                             const Format_description_log_event
2551
2548
  */
2552
2549
  enum_load_dup_handling dup_handling;
2553
2550
 
2554
 
  Execute_load_query_log_event(THD* thd, const char* query_arg,
 
2551
  Execute_load_query_log_event(Session* session, const char* query_arg,
2555
2552
                               ulong query_length, uint32_t fn_pos_start_arg,
2556
2553
                               uint32_t fn_pos_end_arg,
2557
2554
                               enum_load_dup_handling dup_handling_arg,
2558
2555
                               bool using_trans, bool suppress_use,
2559
 
                               THD::killed_state
2560
 
                               killed_err_arg= THD::KILLED_NO_VALUE);
 
2556
                               Session::killed_state
 
2557
                               killed_err_arg= Session::KILLED_NO_VALUE);
2561
2558
  void pack_info(Protocol* protocol);
2562
2559
  Execute_load_query_log_event(const char* buf, uint32_t event_len,
2563
2560
                               const Format_description_log_event
2868
2865
  void clear_flags(flag_set flag) { m_flags &= ~flag; }
2869
2866
  flag_set get_flags(flag_set flag) const { return m_flags & flag; }
2870
2867
 
2871
 
  Table_map_log_event(THD *thd, Table *tbl, ulong tid, 
 
2868
  Table_map_log_event(Session *session, Table *tbl, ulong tid, 
2872
2869
                      bool is_transactional, uint16_t flags);
2873
2870
  Table_map_log_event(const char *buf, uint32_t event_len, 
2874
2871
                      const Format_description_log_event *description_event);
2957
2954
    /* Last event of a statement */
2958
2955
    STMT_END_F = (1U << 0),
2959
2956
 
2960
 
    /* Value of the OPTION_NO_FOREIGN_KEY_CHECKS flag in thd->options */
 
2957
    /* Value of the OPTION_NO_FOREIGN_KEY_CHECKS flag in session->options */
2961
2958
    NO_FOREIGN_KEY_CHECKS_F = (1U << 1),
2962
2959
 
2963
 
    /* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in thd->options */
 
2960
    /* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in session->options */
2964
2961
    RELAXED_UNIQUE_CHECKS_F = (1U << 2),
2965
2962
 
2966
2963
    /** 
3019
3016
     The constructors are protected since you're supposed to inherit
3020
3017
     this class, not create instances of this class.
3021
3018
  */
3022
 
  Rows_log_event(THD*, Table*, ulong table_id, 
 
3019
  Rows_log_event(Session*, Table*, ulong table_id, 
3023
3020
                 MY_BITMAP const *cols, bool is_transactional);
3024
3021
  Rows_log_event(const char *row_data, uint32_t event_len, 
3025
3022
                 Log_event_type event_type,
3063
3060
 
3064
3061
  // Unpack the current row into m_table->record[0]
3065
3062
  int unpack_current_row(const Relay_log_info *const rli,
3066
 
                         MY_BITMAP const *cols)
3067
 
  { 
3068
 
    assert(m_table);
3069
 
    ASSERT_OR_RETURN_ERROR(m_curr_row < m_rows_end, HA_ERR_CORRUPT_EVENT);
3070
 
    int const result= ::unpack_row(rli, m_table, m_width, m_curr_row, cols,
3071
 
                                   &m_curr_row_end, &m_master_reclength);
3072
 
    if (m_curr_row_end > m_rows_end)
3073
 
      my_error(ER_SLAVE_CORRUPT_EVENT, MYF(0));
3074
 
    ASSERT_OR_RETURN_ERROR(m_curr_row_end <= m_rows_end, HA_ERR_CORRUPT_EVENT);
3075
 
    return result;
3076
 
  }
 
3063
                         MY_BITMAP const *cols);
3077
3064
 
3078
3065
private:
3079
3066
 
3149
3136
public:
3150
3137
  enum 
3151
3138
  {
3152
 
    /* Support interface to THD::binlog_prepare_pending_rows_event */
 
3139
    /* Support interface to Session::binlog_prepare_pending_rows_event */
3153
3140
    TYPE_CODE = WRITE_ROWS_EVENT
3154
3141
  };
3155
3142
 
3156
 
  Write_rows_log_event(THD*, Table*, ulong table_id, 
 
3143
  Write_rows_log_event(Session*, Table*, ulong table_id, 
3157
3144
                       bool is_transactional);
3158
3145
  Write_rows_log_event(const char *buf, uint32_t event_len, 
3159
3146
                       const Format_description_log_event *description_event);
3160
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3147
  static bool binlog_row_logging_function(Session *session, Table *table,
3161
3148
                                          bool is_transactional,
3162
3149
                                          const unsigned char *before_record
3163
3150
                                          __attribute__((unused)),
3164
3151
                                          const unsigned char *after_record)
3165
3152
  {
3166
 
    return thd->binlog_write_row(table, is_transactional, after_record);
 
3153
    return session->binlog_write_row(table, is_transactional, after_record);
3167
3154
  }
3168
3155
 
3169
3156
private:
3192
3179
public:
3193
3180
  enum 
3194
3181
  {
3195
 
    /* Support interface to THD::binlog_prepare_pending_rows_event */
 
3182
    /* Support interface to Session::binlog_prepare_pending_rows_event */
3196
3183
    TYPE_CODE = UPDATE_ROWS_EVENT
3197
3184
  };
3198
3185
 
3199
 
  Update_rows_log_event(THD*, Table*, ulong table_id,
 
3186
  Update_rows_log_event(Session*, Table*, ulong table_id,
3200
3187
                        bool is_transactional);
3201
3188
 
3202
3189
  void init(MY_BITMAP const *cols);
3206
3193
  Update_rows_log_event(const char *buf, uint32_t event_len, 
3207
3194
                        const Format_description_log_event *description_event);
3208
3195
 
3209
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3196
  static bool binlog_row_logging_function(Session *session, Table *table,
3210
3197
                                          bool is_transactional,
3211
3198
                                          const unsigned char *before_record,
3212
3199
                                          const unsigned char *after_record)
3213
3200
  {
3214
 
    return thd->binlog_update_row(table, is_transactional,
 
3201
    return session->binlog_update_row(table, is_transactional,
3215
3202
                                  before_record, after_record);
3216
3203
  }
3217
3204
 
3253
3240
public:
3254
3241
  enum 
3255
3242
  {
3256
 
    /* Support interface to THD::binlog_prepare_pending_rows_event */
 
3243
    /* Support interface to Session::binlog_prepare_pending_rows_event */
3257
3244
    TYPE_CODE = DELETE_ROWS_EVENT
3258
3245
  };
3259
3246
 
3260
 
  Delete_rows_log_event(THD*, Table*, ulong, 
 
3247
  Delete_rows_log_event(Session*, Table*, ulong, 
3261
3248
                        bool is_transactional);
3262
3249
  Delete_rows_log_event(const char *buf, uint32_t event_len, 
3263
3250
                        const Format_description_log_event *description_event);
3264
 
  static bool binlog_row_logging_function(THD *thd, Table *table,
 
3251
  static bool binlog_row_logging_function(Session *session, Table *table,
3265
3252
                                          bool is_transactional,
3266
3253
                                          const unsigned char *before_record,
3267
3254
                                          const unsigned char *after_record
3268
3255
                                          __attribute__((unused)))
3269
3256
  {
3270
 
    return thd->binlog_delete_row(table, is_transactional, before_record);
 
3257
    return session->binlog_delete_row(table, is_transactional, before_record);
3271
3258
  }
3272
3259
  
3273
3260
protected:
3317
3304
*/
3318
3305
class Incident_log_event : public Log_event {
3319
3306
public:
3320
 
  Incident_log_event(THD *thd_arg, Incident incident)
3321
 
    : Log_event(thd_arg, 0, false), m_incident(incident)
 
3307
  Incident_log_event(Session *session_arg, Incident incident)
 
3308
    : Log_event(session_arg, 0, false), m_incident(incident)
3322
3309
  {
3323
3310
    m_message.str= NULL;                    /* Just as a precaution */
3324
3311
    m_message.length= 0;
3325
3312
    return;
3326
3313
  }
3327
3314
 
3328
 
  Incident_log_event(THD *thd_arg, Incident incident, LEX_STRING const msg)
3329
 
    : Log_event(thd_arg, 0, false), m_incident(incident)
 
3315
  Incident_log_event(Session *session_arg, Incident incident, LEX_STRING const msg)
 
3316
    : Log_event(session_arg, 0, false), m_incident(incident)
3330
3317
  {
3331
3318
    m_message= msg;
3332
3319
    return;
3407
3394
  @} (end of group Replication)
3408
3395
*/
3409
3396
 
3410
 
#endif /* _log_event_h */
 
3397
#endif /* DRIZZLED_LOG_EVENT_H */