848
848
thread_mask&= thd->lex->slave_thd_opt;
849
849
if (thread_mask) //some threads are stopped, start them
851
if (init_master_info(mi,master_info_file,relay_log_info_file, 0,
851
if (mi->init_master_info(master_info_file, relay_log_info_file, thread_mask))
853
852
slave_errno=ER_MASTER_INFO;
854
else if (server_id_supplied && *mi->host)
853
else if (server_id_supplied && *mi->getHostname())
857
856
If we will start SQL thread we will care about UNTIL options If
1137
thd_proc_info(thd, "Changing master");
1136
thd->set_proc_info("Changing master");
1138
1137
LEX_MASTER_INFO* lex_mi= &thd->lex->mi;
1139
1138
// TODO: see if needs re-write
1140
if (init_master_info(mi, master_info_file, relay_log_info_file, 0,
1139
if (mi->init_master_info(master_info_file, relay_log_info_file, thread_mask))
1143
1141
my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0));
1144
1142
unlock_slave_threads(mi);
1159
1157
if ((lex_mi->host || lex_mi->port) && !lex_mi->log_file_name && !lex_mi->pos)
1161
mi->master_log_name[0] = 0;
1162
mi->master_log_pos= BIN_LOG_HEADER_SIZE;
1165
1160
if (lex_mi->log_file_name)
1166
strmake(mi->master_log_name, lex_mi->log_file_name,
1167
sizeof(mi->master_log_name)-1);
1161
mi->setLogName(lex_mi->log_file_name);
1168
1162
if (lex_mi->pos)
1170
mi->master_log_pos= lex_mi->pos;
1164
mi->setLogPosition(lex_mi->pos);
1173
1167
if (lex_mi->host)
1174
strmake(mi->host, lex_mi->host, sizeof(mi->host)-1);
1168
mi->setHost(lex_mi->host, lex_mi->port);
1175
1169
if (lex_mi->user)
1176
strmake(mi->user, lex_mi->user, sizeof(mi->user)-1);
1170
mi->setUsername(lex_mi->user);
1177
1171
if (lex_mi->password)
1178
strmake(mi->password, lex_mi->password, sizeof(mi->password)-1);
1180
mi->port = lex_mi->port;
1172
mi->setPassword(lex_mi->password);
1181
1173
if (lex_mi->connect_retry)
1182
1174
mi->connect_retry = lex_mi->connect_retry;
1183
1175
if (lex_mi->heartbeat_opt != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
1227
1216
of replication is not 100% clear, so we guard against problems using
1230
mi->master_log_pos = ((BIN_LOG_HEADER_SIZE > mi->rli.group_master_log_pos)
1231
? BIN_LOG_HEADER_SIZE
1232
: mi->rli.group_master_log_pos);
1233
strmake(mi->master_log_name, mi->rli.group_master_log_name,
1234
sizeof(mi->master_log_name)-1);
1219
mi->setLogPosition(((BIN_LOG_HEADER_SIZE > mi->rli.group_master_log_pos)
1220
? BIN_LOG_HEADER_SIZE
1221
: mi->rli.group_master_log_pos));
1222
mi->setLogName(mi->rli.group_master_log_name.c_str());
1237
1225
Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never
1238
1226
a slave before).
1240
if (flush_master_info(mi, 0))
1242
1230
my_error(ER_RELAY_LOG_INIT, MYF(0), "Failed to flush master info file");
1243
1231
unlock_slave_threads(mi);
1282
1270
''/0: we have lost all copies of the original good coordinates.
1283
1271
That's why we always save good coords in rli.
1285
mi->rli.group_master_log_pos= mi->master_log_pos;
1286
strmake(mi->rli.group_master_log_name,mi->master_log_name,
1287
sizeof(mi->rli.group_master_log_name)-1);
1273
mi->rli.group_master_log_pos= mi->getLogPosition();
1274
mi->rli.group_master_log_name.assign(mi->getLogName());
1289
if (!mi->rli.group_master_log_name[0]) // uninitialized case
1290
mi->rli.group_master_log_pos=0;
1276
if (mi->rli.group_master_log_name.size() == 0) // uninitialized case
1277
mi->rli.group_master_log_pos= 0;
1292
1279
pthread_mutex_lock(&mi->rli.data_lock);
1293
1280
mi->rli.abort_pos_wait++; /* for MASTER_POS_WAIT() to abort */
1343
bool mysql_show_binlog_events(THD* thd)
1345
Protocol *protocol= thd->protocol;
1346
List<Item> field_list;
1347
const char *errmsg= 0;
1352
Log_event::init_show_field_list(&field_list);
1353
if (protocol->send_fields(&field_list,
1354
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1357
Format_description_log_event *description_event= new
1358
Format_description_log_event(3); /* MySQL 4.0 by default */
1360
if (mysql_bin_log.is_open())
1362
LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
1363
SELECT_LEX_UNIT *unit= &thd->lex->unit;
1364
ha_rows event_count, limit_start, limit_end;
1365
my_off_t pos = cmax((uint64_t)BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
1366
char search_file_name[FN_REFLEN], *name;
1367
const char *log_file_name = lex_mi->log_file_name;
1368
pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
1372
unit->set_limit(thd->lex->current_select);
1373
limit_start= unit->offset_limit_cnt;
1374
limit_end= unit->select_limit_cnt;
1376
name= search_file_name;
1378
mysql_bin_log.make_log_name(search_file_name, log_file_name);
1380
name=0; // Find first log
1382
linfo.index_file_offset = 0;
1384
if (mysql_bin_log.find_log_pos(&linfo, name, 1))
1386
errmsg = "Could not find target log";
1390
pthread_mutex_lock(&LOCK_thread_count);
1391
thd->current_linfo = &linfo;
1392
pthread_mutex_unlock(&LOCK_thread_count);
1394
if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0)
1398
to account binlog event header size
1400
thd->variables.max_allowed_packet += MAX_LOG_EVENT_HEADER;
1402
pthread_mutex_lock(log_lock);
1405
open_binlog() sought to position 4.
1406
Read the first event in case it's a Format_description_log_event, to
1407
know the format. If there's no such event, we are 3.23 or 4.x. This
1408
code, like before, can't read 3.23 binlogs.
1409
This code will fail on a mixed relay log (one which has Format_desc then
1410
Rotate then Format_desc).
1412
ev = Log_event::read_log_event(&log,(pthread_mutex_t*)0,description_event);
1415
if (ev->get_type_code() == FORMAT_DESCRIPTION_EVENT)
1417
delete description_event;
1418
description_event= (Format_description_log_event*) ev;
1424
my_b_seek(&log, pos);
1426
if (!description_event->is_valid())
1428
errmsg="Invalid Format_description event; could be out of memory";
1432
for (event_count = 0;
1433
(ev = Log_event::read_log_event(&log,(pthread_mutex_t*) 0,
1434
description_event)); )
1436
if (event_count >= limit_start &&
1437
ev->net_send(protocol, linfo.log_file_name, pos))
1439
errmsg = "Net error";
1441
pthread_mutex_unlock(log_lock);
1445
pos = my_b_tell(&log);
1448
if (++event_count >= limit_end)
1452
if (event_count < limit_end && log.error)
1454
errmsg = "Wrong offset or I/O error";
1455
pthread_mutex_unlock(log_lock);
1459
pthread_mutex_unlock(log_lock);
1465
delete description_event;
1469
(void) my_close(file, MYF(MY_WME));
1473
my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0),
1474
"SHOW BINLOG EVENTS", errmsg);
1478
pthread_mutex_lock(&LOCK_thread_count);
1479
thd->current_linfo = 0;
1480
pthread_mutex_unlock(&LOCK_thread_count);
1485
1330
bool show_binlog_info(THD* thd)
1487
1332
Protocol *protocol= thd->protocol;