~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/rpl_rli.h

  • Committer: Monty Taylor
  • Date: 2008-07-09 16:42:25 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: monty@inaugust.com-20080709164225-2r6n4j98nhxh031l
Moved test to tests... 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2005 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
#ifndef RPL_RLI_H
21
17
#define RPL_RLI_H
22
18
 
23
 
#include <drizzled/replication/tblmap.h>
24
 
#include <drizzled/replication/reporting.h>
25
 
#include <drizzled/replication/utility.h>
26
 
#include <string>
 
19
#include "rpl_tblmap.h"
 
20
#include "rpl_reporting.h"
 
21
#include "rpl_utility.h"
27
22
 
28
 
struct RPL_TableList;
 
23
struct RPL_TABLE_LIST;
29
24
class Master_info;
30
25
 
31
26
/****************************************************************************
97
92
    Protected with internal locks.
98
93
    Must get data_lock when resetting the logs.
99
94
  */
100
 
  DRIZZLE_BIN_LOG relay_log;
 
95
  MYSQL_BIN_LOG relay_log;
101
96
  LOG_INFO linfo;
102
97
  IO_CACHE cache_buf,*cur_log;
103
98
 
111
106
    created temporary tables. Modified only on init/end and by the SQL
112
107
    thread, read only by SQL thread.
113
108
  */
114
 
  Table *save_temporary_tables;
 
109
  TABLE *save_temporary_tables;
115
110
 
116
111
  /*
117
112
    standard lock acquistion order to avoid deadlocks:
133
128
    Needed to deal properly with cur_log getting closed and re-opened with
134
129
    a different log under our feet
135
130
  */
136
 
  uint32_t cur_log_old_open_count;
137
 
 
 
131
  uint32 cur_log_old_open_count;
 
132
  
138
133
  /*
139
134
    Let's call a group (of events) :
140
135
      - a transaction
153
148
    happen when, for example, the relay log gets rotated because of
154
149
    max_binlog_size.
155
150
  */
156
 
  std::string group_relay_log_name;
157
 
  uint64_t group_relay_log_pos;
158
 
  std::string event_relay_log_name;
159
 
  uint64_t event_relay_log_pos;
160
 
  uint64_t future_event_relay_log_pos;
 
151
  char group_relay_log_name[FN_REFLEN];
 
152
  ulonglong group_relay_log_pos;
 
153
  char event_relay_log_name[FN_REFLEN];
 
154
  ulonglong event_relay_log_pos;
 
155
  ulonglong future_event_relay_log_pos;
161
156
 
162
157
#ifdef HAVE_purify
163
158
  bool is_fake; /* Mark that this is a fake relay log info structure */
164
159
#endif
165
160
 
166
 
  /*
 
161
  /* 
167
162
     Original log name and position of the group we're currently executing
168
163
     (whose coordinates are group_relay_log_name/pos in the relay log)
169
164
     in the master's binlog. These concern the *group*, because in the master's
170
165
     binlog the log_pos that comes with each event is the position of the
171
166
     beginning of the group.
172
167
  */
173
 
  std::string group_master_log_name;
 
168
  char group_master_log_name[FN_REFLEN];
174
169
  volatile my_off_t group_master_log_pos;
175
170
 
176
171
  /*
179
174
    threads, the SQL thread sets it to unblock the I/O thread and make it
180
175
    temporarily forget about the constraint.
181
176
  */
182
 
  uint64_t log_space_limit,log_space_total;
 
177
  ulonglong log_space_limit,log_space_total;
183
178
  bool ignore_log_space_limit;
184
179
 
185
180
  /*
188
183
    committing event (the COMMIT query event, or the event if in autocommit
189
184
    mode).
190
185
  */
191
 
  uint64_t future_group_master_log_pos;
 
186
#if MYSQL_VERSION_ID < 40100
 
187
  ulonglong future_master_log_pos;
 
188
#else
 
189
  ulonglong future_group_master_log_pos;
 
190
#endif
192
191
 
193
192
  time_t last_master_timestamp;
194
193
 
199
198
    skipping one or more events in the master log that have caused
200
199
    errors, and have been manually applied by DBA already.
201
200
  */
202
 
  volatile uint32_t slave_skip_counter;
203
 
  volatile uint32_t abort_pos_wait;     /* Incremented on change master */
204
 
  volatile uint32_t slave_run_id;               /* Incremented on slave start */
 
201
  volatile uint32 slave_skip_counter;
 
202
  volatile ulong abort_pos_wait;        /* Incremented on change master */
 
203
  volatile ulong slave_run_id;          /* Incremented on slave start */
205
204
  pthread_mutex_t log_space_lock;
206
205
  pthread_cond_t log_space_cond;
207
 
  Session * sql_session;
208
 
  int32_t events_till_abort;
 
206
  THD * sql_thd;
 
207
#ifndef DBUG_OFF
 
208
  int events_till_abort;
 
209
#endif  
209
210
 
210
211
  /* if not set, the value of other members of the structure are undefined */
211
212
  bool inited;
212
213
  volatile bool abort_slave;
213
 
  volatile uint32_t slave_running;
 
214
  volatile uint slave_running;
214
215
 
215
 
  /*
 
216
  /* 
216
217
     Condition and its parameters from START SLAVE UNTIL clause.
217
 
 
218
 
     UNTIL condition is tested with is_until_satisfied() method that is
 
218
     
 
219
     UNTIL condition is tested with is_until_satisfied() method that is 
219
220
     called by exec_relay_log_event(). is_until_satisfied() caches the result
220
221
     of the comparison of log names because log names don't change very often;
221
222
     this cache is invalidated by parts of code which change log names with
222
223
     notify_*_log_name_updated() methods. (They need to be called only if SQL
223
224
     thread is running).
224
225
   */
225
 
 
 
226
  
226
227
  enum {UNTIL_NONE= 0, UNTIL_MASTER_POS, UNTIL_RELAY_POS} until_condition;
227
228
  char until_log_name[FN_REFLEN];
228
 
  uint64_t until_log_pos;
229
 
  /* extension extracted from log_name and converted to int32_t */
230
 
  uint32_t until_log_name_extension;
231
 
  /*
 
229
  ulonglong until_log_pos;
 
230
  /* extension extracted from log_name and converted to int */
 
231
  ulong until_log_name_extension;   
 
232
  /* 
232
233
     Cached result of comparison of until_log_name and current log name
233
 
     -2 means unitialised, -1,0,1 are comarison results
 
234
     -2 means unitialised, -1,0,1 are comarison results 
234
235
  */
235
 
  enum
236
 
  {
 
236
  enum 
 
237
  { 
237
238
    UNTIL_LOG_NAMES_CMP_UNKNOWN= -2, UNTIL_LOG_NAMES_CMP_LESS= -1,
238
239
    UNTIL_LOG_NAMES_CMP_EQUAL= 0, UNTIL_LOG_NAMES_CMP_GREATER= 1
239
240
  } until_log_names_cmp_result;
240
241
 
 
242
  char cached_charset[6];
241
243
  /*
242
244
    trans_retries varies between 0 to slave_transaction_retries and counts how
243
245
    many times the slave has retried the present transaction; gets reset to 0
245
247
    counter: how many times the slave has retried a transaction (any) since
246
248
    slave started.
247
249
  */
248
 
  uint32_t trans_retries, retried_trans;
 
250
  ulong trans_retries, retried_trans;
249
251
 
250
252
  /*
251
253
    If the end of the hot relay log is made of master's events ignored by the
256
258
    are both protected by rli->relay_log.LOCK_log.
257
259
  */
258
260
  char ign_master_log_name_end[FN_REFLEN];
259
 
  uint64_t ign_master_log_pos_end;
 
261
  ulonglong ign_master_log_pos_end;
260
262
 
261
263
  Relay_log_info();
262
264
  ~Relay_log_info();
263
265
 
264
266
  /*
265
 
    Invalidate cached until_log_name and group_relay_log_name comparison
 
267
    Invalidate cached until_log_name and group_relay_log_name comparison 
266
268
    result. Should be called after any update of group_realy_log_name if
267
269
    there chances that sql_thread is running.
268
270
  */
273
275
  }
274
276
 
275
277
  /*
276
 
    The same as previous but for group_master_log_name.
 
278
    The same as previous but for group_master_log_name. 
277
279
  */
278
280
  inline void notify_group_master_log_name_update()
279
281
  {
280
282
    if (until_condition==UNTIL_MASTER_POS)
281
283
      until_log_names_cmp_result= UNTIL_LOG_NAMES_CMP_UNKNOWN;
282
284
  }
283
 
 
 
285
  
284
286
  inline void inc_event_relay_log_pos()
285
287
  {
286
288
    event_relay_log_pos= future_event_relay_log_pos;
287
289
  }
288
290
 
289
 
  void inc_group_relay_log_pos(uint64_t log_pos,
 
291
  void inc_group_relay_log_pos(ulonglong log_pos,
290
292
                               bool skip_lock=0);
291
293
 
292
 
  int32_t wait_for_pos(Session* session, String* log_name, int64_t log_pos,
293
 
                   int64_t timeout);
 
294
  int wait_for_pos(THD* thd, String* log_name, longlong log_pos, 
 
295
                   longlong timeout);
294
296
  void close_temporary_tables();
295
297
 
296
298
  /* Check if UNTIL condition is satisfied. See slave.cc for more. */
297
299
  bool is_until_satisfied(my_off_t master_beg_pos);
298
 
  inline uint64_t until_pos()
 
300
  inline ulonglong until_pos()
299
301
  {
300
302
    return ((until_condition == UNTIL_MASTER_POS) ? group_master_log_pos :
301
303
            group_relay_log_pos);
302
304
  }
303
305
 
304
 
  RPL_TableList *tables_to_lock;           /* RBR: Tables to lock  */
305
 
  uint32_t tables_to_lock_count;        /* RBR: Count of tables to lock */
 
306
  RPL_TABLE_LIST *tables_to_lock;           /* RBR: Tables to lock  */
 
307
  uint tables_to_lock_count;        /* RBR: Count of tables to lock */
306
308
  table_mapping m_table_map;      /* RBR: Mapping table-id to table */
307
309
 
308
 
  inline table_def *get_tabledef(Table *tbl)
 
310
  inline table_def *get_tabledef(TABLE *tbl)
309
311
  {
310
312
    table_def *td= 0;
311
 
    for (TableList *ptr= tables_to_lock; ptr && !td; ptr= ptr->next_global)
 
313
    for (TABLE_LIST *ptr= tables_to_lock; ptr && !td; ptr= ptr->next_global)
312
314
      if (ptr->table == tbl)
313
 
        td= &((RPL_TableList *)ptr)->m_tabledef;
 
315
        td= &((RPL_TABLE_LIST *)ptr)->m_tabledef;
314
316
    return (td);
315
317
  }
316
318
 
317
 
  void cleanup_context(Session *, bool);
 
319
  /*
 
320
    Last charset (6 bytes) seen by slave SQL thread is cached here; it helps
 
321
    the thread save 3 get_charset() per Query_log_event if the charset is not
 
322
    changing from event to event (common situation).
 
323
    When the 6 bytes are equal to 0 is used to mean "cache is invalidated".
 
324
  */
 
325
  void cached_charset_invalidate();
 
326
  bool cached_charset_compare(char *charset) const;
 
327
 
 
328
  void cleanup_context(THD *, bool);
318
329
  void clear_tables_to_lock();
319
330
 
320
331
  /*
390
401
     @retval true Replication thread is currently inside a group
391
402
     @retval false Replication thread is currently not inside a group
392
403
   */
393
 
  bool is_in_group() const;
 
404
  bool is_in_group() const {
 
405
    return (sql_thd->options & OPTION_BEGIN) ||
 
406
      (m_flags & (1UL << IN_STMT));
 
407
  }
394
408
 
395
409
private:
396
 
  uint32_t m_flags;
 
410
  uint32 m_flags;
397
411
};
398
412
 
399
413
 
400
414
// Defined in rpl_rli.cc
401
 
int32_t init_relay_log_info(Relay_log_info* rli, const char* info_fname);
 
415
int init_relay_log_info(Relay_log_info* rli, const char* info_fname);
402
416
 
403
417
 
404
418
#endif /* RPL_RLI_H */