Commit f6a365a5 authored by monty@narttu.mysql.fi's avatar monty@narttu.mysql.fi

Small fixes (nothing nameworthy)

parent f6579fd9
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000-2003 MySQL AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -640,6 +640,9 @@ typedef long my_ptrdiff_t; ...@@ -640,6 +640,9 @@ typedef long my_ptrdiff_t;
typedef long long my_ptrdiff_t; typedef long long my_ptrdiff_t;
#endif #endif
/* typedef used for length of string; Should be unsigned! */
typedef ulong size_str;
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1)) #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double)) #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
/* Size to make adressable obj. */ /* Size to make adressable obj. */
......
...@@ -295,7 +295,8 @@ os_file_handle_error( ...@@ -295,7 +295,8 @@ os_file_handle_error(
/* out: TRUE if we should retry the /* out: TRUE if we should retry the
operation */ operation */
os_file_t file, /* in: file pointer */ os_file_t file, /* in: file pointer */
char* name) /* in: name of a file or NULL */ char* name, /* in: name of a file or NULL */
const char* operation) /* in: type of operation */
{ {
ulint err; ulint err;
...@@ -337,7 +338,8 @@ os_file_handle_error( ...@@ -337,7 +338,8 @@ os_file_handle_error(
if (name) { if (name) {
fprintf(stderr, "InnoDB: File name %s\n", name); fprintf(stderr, "InnoDB: File name %s\n", name);
} }
fprintf(stderr, "InnoDB: system call %s\n", operation);
fprintf(stderr, "InnoDB: Cannot continue operation.\n"); fprintf(stderr, "InnoDB: Cannot continue operation.\n");
fflush(stderr); fflush(stderr);
...@@ -419,7 +421,9 @@ os_file_create_simple( ...@@ -419,7 +421,9 @@ os_file_create_simple(
if (file == INVALID_HANDLE_VALUE) { if (file == INVALID_HANDLE_VALUE) {
*success = FALSE; *success = FALSE;
retry = os_file_handle_error(file, name); retry = os_file_handle_error(file, name,
create_mode == OS_FILE_OPEN ?
"open" : "create");
if (retry) { if (retry) {
goto try_again; goto try_again;
...@@ -460,7 +464,10 @@ os_file_create_simple( ...@@ -460,7 +464,10 @@ os_file_create_simple(
if (file == -1) { if (file == -1) {
*success = FALSE; *success = FALSE;
retry = os_file_handle_error(file, name); retry = os_file_handle_error(file, name,
create_mode == OS_FILE_OPEN ?
"open" : "create");
if (retry) { if (retry) {
goto try_again; goto try_again;
...@@ -568,7 +575,9 @@ os_file_create( ...@@ -568,7 +575,9 @@ os_file_create(
if (file == INVALID_HANDLE_VALUE) { if (file == INVALID_HANDLE_VALUE) {
*success = FALSE; *success = FALSE;
retry = os_file_handle_error(file, name); retry = os_file_handle_error(file, name,
create_mode == OS_FILE_OPEN ?
"open" : "create");
if (retry) { if (retry) {
goto try_again; goto try_again;
...@@ -615,7 +624,9 @@ os_file_create( ...@@ -615,7 +624,9 @@ os_file_create(
if (file == -1) { if (file == -1) {
*success = FALSE; *success = FALSE;
retry = os_file_handle_error(file, name); retry = os_file_handle_error(file, name,
create_mode == OS_FILE_OPEN ?
"open" : "create");
if (retry) { if (retry) {
goto try_again; goto try_again;
...@@ -649,7 +660,7 @@ os_file_close( ...@@ -649,7 +660,7 @@ os_file_close(
return(TRUE); return(TRUE);
} }
os_file_handle_error(file, NULL); os_file_handle_error(file, NULL, "close");
return(FALSE); return(FALSE);
#else #else
int ret; int ret;
...@@ -657,7 +668,7 @@ os_file_close( ...@@ -657,7 +668,7 @@ os_file_close(
ret = close(file); ret = close(file);
if (ret == -1) { if (ret == -1) {
os_file_handle_error(file, NULL); os_file_handle_error(file, NULL, "close");
return(FALSE); return(FALSE);
} }
...@@ -825,7 +836,7 @@ os_file_flush( ...@@ -825,7 +836,7 @@ os_file_flush(
return(TRUE); return(TRUE);
} }
os_file_handle_error(file, NULL); os_file_handle_error(file, NULL, "flush");
/* It is a fatal error if a file flush does not succeed, because then /* It is a fatal error if a file flush does not succeed, because then
the database can get corrupt on disk */ the database can get corrupt on disk */
...@@ -858,7 +869,7 @@ os_file_flush( ...@@ -858,7 +869,7 @@ os_file_flush(
fprintf(stderr, fprintf(stderr,
" InnoDB: Error: the OS said file flush did not succeed\n"); " InnoDB: Error: the OS said file flush did not succeed\n");
os_file_handle_error(file, NULL); os_file_handle_error(file, NULL, "flush");
/* It is a fatal error if a file flush does not succeed, because then /* It is a fatal error if a file flush does not succeed, because then
the database can get corrupt on disk */ the database can get corrupt on disk */
...@@ -1099,7 +1110,7 @@ os_file_read( ...@@ -1099,7 +1110,7 @@ os_file_read(
#ifdef __WIN__ #ifdef __WIN__
error_handling: error_handling:
#endif #endif
retry = os_file_handle_error(file, NULL); retry = os_file_handle_error(file, NULL, "read");
if (retry) { if (retry) {
goto try_again; goto try_again;
...@@ -2014,7 +2025,7 @@ os_aio( ...@@ -2014,7 +2025,7 @@ os_aio(
os_aio_array_free_slot(array, slot); os_aio_array_free_slot(array, slot);
retry = os_file_handle_error(file, name); retry = os_file_handle_error(file, name, "aio");
if (retry) { if (retry) {
...@@ -2113,7 +2124,7 @@ os_aio_windows_handle( ...@@ -2113,7 +2124,7 @@ os_aio_windows_handle(
ut_a(TRUE == os_file_flush(slot->file)); ut_a(TRUE == os_file_flush(slot->file));
} }
} else { } else {
os_file_handle_error(slot->file, slot->name); os_file_handle_error(slot->file, slot->name, "aio");
ret_val = FALSE; ret_val = FALSE;
} }
......
#
# Test some error conditions
#
drop table if exists t1;
!$1146 insert into t1 values(1);
!$1146 delete from t1;
!$1146 update t1 set a=1;
create table t1 (a int);
!$1054 select count(test.t1.b) from t1;
!$1109 select count(not_existing_database.t1) from t1;
!$1109 select count(not_existing_database.t1.a) from t1;
--error 1044,1146
select count(not_existing_database.t1.a) from not_existing_database.t1;
!$1054 select 1 from t1 order by 2;
!$1054 select 1 from t1 group by 2;
!$1054 select 1 from t1 order by t1.b;
!$1054 select count(*),b from t1;
drop table t1;
#
# Test some error conditions
#
drop table if exists t1;
--error 1146
insert into t1 values(1);
--error 1146
delete from t1;
--error 1146
update t1 set a=1;
#
create table t1 (a int);
--error 1054
select count(test.t1.b) from t1;
--error 1109
select count(not_existing_database.t1) from t1;
--error 1109
select count(not_existing_database.t1.a) from t1;
--error 1044,1146
select count(not_existing_database.t1.a) from not_existing_database.t1;
--error 1054
select 1 from t1 order by 2;
--error 1054
select 1 from t1 group by 2;
--error 1054
select 1 from t1 order by t1.b;
--error 1054
select count(*),b from t1;
drop table t1;
...@@ -38,20 +38,21 @@ ...@@ -38,20 +38,21 @@
#endif #endif
static int alarm_aborted=1; /* No alarm thread */ static int alarm_aborted=1; /* No alarm thread */
my_bool thr_alarm_inited=0; my_bool thr_alarm_inited= 0;
volatile my_bool alarm_thread_running= 0;
static sig_handler process_alarm_part2(int sig); static sig_handler process_alarm_part2(int sig);
#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) #if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2)
static pthread_mutex_t LOCK_alarm; static pthread_mutex_t LOCK_alarm;
static pthread_cond_t COND_alarm;
static sigset_t full_signal_set; static sigset_t full_signal_set;
static QUEUE alarm_queue; static QUEUE alarm_queue;
static uint max_used_alarms=0; static uint max_used_alarms=0;
pthread_t alarm_thread; pthread_t alarm_thread;
#ifdef USE_ALARM_THREAD #ifdef USE_ALARM_THREAD
static pthread_cond_t COND_alarm;
static void *alarm_handler(void *arg); static void *alarm_handler(void *arg);
#define reschedule_alarms() pthread_cond_signal(&COND_alarm) #define reschedule_alarms() pthread_cond_signal(&COND_alarm)
#else #else
...@@ -78,6 +79,7 @@ void init_thr_alarm(uint max_alarms) ...@@ -78,6 +79,7 @@ void init_thr_alarm(uint max_alarms)
compare_ulong,NullS); compare_ulong,NullS);
sigfillset(&full_signal_set); /* Neaded to block signals */ sigfillset(&full_signal_set); /* Neaded to block signals */
pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST); pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST);
pthread_cond_init(&COND_alarm,NULL);
#if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD)
#if defined(HAVE_mit_thread) #if defined(HAVE_mit_thread)
sigset(THR_CLIENT_ALARM,thread_alarm); /* int. thread system calls */ sigset(THR_CLIENT_ALARM,thread_alarm); /* int. thread system calls */
...@@ -97,7 +99,6 @@ void init_thr_alarm(uint max_alarms) ...@@ -97,7 +99,6 @@ void init_thr_alarm(uint max_alarms)
{ {
pthread_attr_t thr_attr; pthread_attr_t thr_attr;
pthread_attr_init(&thr_attr); pthread_attr_init(&thr_attr);
pthread_cond_init(&COND_alarm,NULL);
pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS); pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS);
pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize(&thr_attr,8196); pthread_attr_setstacksize(&thr_attr,8196);
...@@ -383,28 +384,45 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused))) ...@@ -383,28 +384,45 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused)))
void end_thr_alarm(my_bool free_structures) void end_thr_alarm(my_bool free_structures)
{ {
DBUG_ENTER("end_thr_alarm"); DBUG_ENTER("end_thr_alarm");
if (alarm_aborted != 1) if (alarm_aborted != 1) /* If memory not freed */
{ {
pthread_mutex_lock(&LOCK_alarm); pthread_mutex_lock(&LOCK_alarm);
DBUG_PRINT("info",("Resheduling %d waiting alarms",alarm_queue.elements)); DBUG_PRINT("info",("Resheduling %d waiting alarms",alarm_queue.elements));
alarm_aborted= -1; /* mark aborted */ alarm_aborted= -1; /* mark aborted */
if (pthread_equal(pthread_self(),alarm_thread)) if (alarm_queue.elements || (alarm_thread_running && free_structures))
alarm(1); /* Shut down everything soon */ {
else if (pthread_equal(pthread_self(),alarm_thread))
reschedule_alarms(); alarm(1); /* Shut down everything soon */
else
reschedule_alarms();
}
if (free_structures) if (free_structures)
{ {
struct timespec abstime;
/* /*
The following test is just for safety, the caller should not The following test is just for safety, the caller should not
depend on this depend on this
*/ */
DBUG_ASSERT(!alarm_queue.elements); DBUG_ASSERT(!alarm_queue.elements);
/* Wait until alarm thread dies */
set_timespec(abstime, 10); /* Wait up to 10 seconds */
while (alarm_thread_running)
{
int error= pthread_cond_timedwait(&COND_alarm, &LOCK_alarm, &abstime);
if (error == ETIME || error == ETIMEDOUT)
break; /* Don't wait forever */
}
if (!alarm_queue.elements) if (!alarm_queue.elements)
{ {
delete_queue(&alarm_queue); delete_queue(&alarm_queue);
alarm_aborted= 1; alarm_aborted= 1;
pthread_mutex_unlock(&LOCK_alarm); pthread_mutex_unlock(&LOCK_alarm);
pthread_mutex_destroy(&LOCK_alarm); if (!alarm_thread_running) /* Safety */
{
pthread_mutex_destroy(&LOCK_alarm);
pthread_cond_destroy(&COND_alarm);
}
} }
} }
else else
...@@ -490,6 +508,7 @@ static void *alarm_handler(void *arg __attribute__((unused))) ...@@ -490,6 +508,7 @@ static void *alarm_handler(void *arg __attribute__((unused)))
puts("Starting alarm thread"); puts("Starting alarm thread");
#endif #endif
my_thread_init(); my_thread_init();
alarm_thread_running= 1;
pthread_mutex_lock(&LOCK_alarm); pthread_mutex_lock(&LOCK_alarm);
for (;;) for (;;)
{ {
...@@ -514,7 +533,7 @@ static void *alarm_handler(void *arg __attribute__((unused))) ...@@ -514,7 +533,7 @@ static void *alarm_handler(void *arg __attribute__((unused)))
} }
} }
} }
else if (alarm_aborted) else if (alarm_aborted == -1)
break; break;
else if ((error=pthread_cond_wait(&COND_alarm,&LOCK_alarm))) else if ((error=pthread_cond_wait(&COND_alarm,&LOCK_alarm)))
{ {
...@@ -526,6 +545,8 @@ static void *alarm_handler(void *arg __attribute__((unused))) ...@@ -526,6 +545,8 @@ static void *alarm_handler(void *arg __attribute__((unused)))
process_alarm(0); process_alarm(0);
} }
bzero((char*) &alarm_thread,sizeof(alarm_thread)); /* For easy debugging */ bzero((char*) &alarm_thread,sizeof(alarm_thread)); /* For easy debugging */
alarm_thread_running= 0;
pthread_cond_signal(&COND_alarm);
pthread_mutex_unlock(&LOCK_alarm); pthread_mutex_unlock(&LOCK_alarm);
pthread_exit(0); pthread_exit(0);
return 0; /* Impossible */ return 0; /* Impossible */
......
...@@ -1520,7 +1520,6 @@ the problem, but since we have already crashed, something is definitely wrong\n\ ...@@ -1520,7 +1520,6 @@ the problem, but since we have already crashed, something is definitely wrong\n\
and this may fail.\n\n"); and this may fail.\n\n");
fprintf(stderr, "key_buffer_size=%lu\n", (ulong) keybuff_size); fprintf(stderr, "key_buffer_size=%lu\n", (ulong) keybuff_size);
fprintf(stderr, "read_buffer_size=%ld\n", global_system_variables.read_buff_size); fprintf(stderr, "read_buffer_size=%ld\n", global_system_variables.read_buff_size);
fprintf(stderr, "sort_buffer_size=%ld\n", thd->variables.sortbuff_size);
fprintf(stderr, "max_used_connections=%ld\n", max_used_connections); fprintf(stderr, "max_used_connections=%ld\n", max_used_connections);
fprintf(stderr, "max_connections=%ld\n", max_connections); fprintf(stderr, "max_connections=%ld\n", max_connections);
fprintf(stderr, "threads_connected=%d\n", thread_count); fprintf(stderr, "threads_connected=%d\n", thread_count);
...@@ -1528,7 +1527,7 @@ and this may fail.\n\n"); ...@@ -1528,7 +1527,7 @@ and this may fail.\n\n");
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = %ld K\n\ key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = %ld K\n\
bytes of memory\n", ((ulong) keybuff_size + bytes of memory\n", ((ulong) keybuff_size +
(global_system_variables.read_buff_size + (global_system_variables.read_buff_size +
thd->variables.sortbuff_size) * global_system_variables.sortbuff_size) *
max_connections)/ 1024); max_connections)/ 1024);
fprintf(stderr, "Hope that's ok; if not, decrease some variables in the equation.\n\n"); fprintf(stderr, "Hope that's ok; if not, decrease some variables in the equation.\n\n");
...@@ -1557,14 +1556,9 @@ the thread stack. Please read http://www.mysql.com/doc/L/i/Linux.html\n\n", ...@@ -1557,14 +1556,9 @@ the thread stack. Please read http://www.mysql.com/doc/L/i/Linux.html\n\n",
Some pointers may be invalid and cause the dump to abort...\n"); Some pointers may be invalid and cause the dump to abort...\n");
safe_print_str("thd->query", thd->query, 1024); safe_print_str("thd->query", thd->query, 1024);
fprintf(stderr, "thd->thread_id=%ld\n", thd->thread_id); fprintf(stderr, "thd->thread_id=%ld\n", thd->thread_id);
fprintf(stderr, "\n\
Successfully dumped variables, if you ran with --log, take a look at the\n\
details of what thread %ld did to cause the crash. In some cases of really\n\
bad corruption, the values shown above may be invalid.\n\n",
thd->thread_id);
} }
fprintf(stderr, "\ fprintf(stderr, "\
The manual page at http://www.mysql.com/doc/C/r/Crashing.html contains\n\ The manual page at http://www.mysql.com/doc/en/Crashing.html contains\n\
information that should help you find out what is causing the crash.\n"); information that should help you find out what is causing the crash.\n");
fflush(stderr); fflush(stderr);
#endif /* HAVE_STACKTRACE */ #endif /* HAVE_STACKTRACE */
...@@ -1639,6 +1633,7 @@ static void init_signals(void) ...@@ -1639,6 +1633,7 @@ static void init_signals(void)
sigaddset(&set,SIGHUP); sigaddset(&set,SIGHUP);
/* Fix signals if blocked by parents (can happen on Mac OS X) */ /* Fix signals if blocked by parents (can happen on Mac OS X) */
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0; sa.sa_flags = 0;
sa.sa_handler = print_signal_warning; sa.sa_handler = print_signal_warning;
sigaction(SIGTERM, &sa, (struct sigaction*) 0); sigaction(SIGTERM, &sa, (struct sigaction*) 0);
...@@ -2279,7 +2274,7 @@ int main(int argc, char **argv) ...@@ -2279,7 +2274,7 @@ int main(int argc, char **argv)
#endif #endif
/* init_slave() must be called after the thread keys are created */ /* init_slave() must be called after the thread keys are created */
init_slave(); init_slave();
DBUG_ASSERT(current_thd == 0); DBUG_ASSERT(current_thd == 0);
if (opt_bin_log && !server_id) if (opt_bin_log && !server_id)
{ {
...@@ -2307,7 +2302,6 @@ The server will not act as a slave."); ...@@ -2307,7 +2302,6 @@ The server will not act as a slave.");
using_update_log=1; using_update_log=1;
} }
if (opt_bootstrap) if (opt_bootstrap)
{ {
int error=bootstrap(stdin); int error=bootstrap(stdin);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment