summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authormonty@donna.mysql.com <>2000-11-28 04:47:47 +0200
committermonty@donna.mysql.com <>2000-11-28 04:47:47 +0200
commit74e7ffe9872e74f3ac1ae4e93a2ef1b0d2c97c03 (patch)
treee3d40dd7c6a7e86bd2388da19d59d5a372bf7bb8 /sql
parentad2e43c7d6f4b7bbe5b92830ef11856c7d18b6b5 (diff)
downloadmariadb-git-74e7ffe9872e74f3ac1ae4e93a2ef1b0d2c97c03.tar.gz
New thr_alarm struct for better integration with OS2
Run bootstrap in separate thread Fix bug in FLUSH TABLES table_name
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_myisam.cc6
-rw-r--r--sql/my_lock.c2
-rw-r--r--sql/mysql_priv.h8
-rw-r--r--sql/mysqld.cc26
-rw-r--r--sql/net_serv.cc20
-rw-r--r--sql/sql_base.cc14
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_delete.cc3
-rw-r--r--sql/sql_load.cc2
-rw-r--r--sql/sql_parse.cc39
-rw-r--r--sql/sql_select.cc3
-rw-r--r--sql/sql_table.cc2
-rw-r--r--sql/violite.c5
14 files changed, 87 insertions, 46 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 7f658303a4c..229c24df107 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -199,11 +199,11 @@ err:
return error;
}
+ /* Name is here without an extension */
+
int ha_myisam::open(const char *name, int mode, uint test_if_locked)
{
- char name_buff[FN_REFLEN];
- if (!(file=mi_open(fn_format(name_buff,name,"","",2 | 4), mode,
- test_if_locked)))
+ if (!(file=mi_open(name, mode, test_if_locked)))
return (my_errno ? my_errno : -1);
if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE))
diff --git a/sql/my_lock.c b/sql/my_lock.c
index 6c35634203f..7025682d40e 100644
--- a/sql/my_lock.c
+++ b/sql/my_lock.c
@@ -54,7 +54,7 @@ int my_lock(File fd,int locktype,my_off_t start,my_off_t length,myf MyFlags)
if (!thr_alarm(&alarmed,wait_for_alarm,&alarm_buff))
{
int value;
- while ((value=fcntl(fd,F_SETLKW,&lock)) && !thr_got_alarm(alarmed) &&
+ while ((value=fcntl(fd,F_SETLKW,&lock)) && !thr_got_alarm(&alarmed) &&
errno == EINTR) ;
thr_end_alarm(&alarmed);
if (value != -1)
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 10e470ffc78..f2f9e48e889 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -27,6 +27,8 @@
#include <my_base.h> /* Needed by field.h */
#include <violite.h>
+#undef write // remove pthread.h macro definition for EMX
+
typedef ulong table_map; /* Used for table bits in join */
typedef ulong key_map; /* Used for finding keys */
typedef ulong key_part_map; /* Used for finding key parts */
@@ -223,7 +225,7 @@ bool mysql_change_db(THD *thd,const char *name);
void mysql_parse(THD *thd,char *inBuf,uint length);
void mysql_init_select(LEX *lex);
pthread_handler_decl(handle_one_connection,arg);
-int handle_bootstrap(THD *thd,FILE *file);
+pthread_handler_decl(handle_bootstrap,arg);
sig_handler end_thread_signal(int sig);
void end_thread(THD *thd,bool put_in_cache);
void flush_thread_cache();
@@ -405,7 +407,8 @@ bool rename_temporary_table(TABLE *table, const char *new_db,
const char *table_name);
void remove_db_from_cache(const my_string db);
void flush_tables();
-bool remove_table_from_cache(THD *thd, const char *db, const char *table);
+bool remove_table_from_cache(THD *thd, const char *db, const char *table,
+ bool return_if_owned_by_thd=0);
bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables);
void copy_field_from_tmp_record(Field *field,int offset);
int fill_record(List<Item> &fields,List<Item> &values);
@@ -462,6 +465,7 @@ extern time_t start_time;
extern const char *command_name[];
extern I_List<THD> threads;
extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log;
+extern FILE *bootstrap_file;
extern pthread_key(MEM_ROOT*,THR_MALLOC);
extern pthread_key(NET*, THR_NET);
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open,
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 316b97f5c52..78fcc2f563c 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -159,6 +159,7 @@ static bool opt_log,opt_update_log,opt_bin_log,opt_slow_log,opt_noacl,
opt_disable_networking=0, opt_bootstrap=0,opt_skip_show_db=0,
opt_ansi_mode=0,opt_myisam_log=0, opt_large_files=sizeof(my_off_t) > 4;
bool opt_sql_bin_update = 0, opt_log_slave_updates = 0;
+FILE *bootstrap_file=0;
extern MASTER_INFO glob_mi;
extern int init_master_info(MASTER_INFO* mi);
@@ -1001,7 +1002,8 @@ static void init_signals(void)
#elif defined(__EMX__)
static void sig_reload(int signo)
{
- reload_acl_and_cache(~0); // Flush everything
+ //reload_acl_and_cache(~0); // Flush everything
+ reload_acl_and_cache((THD*) 0,~0, (TABLE_LIST*) 0); // Flush everything
signal(signo, SIG_ACK);
}
@@ -1327,7 +1329,7 @@ int main(int argc, char **argv)
{
struct tm *start_tm;
start_tm=localtime(&start_time);
- strmov(time_zone=tzname[start_tm->tm_isdst == 1 ? 1 : 0]);
+ strmov(time_zone,tzname[start_tm->tm_isdst == 1 ? 1 : 0]);
}
#endif
#endif
@@ -1780,9 +1782,25 @@ static int bootstrap(FILE *file)
my_net_init(&thd->net,(Vio*) 0);
thd->max_packet_length=thd->net.max_packet;
thd->master_access= ~0;
+ thd->thread_id=thread_id++;
thread_count++;
- thd->real_id=pthread_self();
- error=handle_bootstrap(thd,file);
+
+ bootstrap_file=file;
+ if (pthread_create(&thd->real_id,&connection_attrib,handle_bootstrap,
+ (void*) thd))
+ {
+ sql_print_error("Warning: Can't create thread to handle bootstrap");
+ return -1;
+ }
+ /* Wait for thread to die */
+ (void) pthread_mutex_lock(&LOCK_thread_count);
+ while (thread_count)
+ {
+ (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
+ DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
+ }
+ (void) pthread_mutex_unlock(&LOCK_thread_count);
+ error= thd->fatal_error;
net_end(&thd->net);
delete thd;
return error;
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index 14bf2700378..8b0603473a6 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -71,7 +71,7 @@ extern ulong mysqld_net_retry_count;
typedef my_bool thr_alarm_t;
typedef my_bool ALARM;
#define thr_alarm_init(A) (*A)=0
-#define thr_alarm_in_use(A) (A)
+#define thr_alarm_in_use(A) (*(A))
#define thr_end_alarm(A)
#define thr_alarm(A,B,C) local_thr_alarm((A),(B),(C))
static inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM *C __attribute__((unused)))
@@ -271,7 +271,7 @@ net_real_write(NET *net,const char *packet,ulong len)
int length;
char *pos,*end;
thr_alarm_t alarmed;
-#if (!defined(__WIN__) && !defined(__EMX__))
+#if !defined(__WIN__)
ALARM alarm_buff;
#endif
uint retry_count=0;
@@ -330,7 +330,7 @@ net_real_write(NET *net,const char *packet,ulong len)
{
my_bool interrupted = vio_should_retry(net->vio);
#if (!defined(__WIN__) && !defined(__EMX__))
- if ((interrupted || length==0) && !thr_alarm_in_use(alarmed))
+ if ((interrupted || length==0) && !thr_alarm_in_use(&alarmed))
{
if (!thr_alarm(&alarmed,(uint) net_write_timeout,&alarm_buff))
{ /* Always true for client */
@@ -355,7 +355,7 @@ net_real_write(NET *net,const char *packet,ulong len)
}
else
#endif /* (!defined(__WIN__) && !defined(__EMX__)) */
- if (thr_alarm_in_use(alarmed) && !thr_got_alarm(alarmed) &&
+ if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) &&
interrupted)
{
if (retry_count++ < RETRY_COUNT)
@@ -389,7 +389,7 @@ net_real_write(NET *net,const char *packet,ulong len)
if (net->compress)
my_free((char*) packet,MYF(0));
#endif
- if (thr_alarm_in_use(alarmed))
+ if (thr_alarm_in_use(&alarmed))
{
thr_end_alarm(&alarmed);
vio_blocking(net->vio, net_blocking);
@@ -414,7 +414,7 @@ static void my_net_skip_rest(NET *net, ulong remain, thr_alarm_t *alarmed)
{
ALARM alarm_buff;
uint retry_count=0;
- if (!thr_alarm_in_use(alarmed))
+ if (!thr_alarm_in_use(&alarmed))
{
if (!thr_alarm(alarmed,net->timeout,&alarm_buff) ||
(!vio_is_blocking(net->vio) && vio_blocking(net->vio,TRUE) < 0))
@@ -426,7 +426,7 @@ static void my_net_skip_rest(NET *net, ulong remain, thr_alarm_t *alarmed)
if ((int) (length=vio_read(net->vio,(char*) net->buff,remain)) <= 0L)
{
my_bool interrupted = vio_should_retry(net->vio);
- if (!thr_got_alarm(alarmed) && interrupted)
+ if (!thr_got_alarm(&alarmed) && interrupted)
{ /* Probably in MIT threads */
if (retry_count++ < RETRY_COUNT)
continue;
@@ -481,7 +481,7 @@ my_real_read(NET *net, ulong *complen)
an alarm to not 'read forever', change the socket to non blocking
mode and try again
*/
- if ((interrupted || length == 0) && !thr_alarm_in_use(alarmed))
+ if ((interrupted || length == 0) && !thr_alarm_in_use(&alarmed))
{
if (!thr_alarm(&alarmed,net->timeout,&alarm_buff)) /* Don't wait too long */
{
@@ -513,7 +513,7 @@ my_real_read(NET *net, ulong *complen)
}
}
#endif /* (!defined(__WIN__) && !defined(__EMX__)) || defined(MYSQL_SERVER) */
- if (thr_alarm_in_use(alarmed) && !thr_got_alarm(alarmed) &&
+ if (thr_alarm_in_use(&alarmed) && !thr_got_alarm(&alarmed) &&
interrupted)
{ /* Probably in MIT threads */
if (retry_count++ < RETRY_COUNT)
@@ -597,7 +597,7 @@ my_real_read(NET *net, ulong *complen)
}
end:
- if (thr_alarm_in_use(alarmed))
+ if (thr_alarm_in_use(&alarmed))
{
thr_end_alarm(&alarmed);
vio_blocking(net->vio, net_blocking);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 3560fc42d49..66c4a22ad67 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -275,7 +275,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
bool found=0;
for (TABLE_LIST *table=tables ; table ; table=table->next)
{
- if (remove_table_from_cache(thd, table->db, table->name))
+ if (remove_table_from_cache(thd, table->db, table->name, 1))
found=1;
}
if (!found)
@@ -1972,7 +1972,8 @@ void flush_tables()
** Returns true if the table is in use by another thread
*/
-bool remove_table_from_cache(THD *thd, const char *db,const char *table_name)
+bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
+ bool return_if_owned_by_thd)
{
char key[MAX_DBKEY_LENGTH];
uint key_length;
@@ -1985,13 +1986,12 @@ bool remove_table_from_cache(THD *thd, const char *db,const char *table_name)
table;
table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length))
{
+ THD *in_use;
table->version=0L; /* Free when thread is ready */
- if (!table->in_use)
+ if (!(in_use=table->in_use))
relink_unused(table);
- else if (table->in_use != thd)
+ else if (in_use != thd)
{
- THD *in_use=table->in_use;
-
in_use->some_tables_deleted=1;
if (table->db_stat)
result=1;
@@ -2009,6 +2009,8 @@ bool remove_table_from_cache(THD *thd, const char *db,const char *table_name)
pthread_mutex_unlock(&in_use->mysys_var->mutex);
}
}
+ else
+ result= result || return_if_owned_by_thd;
}
while (unused_tables && !unused_tables->version)
VOID(hash_delete(&open_cache,(byte*) unused_tables));
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 696c111c01a..5be229a2695 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -80,7 +80,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
global_read_lock(0)
{
proc_info="login";
- host=user=db=query=ip=0;
+ host=user=priv_user=db=query=ip=0;
locked=killed=count_cuted_fields=some_tables_deleted=no_errors=password=
query_start_used=0;
query_length=col_access=0;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 4003b057c06..83c70f29d19 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -21,7 +21,6 @@
#pragma interface /* gcc class implementation */
#endif
-
class Query_log_event;
class Load_log_event;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 1159fc56ee6..807464552a7 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -24,8 +24,7 @@
This will work even if the .ISM and .ISD tables are destroyed
*/
-int generate_table(THD *thd, TABLE_LIST *table_list,
- TABLE *locked_table)
+int generate_table(THD *thd, TABLE_LIST *table_list, TABLE *locked_table)
{
char path[FN_REFLEN];
int error;
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index de6d006a80e..1cb042537fc 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -163,7 +163,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
// the file must be:
if (!((stat_info.st_mode & S_IROTH) == S_IROTH && // readable by others
+#ifndef __EMX__
(stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
+#endif
((stat_info.st_mode & S_IFREG) == S_IFREG ||
(stat_info.st_mode & S_IFIFO) == S_IFIFO)))
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 195a7a4f525..5eba2ab880b 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -428,19 +428,26 @@ end_thread:
return(0); /* purecov: deadcode */
}
+/*
+ Execute commands from bootstrap_file.
+ Used when creating the initial grant tables
+*/
-int handle_bootstrap(THD *thd,FILE *file)
+pthread_handler_decl(handle_bootstrap,arg)
{
+ THD *thd=(THD*) arg;
+ FILE *file=bootstrap_file;
+ char *buff;
DBUG_ENTER("handle_bootstrap");
+
+ pthread_detach_this_thread();
thd->thread_stack= (char*) &thd;
- if (init_thr_lock() ||
- my_pthread_setspecific_ptr(THR_THD, thd) ||
- my_pthread_setspecific_ptr(THR_MALLOC, &thd->mem_root) ||
- my_pthread_setspecific_ptr(THR_NET, &thd->net))
+ if (my_thread_init() || thd->store_globals())
{
close_connection(&thd->net,ER_OUT_OF_RESOURCES);
- DBUG_RETURN(-1);
+ thd->fatal_error=1;
+ goto end;
}
thd->mysys_var=my_thread_var;
thd->dbug_thread_id=my_thread_id();
@@ -455,8 +462,9 @@ int handle_bootstrap(THD *thd,FILE *file)
thd->proc_info=0;
thd->version=refresh_version;
+ thd->priv_user=thd->user="boot";
- char *buff= (char*) thd->net.buff;
+ buff= (char*) thd->net.buff;
init_sql_alloc(&thd->mem_root,8192,8192);
while (fgets(buff, thd->net.max_packet, file))
{
@@ -470,13 +478,20 @@ int handle_bootstrap(THD *thd,FILE *file)
mysql_parse(thd,thd->query,length);
close_thread_tables(thd); // Free tables
if (thd->fatal_error)
- {
- DBUG_RETURN(-1);
- }
+ break;
free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC));
}
- free_root(&thd->mem_root,MYF(0));
- DBUG_RETURN(0);
+ thd->priv_user=thd->user=0;
+
+ /* thd->fatal_error should be set in case something went wrong */
+end:
+ (void) pthread_mutex_lock(&LOCK_thread_count);
+ thread_count--;
+ (void) pthread_cond_broadcast(&COND_thread_count);
+ (void) pthread_mutex_unlock(&LOCK_thread_count);
+ my_thread_end();
+ pthread_exit(0);
+ DBUG_RETURN(0); // Never reached
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 29ef01e8196..8856d31645c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3520,6 +3520,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
{
Field *field=(*group->item)->tmp_table_field();
bool maybe_null=(*group->item)->maybe_null;
+ key_part_info->null_bit=0;
key_part_info->field= field;
key_part_info->offset= field->offset();
key_part_info->length= (uint16) field->pack_length();
@@ -3581,6 +3582,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
keyinfo->name=(char*) "tmp";
if (null_count)
{
+ key_part_info->null_bit=0;
key_part_info->offset=0;
key_part_info->length=(null_count+7)/8;
key_part_info->field=new Field_string((char*) table->record[0],
@@ -3596,6 +3598,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
for (i=0,reg_field=table->field; i < field_count;
i++, reg_field++, key_part_info++)
{
+ key_part_info->null_bit=0;
key_part_info->field= *reg_field;
key_part_info->offset= (*reg_field)->offset();
key_part_info->length= (uint16) (*reg_field)->pack_length();
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 2c59f4b3482..f51e1d1abe8 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1482,7 +1482,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
}
-#ifdef __WIN__
+#if defined( __WIN__) || defined( __EMX__)
// Win32 can't rename an open table, so we must close the org table!
table_name=thd->strdup(table_name); // must be saved
if (close_cached_table(thd,table))
diff --git a/sql/violite.c b/sql/violite.c
index 4efda9f3b90..253ef7bb468 100644
--- a/sql/violite.c
+++ b/sql/violite.c
@@ -38,8 +38,7 @@
#if defined(__EMX__)
#include <sys/ioctl.h>
-#define ioctlsocket(A,B,C) ioctl((A),(B),(void *)(C),sizeof(*(C)))
-#undef HAVE_FCNTL
+#define ioctlsocket ioctl
#endif /* defined(__EMX__) */
#if defined(MSDOS) || defined(__WIN__)
@@ -111,7 +110,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost)
#else /* !defined(__WIN__) && !defined(__EMX__) */
{
/* set to blocking mode by default */
- ulong arg=0;
+ ulong arg=0, r;
r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg, sizeof(arg));
}
#endif