14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
#include <drizzled/server_includes.h>
17
#include <drizzled/rpl_mi.h>
18
#include <drizzled/rpl_rli.h>
19
// For check_binlog_magic
20
#include <drizzled/sql_repl.h>
21
#include <drizzled/rpl_utility.h>
22
#include <drizzled/data_home.h>
23
#include <drizzled/sql_parse.h>
24
#include <drizzled/gettext.h>
26
#if TIME_WITH_SYS_TIME
27
# include <sys/time.h>
31
# include <sys/time.h>
20
#include "sql_repl.h" // For check_binlog_magic
21
#include "rpl_utility.h"
23
#include <libdrizzle/gettext.h>
39
25
static int32_t count_relay_log_space(Relay_log_info* rli);
54
40
cur_log_old_open_count(0), group_relay_log_pos(0), event_relay_log_pos(0),
55
41
group_master_log_pos(0), log_space_total(0), ignore_log_space_limit(0),
56
42
last_master_timestamp(0), slave_skip_counter(0),
57
abort_pos_wait(0), slave_run_id(0), sql_session(0),
43
abort_pos_wait(0), slave_run_id(0), sql_thd(0),
58
44
inited(0), abort_slave(0), slave_running(0), until_condition(UNTIL_NONE),
59
45
until_log_pos(0), retried_trans(0),
60
46
tables_to_lock(0), tables_to_lock_count(0),
170
157
/* if file does not exist */
171
158
if (access(fname,F_OK))
173
/* Create a new file */
161
If someone removed the file from underneath our feet, just close
162
the old descriptor and re-create the old file
165
my_close(info_fd, MYF(MY_WME));
166
if ((info_fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
168
sql_print_error(_("Failed to create a new relay log info file "
169
"( file '%s', errno %d)"), fname, my_errno);
170
msg= current_thd->main_da.message();
173
if (init_io_cache(&rli->info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,
176
sql_print_error(_("Failed to create a cache on relay log info file '%s'"),
178
msg= current_thd->main_da.message();
182
/* Init relay log with first entry in the relay index file */
183
if (init_relay_log_pos(rli,NullS,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
186
sql_print_error(_("Failed to open the relay log 'FIRST' (relay_log_pos 4)"));
189
rli->group_master_log_name[0]= 0;
190
rli->group_master_log_pos= 0;
191
rli->info_fd= info_fd;
175
193
else // file exists
177
/* Open up fname here and pull out the relay.info data */
196
reinit_io_cache(&rli->info_file, READ_CACHE, 0L,0,0);
200
if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
202
sql_print_error(_("Failed to open the existing relay log info "
203
"file '%s' (errno %d)"),
207
else if (init_io_cache(&rli->info_file, info_fd,
208
IO_SIZE*2, READ_CACHE, 0L, 0, MYF(MY_WME)))
210
sql_print_error(_("Failed to create a cache on relay log info "
218
my_close(info_fd, MYF(0));
220
rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
221
pthread_mutex_unlock(&rli->data_lock);
226
rli->info_fd = info_fd;
227
int32_t relay_log_pos, master_log_pos;
228
if (init_strvar_from_file(rli->group_relay_log_name,
229
sizeof(rli->group_relay_log_name),
230
&rli->info_file, "") ||
231
init_intvar_from_file(&relay_log_pos,
232
&rli->info_file, BIN_LOG_HEADER_SIZE) ||
233
init_strvar_from_file(rli->group_master_log_name,
234
sizeof(rli->group_master_log_name),
235
&rli->info_file, "") ||
236
init_intvar_from_file(&master_log_pos, &rli->info_file, 0))
238
msg="Error reading slave log configuration";
241
strmake(rli->event_relay_log_name,rli->group_relay_log_name,
242
sizeof(rli->event_relay_log_name)-1);
243
rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
244
rli->group_master_log_pos= master_log_pos;
246
if (init_relay_log_pos(rli,
247
rli->group_relay_log_name,
248
rli->group_relay_log_pos,
253
sql_print_error(_("Failed to open the relay log '%s' (relay_log_pos %s)"),
254
rli->group_relay_log_name,
255
llstr(rli->group_relay_log_pos, llbuf));
259
assert(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
260
assert(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
181
263
Now change the cache from READ to WRITE - must do this
572
654
configuration which does nothing), then group_master_log_pos
573
655
will grow and group_master_log_name will stay "".
575
if (group_master_log_name.length())
657
if (*group_master_log_name)
577
const char *basename= (group_master_log_name.c_str() +
578
dirname_length(group_master_log_name.c_str()));
659
char *basename= (group_master_log_name +
660
dirname_length(group_master_log_name));
580
662
First compare the parts before the extension.
581
663
Find the dot in the master's log basename,
772
855
rli->cur_log_fd= -1;
775
if (rli->relay_log.reset_logs(session))
858
if (rli->relay_log.reset_logs(thd))
777
860
*errmsg = "Failed during log reset";
781
864
/* Save name of used relay log file */
782
rli->group_relay_log_name.assign(rli->relay_log.get_log_fname());
783
rli->event_relay_log_name.assign(rli->relay_log.get_log_fname());
865
strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(),
866
sizeof(rli->group_relay_log_name)-1);
867
strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(),
868
sizeof(rli->event_relay_log_name)-1);
784
869
rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
785
870
if (count_relay_log_space(rli))
982
void Relay_log_info::cached_charset_invalidate()
984
/* Full of zeroes means uninitialized. */
985
memset(cached_charset, 0, sizeof(cached_charset));
990
bool Relay_log_info::cached_charset_compare(char *charset) const
992
if (memcmp(cached_charset, charset, sizeof(cached_charset)))
994
memcpy(const_cast<char*>(cached_charset), charset, sizeof(cached_charset));
897
1001
void Relay_log_info::stmt_done(my_off_t event_master_log_pos,
898
1002
time_t event_creation_time)
962
ha_autocommit_or_rollback(session, 1); // if a "statement transaction"
963
end_trans(session, ROLLBACK); // if a "real transaction"
1067
ha_autocommit_or_rollback(thd, 1); // if a "statement transaction"
1068
end_trans(thd, ROLLBACK); // if a "real transaction"
965
1070
m_table_map.clear_tables();
966
close_thread_tables(session);
1071
close_thread_tables(thd);
967
1072
clear_tables_to_lock();
968
1073
clear_flag(IN_STMT);
970
1075
Cleanup for the flags that have been set at do_apply_event.
972
session->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
973
session->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
1077
thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
1078
thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
974
1079
last_event_start_time= 0;