14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
#include <drizzled/server_includes.h>
20
#include "sql_repl.h" // For check_binlog_magic
21
#include "rpl_utility.h"
17
#include <drizzled/replication/mi.h>
18
#include <drizzled/replication/rli.h>
19
// For check_binlog_magic
20
#include <drizzled/replication/replication.h>
21
#include <drizzled/replication/utility.h>
22
#include <drizzled/data_home.h>
23
#include <drizzled/sql_parse.h>
24
#include <drizzled/gettext.h>
25
#include <drizzled/log_event.h>
26
#include <drizzled/sql_base.h>
28
#if TIME_WITH_SYS_TIME
29
# include <sys/time.h>
33
# include <sys/time.h>
23
41
static int32_t count_relay_log_space(Relay_log_info* rli);
25
43
// Defined in slave.cc
26
44
int32_t init_intvar_from_file(int32_t* var, IO_CACHE* f, int32_t default_val);
27
45
int32_t init_strvar_from_file(char *var, int32_t max_size, IO_CACHE *f,
28
const char *default_val);
46
const char *default_val);
31
49
Relay_log_info::Relay_log_info()
32
50
:Slave_reporting_capability("SQL"),
33
51
no_storage(false), replicate_same_server_id(::replicate_same_server_id),
34
52
info_fd(-1), cur_log_fd(-1), save_temporary_tables(0),
53
cur_log_old_open_count(0), group_relay_log_pos(0), event_relay_log_pos(0),
35
54
#if defined(HAVE_purify) && HAVE_purify
38
cur_log_old_open_count(0), group_relay_log_pos(0), event_relay_log_pos(0),
39
57
group_master_log_pos(0), log_space_total(0), ignore_log_space_limit(0),
40
58
last_master_timestamp(0), slave_skip_counter(0),
41
abort_pos_wait(0), slave_run_id(0), sql_thd(0),
59
abort_pos_wait(0), slave_run_id(0), sql_session(0),
42
60
inited(0), abort_slave(0), slave_running(0), until_condition(UNTIL_NONE),
43
61
until_log_pos(0), retried_trans(0),
44
62
tables_to_lock(0), tables_to_lock_count(0),
129
146
instead require a name. But as we don't want to break many existing
130
147
setups, we only give warning, not error.
132
sql_print_warning("Neither --relay-log nor --relay-log-index were used;"
149
errmsg_printf(ERRMSG_LVL_WARN, _("Neither --relay-log nor --relay-log-index were used;"
133
150
" so replication "
134
"may break when this MySQL server acts as a "
151
"may break when this Drizzle server acts as a "
135
152
"slave and has his hostname changed!! Please "
136
"use '--relay-log=%s' to avoid this problem.", ln);
153
"use '--relay-log=%s' to avoid this problem."), ln);
137
154
name_warning_sent= 1;
154
172
/* if file does not exist */
155
173
if (access(fname,F_OK))
158
If someone removed the file from underneath our feet, just close
159
the old descriptor and re-create the old file
162
my_close(info_fd, MYF(MY_WME));
163
if ((info_fd = my_open(fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
165
sql_print_error("Failed to create a new relay log info file (\
166
file '%s', errno %d)", fname, my_errno);
167
msg= current_thd->main_da.message();
170
if (init_io_cache(&rli->info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,
173
sql_print_error("Failed to create a cache on relay log info file '%s'",
175
msg= current_thd->main_da.message();
179
/* Init relay log with first entry in the relay index file */
180
if (init_relay_log_pos(rli,NullS,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
183
sql_print_error("Failed to open the relay log 'FIRST' (relay_log_pos 4)");
186
rli->group_master_log_name[0]= 0;
187
rli->group_master_log_pos= 0;
188
rli->info_fd= info_fd;
175
/* Create a new file */
190
177
else // file exists
193
reinit_io_cache(&rli->info_file, READ_CACHE, 0L,0,0);
197
if ((info_fd = my_open(fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
200
Failed to open the existing relay log info file '%s' (errno %d)",
204
else if (init_io_cache(&rli->info_file, info_fd,
205
IO_SIZE*2, READ_CACHE, 0L, 0, MYF(MY_WME)))
207
sql_print_error("Failed to create a cache on relay log info file '%s'",
214
my_close(info_fd, MYF(0));
216
rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
217
pthread_mutex_unlock(&rli->data_lock);
222
rli->info_fd = info_fd;
223
int32_t relay_log_pos, master_log_pos;
224
if (init_strvar_from_file(rli->group_relay_log_name,
225
sizeof(rli->group_relay_log_name),
226
&rli->info_file, "") ||
227
init_intvar_from_file(&relay_log_pos,
228
&rli->info_file, BIN_LOG_HEADER_SIZE) ||
229
init_strvar_from_file(rli->group_master_log_name,
230
sizeof(rli->group_master_log_name),
231
&rli->info_file, "") ||
232
init_intvar_from_file(&master_log_pos, &rli->info_file, 0))
234
msg="Error reading slave log configuration";
237
strmake(rli->event_relay_log_name,rli->group_relay_log_name,
238
sizeof(rli->event_relay_log_name)-1);
239
rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
240
rli->group_master_log_pos= master_log_pos;
242
if (init_relay_log_pos(rli,
243
rli->group_relay_log_name,
244
rli->group_relay_log_pos,
249
sql_print_error("Failed to open the relay log '%s' (relay_log_pos %s)",
250
rli->group_relay_log_name,
251
llstr(rli->group_relay_log_pos, llbuf));
179
/* Open up fname here and pull out the relay.info data */
255
assert(rli->event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
256
assert(my_b_tell(rli->cur_log) == rli->event_relay_log_pos);
259
183
Now change the cache from READ to WRITE - must do this
649
575
configuration which does nothing), then group_master_log_pos
650
576
will grow and group_master_log_name will stay "".
652
if (*group_master_log_name)
578
if (group_master_log_name.length())
654
char *basename= (group_master_log_name +
655
dirname_length(group_master_log_name));
580
const char *basename= (group_master_log_name.c_str() +
581
dirname_length(group_master_log_name.c_str()));
657
583
First compare the parts before the extension.
658
584
Find the dot in the master's log basename,
850
775
rli->cur_log_fd= -1;
853
if (rli->relay_log.reset_logs(thd))
778
if (rli->relay_log.reset_logs(session))
855
780
*errmsg = "Failed during log reset";
859
784
/* Save name of used relay log file */
860
strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(),
861
sizeof(rli->group_relay_log_name)-1);
862
strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(),
863
sizeof(rli->event_relay_log_name)-1);
785
rli->group_relay_log_name.assign(rli->relay_log.get_log_fname());
786
rli->event_relay_log_name.assign(rli->relay_log.get_log_fname());
864
787
rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
865
788
if (count_relay_log_space(rli))
977
void Relay_log_info::cached_charset_invalidate()
979
/* Full of zeroes means uninitialized. */
980
memset(cached_charset, 0, sizeof(cached_charset));
985
bool Relay_log_info::cached_charset_compare(char *charset) const
987
if (memcmp(cached_charset, charset, sizeof(cached_charset)))
989
memcpy(const_cast<char*>(cached_charset), charset, sizeof(cached_charset));
996
900
void Relay_log_info::stmt_done(my_off_t event_master_log_pos,
997
901
time_t event_creation_time)
1062
ha_autocommit_or_rollback(thd, 1); // if a "statement transaction"
1063
end_trans(thd, ROLLBACK); // if a "real transaction"
965
ha_autocommit_or_rollback(session, 1); // if a "statement transaction"
966
end_trans(session, ROLLBACK); // if a "real transaction"
1065
968
m_table_map.clear_tables();
1066
close_thread_tables(thd);
969
close_thread_tables(session);
1067
970
clear_tables_to_lock();
1068
971
clear_flag(IN_STMT);
1070
973
Cleanup for the flags that have been set at do_apply_event.
1072
thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
1073
thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
975
session->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
976
session->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
1074
977
last_event_start_time= 0;
982
bool Relay_log_info::is_in_group() const {
983
return (sql_session->options & OPTION_BEGIN) ||
984
(m_flags & (1UL << IN_STMT));
1078
988
void Relay_log_info::clear_tables_to_lock()
1080
990
while (tables_to_lock)
1082
uchar* to_free= reinterpret_cast<uchar*>(tables_to_lock);
992
unsigned char* to_free= reinterpret_cast<unsigned char*>(tables_to_lock);
1083
993
if (tables_to_lock->m_tabledef_valid)
1085
995
tables_to_lock->m_tabledef.table_def::~table_def();
1086
996
tables_to_lock->m_tabledef_valid= false;
1089
static_cast<RPL_TABLE_LIST*>(tables_to_lock->next_global);
999
static_cast<RPL_TableList*>(tables_to_lock->next_global);
1090
1000
tables_to_lock_count--;
1091
my_free(to_free, MYF(MY_WME));
1093
1003
assert(tables_to_lock == NULL && tables_to_lock_count == 0);