sql_repl.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:40k
- /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB & Sasha
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
- #include "mysql_priv.h"
- #ifdef HAVE_REPLICATION
- #include "sql_repl.h"
- #include "log_event.h"
- #include <my_dir.h>
- int max_binlog_dump_events = 0; // unlimited
- my_bool opt_sporadic_binlog_dump_fail = 0;
- static int binlog_dump_count = 0;
- int check_binlog_magic(IO_CACHE* log, const char** errmsg)
- {
- char magic[4];
- DBUG_ASSERT(my_b_tell(log) == 0);
- if (my_b_read(log, (byte*) magic, sizeof(magic)))
- {
- *errmsg = "I/O error reading the header from the binary log";
- sql_print_error("%s, errno=%d, io cache code=%d", *errmsg, my_errno,
- log->error);
- return 1;
- }
- if (memcmp(magic, BINLOG_MAGIC, sizeof(magic)))
- {
- *errmsg = "Binlog has bad magic number; It's not a binary log file that can be used by this version of MySQL";
- return 1;
- }
- return 0;
- }
- static int fake_rotate_event(NET* net, String* packet, char* log_file_name,
- ulonglong position, const char**errmsg)
- {
- char header[LOG_EVENT_HEADER_LEN], buf[ROTATE_HEADER_LEN];
- memset(header, 0, 4); // when does not matter
- header[EVENT_TYPE_OFFSET] = ROTATE_EVENT;
- char* p = log_file_name+dirname_length(log_file_name);
- uint ident_len = (uint) strlen(p);
- ulong event_len = ident_len + ROTATE_EVENT_OVERHEAD;
- int4store(header + SERVER_ID_OFFSET, server_id);
- int4store(header + EVENT_LEN_OFFSET, event_len);
- int2store(header + FLAGS_OFFSET, 0);
-
- // TODO: check what problems this may cause and fix them
- int4store(header + LOG_POS_OFFSET, 0);
-
- packet->append(header, sizeof(header));
- int8store(buf+R_POS_OFFSET,position);
- packet->append(buf, ROTATE_HEADER_LEN);
- packet->append(p,ident_len);
- if (my_net_write(net, (char*)packet->ptr(), packet->length()))
- {
- *errmsg = "failed on my_net_write()";
- return -1;
- }
- return 0;
- }
- static int send_file(THD *thd)
- {
- NET* net = &thd->net;
- int fd = -1,bytes, error = 1;
- char fname[FN_REFLEN+1];
- const char *errmsg = 0;
- int old_timeout;
- unsigned long packet_len;
- char buf[IO_SIZE]; // It's safe to alloc this
- DBUG_ENTER("send_file");
- /*
- The client might be slow loading the data, give him wait_timeout to do
- the job
- */
- old_timeout = thd->net.read_timeout;
- thd->net.read_timeout = thd->variables.net_wait_timeout;
- /*
- We need net_flush here because the client will not know it needs to send
- us the file name until it has processed the load event entry
- */
- if (net_flush(net) || (packet_len = my_net_read(net)) == packet_error)
- {
- errmsg = "while reading file name";
- goto err;
- }
- // terminate with