mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
bug fixes in server-id, moved replication functionality to
sql_repl.* will push this one, since the replication code now works
This commit is contained in:
287
sql/sql_base.cc
287
sql/sql_base.cc
@ -42,71 +42,6 @@ static void mysql_rm_tmp_tables(void);
|
||||
static key_map get_key_map_from_key_list(THD *thd, TABLE *table,
|
||||
List<String> *index_list);
|
||||
|
||||
static int send_file(THD *thd)
|
||||
{
|
||||
NET* net = &thd->net;
|
||||
int fd = -1,bytes, error = 1;
|
||||
char fname[FN_REFLEN+1];
|
||||
char buf[IO_SIZE*15];
|
||||
const char *errmsg = 0;
|
||||
int old_timeout;
|
||||
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;
|
||||
|
||||
// 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) || my_net_read(net) == packet_error)
|
||||
{
|
||||
errmsg = "Failed reading file name";
|
||||
goto err;
|
||||
}
|
||||
|
||||
fn_format(fname, (char*)net->read_pos + 1, "", "", 4);
|
||||
// this is needed to make replicate-ignore-db
|
||||
if (!strcmp(fname,"/dev/null"))
|
||||
goto end;
|
||||
// TODO: work on the well-known system that does not have a /dev/null :-)
|
||||
|
||||
if ((fd = my_open(fname, O_RDONLY, MYF(MY_WME))) < 0)
|
||||
{
|
||||
errmsg = "Failed on my_open()";
|
||||
goto err;
|
||||
}
|
||||
|
||||
while ((bytes = (int) my_read(fd, (byte*) buf, sizeof(buf),
|
||||
MYF(MY_WME))) > 0)
|
||||
{
|
||||
if (my_net_write(net, buf, bytes))
|
||||
{
|
||||
errmsg = "Failed on my_net_write()";
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
if (my_net_write(net, "", 0) || net_flush(net) ||
|
||||
(my_net_read(net) == packet_error))
|
||||
{
|
||||
errmsg = "failed negotiating file transfer close";
|
||||
goto err;
|
||||
}
|
||||
error = 0;
|
||||
|
||||
err:
|
||||
thd->net.timeout = old_timeout;
|
||||
if(fd >= 0)
|
||||
(void) my_close(fd, MYF(MY_WME));
|
||||
if (errmsg)
|
||||
{
|
||||
sql_print_error("failed in send_file() : %s", errmsg);
|
||||
DBUG_PRINT("error", (errmsg));
|
||||
}
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
static byte *cache_key(const byte *record,uint *length,
|
||||
my_bool not_used __attribute__((unused)))
|
||||
@ -177,228 +112,6 @@ static void check_unused(void)
|
||||
#define check_unused()
|
||||
#endif
|
||||
|
||||
void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags)
|
||||
{
|
||||
LOG_INFO linfo;
|
||||
char *log_file_name = linfo.log_file_name;
|
||||
char search_file_name[FN_REFLEN];
|
||||
FILE* log = NULL;
|
||||
String* packet = &thd->packet;
|
||||
int error;
|
||||
const char *errmsg = "Unknown error";
|
||||
NET* net = &thd->net;
|
||||
|
||||
DBUG_ENTER("mysql_binlog_send");
|
||||
|
||||
if(!mysql_bin_log.is_open())
|
||||
{
|
||||
errmsg = "Binary log is not open";
|
||||
goto err;
|
||||
}
|
||||
|
||||
if(log_ident[0])
|
||||
mysql_bin_log.make_log_name(search_file_name, log_ident);
|
||||
else
|
||||
search_file_name[0] = 0;
|
||||
|
||||
if(mysql_bin_log.find_first_log(&linfo, search_file_name))
|
||||
{
|
||||
errmsg = "Could not find first log";
|
||||
goto err;
|
||||
}
|
||||
log = my_fopen(log_file_name, O_RDONLY, MYF(MY_WME));
|
||||
|
||||
if(!log)
|
||||
{
|
||||
errmsg = "Could not open log file";
|
||||
goto err;
|
||||
}
|
||||
|
||||
if(my_fseek(log, pos, MY_SEEK_SET, MYF(MY_WME)) == MY_FILEPOS_ERROR )
|
||||
{
|
||||
errmsg = "Error on fseek()";
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
packet->length(0);
|
||||
packet->append("\0", 1); // we need to start a packet with something other than 255
|
||||
// to distiquish it from error
|
||||
|
||||
while(!net->error && net->vio != 0 && !thd->killed)
|
||||
{
|
||||
while(!(error = Log_event::read_log_event(log, packet)))
|
||||
{
|
||||
if(my_net_write(net, (char*)packet->ptr(), packet->length()) )
|
||||
{
|
||||
errmsg = "Failed on my_net_write()";
|
||||
goto err;
|
||||
}
|
||||
DBUG_PRINT("info", ("log event code %d",(*packet)[LOG_EVENT_OFFSET+1] ));
|
||||
if((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT)
|
||||
{
|
||||
if(send_file(thd))
|
||||
{
|
||||
errmsg = "failed in send_file()";
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
packet->length(0);
|
||||
packet->append("\0",1);
|
||||
}
|
||||
if(error != LOG_READ_EOF)
|
||||
{
|
||||
errmsg = "error reading log event";
|
||||
goto err;
|
||||
}
|
||||
|
||||
if(!(flags & BINLOG_DUMP_NON_BLOCK) && mysql_bin_log.is_active(log_file_name))
|
||||
// block until there is more data in the log
|
||||
// unless non-blocking mode requested
|
||||
{
|
||||
if(net_flush(net))
|
||||
{
|
||||
errmsg = "failed on net_flush()";
|
||||
goto err;
|
||||
}
|
||||
|
||||
// we may have missed the update broadcast from the log
|
||||
// that has just happened, let's try to catch it if it did
|
||||
// if we did not miss anything, we just wait for other threads
|
||||
// to signal us
|
||||
{
|
||||
pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
|
||||
clearerr(log);
|
||||
|
||||
// tell the kill thread how to wake us up
|
||||
pthread_mutex_lock(&thd->mysys_var->mutex);
|
||||
thd->mysys_var->current_mutex = log_lock;
|
||||
thd->mysys_var->current_cond = &COND_binlog_update;
|
||||
const char* proc_info = thd->proc_info;
|
||||
thd->proc_info = "Waiting for update";
|
||||
pthread_mutex_unlock(&thd->mysys_var->mutex);
|
||||
|
||||
bool read_packet = 0, fatal_error = 0;
|
||||
|
||||
pthread_mutex_lock(log_lock); // no one will update the log while we are reading
|
||||
// now, but we'll be quick and just read one record
|
||||
|
||||
|
||||
switch(Log_event::read_log_event(log, packet))
|
||||
{
|
||||
case 0:
|
||||
read_packet = 1; // we read successfully, so we'll need to send it to the
|
||||
// slave
|
||||
break;
|
||||
case LOG_READ_EOF:
|
||||
pthread_cond_wait(&COND_binlog_update, log_lock);
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal_error = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(log_lock);
|
||||
|
||||
pthread_mutex_lock(&thd->mysys_var->mutex);
|
||||
thd->mysys_var->current_mutex= 0;
|
||||
thd->mysys_var->current_cond= 0;
|
||||
thd->proc_info= proc_info;
|
||||
pthread_mutex_unlock(&thd->mysys_var->mutex);
|
||||
|
||||
if(read_packet)
|
||||
{
|
||||
if(my_net_write(net, (char*)packet->ptr(), packet->length()) )
|
||||
{
|
||||
errmsg = "Failed on my_net_write()";
|
||||
goto err;
|
||||
}
|
||||
|
||||
if((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT)
|
||||
{
|
||||
if(send_file(thd))
|
||||
{
|
||||
errmsg = "failed in send_file()";
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
packet->length(0);
|
||||
packet->append("\0",1);
|
||||
// no need to net_flush because we will get to flush later when
|
||||
// we hit EOF pretty quick
|
||||
}
|
||||
|
||||
if(fatal_error)
|
||||
{
|
||||
errmsg = "error reading log entry";
|
||||
goto err;
|
||||
}
|
||||
|
||||
clearerr(log);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool loop_breaker = 0; // need this to break out of the for loop from switch
|
||||
|
||||
switch(mysql_bin_log.find_next_log(&linfo))
|
||||
{
|
||||
case LOG_INFO_EOF:
|
||||
loop_breaker = (flags & BINLOG_DUMP_NON_BLOCK);
|
||||
break;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
errmsg = "could not find next log";
|
||||
goto err;
|
||||
}
|
||||
|
||||
if(loop_breaker)
|
||||
break;
|
||||
|
||||
(void) my_fclose(log, MYF(MY_WME));
|
||||
log = my_fopen(log_file_name, O_RDONLY, MYF(MY_WME));
|
||||
if(!log)
|
||||
goto err;
|
||||
// fake Rotate_log event just in case it did not make it to the log
|
||||
// otherwise the slave make get confused about the offset
|
||||
{
|
||||
char header[9];
|
||||
memset(header, 0, 4); // when does not matter
|
||||
header[4] = 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 + 5, 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()";
|
||||
goto err;
|
||||
}
|
||||
packet->length(0);
|
||||
packet->append("\0",1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(void)my_fclose(log, MYF(MY_WME));
|
||||
|
||||
send_eof(&thd->net);
|
||||
DBUG_VOID_RETURN;
|
||||
err:
|
||||
if(log)
|
||||
(void) my_fclose(log, MYF(MY_WME));
|
||||
send_error(&thd->net, 0, errmsg);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
|
Reference in New Issue
Block a user