sql_repl.cc
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:21k
- /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
- 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 */
- // Sasha Pachev <sasha@mysql.com> is currently in charge of this file
- // Do not mess with it without his permission!
- #include "mysql_priv.h"
- #include "sql_repl.h"
- #include "sql_acl.h"
- #include "log_event.h"
- #include <thr_alarm.h>
- #include <my_dir.h>
- extern const char* any_db;
- extern pthread_handler_decl(handle_slave,arg);
- static int fake_rotate_event(NET* net, String* packet, char* log_file_name,
- const char**errmsg)
- {
- char header[LOG_EVENT_HEADER_LEN];
- memset(header, 0, 4); // when does not matter
- header[EVENT_TYPE_OFFSET] = ROTATE_EVENT;
- char* p = strrchr(log_file_name, FN_LIBCHAR);
- // find the last slash
- if(p)
- p++;
- else
- p = log_file_name;
- uint ident_len = (uint) strlen(p);
- ulong event_len = ident_len + sizeof(header);
- int4store(header + EVENT_TYPE_OFFSET + 1, server_id);
- int4store(header + EVENT_LEN_OFFSET, event_len);
- packet->append(header, sizeof(header));
- 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];
- char *buf;
- const char *errmsg = 0;
- int old_timeout;
- uint packet_len;
- DBUG_ENTER("send_file");
- // the client might be slow loading the data, give him wait_timeout to do
- // the job
- old_timeout = thd->net.timeout;
- thd->net.timeout = thd->inactive_timeout;
- // spare the stack
- if(!(buf = alloc_root(&thd->mem_root,IO_SIZE)))
- {
- errmsg = "Out of memory";
- goto err;
- }
- // 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 = "Failed reading file name";
- goto err;
- }
- *((char*)net->read_pos + packet_len) = 0; // terminate with