summaryrefslogtreecommitdiff
path: root/innobase/sync
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2004-03-16 22:41:30 +0200
committerunknown <monty@mysql.com>2004-03-16 22:41:30 +0200
commita8aacf87648f64e7489220dab7d8729c5c01e13d (patch)
treeaf285d8080c003d1ecb1479ec43c9b6996fd567f /innobase/sync
parent17f8d3d725f4b465a8a0dc8e96b04cd973c47fd5 (diff)
parent277cf702da7e6f0642742eb10582cfc382e537ec (diff)
downloadmariadb-git-a8aacf87648f64e7489220dab7d8729c5c01e13d.tar.gz
merge with 4.0
BitKeeper/etc/logging_ok: auto-union VC++Files/innobase/innobase.dsp: Auto merged VC++Files/libmysql/libmysql.dsp: Auto merged acinclude.m4: Auto merged configure.in: Auto merged BitKeeper/deleted/.del-com0shm.c~6a16f0c3d81de1f: Auto merged BitKeeper/deleted/.del-mysql_fix_privilege_tables.sql: Auto merged extra/replace.c: Auto merged include/my_sys.h: Auto merged innobase/btr/btr0btr.c: Auto merged innobase/btr/btr0cur.c: Auto merged innobase/btr/btr0pcur.c: Auto merged innobase/btr/btr0sea.c: Auto merged innobase/configure.in: Auto merged innobase/data/data0data.c: Auto merged innobase/dict/dict0boot.c: Auto merged innobase/dict/dict0crea.c: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/dict/dict0load.c: Auto merged innobase/dict/dict0mem.c: Auto merged innobase/ha/ha0ha.c: Auto merged innobase/ha/hash0hash.c: Auto merged innobase/include/btr0btr.ic: Auto merged innobase/include/data0type.ic: Auto merged innobase/include/dict0mem.h: Auto merged innobase/include/log0log.ic: Auto merged innobase/include/mach0data.ic: Auto merged innobase/include/mtr0log.h: Auto merged innobase/include/mtr0mtr.h: Auto merged innobase/include/os0file.h: Auto merged innobase/include/row0upd.ic: Auto merged innobase/include/srv0srv.h: Auto merged innobase/include/sync0sync.h: Auto merged innobase/include/trx0rseg.ic: Auto merged innobase/lock/lock0lock.c: Auto merged innobase/log/log0recv.c: Auto merged innobase/mem/mem0dbg.c: Auto merged innobase/mtr/mtr0log.c: Auto merged innobase/mtr/mtr0mtr.c: Auto merged innobase/os/os0file.c: Auto merged innobase/page/page0cur.c: Auto merged innobase/page/page0page.c: Auto merged innobase/pars/lexyy.c: Auto merged innobase/read/read0read.c: Auto merged innobase/rem/rem0cmp.c: Auto merged innobase/rem/rem0rec.c: Auto merged innobase/row/row0ins.c: Auto merged innobase/row/row0mysql.c: Auto merged innobase/row/row0purge.c: Auto merged innobase/row/row0sel.c: Auto merged innobase/row/row0undo.c: Auto merged innobase/row/row0upd.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/sync/sync0rw.c: Auto merged innobase/thr/thr0loc.c: Auto merged innobase/trx/trx0purge.c: Auto merged innobase/trx/trx0rec.c: Auto merged innobase/trx/trx0roll.c: Auto merged innobase/trx/trx0trx.c: Auto merged innobase/trx/trx0undo.c: Auto merged myisam/mi_check.c: Auto merged myisam/myisamchk.c: Auto merged mysql-test/r/multi_update.result: Auto merged mysql-test/r/mysqlbinlog.result: Auto merged mysql-test/r/rpl_error_ignored_table.result: Auto merged mysql-test/t/multi_update.test: Auto merged mysql-test/t/rpl_error_ignored_table.test: Auto merged mysys/mf_iocache.c: Auto merged mysys/mf_pack.c: Auto merged mysys/my_getopt.c: Auto merged sql/ha_berkeley.cc: Auto merged sql/ha_myisam.cc: Auto merged sql/lock.cc: Auto merged sql/log.cc: Auto merged sql/opt_range.cc: Auto merged sql/set_var.h: Auto merged sql/sql_cache.cc: Auto merged sql/sql_cache.h: Auto merged sql/sql_delete.cc: Auto merged sql/sql_handler.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_list.h: Auto merged sql/sql_select.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_update.cc: Auto merged tests/thread_test.c: Auto merged client/mysqldump.c: Keep original indentation mysql-test/r/merge.result: keep old file scripts/mysql_fix_privilege_tables.sh: Keep old structure in merge with 4.0 sql/table.cc: merge with 4.0 + simple optimizations
Diffstat (limited to 'innobase/sync')
-rw-r--r--innobase/sync/sync0arr.c36
-rw-r--r--innobase/sync/sync0rw.c34
-rw-r--r--innobase/sync/sync0sync.c75
3 files changed, 74 insertions, 71 deletions
diff --git a/innobase/sync/sync0arr.c b/innobase/sync/sync0arr.c
index 9bcee34a7d1..8082f598b0c 100644
--- a/innobase/sync/sync0arr.c
+++ b/innobase/sync/sync0arr.c
@@ -14,6 +14,7 @@ Created 9/5/1995 Heikki Tuuri
#include "sync0sync.h"
#include "sync0rw.h"
#include "os0sync.h"
+#include "os0file.h"
#include "srv0srv.h"
/*
@@ -99,6 +100,7 @@ struct sync_array_struct {
since creation of the array */
};
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
This function is called only in the debug version. Detects a deadlock
of one or more threads because of waits of semaphores. */
@@ -112,6 +114,7 @@ sync_array_detect_deadlock(
sync_cell_t* start, /* in: cell where recursive search started */
sync_cell_t* cell, /* in: cell to search */
ulint depth); /* in: recursion depth */
+#endif /* UNIV_SYNC_DEBUG */
/*********************************************************************
Gets the nth cell in array. */
@@ -464,13 +467,17 @@ sync_array_cell_print(
mutex = cell->old_wait_mutex;
buf += sprintf(buf,
- "Mutex at %lx created file %s line %lu, lock var %lu\n",
- (ulong) mutex, mutex->cfile_name,
- (ulong) mutex->cline, (ulong) mutex->lock_word);
- buf += sprintf(buf,
- "Last time reserved in file %s line %lu, waiters flag %lu\n",
- mutex->file_name, (ulong) mutex->line,
- (ulong) mutex->waiters);
+ "Mutex at %p created file %s line %lu, lock var %lu\n"
+#ifdef UNIV_SYNC_DEBUG
+ "Last time reserved in file %s line %lu, "
+#endif /* UNIV_SYNC_DEBUG */
+ "waiters flag %lu\n",
+ mutex, mutex->cfile_name, (ulong) mutex->cline,
+ (ulong) mutex->lock_word,
+#ifdef UNIV_SYNC_DEBUG
+ mutex->file_name, (ulong) mutex->line,
+#endif /* UNIV_SYNC_DEBUG */
+ (ulong) mutex->waiters);
} else if (type == RW_LOCK_EX || type == RW_LOCK_SHARED) {
@@ -522,6 +529,7 @@ sync_array_cell_print(
}
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Looks for a cell with the given thread id. */
static
@@ -693,7 +701,6 @@ sync_array_detect_deadlock(
sync_array_cell_print(buf, cell);
printf("rw-lock %lx %s ", (ulong) lock, buf);
rw_lock_debug_print(debug);
-
return(TRUE);
}
}
@@ -743,6 +750,7 @@ sync_array_detect_deadlock(
return(TRUE); /* Execution never reaches this line: for compiler
fooling only */
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Determines if we can wake up the thread waiting for a sempahore. */
@@ -936,7 +944,7 @@ sync_array_print_long_waits(void)
"InnoDB: We intentionally crash the server, because it appears to be hung.\n"
);
- ut_a(0);
+ ut_error;
}
}
@@ -945,6 +953,16 @@ sync_array_print_long_waits(void)
"InnoDB: ###### Starts InnoDB Monitor for 30 secs to print diagnostic info:\n");
old_val = srv_print_innodb_monitor;
+ /* If some crucial semaphore is reserved, then also the InnoDB
+ Monitor can hang, and we do not get diagnostics. Since in
+ many cases an InnoDB hang is caused by a pwrite() or a pread()
+ call hanging inside the operating system, let us print right
+ now the values of pending calls of these. */
+
+ fprintf(stderr,
+"InnoDB: Pending preads %lu, pwrites %lu\n", (ulong)os_file_n_pending_preads,
+ (ulong)os_file_n_pending_pwrites);
+
srv_print_innodb_monitor = TRUE;
os_event_set(srv_lock_timeout_thread_event);
diff --git a/innobase/sync/sync0rw.c b/innobase/sync/sync0rw.c
index e6da03c53fa..93fd9f14575 100644
--- a/innobase/sync/sync0rw.c
+++ b/innobase/sync/sync0rw.c
@@ -31,6 +31,7 @@ ulint rw_x_exit_count = 0;
rw_lock_list_t rw_lock_list;
mutex_t rw_lock_list_mutex;
+#ifdef UNIV_SYNC_DEBUG
/* The global mutex which protects debug info lists of all rw-locks.
To modify the debug info list of an rw-lock, this mutex has to be
acquired in addition to the mutex protecting the lock. */
@@ -76,6 +77,7 @@ rw_lock_debug_free(
{
mem_free(info);
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Creates, or rather, initializes an rw-lock object in a specified memory
@@ -107,10 +109,12 @@ rw_lock_create_func(
lock->writer_is_wait_ex = FALSE;
+#ifdef UNIV_SYNC_DEBUG
UT_LIST_INIT(lock->debug_list);
- lock->magic_n = RW_LOCK_MAGIC_N;
lock->level = SYNC_LEVEL_NONE;
+#endif /* UNIV_SYNC_DEBUG */
+ lock->magic_n = RW_LOCK_MAGIC_N;
lock->cfile_name = cfile_name;
lock->cline = cline;
@@ -319,8 +323,9 @@ rw_lock_x_lock_low(
char* file_name,/* in: file name where lock requested */
ulint line) /* in: line where requested */
{
+#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(rw_lock_get_mutex(lock)));
-
+#endif /* UNIV_SYNC_DEBUG */
if (rw_lock_get_writer(lock) == RW_LOCK_NOT_LOCKED) {
if (rw_lock_get_reader_count(lock) == 0) {
@@ -528,6 +533,7 @@ lock_loop:
goto lock_loop;
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Acquires the debug mutex. We cannot use the mutex defined in sync0sync,
because the debug mutex is also acquired in sync0arr while holding the OS
@@ -653,6 +659,7 @@ rw_lock_remove_debug_info(
ut_error;
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Sets the rw-lock latching level field. */
@@ -666,6 +673,7 @@ rw_lock_set_level(
lock->level = level;
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Checks if the thread has locked the rw-lock in the specified mode, with
the pass value == 0. */
@@ -683,9 +691,6 @@ rw_lock_own(
ut_ad(lock);
ut_ad(rw_lock_validate(lock));
-#ifndef UNIV_SYNC_DEBUG
- ut_error;
-#endif
mutex_enter(&(lock->mutex));
info = UT_LIST_GET_FIRST(lock->debug_list);
@@ -708,6 +713,7 @@ rw_lock_own(
return(FALSE);
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Checks if somebody has locked the rw-lock in the specified mode. */
@@ -744,6 +750,7 @@ rw_lock_is_locked(
return(ret);
}
+#ifdef UNIV_SYNC_DEBUG
/*******************************************************************
Prints debug info of currently locked rw-locks. */
@@ -751,8 +758,6 @@ void
rw_lock_list_print_info(void)
/*=========================*/
{
-#ifndef UNIV_SYNC_DEBUG
-#else
rw_lock_t* lock;
ulint count = 0;
rw_lock_debug_t* info;
@@ -796,7 +801,6 @@ rw_lock_list_print_info(void)
printf("Total number of rw-locks %ld\n", count);
mutex_exit(&rw_lock_list_mutex);
-#endif
}
/*******************************************************************
@@ -807,11 +811,6 @@ rw_lock_print(
/*==========*/
rw_lock_t* lock __attribute__((unused))) /* in: rw-lock */
{
-#ifndef UNIV_SYNC_DEBUG
- printf(
- "Sorry, cannot give rw-lock info in non-debug version!\n");
-#else
- ulint count = 0;
rw_lock_debug_t* info;
printf("-------------\n");
@@ -834,7 +833,6 @@ rw_lock_print(
info = UT_LIST_GET_NEXT(list, info);
}
}
-#endif
}
/*************************************************************************
@@ -875,12 +873,6 @@ ulint
rw_lock_n_locked(void)
/*==================*/
{
-#ifndef UNIV_SYNC_DEBUG
- printf(
- "Sorry, cannot give rw-lock info in non-debug version!\n");
- ut_error;
- return(0);
-#else
rw_lock_t* lock;
ulint count = 0;
@@ -903,5 +895,5 @@ rw_lock_n_locked(void)
mutex_exit(&rw_lock_list_mutex);
return(count);
-#endif
}
+#endif /* UNIV_SYNC_DEBUG */
diff --git a/innobase/sync/sync0sync.c b/innobase/sync/sync0sync.c
index 22e0975dd37..6ad766d8bc8 100644
--- a/innobase/sync/sync0sync.c
+++ b/innobase/sync/sync0sync.c
@@ -188,8 +188,10 @@ mutex_create_func(
#endif
mutex_set_waiters(mutex, 0);
mutex->magic_n = MUTEX_MAGIC_N;
+#ifdef UNIV_SYNC_DEBUG
mutex->line = 0;
mutex->file_name = (char *) "not yet reserved";
+#endif /* UNIV_SYNC_DEBUG */
mutex->level = SYNC_LEVEL_NONE;
mutex->cfile_name = cfile_name;
mutex->cline = cline;
@@ -266,9 +268,11 @@ mutex_enter_nowait(
/*===============*/
/* out: 0 if succeed, 1 if not */
mutex_t* mutex, /* in: pointer to mutex */
- char* file_name, /* in: file name where mutex
+ char* file_name __attribute__((unused)),
+ /* in: file name where mutex
requested */
- ulint line) /* in: line where requested */
+ ulint line __attribute__((unused)))
+ /* in: line where requested */
{
ut_ad(mutex_validate(mutex));
@@ -277,9 +281,6 @@ mutex_enter_nowait(
#ifdef UNIV_SYNC_DEBUG
mutex_set_debug_info(mutex, file_name, line);
#endif
-
- mutex->file_name = file_name;
- mutex->line = line;
return(0); /* Succeeded! */
}
@@ -379,9 +380,6 @@ spin_loop:
mutex_set_debug_info(mutex, file_name, line);
#endif
- mutex->file_name = file_name;
- mutex->line = line;
-
return;
}
@@ -426,9 +424,6 @@ spin_loop:
mutex_set_debug_info(mutex, file_name, line);
#endif
- mutex->file_name = file_name;
- mutex->line = line;
-
if (srv_print_latch_waits) {
printf(
"Thread %lu spin wait succeeds at 2: mutex at %lx\n",
@@ -479,6 +474,7 @@ mutex_signal_object(
sync_array_signal_object(sync_primary_wait_array, mutex);
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Sets the debug information for a reserved mutex. */
@@ -516,7 +512,8 @@ mutex_get_debug_info(
*file_name = mutex->file_name;
*line = mutex->line;
*thread_id = mutex->thread_id;
-}
+}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Sets the mutex latching level field. */
@@ -530,6 +527,7 @@ mutex_set_level(
mutex->level = level;
}
+#ifdef UNIV_SYNC_DEBUG
/**********************************************************************
Checks that the current thread owns the mutex. Works only in the debug
version. */
@@ -562,8 +560,6 @@ void
mutex_list_print_info(void)
/*=======================*/
{
-#ifndef UNIV_SYNC_DEBUG
-#else
mutex_t* mutex;
char* file_name;
ulint line;
@@ -596,7 +592,6 @@ mutex_list_print_info(void)
printf("Total number of mutexes %ld\n", count);
mutex_exit(&mutex_list_mutex);
-#endif
}
/**********************************************************************
@@ -606,12 +601,6 @@ ulint
mutex_n_reserved(void)
/*==================*/
{
-#ifndef UNIV_SYNC_DEBUG
- printf("Sorry, cannot give mutex info in non-debug version!\n");
- ut_error;
-
- return(0);
-#else
mutex_t* mutex;
ulint count = 0;
@@ -634,7 +623,6 @@ mutex_n_reserved(void)
return(count - 1); /* Subtract one, because this function itself
was holding one mutex (mutex_list_mutex) */
-#endif
}
/**********************************************************************
@@ -645,19 +633,9 @@ ibool
sync_all_freed(void)
/*================*/
{
-#ifdef UNIV_SYNC_DEBUG
- if (mutex_n_reserved() + rw_lock_n_locked() == 0) {
-
- return(TRUE);
- } else {
- return(FALSE);
- }
-#else
- ut_error;
-
- return(FALSE);
-#endif
+ return(mutex_n_reserved() + rw_lock_n_locked() == 0);
}
+#endif /* UNIV_SYNC_DEBUG */
/**********************************************************************
Gets the value in the nth slot in the thread level arrays. */
@@ -754,9 +732,6 @@ sync_thread_levels_g(
thread */
ulint limit) /* in: level limit */
{
- char* file_name;
- ulint line;
- os_thread_id_t thread_id;
sync_level_t* slot;
rw_lock_t* lock;
mutex_t* mutex;
@@ -781,18 +756,28 @@ sync_thread_levels_g(
(ulong) mutex->cline);
if (mutex_get_lock_word(mutex) != 0) {
+#ifdef UNIV_SYNC_DEBUG
+ char* file_name;
+ ulint line;
+ os_thread_id_t thread_id;
mutex_get_debug_info(mutex,
&file_name, &line, &thread_id);
- printf("InnoDB: Locked mutex: addr %lx thread %ld file %s line %ld\n",
- (ulong) mutex, (ulong) os_thread_pf(thread_id),
- file_name, (ulong) line);
+ fprintf(stderr,
+ "InnoDB: Locked mutex: addr %p thread %ld file %s line %ld\n",
+ mutex, os_thread_pf(thread_id), file_name, (ulong) line);
+#else /* UNIV_SYNC_DEBUG */
+ fprintf(stderr,
+ "InnoDB: Locked mutex: addr %p\n", mutex);
+#endif /* UNIV_SYNC_DEBUG */
} else {
- printf("Not locked\n");
+ fputs("Not locked\n", stderr);
}
} else {
+#ifdef UNIV_SYNC_DEBUG
rw_lock_print(lock);
+#endif /* UNIV_SYNC_DEBUG */
}
return(FALSE);
@@ -932,7 +917,9 @@ sync_thread_add_level(
if ((latch == (void*)&sync_thread_mutex)
|| (latch == (void*)&mutex_list_mutex)
+#ifdef UNIV_SYNC_DEBUG
|| (latch == (void*)&rw_lock_debug_mutex)
+#endif /* UNIV_SYNC_DEBUG */
|| (latch == (void*)&rw_lock_list_mutex)) {
return;
@@ -1112,7 +1099,9 @@ sync_thread_reset_level(
if ((latch == (void*)&sync_thread_mutex)
|| (latch == (void*)&mutex_list_mutex)
+#ifdef UNIV_SYNC_DEBUG
|| (latch == (void*)&rw_lock_debug_mutex)
+#endif /* UNIV_SYNC_DEBUG */
|| (latch == (void*)&rw_lock_list_mutex)) {
return(FALSE);
@@ -1198,11 +1187,13 @@ sync_init(void)
mutex_create(&rw_lock_list_mutex);
mutex_set_level(&rw_lock_list_mutex, SYNC_NO_ORDER_CHECK);
+#ifdef UNIV_SYNC_DEBUG
mutex_create(&rw_lock_debug_mutex);
mutex_set_level(&rw_lock_debug_mutex, SYNC_NO_ORDER_CHECK);
rw_lock_debug_event = os_event_create(NULL);
rw_lock_debug_waiters = FALSE;
+#endif /* UNIV_SYNC_DEBUG */
}
/**********************************************************************
@@ -1267,9 +1258,11 @@ sync_print(
char* buf, /* in/out: buffer where to print */
char* buf_end) /* in: buffer end */
{
+#ifdef UNIV_SYNC_DEBUG
mutex_list_print_info();
rw_lock_list_print_info();
+#endif /* UNIV_SYNC_DEBUG */
sync_array_print_info(buf, buf_end, sync_primary_wait_array);