mirror of
https://github.com/MariaDB/server.git
synced 2026-04-26 10:15:29 +02:00
updates for LOAD DATA FROM MASTER + some cleanup of replication code
include/mysqld_error.h: new errors mysql-test/r/rpl000009.result: test load data from master mysql-test/t/rpl000009.test: test load data from master sql/mini_client.cc: extra functionality needed for load data from master and other things sql/mini_client.h: addition to API sql/mysql_priv.h: mysql_create_db()/mysql_rm_db() now return a value sql/share/english/errmsg.txt: more error messages sql/slave.cc: cleanup of fetch_nx_table() sql/slave.h: cleanup of fetch_nx_table() sql/sql_base.cc: remove unused code originally written for retrieving a non-existent table in slave thread sql/sql_class.cc: remove unused replication variables sql/sql_class.h: remove unused replication variabled sql/sql_db.cc: make mysql_create_db()/mysql_rm_db() work with thd == 0 (do not write messages to the net) and instead return success/error sql/sql_lex.h: added SQLCOM_LOAD_MASTER_DATA sql/sql_parse.cc: LOAD MASTER DATA, cleanup of LOAD TABLE FROM MASTER sql/sql_repl.cc: LOAD DATA FROM MASTER sql/sql_repl.h: LOAD DATA FROM MASTER sql/sql_yacc.yy: LOAD DATA FROM MASTER
This commit is contained in:
parent
403b38ee50
commit
704becf228
18 changed files with 932 additions and 83 deletions
|
|
@ -30,11 +30,12 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *path,
|
|||
|
||||
/* db-name is already validated when we come here */
|
||||
|
||||
void mysql_create_db(THD *thd, char *db, uint create_options)
|
||||
int mysql_create_db(THD *thd, char *db, uint create_options)
|
||||
{
|
||||
char path[FN_REFLEN+16];
|
||||
MY_DIR *dirp;
|
||||
long result=1;
|
||||
int error = 0;
|
||||
DBUG_ENTER("mysql_create_db");
|
||||
|
||||
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
|
||||
|
|
@ -47,7 +48,9 @@ void mysql_create_db(THD *thd, char *db, uint create_options)
|
|||
my_dirend(dirp);
|
||||
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
|
||||
{
|
||||
net_printf(&thd->net,ER_DB_CREATE_EXISTS,db);
|
||||
if(thd)
|
||||
net_printf(&thd->net,ER_DB_CREATE_EXISTS,db);
|
||||
error = 1;
|
||||
goto exit;
|
||||
}
|
||||
result = 0;
|
||||
|
|
@ -57,34 +60,39 @@ void mysql_create_db(THD *thd, char *db, uint create_options)
|
|||
strend(path)[-1]=0; // Remove last '/' from path
|
||||
if (my_mkdir(path,0777,MYF(0)) < 0)
|
||||
{
|
||||
net_printf(&thd->net,ER_CANT_CREATE_DB,db,my_errno);
|
||||
if(thd)
|
||||
net_printf(&thd->net,ER_CANT_CREATE_DB,db,my_errno);
|
||||
error = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
if (!thd->query)
|
||||
{
|
||||
thd->query = path;
|
||||
thd->query_length = (uint) (strxmov(path,"create database ", db, NullS)-
|
||||
path);
|
||||
}
|
||||
{
|
||||
mysql_update_log.write(thd,thd->query, thd->query_length);
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
Query_log_event qinfo(thd, thd->query);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
}
|
||||
if (thd->query == path)
|
||||
{
|
||||
thd->query = 0; // just in case
|
||||
thd->query_length = 0;
|
||||
}
|
||||
send_ok(&thd->net, result);
|
||||
|
||||
if(thd)
|
||||
{
|
||||
if (!thd->query)
|
||||
{
|
||||
thd->query = path;
|
||||
thd->query_length = (uint) (strxmov(path,"create database ", db, NullS)-
|
||||
path);
|
||||
}
|
||||
{
|
||||
mysql_update_log.write(thd,thd->query, thd->query_length);
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
Query_log_event qinfo(thd, thd->query);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
}
|
||||
if (thd->query == path)
|
||||
{
|
||||
thd->query = 0; // just in case
|
||||
thd->query_length = 0;
|
||||
}
|
||||
send_ok(&thd->net, result);
|
||||
}
|
||||
exit:
|
||||
VOID(pthread_mutex_unlock(&LOCK_mysql_create_db));
|
||||
DBUG_VOID_RETURN;
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
const char *del_exts[]=
|
||||
|
|
@ -94,10 +102,14 @@ static TYPELIB deletable_extentions=
|
|||
|
||||
|
||||
/* db-name is already validated when we come here */
|
||||
|
||||
void mysql_rm_db(THD *thd,char *db,bool if_exists)
|
||||
/* If thd == 0, do not write any messages
|
||||
This is useful in replication when we want to remove
|
||||
a stale database before replacing it with the new one
|
||||
*/
|
||||
int mysql_rm_db(THD *thd,char *db,bool if_exists)
|
||||
{
|
||||
long deleted=0;
|
||||
int error = 0;
|
||||
char path[FN_REFLEN+16];
|
||||
MY_DIR *dirp;
|
||||
DBUG_ENTER("mysql_rm_db");
|
||||
|
|
@ -110,15 +122,19 @@ void mysql_rm_db(THD *thd,char *db,bool if_exists)
|
|||
/* See if the directory exists */
|
||||
if (!(dirp = my_dir(path,MYF(MY_WME | MY_DONT_SORT))))
|
||||
{
|
||||
if (!if_exists)
|
||||
net_printf(&thd->net,ER_DB_DROP_EXISTS,db);
|
||||
else
|
||||
send_ok(&thd->net,0);
|
||||
if(thd)
|
||||
{
|
||||
if (!if_exists)
|
||||
net_printf(&thd->net,ER_DB_DROP_EXISTS,db);
|
||||
else
|
||||
send_ok(&thd->net,0);
|
||||
}
|
||||
error = !if_exists;
|
||||
goto exit;
|
||||
}
|
||||
remove_db_from_cache(db);
|
||||
|
||||
if ((deleted=mysql_rm_known_files(thd, dirp, path,0)) >= 0)
|
||||
if ((deleted=mysql_rm_known_files(thd, dirp, path,0)) >= 0 && thd)
|
||||
{
|
||||
if (!thd->query)
|
||||
{
|
||||
|
|
@ -137,13 +153,14 @@ void mysql_rm_db(THD *thd,char *db,bool if_exists)
|
|||
thd->query = 0; // just in case
|
||||
thd->query_length = 0;
|
||||
}
|
||||
|
||||
send_ok(&thd->net,(ulong) deleted);
|
||||
}
|
||||
|
||||
exit:
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
VOID(pthread_mutex_unlock(&LOCK_mysql_create_db));
|
||||
DBUG_VOID_RETURN;
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -151,6 +168,7 @@ exit:
|
|||
are 2 digits (raid directories).
|
||||
*/
|
||||
|
||||
/* This one also needs to work with thd == 0 for replication */
|
||||
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *org_path,
|
||||
uint level)
|
||||
{
|
||||
|
|
@ -162,7 +180,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *org_path,
|
|||
/* remove all files with known extensions */
|
||||
|
||||
for (uint idx=2 ;
|
||||
idx < (uint) dirp->number_off_files && !thd->killed ;
|
||||
idx < (uint) dirp->number_off_files && (!thd || !thd->killed) ;
|
||||
idx++)
|
||||
{
|
||||
FILEINFO *file=dirp->dir_entry+idx;
|
||||
|
|
@ -196,7 +214,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *org_path,
|
|||
unpack_filename(filePath,filePath);
|
||||
if (my_delete(filePath,MYF(MY_WME)))
|
||||
{
|
||||
net_printf(&thd->net,ER_DB_DROP_DELETE,filePath,my_error);
|
||||
if(thd)
|
||||
net_printf(&thd->net,ER_DB_DROP_DELETE,filePath,my_error);
|
||||
my_dirend(dirp);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
|
@ -205,7 +224,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *org_path,
|
|||
|
||||
my_dirend(dirp);
|
||||
|
||||
if (thd->killed)
|
||||
if (thd && thd->killed)
|
||||
{
|
||||
send_error(&thd->net,ER_SERVER_SHUTDOWN);
|
||||
DBUG_RETURN(-1);
|
||||
|
|
@ -229,7 +248,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *org_path,
|
|||
/* Don't give errors if we can't delete 'RAID' directory */
|
||||
if (level)
|
||||
DBUG_RETURN(deleted);
|
||||
send_error(&thd->net);
|
||||
if(thd)
|
||||
send_error(&thd->net);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
path=filePath;
|
||||
|
|
@ -242,7 +262,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *org_path,
|
|||
/* Don't give errors if we can't delete 'RAID' directory */
|
||||
if (rmdir(path) < 0 && !level)
|
||||
{
|
||||
net_printf(&thd->net,ER_DB_DROP_RMDIR, path,errno);
|
||||
if(thd)
|
||||
net_printf(&thd->net,ER_DB_DROP_RMDIR, path,errno);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue