1157
1163
if ((lex_mi->host || lex_mi->port) && !lex_mi->log_file_name && !lex_mi->pos)
1165
mi->master_log_name[0] = 0;
1166
mi->master_log_pos= BIN_LOG_HEADER_SIZE;
1160
1169
if (lex_mi->log_file_name)
1161
mi->setLogName(lex_mi->log_file_name);
1170
strmake(mi->master_log_name, lex_mi->log_file_name,
1171
sizeof(mi->master_log_name)-1);
1162
1172
if (lex_mi->pos)
1164
mi->setLogPosition(lex_mi->pos);
1174
mi->master_log_pos= lex_mi->pos;
1167
1177
if (lex_mi->host)
1168
mi->setHost(lex_mi->host, lex_mi->port);
1178
strmake(mi->host, lex_mi->host, sizeof(mi->host)-1);
1169
1179
if (lex_mi->user)
1170
mi->setUsername(lex_mi->user);
1180
strmake(mi->user, lex_mi->user, sizeof(mi->user)-1);
1171
1181
if (lex_mi->password)
1172
mi->setPassword(lex_mi->password);
1182
strmake(mi->password, lex_mi->password, sizeof(mi->password)-1);
1184
mi->port = lex_mi->port;
1173
1185
if (lex_mi->connect_retry)
1174
1186
mi->connect_retry = lex_mi->connect_retry;
1175
1187
if (lex_mi->heartbeat_opt != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
1176
1188
mi->heartbeat_period = lex_mi->heartbeat_period;
1178
mi->heartbeat_period= (float) cmin((double)SLAVE_MAX_HEARTBEAT_PERIOD,
1190
mi->heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
1179
1191
(slave_net_timeout/2.0));
1180
mi->received_heartbeats= 0L; // counter lives until master is CHANGEd
1192
mi->received_heartbeats= 0LL; // counter lives until master is CHANGEd
1193
if (lex_mi->ssl != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
1194
mi->ssl= (lex_mi->ssl == LEX_MASTER_INFO::LEX_MI_ENABLE);
1196
if (lex_mi->ssl_verify_server_cert != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
1197
mi->ssl_verify_server_cert=
1198
(lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::LEX_MI_ENABLE);
1201
strmake(mi->ssl_ca, lex_mi->ssl_ca, sizeof(mi->ssl_ca)-1);
1202
if (lex_mi->ssl_capath)
1203
strmake(mi->ssl_capath, lex_mi->ssl_capath, sizeof(mi->ssl_capath)-1);
1204
if (lex_mi->ssl_cert)
1205
strmake(mi->ssl_cert, lex_mi->ssl_cert, sizeof(mi->ssl_cert)-1);
1206
if (lex_mi->ssl_cipher)
1207
strmake(mi->ssl_cipher, lex_mi->ssl_cipher, sizeof(mi->ssl_cipher)-1);
1208
if (lex_mi->ssl_key)
1209
strmake(mi->ssl_key, lex_mi->ssl_key, sizeof(mi->ssl_key)-1);
1210
if (lex_mi->ssl || lex_mi->ssl_ca || lex_mi->ssl_capath ||
1211
lex_mi->ssl_cert || lex_mi->ssl_cipher || lex_mi->ssl_key ||
1212
lex_mi->ssl_verify_server_cert )
1213
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
1214
ER_SLAVE_IGNORED_SSL_PARAMS, ER(ER_SLAVE_IGNORED_SSL_PARAMS));
1182
1216
if (lex_mi->relay_log_name)
1184
1218
need_relay_log_purge= 0;
1185
mi->rli.event_relay_log_name.assign(lex_mi->relay_log_name);
1219
strmake(mi->rli.group_relay_log_name,lex_mi->relay_log_name,
1220
sizeof(mi->rli.group_relay_log_name)-1);
1221
strmake(mi->rli.event_relay_log_name,lex_mi->relay_log_name,
1222
sizeof(mi->rli.event_relay_log_name)-1);
1188
1225
if (lex_mi->relay_log_pos)
1213
1250
Sometimes mi->rli.master_log_pos == 0 (it happens when the SQL thread is
1214
not initialized), so we use a cmax().
1251
not initialized), so we use a max().
1215
1252
What happens to mi->rli.master_log_pos during the initialization stages
1216
1253
of replication is not 100% clear, so we guard against problems using
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());
1256
mi->master_log_pos = max(BIN_LOG_HEADER_SIZE,
1257
mi->rli.group_master_log_pos);
1258
strmake(mi->master_log_name, mi->rli.group_master_log_name,
1259
sizeof(mi->master_log_name)-1);
1225
1262
Relay log's IO_CACHE may not be inited, if rli->inited==0 (server was never
1226
1263
a slave before).
1265
if (flush_master_info(mi, 0))
1230
1267
my_error(ER_RELAY_LOG_INIT, MYF(0), "Failed to flush master info file");
1231
1268
unlock_slave_threads(mi);
1270
1307
''/0: we have lost all copies of the original good coordinates.
1271
1308
That's why we always save good coords in rli.
1273
mi->rli.group_master_log_pos= mi->getLogPosition();
1274
mi->rli.group_master_log_name.assign(mi->getLogName());
1310
mi->rli.group_master_log_pos= mi->master_log_pos;
1311
strmake(mi->rli.group_master_log_name,mi->master_log_name,
1312
sizeof(mi->rli.group_master_log_name)-1);
1276
if (mi->rli.group_master_log_name.size() == 0) // uninitialized case
1277
mi->rli.group_master_log_pos= 0;
1314
if (!mi->rli.group_master_log_name[0]) // uninitialized case
1315
mi->rli.group_master_log_pos=0;
1279
1317
pthread_mutex_lock(&mi->rli.data_lock);
1280
1318
mi->rli.abort_pos_wait++; /* for MASTER_POS_WAIT() to abort */
1368
bool mysql_show_binlog_events(THD* thd)
1370
Protocol *protocol= thd->protocol;
1371
List<Item> field_list;
1372
const char *errmsg= 0;
1377
Log_event::init_show_field_list(&field_list);
1378
if (protocol->send_fields(&field_list,
1379
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1382
Format_description_log_event *description_event= new
1383
Format_description_log_event(3); /* MySQL 4.0 by default */
1386
Wait for handlers to insert any pending information
1387
into the binlog. For e.g. ndb which updates the binlog asynchronously
1388
this is needed so that the uses sees all its own commands in the binlog
1390
ha_binlog_wait(thd);
1392
if (mysql_bin_log.is_open())
1394
LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
1395
SELECT_LEX_UNIT *unit= &thd->lex->unit;
1396
ha_rows event_count, limit_start, limit_end;
1397
my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
1398
char search_file_name[FN_REFLEN], *name;
1399
const char *log_file_name = lex_mi->log_file_name;
1400
pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
1404
unit->set_limit(thd->lex->current_select);
1405
limit_start= unit->offset_limit_cnt;
1406
limit_end= unit->select_limit_cnt;
1408
name= search_file_name;
1410
mysql_bin_log.make_log_name(search_file_name, log_file_name);
1412
name=0; // Find first log
1414
linfo.index_file_offset = 0;
1416
if (mysql_bin_log.find_log_pos(&linfo, name, 1))
1418
errmsg = "Could not find target log";
1422
pthread_mutex_lock(&LOCK_thread_count);
1423
thd->current_linfo = &linfo;
1424
pthread_mutex_unlock(&LOCK_thread_count);
1426
if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0)
1430
to account binlog event header size
1432
thd->variables.max_allowed_packet += MAX_LOG_EVENT_HEADER;
1434
pthread_mutex_lock(log_lock);
1437
open_binlog() sought to position 4.
1438
Read the first event in case it's a Format_description_log_event, to
1439
know the format. If there's no such event, we are 3.23 or 4.x. This
1440
code, like before, can't read 3.23 binlogs.
1441
This code will fail on a mixed relay log (one which has Format_desc then
1442
Rotate then Format_desc).
1444
ev = Log_event::read_log_event(&log,(pthread_mutex_t*)0,description_event);
1447
if (ev->get_type_code() == FORMAT_DESCRIPTION_EVENT)
1449
delete description_event;
1450
description_event= (Format_description_log_event*) ev;
1456
my_b_seek(&log, pos);
1458
if (!description_event->is_valid())
1460
errmsg="Invalid Format_description event; could be out of memory";
1464
for (event_count = 0;
1465
(ev = Log_event::read_log_event(&log,(pthread_mutex_t*) 0,
1466
description_event)); )
1468
if (event_count >= limit_start &&
1469
ev->net_send(protocol, linfo.log_file_name, pos))
1471
errmsg = "Net error";
1473
pthread_mutex_unlock(log_lock);
1477
pos = my_b_tell(&log);
1480
if (++event_count >= limit_end)
1484
if (event_count < limit_end && log.error)
1486
errmsg = "Wrong offset or I/O error";
1487
pthread_mutex_unlock(log_lock);
1491
pthread_mutex_unlock(log_lock);
1497
delete description_event;
1501
(void) my_close(file, MYF(MY_WME));
1505
my_error(ER_ERROR_WHEN_EXECUTING_COMMAND, MYF(0),
1506
"SHOW BINLOG EVENTS", errmsg);
1510
pthread_mutex_lock(&LOCK_thread_count);
1511
thd->current_linfo = 0;
1512
pthread_mutex_unlock(&LOCK_thread_count);
1330
1517
bool show_binlog_info(THD* thd)
1332
1519
Protocol *protocol= thd->protocol;
1333
1520
List<Item> field_list;
1334
1521
field_list.push_back(new Item_empty_string("File", FN_REFLEN));
1335
1522
field_list.push_back(new Item_return_int("Position",20,
1336
DRIZZLE_TYPE_LONGLONG));
1523
MYSQL_TYPE_LONGLONG));
1337
1524
field_list.push_back(new Item_empty_string("Binlog_Do_DB",255));
1338
1525
field_list.push_back(new Item_empty_string("Binlog_Ignore_DB",255));
1469
1656
for (block_len= my_b_get_bytes_in_buffer(file); block_len > 0;
1470
buffer += cmin(block_len, max_event_size),
1471
block_len -= cmin(block_len, max_event_size))
1657
buffer += min(block_len, max_event_size),
1658
block_len -= min(block_len, max_event_size))
1473
1660
lf_info->last_pos_in_file= my_b_get_pos_in_file(file);
1474
1661
if (lf_info->wrote_create_file)
1476
1663
Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer,
1477
cmin(block_len, max_event_size),
1664
min(block_len, max_event_size),
1478
1665
lf_info->log_delayed);
1479
1666
mysql_bin_log.write(&a);
1522
1709
static void fix_slave_net_timeout(THD *thd,
1523
enum_var_type type __attribute__((unused)))
1710
enum_var_type type __attribute__((__unused__)))
1712
#ifdef HAVE_REPLICATION
1525
1713
pthread_mutex_lock(&LOCK_active_mi);
1526
1714
if (active_mi && slave_net_timeout < active_mi->heartbeat_period)
1527
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1715
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1528
1716
ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
1529
1717
"The currect value for master_heartbeat_period"
1530
1718
" exceeds the new value of `slave_net_timeout' sec."
1531
1719
" A sensible value for the period should be"
1532
1720
" less than the timeout.");
1533
1721
pthread_mutex_unlock(&LOCK_active_mi);