Merge next-mr -> next-4284.

This commit is contained in:
Konstantin Osipov 2009-12-15 21:45:22 +03:00
commit 7a6e5c3f4c
76 changed files with 4888 additions and 597 deletions

View File

@ -269,11 +269,12 @@ test-full-qa:
# #
API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin.h \ API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin.h \
$(top_srcdir)/include/mysql.h $(top_srcdir)/include/mysql.h \
$(top_srcdir)/include/mysql/psi/psi_abi_v1.h \
$(top_srcdir)/include/mysql/psi/psi_abi_v2.h
TEST_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin.h \ TEST_PREPROCESSOR_HEADER = $(API_PREPROCESSOR_HEADER) \
$(top_srcdir)/sql/mysql_priv.h \ $(top_srcdir)/sql/mysql_priv.h
$(top_srcdir)/include/mysql.h
# #
# Rules for checking that the abi/api has not changed. # Rules for checking that the abi/api has not changed.

View File

@ -1,4 +1,4 @@
# Copyright (C) 2000-2006 MySQL AB # Copyright (C) 2000-2006 MySQL AB, 2009 Sun Microsystems, Inc
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public # modify it under the terms of the GNU Library General Public
@ -24,6 +24,8 @@ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \
my_xml.h mysql_embed.h mysql/services.h \ my_xml.h mysql_embed.h mysql/services.h \
mysql/service_my_snprintf.h mysql/service_thd_alloc.h \ mysql/service_my_snprintf.h mysql/service_thd_alloc.h \
my_pthread.h my_no_pthread.h \ my_pthread.h my_no_pthread.h \
mysql/psi/psi.h mysql/psi/mysql_thread.h \
mysql/psi/mysql_file.h \
decimal.h errmsg.h my_global.h my_net.h \ decimal.h errmsg.h my_global.h my_net.h \
my_getopt.h sslopt-longopts.h my_dir.h \ my_getopt.h sslopt-longopts.h my_dir.h \
sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \
@ -38,13 +40,15 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \
my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \ my_aes.h my_tree.h my_trie.h hash.h thr_alarm.h \
thr_lock.h t_ctype.h violite.h my_md5.h base64.h \ thr_lock.h t_ctype.h violite.h my_md5.h base64.h \
my_handler.h my_time.h service_versions.h \ my_handler.h my_time.h service_versions.h \
my_rdtsc.h \ my_rdtsc.h mysql/psi/psi_abi_v1.h mysql/psi/psi_abi_v2.h \
my_vle.h my_user.h my_atomic.h atomic/nolock.h \ my_vle.h my_user.h my_atomic.h atomic/nolock.h \
atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \ atomic/rwlock.h atomic/x86-gcc.h atomic/generic-msvc.h \
atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \
atomic/solaris.h atomic/solaris.h
EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp probes_mysql.d.base EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp probes_mysql.d.base \
mysql/psi/psi_abi_v1.h.pp \
mysql/psi/psi_abi_v2.h.pp
# Remove built files and the symlinked directories # Remove built files and the symlinked directories
CLEANFILES = $(BUILT_SOURCES) readline openssl probes_mysql.d probes_mysql_nodtrace.h CLEANFILES = $(BUILT_SOURCES) readline openssl probes_mysql.d probes_mysql_nodtrace.h

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000,2004 MySQL AB /* Copyright (C) 2000-2004 MySQL AB, 2009 Sun Microsystems, Inc
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
@ -148,7 +148,7 @@ typedef struct st_heap_share
char * name; /* Name of "memory-file" */ char * name; /* Name of "memory-file" */
#ifdef THREAD #ifdef THREAD
THR_LOCK lock; THR_LOCK lock;
pthread_mutex_t intern_lock; /* Locking for use with _locking */ mysql_mutex_t intern_lock; /* Locking for use with _locking */
#endif #endif
my_bool delete_on_close; my_bool delete_on_close;
LIST open_list; LIST open_list;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2003 MySQL AB /* Copyright (C) 2000-2003 MySQL AB, 2009 Sun Microsystems, Inc
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
@ -83,6 +83,16 @@
#endif #endif
#endif /* _WIN32... */ #endif /* _WIN32... */
#ifdef EMBEDDED_LIBRARY
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
#undef WITH_PERFSCHEMA_STORAGE_ENGINE
#endif
#endif /* EMBEDDED_LIBRARY */
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
#define HAVE_PSI_INTERFACE
#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
/* Make it easier to add conditionl code for windows */ /* Make it easier to add conditionl code for windows */
#ifdef __WIN__ #ifdef __WIN__
#define IF_WIN(A,B) (A) #define IF_WIN(A,B) (A)

View File

@ -1,7 +1,7 @@
#ifndef MY_NO_PTHREAD_INCLUDED #ifndef MY_NO_PTHREAD_INCLUDED
#define MY_NO_PTHREAD_INCLUDED #define MY_NO_PTHREAD_INCLUDED
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -48,5 +48,16 @@
#define rw_unlock(A) #define rw_unlock(A)
#define rwlock_destroy(A) #define rwlock_destroy(A)
#define mysql_mutex_init(A, B, C) do {} while (0)
#define mysql_mutex_lock(A) do {} while (0)
#define mysql_mutex_unlock(A) do {} while (0)
#define mysql_mutex_destroy(A) do {} while (0)
#define mysql_rwlock_init(A, B, C) do {} while (0)
#define mysql_rwlock_rdlock(A) do {} while (0)
#define mysql_rwlock_wrlock(A) do {} while (0)
#define mysql_rwlock_unlock(A) do {} while (0)
#define mysql_rwlock_destroy(A) do {} while (0)
#endif #endif
#endif /* MY_NO_PTHREAD_INCLUDED */ #endif /* MY_NO_PTHREAD_INCLUDED */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
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
@ -99,7 +99,7 @@ struct timespec {
int win_pthread_mutex_trylock(pthread_mutex_t *mutex); int win_pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *); int pthread_create(pthread_t *, const pthread_attr_t *, pthread_handler, void *);
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
@ -137,8 +137,8 @@ int pthread_join(pthread_t thread, void **value_ptr);
#define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0) #define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0)
#define pthread_mutex_lock(A) (EnterCriticalSection(A),0) #define pthread_mutex_lock(A) (EnterCriticalSection(A),0)
#define pthread_mutex_trylock(A) win_pthread_mutex_trylock((A)) #define pthread_mutex_trylock(A) win_pthread_mutex_trylock((A))
#define pthread_mutex_unlock(A) LeaveCriticalSection(A) #define pthread_mutex_unlock(A) (LeaveCriticalSection(A), 0)
#define pthread_mutex_destroy(A) DeleteCriticalSection(A) #define pthread_mutex_destroy(A) (DeleteCriticalSection(A), 0)
#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) #define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH)
@ -630,6 +630,10 @@ extern int pthread_dummy(int);
#endif #endif
#endif #endif
#include <mysql/psi/mysql_thread.h>
#define INSTRUMENT_ME 0
struct st_my_thread_var struct st_my_thread_var
{ {
int thr_errno; int thr_errno;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2003 MySQL AB /* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -1021,5 +1021,15 @@ void netware_reg_user(const char *ip, const char *user,
const char *application); const char *application);
#endif #endif
#include <mysql/psi/psi.h>
#ifdef HAVE_PSI_INTERFACE
extern MYSQL_PLUGIN_IMPORT struct PSI_bootstrap *PSI_hook;
void my_init_mysys_psi_keys(void);
#endif
struct st_mysql_file;
extern struct st_mysql_file *mysql_stdin;
C_MODE_END C_MODE_END
#endif /* _my_sys_h */ #endif /* _my_sys_h */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -433,7 +433,7 @@ typedef struct st_mi_check_param
const char *op_name; const char *op_name;
enum_mi_stats_method stats_method; enum_mi_stats_method stats_method;
#ifdef THREAD #ifdef THREAD
pthread_mutex_t print_msg_mutex; mysql_mutex_t print_msg_mutex;
my_bool need_print_msg_lock; my_bool need_print_msg_lock;
#endif #endif
} MI_CHECK; } MI_CHECK;
@ -460,8 +460,8 @@ typedef struct st_sort_info
/* sync things */ /* sync things */
uint got_error, threads_running; uint got_error, threads_running;
#ifdef THREAD #ifdef THREAD
pthread_mutex_t mutex; mysql_mutex_t mutex;
pthread_cond_t cond; mysql_cond_t cond;
#endif #endif
} SORT_INFO; } SORT_INFO;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -75,7 +75,7 @@ typedef struct st_myrg_info
LIST open_list; LIST open_list;
QUEUE by_key; QUEUE by_key;
ulong *rec_per_key_part; /* for sql optimizing */ ulong *rec_per_key_part; /* for sql optimizing */
pthread_mutex_t mutex; mysql_mutex_t mutex;
} MYRG_INFO; } MYRG_INFO;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,884 @@
/* Copyright (C) 2008-2009 Sun Microsystems, Inc
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
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef MYSQL_THREAD_H
#define MYSQL_THREAD_H
/**
@file mysql/psi/mysql_thread.h
Instrumentation helpers for mysys threads, mutexes,
read write locks and conditions.
This header file provides the necessary declarations
to use the mysys thread API with the performance schema instrumentation.
In some compilers (SunStudio), 'static inline' functions, when declared
but not used, are not optimized away (because they are unused) by default,
so that including a static inline function from a header file does
create unwanted dependencies, causing unresolved symbols at link time.
Other compilers, like gcc, optimize these dependencies by default.
Since the instrumented APIs declared here are wrapper on top
of my_pthread / safemutex / etc APIs,
including mysql/psi/mysql_thread.h assumes that
the dependency on my_pthread and safemutex already exists.
*/
/*
Note: there are several orthogonal dimensions here.
Dimension 1: Instrumentation
HAVE_PSI_INTERFACE is defined when the instrumentation is compiled in.
This may happen both in debug or production builds.
Dimension 2: Debug
SAFE_MUTEX is defined when debug is compiled in.
This may happen both with and without instrumentation.
Dimension 3: Platform
Mutexes are implemented with one of:
- the pthread library
- fast mutexes
- window apis
This is implemented by various macro definitions in my_pthread.h
This causes complexity with '#ifdef'-ery that can't be avoided.
*/
#include "mysql/psi/psi.h"
/**
@defgroup Thread_instrumentation Thread Instrumentation
@ingroup Instrumentation_interface
@{
*/
/**
An instrumented mutex structure.
@sa mysql_mutex_t
*/
struct st_mysql_mutex
{
/** The real mutex. */
pthread_mutex_t m_mutex;
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_mutex_t interface.
*/
struct PSI_mutex *m_psi;
};
/**
Type of an instrumented mutex.
@c mysql_mutex_t is a drop-in replacement for @c pthread_mutex_t.
@sa mysql_mutex_assert_owner
@sa mysql_mutex_assert_not_owner
@sa mysql_mutex_init
@sa mysql_mutex_lock
@sa mysql_mutex_unlock
@sa mysql_mutex_destroy
*/
typedef struct st_mysql_mutex mysql_mutex_t;
/**
An instrumented rwlock structure.
@sa mysql_rwlock_t
*/
struct st_mysql_rwlock
{
/** The real rwlock */
rw_lock_t m_rwlock;
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_rwlock_t interface.
*/
struct PSI_rwlock *m_psi;
};
/**
Type of an instrumented rwlock.
@c mysql_rwlock_t is a drop-in replacement for @c pthread_rwlock_t.
@sa mysql_rwlock_init
@sa mysql_rwlock_rdlock
@sa mysql_rwlock_tryrdlock
@sa mysql_rwlock_wrlock
@sa mysql_rwlock_trywrlock
@sa mysql_rwlock_unlock
@sa mysql_rwlock_destroy
*/
typedef struct st_mysql_rwlock mysql_rwlock_t;
/**
An instrumented cond structure.
@sa mysql_cond_t
*/
struct st_mysql_cond
{
/** The real condition */
pthread_cond_t m_cond;
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_cond_t interface.
*/
struct PSI_cond *m_psi;
};
/**
Type of an instrumented condition.
@c mysql_cond_t is a drop-in replacement for @c pthread_cond_t.
@sa mysql_cond_init
@sa mysql_cond_wait
@sa mysql_cond_timedwait
@sa mysql_cond_signal
@sa mysql_cond_broadcast
@sa mysql_cond_destroy
*/
typedef struct st_mysql_cond mysql_cond_t;
/*
Consider the following code:
static inline void foo() { bar(); }
when foo() is never called.
With gcc, foo() is a local static function, so the dependencies
are optimized away at compile time, and there is no dependency on bar().
With other compilers (HP, Sun Studio), the function foo() implementation
is compiled, and bar() needs to be present to link.
Due to the existing header dependencies in MySQL code, this header file
is sometime used when it is not needed, which in turn cause link failures
on some platforms.
The proper fix would be to cut these extra dependencies in the calling code.
DISABLE_MYSQL_THREAD_H is a work around to limit dependencies.
*/
#ifndef DISABLE_MYSQL_THREAD_H
/**
@def mysql_mutex_assert_owner(M)
Wrapper, to use safe_mutex_assert_owner with instrumented mutexes.
@c mysql_mutex_assert_owner is a drop-in replacement
for @c safe_mutex_assert_owner.
*/
#define mysql_mutex_assert_owner(M) \
safe_mutex_assert_owner(&(M)->m_mutex)
/**
@def mysql_mutex_assert_not_owner(M)
Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
@c mysql_mutex_assert_not_owner is a drop-in replacement
for @c safe_mutex_assert_not_owner.
*/
#define mysql_mutex_assert_not_owner(M) \
safe_mutex_assert_not_owner(&(M)->m_mutex)
/**
@def mysql_mutex_init(K, M, A)
Instrumented mutex_init.
@c mysql_mutex_init is a replacement for @c pthread_mutex_init.
@param K The PSI_mutex_key for this instrumented mutex
@param M The mutex to initialize
@param A Mutex attributes
*/
#ifdef HAVE_PSI_INTERFACE
#ifdef SAFE_MUTEX
#define mysql_mutex_init(K, M, A) \
inline_mysql_mutex_init(K, M, A, __FILE__, __LINE__)
#else
#define mysql_mutex_init(K, M, A) \
inline_mysql_mutex_init(K, M, A)
#endif
#else
#ifdef SAFE_MUTEX
#define mysql_mutex_init(K, M, A) \
inline_mysql_mutex_init(M, A, __FILE__, __LINE__)
#else
#define mysql_mutex_init(K, M, A) \
inline_mysql_mutex_init(M, A)
#endif
#endif
/**
@def mysql_mutex_destroy(M)
Instrumented mutex_destroy.
@c mysql_mutex_destroy is a drop-in replacement
for @c pthread_mutex_destroy.
*/
#ifdef SAFE_MUTEX
#define mysql_mutex_destroy(M) \
inline_mysql_mutex_destroy(M, __FILE__, __LINE__)
#else
#define mysql_mutex_destroy(M) \
inline_mysql_mutex_destroy(M)
#endif
/**
@def mysql_mutex_lock(M)
Instrumented mutex_lock.
@c mysql_mutex_lock is a drop-in replacement for @c pthread_mutex_lock.
@param M The mutex to lock
*/
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE)
#define mysql_mutex_lock(M) \
inline_mysql_mutex_lock(M, __FILE__, __LINE__)
#else
#define mysql_mutex_lock(M) \
inline_mysql_mutex_lock(M)
#endif
/**
@def mysql_mutex_trylock(M)
Instrumented mutex_lock.
@c mysql_mutex_trylock is a drop-in replacement
for @c pthread_mutex_trylock.
*/
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE)
#define mysql_mutex_trylock(M) \
inline_mysql_mutex_trylock(M, __FILE__, __LINE__)
#else
#define mysql_mutex_trylock(M) \
inline_mysql_mutex_trylock(M)
#endif
/**
@def mysql_mutex_unlock(M)
Instrumented mutex_unlock.
@c mysql_mutex_unlock is a drop-in replacement for @c pthread_mutex_unlock.
*/
#ifdef SAFE_MUTEX
#define mysql_mutex_unlock(M) \
inline_mysql_mutex_unlock(M, __FILE__, __LINE__)
#else
#define mysql_mutex_unlock(M) \
inline_mysql_mutex_unlock(M)
#endif
/**
@def mysql_rwlock_init(K, RW)
Instrumented rwlock_init.
@c mysql_rwlock_init is a replacement for @c pthread_rwlock_init.
Note that pthread_rwlockattr_t is not supported in MySQL.
@param K The PSI_rwlock_key for this instrumented rwlock
@param RW The rwlock to initialize
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(K, RW)
#else
#define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW)
#endif
/**
@def mysql_rwlock_destroy(RW)
Instrumented rwlock_destroy.
@c mysql_rwlock_destroy is a drop-in replacement
for @c pthread_rwlock_destroy.
*/
#define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW)
/**
@def mysql_rwlock_rdlock(RW)
Instrumented rwlock_rdlock.
@c mysql_rwlock_rdlock is a drop-in replacement
for @c pthread_rwlock_rdlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_rwlock_rdlock(RW) \
inline_mysql_rwlock_rdlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_rdlock(RW) \
inline_mysql_rwlock_rdlock(RW)
#endif
/**
@def mysql_rwlock_wrlock(RW)
Instrumented rwlock_wrlock.
@c mysql_rwlock_wrlock is a drop-in replacement
for @c pthread_rwlock_wrlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_rwlock_wrlock(RW) \
inline_mysql_rwlock_wrlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_wrlock(RW) \
inline_mysql_rwlock_wrlock(RW)
#endif
/**
@def mysql_rwlock_tryrdlock(RW)
Instrumented rwlock_tryrdlock.
@c mysql_rwlock_tryrdlock is a drop-in replacement
for @c pthread_rwlock_tryrdlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_rwlock_tryrdlock(RW) \
inline_mysql_rwlock_tryrdlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_tryrdlock(RW) \
inline_mysql_rwlock_tryrdlock(RW)
#endif
/**
@def mysql_rwlock_trywrlock(RW)
Instrumented rwlock_trywrlock.
@c mysql_rwlock_trywrlock is a drop-in replacement
for @c pthread_rwlock_trywrlock.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_rwlock_trywrlock(RW) \
inline_mysql_rwlock_trywrlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_trywrlock(RW) \
inline_mysql_rwlock_trywrlock(RW)
#endif
/**
@def mysql_rwlock_unlock(RW)
Instrumented rwlock_unlock.
@c mysql_rwlock_unlock is a drop-in replacement
for @c pthread_rwlock_unlock.
*/
#define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW)
/**
@def mysql_cond_init(K, C, A)
Instrumented rwlock_init.
@c mysql_cond_init is a replacement for @c pthread_cond_init.
@param C The cond to initialize
@param K The PSI_cond_key for this instrumented cond
@param A Condition attributes
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_cond_init(K, C, A) inline_mysql_cond_init(K, C, A)
#else
#define mysql_cond_init(K, C, A) inline_mysql_cond_init(C, A)
#endif
/**
@def mysql_cond_destroy(C)
Instrumented cond_destroy.
@c mysql_cond_destroy is a drop-in replacement for @c pthread_cond_destroy.
*/
#define mysql_cond_destroy(C) inline_mysql_cond_destroy(C)
/**
@def mysql_cond_wait(C)
Instrumented cond_wait.
@c mysql_cond_wait is a drop-in replacement for @c pthread_cond_wait.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_cond_wait(C, M) \
inline_mysql_cond_wait(C, M, __FILE__, __LINE__)
#else
#define mysql_cond_wait(C, M) \
inline_mysql_cond_wait(C, M)
#endif
/**
@def mysql_cond_timedwait(C, M, W)
Instrumented cond_timedwait.
@c mysql_cond_timedwait is a drop-in replacement
for @c pthread_cond_timedwait.
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_cond_timedwait(C, M, W) \
inline_mysql_cond_timedwait(C, M, W, __FILE__, __LINE__)
#else
#define mysql_cond_timedwait(C, M, W) \
inline_mysql_cond_timedwait(C, M, W)
#endif
/**
@def mysql_cond_signal(C)
Instrumented cond_signal.
@c mysql_cond_signal is a drop-in replacement for @c pthread_cond_signal.
*/
#define mysql_cond_signal(C) inline_mysql_cond_signal(C)
/**
@def mysql_cond_broadcast(C)
Instrumented cond_broadcast.
@c mysql_cond_broadcast is a drop-in replacement
for @c pthread_cond_broadcast.
*/
#define mysql_cond_broadcast(C) inline_mysql_cond_broadcast(C)
/**
@def mysql_thread_create(K, P1, P2, P3, P4)
Instrumented pthread_create.
This function creates both the thread instrumentation and a thread.
@c mysql_thread_create is a replacement for @c pthread_create.
The parameter P4 (or, if it is NULL, P1) will be used as the
instrumented thread "indentity".
Providing a P1 / P4 parameter with a different value for each call
will on average improve performances, since this thread identity value
is used internally to randomize access to data and prevent contention.
This is optional, and the improvement is not guaranteed, only statistical.
@param K The PSI_thread_key for this instrumented thread
@param P1 pthread_create parameter 1
@param P2 pthread_create parameter 2
@param P3 pthread_create parameter 3
@param P4 pthread_create parameter 4
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_thread_create(K, P1, P2, P3, P4) \
inline_mysql_thread_create(K, P1, P2, P3, P4)
#else
#define mysql_thread_create(K, P1, P2, P3, P4) \
pthread_create(P1, P2, P3, P4)
#endif
/**
@def mysql_thread_set_psi_id(I)
Set the thread indentifier for the instrumentation.
@param I The thread identifier
*/
#ifdef HAVE_PSI_INTERFACE
#define mysql_thread_set_psi_id(I) inline_mysql_thread_set_psi_id(I)
#else
#define mysql_thread_set_psi_id(I) do {} while (0)
#endif
static inline int inline_mysql_mutex_init(
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key key,
#endif
mysql_mutex_t *that,
const pthread_mutexattr_t *attr
#ifdef SAFE_MUTEX
, const char *src_file, uint src_line
#endif
)
{
#ifdef HAVE_PSI_INTERFACE
that->m_psi= PSI_server ? PSI_server->init_mutex(key, &that->m_mutex)
: NULL;
#else
that->m_psi= NULL;
#endif
#ifdef SAFE_MUTEX
return safe_mutex_init(&that->m_mutex, attr, src_file, src_line);
#else
return pthread_mutex_init(&that->m_mutex, attr);
#endif
}
static inline int inline_mysql_mutex_destroy(
mysql_mutex_t *that
#ifdef SAFE_MUTEX
, const char *src_file, uint src_line
#endif
)
{
#ifdef HAVE_PSI_INTERFACE
if (likely(PSI_server && that->m_psi))
{
PSI_server->destroy_mutex(that->m_psi);
that->m_psi= NULL;
}
#endif
#ifdef SAFE_MUTEX
return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
#else
return pthread_mutex_destroy(&that->m_mutex);
#endif
}
static inline int inline_mysql_mutex_lock(
mysql_mutex_t *that
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE)
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_mutex_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_mutex_locker(that->m_psi, PSI_MUTEX_LOCK);
if (likely(locker != NULL))
PSI_server->start_mutex_wait(locker, src_file, src_line);
}
#endif
#ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
#else
result= pthread_mutex_lock(&that->m_mutex);
#endif
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_mutex_wait(locker, result);
#endif
return result;
}
static inline int inline_mysql_mutex_trylock(
mysql_mutex_t *that
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_INTERFACE)
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_mutex_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_mutex_locker(that->m_psi, PSI_MUTEX_TRYLOCK);
if (likely(locker != NULL))
PSI_server->start_mutex_wait(locker, src_file, src_line);
}
#endif
#ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
#else
result= pthread_mutex_trylock(&that->m_mutex);
#endif
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_mutex_wait(locker, result);
#endif
return result;
}
static inline int inline_mysql_mutex_unlock(
mysql_mutex_t *that
#ifdef SAFE_MUTEX
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_thread *thread;
if (likely(PSI_server && that->m_psi))
{
thread= PSI_server->get_thread();
if (likely(thread != NULL))
PSI_server->unlock_mutex(thread, that->m_psi);
}
#endif
#ifdef SAFE_MUTEX
result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
#else
result= pthread_mutex_unlock(&that->m_mutex);
#endif
return result;
}
static inline int inline_mysql_rwlock_init(
#ifdef HAVE_PSI_INTERFACE
PSI_rwlock_key key,
#endif
mysql_rwlock_t *that)
{
#ifdef HAVE_PSI_INTERFACE
that->m_psi= (PSI_server ? PSI_server->init_rwlock(key, &that->m_rwlock)
: NULL);
#else
that->m_psi= NULL;
#endif
/*
pthread_rwlockattr_t is not used in MySQL.
*/
return my_rwlock_init(&that->m_rwlock, NULL);
}
static inline int inline_mysql_rwlock_destroy(
mysql_rwlock_t *that)
{
#ifdef HAVE_PSI_INTERFACE
if (likely(PSI_server && that->m_psi))
{
PSI_server->destroy_rwlock(that->m_psi);
that->m_psi= NULL;
}
#endif
return rwlock_destroy(&that->m_rwlock);
}
static inline int inline_mysql_rwlock_rdlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_READLOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_rdwait(locker, src_file, src_line);
}
#endif
result= rw_rdlock(&that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_rdwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_wrlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_WRITELOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_wrwait(locker, src_file, src_line);
}
#endif
result= rw_wrlock(&that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_wrwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_tryrdlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_TRYREADLOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_rdwait(locker, src_file, src_line);
}
#endif
result= rw_tryrdlock(&that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_rdwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_trywrlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_rwlock_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_rwlock_locker(that->m_psi,
PSI_RWLOCK_TRYWRITELOCK);
if (likely(locker != NULL))
PSI_server->start_rwlock_wrwait(locker, src_file, src_line);
}
#endif
result= rw_trywrlock(&that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_rwlock_wrwait(locker, result);
#endif
return result;
}
static inline int inline_mysql_rwlock_unlock(
mysql_rwlock_t *that)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_thread *thread;
if (likely(PSI_server && that->m_psi))
{
thread= PSI_server->get_thread();
if (likely(thread != NULL))
PSI_server->unlock_rwlock(thread, that->m_psi);
}
#endif
result= rw_unlock(&that->m_rwlock);
return result;
}
static inline int inline_mysql_cond_init(
#ifdef HAVE_PSI_INTERFACE
PSI_cond_key key,
#endif
mysql_cond_t *that,
const pthread_condattr_t *attr)
{
#ifdef HAVE_PSI_INTERFACE
that->m_psi= (PSI_server ? PSI_server->init_cond(key, &that->m_cond)
: NULL);
#else
that->m_psi= NULL;
#endif
return pthread_cond_init(&that->m_cond, attr);
}
static inline int inline_mysql_cond_destroy(
mysql_cond_t *that)
{
#ifdef HAVE_PSI_INTERFACE
if (likely(PSI_server && that->m_psi))
{
PSI_server->destroy_cond(that->m_psi);
that->m_psi= NULL;
}
#endif
return pthread_cond_destroy(&that->m_cond);
}
static inline int inline_mysql_cond_wait(
mysql_cond_t *that,
mysql_mutex_t *mutex
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_cond_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_cond_locker(that->m_psi, mutex->m_psi,
PSI_COND_WAIT);
if (likely(locker != NULL))
PSI_server->start_cond_wait(locker, src_file, src_line);
}
#endif
result= pthread_cond_wait(&that->m_cond, &mutex->m_mutex);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_cond_wait(locker, result);
#endif
return result;
}
static inline int inline_mysql_cond_timedwait(
mysql_cond_t *that,
mysql_mutex_t *mutex,
struct timespec *abstime
#ifdef HAVE_PSI_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_cond_locker *locker= NULL;
if (likely(PSI_server && that->m_psi))
{
locker= PSI_server->get_thread_cond_locker(that->m_psi, mutex->m_psi,
PSI_COND_TIMEDWAIT);
if (likely(locker != NULL))
PSI_server->start_cond_wait(locker, src_file, src_line);
}
#endif
result= pthread_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
#ifdef HAVE_PSI_INTERFACE
if (likely(locker != NULL))
PSI_server->end_cond_wait(locker, result);
#endif
return result;
}
static inline int inline_mysql_cond_signal(
mysql_cond_t *that)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_thread *thread;
if (likely(PSI_server && that->m_psi))
{
thread= PSI_server->get_thread();
if (likely(thread != NULL))
PSI_server->signal_cond(thread, that->m_psi);
}
#endif
result= pthread_cond_signal(&that->m_cond);
return result;
}
static inline int inline_mysql_cond_broadcast(
mysql_cond_t *that)
{
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_thread *thread;
if (likely(PSI_server && that->m_psi))
{
thread= PSI_server->get_thread();
if (likely(thread != NULL))
PSI_server->broadcast_cond(thread, that->m_psi);
}
#endif
result= pthread_cond_broadcast(&that->m_cond);
return result;
}
#ifdef HAVE_PSI_INTERFACE
static inline int inline_mysql_thread_create(
PSI_thread_key key,
pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg)
{
int result;
if (likely(PSI_server != NULL))
result= PSI_server->spawn_thread(key, thread, attr, start_routine, arg);
else
result= pthread_create(thread, attr, start_routine, arg);
return result;
}
static inline void inline_mysql_thread_set_psi_id(ulong id)
{
if (likely(PSI_server != NULL))
{
struct PSI_thread *psi= PSI_server->get_thread();
if (likely(psi != NULL))
PSI_server->set_thread_id(psi, id);
}
}
#endif
#endif /* DISABLE_MYSQL_THREAD_H */
/** @} (end of group Thread_instrumentation) */
#endif

1086
include/mysql/psi/psi.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
/* Copyright (C) 2008-2009 Sun Microsystems, Inc
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
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
@file mysql/psi/psi_abi_v1.h
ABI check for mysql/psi/psi.h, when using PSI_VERSION_1.
This file is only used to automate detection of changes between versions.
Do not include this file, include mysql/psi/psi.h instead.
*/
#define USE_PSI_1
#define HAVE_PSI_INTERFACE
#define _global_h
#include "mysql/psi/psi.h"

View File

@ -0,0 +1,242 @@
#include "mysql/psi/psi.h"
C_MODE_START
struct PSI_mutex;
struct PSI_rwlock;
struct PSI_cond;
struct PSI_table_share;
struct PSI_table;
struct PSI_thread;
struct PSI_file;
struct PSI_bootstrap
{
void* (*get_interface)(int version);
};
struct PSI_mutex_locker;
struct PSI_rwlock_locker;
struct PSI_cond_locker;
struct PSI_file_locker;
enum PSI_mutex_operation
{
PSI_MUTEX_LOCK= 0,
PSI_MUTEX_TRYLOCK= 1
};
enum PSI_rwlock_operation
{
PSI_RWLOCK_READLOCK= 0,
PSI_RWLOCK_WRITELOCK= 1,
PSI_RWLOCK_TRYREADLOCK= 2,
PSI_RWLOCK_TRYWRITELOCK= 3
};
enum PSI_cond_operation
{
PSI_COND_WAIT= 0,
PSI_COND_TIMEDWAIT= 1
};
enum PSI_file_operation
{
PSI_FILE_CREATE= 0,
PSI_FILE_CREATE_TMP= 1,
PSI_FILE_OPEN= 2,
PSI_FILE_STREAM_OPEN= 3,
PSI_FILE_CLOSE= 4,
PSI_FILE_STREAM_CLOSE= 5,
PSI_FILE_READ= 6,
PSI_FILE_WRITE= 7,
PSI_FILE_SEEK= 8,
PSI_FILE_TELL= 9,
PSI_FILE_FLUSH= 10,
PSI_FILE_STAT= 11,
PSI_FILE_FSTAT= 12,
PSI_FILE_CHSIZE= 13,
PSI_FILE_DELETE= 14,
PSI_FILE_RENAME= 15,
PSI_FILE_SYNC= 16
};
struct PSI_table_locker;
typedef unsigned int PSI_mutex_key;
typedef unsigned int PSI_rwlock_key;
typedef unsigned int PSI_cond_key;
typedef unsigned int PSI_thread_key;
typedef unsigned int PSI_file_key;
struct PSI_mutex_info_v1
{
PSI_mutex_key *m_key;
const char *m_name;
int m_flags;
};
struct PSI_rwlock_info_v1
{
PSI_rwlock_key *m_key;
const char *m_name;
int m_flags;
};
struct PSI_cond_info_v1
{
PSI_cond_key *m_key;
const char *m_name;
int m_flags;
};
struct PSI_thread_info_v1
{
PSI_thread_key *m_key;
const char *m_name;
int m_flags;
};
struct PSI_file_info_v1
{
PSI_file_key *m_key;
const char *m_name;
int m_flags;
};
typedef void (*register_mutex_v1_t)
(const char *category, struct PSI_mutex_info_v1 *info, int count);
typedef void (*register_rwlock_v1_t)
(const char *category, struct PSI_rwlock_info_v1 *info, int count);
typedef void (*register_cond_v1_t)
(const char *category, struct PSI_cond_info_v1 *info, int count);
typedef void (*register_thread_v1_t)
(const char *category, struct PSI_thread_info_v1 *info, int count);
typedef void (*register_file_v1_t)
(const char *category, struct PSI_file_info_v1 *info, int count);
typedef struct PSI_mutex* (*init_mutex_v1_t)
(PSI_mutex_key key, const void *identity);
typedef void (*destroy_mutex_v1_t)(struct PSI_mutex *mutex);
typedef struct PSI_rwlock* (*init_rwlock_v1_t)
(PSI_rwlock_key key, const void *identity);
typedef void (*destroy_rwlock_v1_t)(struct PSI_rwlock *rwlock);
typedef struct PSI_cond* (*init_cond_v1_t)
(PSI_cond_key key, const void *identity);
typedef void (*destroy_cond_v1_t)(struct PSI_cond *cond);
typedef struct PSI_table_share* (*get_table_share_v1_t)
(const char *schema_name, int schema_name_length, const char *table_name,
int table_name_length, const void *identity);
typedef void (*release_table_share_v1_t)(struct PSI_table_share *share);
typedef struct PSI_table* (*open_table_v1_t)
(struct PSI_table_share *share, const void *identity);
typedef void (*close_table_v1_t)(struct PSI_table *table);
typedef void (*create_file_v1_t)(PSI_file_key key, const char *name,
File file);
typedef int (*spawn_thread_v1_t)(PSI_thread_key key,
pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg);
typedef struct PSI_thread* (*new_thread_v1_t)
(PSI_thread_key key, const void *identity, ulong thread_id);
typedef void (*set_thread_id_v1_t)(struct PSI_thread *thread,
unsigned long id);
typedef struct PSI_thread* (*get_thread_v1_t)(void);
typedef void (*set_thread_v1_t)(struct PSI_thread *thread);
typedef void (*delete_current_thread_v1_t)(void);
typedef struct PSI_mutex_locker* (*get_thread_mutex_locker_v1_t)
(struct PSI_mutex *mutex, enum PSI_mutex_operation op);
typedef struct PSI_rwlock_locker* (*get_thread_rwlock_locker_v1_t)
(struct PSI_rwlock *rwlock, enum PSI_rwlock_operation op);
typedef struct PSI_cond_locker* (*get_thread_cond_locker_v1_t)
(struct PSI_cond *cond, struct PSI_mutex *mutex,
enum PSI_cond_operation op);
typedef struct PSI_table_locker* (*get_thread_table_locker_v1_t)
(struct PSI_table *table);
typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t)
(PSI_file_key key, enum PSI_file_operation op, const char *name,
const void *identity);
typedef struct PSI_file_locker* (*get_thread_file_stream_locker_v1_t)
(struct PSI_file *file, enum PSI_file_operation op);
typedef struct PSI_file_locker* (*get_thread_file_descriptor_locker_v1_t)
(File file, enum PSI_file_operation op);
typedef void (*unlock_mutex_v1_t)
(struct PSI_thread *thread, struct PSI_mutex *mutex);
typedef void (*unlock_rwlock_v1_t)
(struct PSI_thread *thread, struct PSI_rwlock *rwlock);
typedef void (*signal_cond_v1_t)
(struct PSI_thread *thread, struct PSI_cond *cond);
typedef void (*broadcast_cond_v1_t)
(struct PSI_thread *thread, struct PSI_cond *cond);
typedef void (*start_mutex_wait_v1_t)
(struct PSI_mutex_locker *locker, const char *src_file, uint src_line);
typedef void (*end_mutex_wait_v1_t)
(struct PSI_mutex_locker *locker, int rc);
typedef void (*start_rwlock_rdwait_v1_t)
(struct PSI_rwlock_locker *locker, const char *src_file, uint src_line);
typedef void (*end_rwlock_rdwait_v1_t)
(struct PSI_rwlock_locker *locker, int rc);
typedef void (*start_rwlock_wrwait_v1_t)
(struct PSI_rwlock_locker *locker, const char *src_file, uint src_line);
typedef void (*end_rwlock_wrwait_v1_t)
(struct PSI_rwlock_locker *locker, int rc);
typedef void (*start_cond_wait_v1_t)
(struct PSI_cond_locker *locker, const char *src_file, uint src_line);
typedef void (*end_cond_wait_v1_t)
(struct PSI_cond_locker *locker, int rc);
typedef void (*start_table_wait_v1_t)
(struct PSI_table_locker *locker, const char *src_file, uint src_line);
typedef void (*end_table_wait_v1_t)(struct PSI_table_locker *locker);
typedef struct PSI_file* (*start_file_open_wait_v1_t)
(struct PSI_file_locker *locker, const char *src_file, uint src_line);
typedef void (*end_file_open_wait_v1_t)(struct PSI_file_locker *locker);
typedef void (*end_file_open_wait_and_bind_to_descriptor_v1_t)
(struct PSI_file_locker *locker, File file);
typedef void (*start_file_wait_v1_t)
(struct PSI_file_locker *locker, size_t count,
const char *src_file, uint src_line);
typedef void (*end_file_wait_v1_t)
(struct PSI_file_locker *locker, size_t count);
struct PSI_v1
{
register_mutex_v1_t register_mutex;
register_rwlock_v1_t register_rwlock;
register_cond_v1_t register_cond;
register_thread_v1_t register_thread;
register_file_v1_t register_file;
init_mutex_v1_t init_mutex;
destroy_mutex_v1_t destroy_mutex;
init_rwlock_v1_t init_rwlock;
destroy_rwlock_v1_t destroy_rwlock;
init_cond_v1_t init_cond;
destroy_cond_v1_t destroy_cond;
get_table_share_v1_t get_table_share;
release_table_share_v1_t release_table_share;
open_table_v1_t open_table;
close_table_v1_t close_table;
create_file_v1_t create_file;
spawn_thread_v1_t spawn_thread;
new_thread_v1_t new_thread;
set_thread_id_v1_t set_thread_id;
get_thread_v1_t get_thread;
set_thread_v1_t set_thread;
delete_current_thread_v1_t delete_current_thread;
get_thread_mutex_locker_v1_t get_thread_mutex_locker;
get_thread_rwlock_locker_v1_t get_thread_rwlock_locker;
get_thread_cond_locker_v1_t get_thread_cond_locker;
get_thread_table_locker_v1_t get_thread_table_locker;
get_thread_file_name_locker_v1_t get_thread_file_name_locker;
get_thread_file_stream_locker_v1_t get_thread_file_stream_locker;
get_thread_file_descriptor_locker_v1_t get_thread_file_descriptor_locker;
unlock_mutex_v1_t unlock_mutex;
unlock_rwlock_v1_t unlock_rwlock;
signal_cond_v1_t signal_cond;
broadcast_cond_v1_t broadcast_cond;
start_mutex_wait_v1_t start_mutex_wait;
end_mutex_wait_v1_t end_mutex_wait;
start_rwlock_rdwait_v1_t start_rwlock_rdwait;
end_rwlock_rdwait_v1_t end_rwlock_rdwait;
start_rwlock_wrwait_v1_t start_rwlock_wrwait;
end_rwlock_wrwait_v1_t end_rwlock_wrwait;
start_cond_wait_v1_t start_cond_wait;
end_cond_wait_v1_t end_cond_wait;
start_table_wait_v1_t start_table_wait;
end_table_wait_v1_t end_table_wait;
start_file_open_wait_v1_t start_file_open_wait;
end_file_open_wait_v1_t end_file_open_wait;
end_file_open_wait_and_bind_to_descriptor_v1_t
end_file_open_wait_and_bind_to_descriptor;
start_file_wait_v1_t start_file_wait;
end_file_wait_v1_t end_file_wait;
};
typedef struct PSI_v1 PSI;
typedef struct PSI_mutex_info_v1 PSI_mutex_info;
typedef struct PSI_rwlock_info_v1 PSI_rwlock_info;
typedef struct PSI_cond_info_v1 PSI_cond_info;
typedef struct PSI_thread_info_v1 PSI_thread_info;
typedef struct PSI_file_info_v1 PSI_file_info;
extern MYSQL_PLUGIN_IMPORT PSI *PSI_server;
C_MODE_END

View File

@ -0,0 +1,26 @@
/* Copyright (C) 2008-2009 Sun Microsystems, Inc
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
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
@file mysql/psi/psi_abi_v1.h
ABI check for mysql/psi/psi.h, when using PSI_VERSION_2.
This file is only used to automate detection of changes between versions.
Do not include this file, include mysql/psi/psi.h instead.
*/
#define USE_PSI_2
#define HAVE_PSI_INTERFACE
#define _global_h
#include "mysql/psi/psi.h"

View File

@ -0,0 +1,92 @@
#include "mysql/psi/psi.h"
C_MODE_START
struct PSI_mutex;
struct PSI_rwlock;
struct PSI_cond;
struct PSI_table_share;
struct PSI_table;
struct PSI_thread;
struct PSI_file;
struct PSI_bootstrap
{
void* (*get_interface)(int version);
};
struct PSI_mutex_locker;
struct PSI_rwlock_locker;
struct PSI_cond_locker;
struct PSI_file_locker;
enum PSI_mutex_operation
{
PSI_MUTEX_LOCK= 0,
PSI_MUTEX_TRYLOCK= 1
};
enum PSI_rwlock_operation
{
PSI_RWLOCK_READLOCK= 0,
PSI_RWLOCK_WRITELOCK= 1,
PSI_RWLOCK_TRYREADLOCK= 2,
PSI_RWLOCK_TRYWRITELOCK= 3
};
enum PSI_cond_operation
{
PSI_COND_WAIT= 0,
PSI_COND_TIMEDWAIT= 1
};
enum PSI_file_operation
{
PSI_FILE_CREATE= 0,
PSI_FILE_CREATE_TMP= 1,
PSI_FILE_OPEN= 2,
PSI_FILE_STREAM_OPEN= 3,
PSI_FILE_CLOSE= 4,
PSI_FILE_STREAM_CLOSE= 5,
PSI_FILE_READ= 6,
PSI_FILE_WRITE= 7,
PSI_FILE_SEEK= 8,
PSI_FILE_TELL= 9,
PSI_FILE_FLUSH= 10,
PSI_FILE_STAT= 11,
PSI_FILE_FSTAT= 12,
PSI_FILE_CHSIZE= 13,
PSI_FILE_DELETE= 14,
PSI_FILE_RENAME= 15,
PSI_FILE_SYNC= 16
};
struct PSI_table_locker;
typedef unsigned int PSI_mutex_key;
typedef unsigned int PSI_rwlock_key;
typedef unsigned int PSI_cond_key;
typedef unsigned int PSI_thread_key;
typedef unsigned int PSI_file_key;
struct PSI_v2
{
int placeholder;
};
struct PSI_mutex_info_v2
{
int placeholder;
};
struct PSI_rwlock_info_v2
{
int placeholder;
};
struct PSI_cond_info_v2
{
int placeholder;
};
struct PSI_thread_info_v2
{
int placeholder;
};
struct PSI_file_info_v2
{
int placeholder;
};
typedef struct PSI_v2 PSI;
typedef struct PSI_mutex_info_v2 PSI_mutex_info;
typedef struct PSI_rwlock_info_v2 PSI_rwlock_info;
typedef struct PSI_cond_info_v2 PSI_cond_info;
typedef struct PSI_thread_info_v2 PSI_thread_info;
typedef struct PSI_file_info_v2 PSI_file_info;
extern MYSQL_PLUGIN_IMPORT PSI *PSI_server;
C_MODE_END

View File

@ -1,4 +1,4 @@
# Copyright (C) 2000-2004 MySQL AB # Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc.
# #
# 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 version 2 GNU General Public License as # it under the terms of version 2 GNU General Public License as
@ -21,7 +21,9 @@
# This file is public domain and comes with NO WARRANTY of any kind # This file is public domain and comes with NO WARRANTY of any kind
target = libmysqlclient.la target = libmysqlclient.la
target_defs = -DMYSQL_CLIENT_NO_THREADS -DDONT_USE_RAID @LIB_EXTRA_CCFLAGS@ target_defs = -DMYSQL_CLIENT_NO_THREADS -DDONT_USE_RAID \
-DDISABLE_MYSQL_THREAD_H @LIB_EXTRA_CCFLAGS@
LIBS = @CLIENT_LIBS@ LIBS = @CLIENT_LIBS@
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
$(openssl_includes) @ZLIB_INCLUDES@ $(openssl_includes) @ZLIB_INCLUDES@

View File

@ -1,4 +1,4 @@
# Copyright (C) 2000-2004 MySQL AB # Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc.
# #
# 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 version 2 GNU General Public License as # it under the terms of version 2 GNU General Public License as
@ -68,7 +68,8 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \
mf_iocache2.lo my_seek.lo my_sleep.lo \ mf_iocache2.lo my_seek.lo my_sleep.lo \
my_pread.lo mf_cache.lo md5.lo sha1.lo \ my_pread.lo mf_cache.lo md5.lo sha1.lo \
my_getopt.lo my_gethostbyname.lo my_port.lo \ my_getopt.lo my_gethostbyname.lo my_port.lo \
my_rename.lo my_chsize.lo my_sync.lo my_getsystime.lo my_rename.lo my_chsize.lo my_sync.lo \
my_getsystime.lo my_symlink2.lo mf_same.lo
sqlobjects = net.lo sqlobjects = net.lo
sql_cmn_objects = pack.lo client.lo my_time.lo sql_cmn_objects = pack.lo client.lo my_time.lo

View File

@ -124,3 +124,31 @@ my_bool NEAR my_disable_async_io=0;
my_bool NEAR my_disable_flush_key_blocks=0; my_bool NEAR my_disable_flush_key_blocks=0;
my_bool NEAR my_disable_symlinks=0; my_bool NEAR my_disable_symlinks=0;
my_bool NEAR mysys_uses_curses=0; my_bool NEAR mysys_uses_curses=0;
/*
Note that PSI_hook and PSI_server are unconditionally
(no ifdef HAVE_PSI_INTERFACE) defined.
This is to ensure binary compatibility between the server and plugins,
in the case when:
- the server is not compiled with HAVE_PSI_INTERFACE
- a plugin is compiled with HAVE_PSI_INTERFACE
See the doxygen documentation for the performance schema.
*/
/**
Hook for the instrumentation interface.
Code implementing the instrumentation interface should register here.
*/
struct PSI_bootstrap *PSI_hook= NULL;
/**
Instance of the instrumentation interface for the MySQL server.
@todo This is currently a global variable, which is handy when
compiling instrumented code that is bundled with the server.
When dynamic plugin are truly supported, this variable will need
to be replaced by a macro, so that each XYZ plugin can have it's own
xyz_psi_server variable, obtained from PSI_bootstrap::get_interface()
with the version used at compile time for plugin XYZ.
*/
PSI *PSI_server= NULL;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -63,8 +63,8 @@ static unsigned int __stdcall pthread_start(void *p)
} }
int pthread_create(pthread_t *thread_id, pthread_attr_t *attr, int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr,
pthread_handler func, void *param) pthread_handler func, void *param)
{ {
uintptr_t handle; uintptr_t handle;
struct thread_start_parameter *par; struct thread_start_parameter *par;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000 MySQL AB /* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -26,12 +26,54 @@
#ifdef THREAD #ifdef THREAD
#include <my_pthread.h> #include <my_pthread.h>
#ifdef HAVE_PSI_INTERFACE
#if !defined(HAVE_PREAD) && !defined(_WIN32)
extern PSI_mutex_key key_my_file_info_mutex;
#endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
extern PSI_mutex_key key_LOCK_localtime_r;
#endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */
#ifndef HAVE_GETHOSTBYNAME_R
extern PSI_mutex_key key_LOCK_gethostbyname_r;
#endif /* HAVE_GETHOSTBYNAME_R */
extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock, key_LOCK_alarm,
key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap,
key_THR_LOCK_isam, key_THR_LOCK_lock, key_THR_LOCK_malloc,
key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net,
key_THR_LOCK_open, key_THR_LOCK_threads, key_THR_LOCK_time,
key_TMPDIR_mutex;
extern PSI_cond_key key_COND_alarm, key_IO_CACHE_SHARE_cond,
key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,
key_THR_COND_threads;
#ifdef USE_ALARM_THREAD
extern PSI_thread_key key_thread_alarm;
#endif /* USE_ALARM_THREAD */
#endif /* HAVE_PSI_INTERFACE */
extern pthread_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache; extern pthread_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache;
extern pthread_mutex_t THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_net; extern pthread_mutex_t THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_net;
extern pthread_mutex_t THR_LOCK_charset, THR_LOCK_time; extern pthread_mutex_t THR_LOCK_charset, THR_LOCK_time;
#else #else /* THREAD */
#include <my_no_pthread.h> #include <my_no_pthread.h>
#endif #endif /* THREAD */
#include <mysql/psi/mysql_file.h>
#ifdef HAVE_PSI_INTERFACE
#ifdef HUGETLB_USE_PROC_MEMINFO
extern PSI_file_key key_file_proc_meminfo;
#endif /* HUGETLB_USE_PROC_MEMINFO */
extern PSI_file_key key_file_charset, key_file_cnf;
#endif /* HAVE_PSI_INTERFACE */
/* /*
EDQUOT is used only in 3 C files only in mysys/. If it does not exist on EDQUOT is used only in 3 C files only in mysys/. If it does not exist on

View File

@ -1,4 +1,4 @@
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. /* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
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
@ -53,6 +53,7 @@
#include "sql_array.h" #include "sql_array.h"
#include "sql_plugin.h" #include "sql_plugin.h"
#include "scheduler.h" #include "scheduler.h"
#include <mysql/psi/mysql_file.h>
#ifndef __WIN__ #ifndef __WIN__
#include <netdb.h> #include <netdb.h>
#endif #endif

View File

@ -2098,6 +2098,12 @@ public:
proc_info = msg; proc_info = msg;
return old_msg; return old_msg;
} }
inline const char* enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex,
const char *msg)
{
/* TO BE REMOVED: temporary helper, to help with merges */
return enter_cond(&cond->m_cond, &mutex->m_mutex, msg);
}
inline void exit_cond(const char* old_msg) inline void exit_cond(const char* old_msg)
{ {
/* /*

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -95,7 +95,7 @@
*/ */
/* Variables for archive share methods */ /* Variables for archive share methods */
pthread_mutex_t archive_mutex; mysql_mutex_t archive_mutex;
static HASH archive_open_tables; static HASH archive_open_tables;
/* The file extension */ /* The file extension */
@ -145,6 +145,28 @@ static uchar* archive_get_key(ARCHIVE_SHARE *share, size_t *length,
return (uchar*) share->table_name; return (uchar*) share->table_name;
} }
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key az_key_mutex_archive_mutex, az_key_mutex_ARCHIVE_SHARE_mutex;
static PSI_mutex_info all_archive_mutexes[]=
{
{ &az_key_mutex_archive_mutex, "archive_mutex", PSI_FLAG_GLOBAL},
{ &az_key_mutex_ARCHIVE_SHARE_mutex, "ARCHIVE_SHARE::mutex", 0}
};
static void init_archive_psi_keys(void)
{
const char* category= "archive";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_archive_mutexes);
PSI_server->register_mutex(category, all_archive_mutexes, count);
}
#endif /* HAVE_PSI_INTERFACE */
/* /*
Initialize the archive handler. Initialize the archive handler.
@ -163,6 +185,10 @@ int archive_db_init(void *p)
DBUG_ENTER("archive_db_init"); DBUG_ENTER("archive_db_init");
handlerton *archive_hton; handlerton *archive_hton;
#ifdef HAVE_PSI_INTERFACE
init_archive_psi_keys();
#endif
archive_hton= (handlerton *)p; archive_hton= (handlerton *)p;
archive_hton->state= SHOW_OPTION_YES; archive_hton->state= SHOW_OPTION_YES;
archive_hton->db_type= DB_TYPE_ARCHIVE_DB; archive_hton->db_type= DB_TYPE_ARCHIVE_DB;
@ -170,12 +196,13 @@ int archive_db_init(void *p)
archive_hton->flags= HTON_NO_FLAGS; archive_hton->flags= HTON_NO_FLAGS;
archive_hton->discover= archive_discover; archive_hton->discover= archive_discover;
if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST)) if (mysql_mutex_init(az_key_mutex_archive_mutex,
&archive_mutex, MY_MUTEX_INIT_FAST))
goto error; goto error;
if (my_hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0, if (my_hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0,
(my_hash_get_key) archive_get_key, 0, 0)) (my_hash_get_key) archive_get_key, 0, 0))
{ {
pthread_mutex_destroy(&archive_mutex); mysql_mutex_destroy(&archive_mutex);
} }
else else
{ {
@ -199,7 +226,7 @@ error:
int archive_db_done(void *p) int archive_db_done(void *p)
{ {
my_hash_free(&archive_open_tables); my_hash_free(&archive_open_tables);
pthread_mutex_destroy(&archive_mutex); mysql_mutex_destroy(&archive_mutex);
return 0; return 0;
} }
@ -313,7 +340,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
uint length; uint length;
DBUG_ENTER("ha_archive::get_share"); DBUG_ENTER("ha_archive::get_share");
pthread_mutex_lock(&archive_mutex); mysql_mutex_lock(&archive_mutex);
length=(uint) strlen(table_name); length=(uint) strlen(table_name);
if (!(share=(ARCHIVE_SHARE*) my_hash_search(&archive_open_tables, if (!(share=(ARCHIVE_SHARE*) my_hash_search(&archive_open_tables,
@ -328,7 +355,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
&tmp_name, length+1, &tmp_name, length+1,
NullS)) NullS))
{ {
pthread_mutex_unlock(&archive_mutex); mysql_mutex_unlock(&archive_mutex);
*rc= HA_ERR_OUT_OF_MEM; *rc= HA_ERR_OUT_OF_MEM;
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
@ -346,7 +373,8 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
/* /*
We will use this lock for rows. We will use this lock for rows.
*/ */
pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); mysql_mutex_init(az_key_mutex_ARCHIVE_SHARE_mutex,
&share->mutex, MY_MUTEX_INIT_FAST);
/* /*
We read the meta file, but do not mark it dirty. Since we are not We read the meta file, but do not mark it dirty. Since we are not
@ -372,7 +400,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
share->use_count)); share->use_count));
if (share->crashed) if (share->crashed)
*rc= HA_ERR_CRASHED_ON_USAGE; *rc= HA_ERR_CRASHED_ON_USAGE;
pthread_mutex_unlock(&archive_mutex); mysql_mutex_unlock(&archive_mutex);
DBUG_RETURN(share); DBUG_RETURN(share);
} }
@ -391,12 +419,12 @@ int ha_archive::free_share()
share->table_name_length, share->table_name, share->table_name_length, share->table_name,
share->use_count)); share->use_count));
pthread_mutex_lock(&archive_mutex); mysql_mutex_lock(&archive_mutex);
if (!--share->use_count) if (!--share->use_count)
{ {
my_hash_delete(&archive_open_tables, (uchar*) share); my_hash_delete(&archive_open_tables, (uchar*) share);
thr_lock_delete(&share->lock); thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->mutex); mysql_mutex_destroy(&share->mutex);
/* /*
We need to make sure we don't reset the crashed state. We need to make sure we don't reset the crashed state.
If we open a crashed file, wee need to close it as crashed unless If we open a crashed file, wee need to close it as crashed unless
@ -411,7 +439,7 @@ int ha_archive::free_share()
} }
my_free((uchar*) share, MYF(0)); my_free((uchar*) share, MYF(0));
} }
pthread_mutex_unlock(&archive_mutex); mysql_mutex_unlock(&archive_mutex);
DBUG_RETURN(rc); DBUG_RETURN(rc);
} }
@ -651,7 +679,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
*/ */
if ((frm_file= my_open(name_buff, O_RDONLY, MYF(0))) > 0) if ((frm_file= my_open(name_buff, O_RDONLY, MYF(0))) > 0)
{ {
if (!my_fstat(frm_file, &file_stat, MYF(MY_WME))) if (!mysql_file_fstat(frm_file, &file_stat, MYF(MY_WME)))
{ {
frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0)); frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0));
if (frm_ptr) if (frm_ptr)
@ -800,7 +828,7 @@ int ha_archive::write_row(uchar *buf)
ha_statistic_increment(&SSV::ha_write_count); ha_statistic_increment(&SSV::ha_write_count);
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
table->timestamp_field->set_time(); table->timestamp_field->set_time();
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
if (!share->archive_write_open) if (!share->archive_write_open)
if (init_archive_writer()) if (init_archive_writer())
@ -883,7 +911,7 @@ int ha_archive::write_row(uchar *buf)
share->rows_recorded++; share->rows_recorded++;
rc= real_write_row(buf, &(share->archive_write)); rc= real_write_row(buf, &(share->archive_write));
error: error:
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
if (read_buf) if (read_buf)
my_free((uchar*) read_buf, MYF(0)); my_free((uchar*) read_buf, MYF(0));
@ -1387,7 +1415,7 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
azclose(&archive); azclose(&archive);
// make the file we just wrote be our data file // make the file we just wrote be our data file
rc = my_rename(writer_filename,share->data_file_name,MYF(0)); rc= my_rename(writer_filename, share->data_file_name, MYF(0));
DBUG_RETURN(rc); DBUG_RETURN(rc);
@ -1471,7 +1499,7 @@ int ha_archive::info(uint flag)
If dirty, we lock, and then reset/flush the data. If dirty, we lock, and then reset/flush the data.
I found that just calling azflush() doesn't always work. I found that just calling azflush() doesn't always work.
*/ */
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
if (share->dirty == TRUE) if (share->dirty == TRUE)
{ {
if (share->dirty == TRUE) if (share->dirty == TRUE)
@ -1487,7 +1515,7 @@ int ha_archive::info(uint flag)
cause the number to be inaccurate. cause the number to be inaccurate.
*/ */
stats.records= share->rows_recorded; stats.records= share->rows_recorded;
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
stats.deleted= 0; stats.deleted= 0;
@ -1512,9 +1540,9 @@ int ha_archive::info(uint flag)
if (flag & HA_STATUS_AUTO) if (flag & HA_STATUS_AUTO)
{ {
init_archive_reader(); init_archive_reader();
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
azflush(&archive, Z_SYNC_FLUSH); azflush(&archive, Z_SYNC_FLUSH);
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
stats.auto_increment_value= archive.auto_increment + 1; stats.auto_increment_value= archive.auto_increment + 1;
} }
@ -1582,9 +1610,9 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
old_proc_info= thd_proc_info(thd, "Checking table"); old_proc_info= thd_proc_info(thd, "Checking table");
/* Flush any waiting data */ /* Flush any waiting data */
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
azflush(&(share->archive_write), Z_SYNC_FLUSH); azflush(&(share->archive_write), Z_SYNC_FLUSH);
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
/* /*
Now we will rewind the archive file so that we are positioned at the Now we will rewind the archive file so that we are positioned at the

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -36,7 +36,7 @@ typedef struct st_archive_share {
char *table_name; char *table_name;
char data_file_name[FN_REFLEN]; char data_file_name[FN_REFLEN];
uint table_name_length,use_count; uint table_name_length,use_count;
pthread_mutex_t mutex; mysql_mutex_t mutex;
THR_LOCK lock; THR_LOCK lock;
azio_stream archive_write; /* Archive file we are working with */ azio_stream archive_write; /* Archive file we are working with */
bool archive_write_open; bool archive_write_open;

View File

@ -1,4 +1,4 @@
/* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc. /* Copyright 2005-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
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
@ -35,7 +35,7 @@ static handler *blackhole_create_handler(handlerton *hton,
/* Static declarations for shared structures */ /* Static declarations for shared structures */
static pthread_mutex_t blackhole_mutex; static mysql_mutex_t blackhole_mutex;
static HASH blackhole_open_tables; static HASH blackhole_open_tables;
static st_blackhole_share *get_share(const char *table_name); static st_blackhole_share *get_share(const char *table_name);
@ -317,7 +317,7 @@ static st_blackhole_share *get_share(const char *table_name)
uint length; uint length;
length= (uint) strlen(table_name); length= (uint) strlen(table_name);
pthread_mutex_lock(&blackhole_mutex); mysql_mutex_lock(&blackhole_mutex);
if (!(share= (st_blackhole_share*) if (!(share= (st_blackhole_share*)
my_hash_search(&blackhole_open_tables, my_hash_search(&blackhole_open_tables,
@ -343,16 +343,16 @@ static st_blackhole_share *get_share(const char *table_name)
share->use_count++; share->use_count++;
error: error:
pthread_mutex_unlock(&blackhole_mutex); mysql_mutex_unlock(&blackhole_mutex);
return share; return share;
} }
static void free_share(st_blackhole_share *share) static void free_share(st_blackhole_share *share)
{ {
pthread_mutex_lock(&blackhole_mutex); mysql_mutex_lock(&blackhole_mutex);
if (!--share->use_count) if (!--share->use_count)
my_hash_delete(&blackhole_open_tables, (uchar*) share); my_hash_delete(&blackhole_open_tables, (uchar*) share);
pthread_mutex_unlock(&blackhole_mutex); mysql_mutex_unlock(&blackhole_mutex);
} }
static void blackhole_free_key(st_blackhole_share *share) static void blackhole_free_key(st_blackhole_share *share)
@ -368,16 +368,43 @@ static uchar* blackhole_get_key(st_blackhole_share *share, size_t *length,
return (uchar*) share->table_name; return (uchar*) share->table_name;
} }
#ifdef HAVE_PSI_INTERFACE
static PSI_mutex_key bh_key_mutex_blackhole;
static PSI_mutex_info all_blackhole_mutexes[]=
{
{ &bh_key_mutex_blackhole, "blackhole", PSI_FLAG_GLOBAL}
};
void init_blackhole_psi_keys()
{
const char* category= "blackhole";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_blackhole_mutexes);
PSI_server->register_mutex(category, all_blackhole_mutexes, count);
}
#endif
static int blackhole_init(void *p) static int blackhole_init(void *p)
{ {
handlerton *blackhole_hton; handlerton *blackhole_hton;
#ifdef HAVE_PSI_INTERFACE
init_blackhole_psi_keys();
#endif
blackhole_hton= (handlerton *)p; blackhole_hton= (handlerton *)p;
blackhole_hton->state= SHOW_OPTION_YES; blackhole_hton->state= SHOW_OPTION_YES;
blackhole_hton->db_type= DB_TYPE_BLACKHOLE_DB; blackhole_hton->db_type= DB_TYPE_BLACKHOLE_DB;
blackhole_hton->create= blackhole_create_handler; blackhole_hton->create= blackhole_create_handler;
blackhole_hton->flags= HTON_CAN_RECREATE; blackhole_hton->flags= HTON_CAN_RECREATE;
pthread_mutex_init(&blackhole_mutex, MY_MUTEX_INIT_FAST); mysql_mutex_init(bh_key_mutex_blackhole,
&blackhole_mutex, MY_MUTEX_INIT_FAST);
(void) my_hash_init(&blackhole_open_tables, system_charset_info,32,0,0, (void) my_hash_init(&blackhole_open_tables, system_charset_info,32,0,0,
(my_hash_get_key) blackhole_get_key, (my_hash_get_key) blackhole_get_key,
(my_hash_free_key) blackhole_free_key, 0); (my_hash_free_key) blackhole_free_key, 0);
@ -388,7 +415,7 @@ static int blackhole_init(void *p)
static int blackhole_fini(void *p) static int blackhole_fini(void *p)
{ {
my_hash_free(&blackhole_open_tables); my_hash_free(&blackhole_open_tables);
pthread_mutex_destroy(&blackhole_mutex); mysql_mutex_destroy(&blackhole_mutex);
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -75,7 +75,7 @@ extern "C" void tina_update_status(void* param);
extern "C" my_bool tina_check_status(void* param); extern "C" my_bool tina_check_status(void* param);
/* Stuff for shares */ /* Stuff for shares */
pthread_mutex_t tina_mutex; mysql_mutex_t tina_mutex;
static HASH tina_open_tables; static HASH tina_open_tables;
static handler *tina_create_handler(handlerton *hton, static handler *tina_create_handler(handlerton *hton,
TABLE_SHARE *table, TABLE_SHARE *table,
@ -105,12 +105,52 @@ static uchar* tina_get_key(TINA_SHARE *share, size_t *length,
return (uchar*) share->table_name; return (uchar*) share->table_name;
} }
#ifdef HAVE_PSI_INTERFACE
static PSI_mutex_key csv_key_mutex_tina, csv_key_mutex_TINA_SHARE_mutex;
static PSI_mutex_info all_tina_mutexes[]=
{
{ &csv_key_mutex_tina, "tina", PSI_FLAG_GLOBAL},
{ &csv_key_mutex_TINA_SHARE_mutex, "TINA_SHARE::mutex", 0}
};
static PSI_file_key csv_key_file_metadata, csv_key_file_data,
csv_key_file_update;
static PSI_file_info all_tina_files[]=
{
{ &csv_key_file_metadata, "metadata", 0},
{ &csv_key_file_data, "data", 0},
{ &csv_key_file_update, "update", 0}
};
static void init_tina_psi_keys(void)
{
const char* category= "csv";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_tina_mutexes);
PSI_server->register_mutex(category, all_tina_mutexes, count);
count= array_elements(all_tina_files);
PSI_server->register_file(category, all_tina_files, count);
}
#endif /* HAVE_PSI_INTERFACE */
static int tina_init_func(void *p) static int tina_init_func(void *p)
{ {
handlerton *tina_hton; handlerton *tina_hton;
#ifdef HAVE_PSI_INTERFACE
init_tina_psi_keys();
#endif
tina_hton= (handlerton *)p; tina_hton= (handlerton *)p;
pthread_mutex_init(&tina_mutex,MY_MUTEX_INIT_FAST); mysql_mutex_init(csv_key_mutex_tina, &tina_mutex, MY_MUTEX_INIT_FAST);
(void) my_hash_init(&tina_open_tables,system_charset_info,32,0,0, (void) my_hash_init(&tina_open_tables,system_charset_info,32,0,0,
(my_hash_get_key) tina_get_key,0,0); (my_hash_get_key) tina_get_key,0,0);
tina_hton->state= SHOW_OPTION_YES; tina_hton->state= SHOW_OPTION_YES;
@ -124,7 +164,7 @@ static int tina_init_func(void *p)
static int tina_done_func(void *p) static int tina_done_func(void *p)
{ {
my_hash_free(&tina_open_tables); my_hash_free(&tina_open_tables);
pthread_mutex_destroy(&tina_mutex); mysql_mutex_destroy(&tina_mutex);
return 0; return 0;
} }
@ -141,7 +181,7 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
char *tmp_name; char *tmp_name;
uint length; uint length;
pthread_mutex_lock(&tina_mutex); mysql_mutex_lock(&tina_mutex);
length=(uint) strlen(table_name); length=(uint) strlen(table_name);
/* /*
@ -157,7 +197,7 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
&tmp_name, length+1, &tmp_name, length+1,
NullS)) NullS))
{ {
pthread_mutex_unlock(&tina_mutex); mysql_mutex_unlock(&tina_mutex);
return NULL; return NULL;
} }
@ -176,14 +216,16 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
fn_format(meta_file_name, table_name, "", CSM_EXT, fn_format(meta_file_name, table_name, "", CSM_EXT,
MY_REPLACE_EXT|MY_UNPACK_FILENAME); MY_REPLACE_EXT|MY_UNPACK_FILENAME);
if (my_stat(share->data_file_name, &file_stat, MYF(MY_WME)) == NULL) if (mysql_file_stat(csv_key_file_data,
share->data_file_name, &file_stat, MYF(MY_WME)) == NULL)
goto error; goto error;
share->saved_data_file_length= file_stat.st_size; share->saved_data_file_length= file_stat.st_size;
if (my_hash_insert(&tina_open_tables, (uchar*) share)) if (my_hash_insert(&tina_open_tables, (uchar*) share))
goto error; goto error;
thr_lock_init(&share->lock); thr_lock_init(&share->lock);
pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); mysql_mutex_init(csv_key_mutex_TINA_SHARE_mutex,
&share->mutex, MY_MUTEX_INIT_FAST);
/* /*
Open or create the meta file. In the latter case, we'll get Open or create the meta file. In the latter case, we'll get
@ -191,19 +233,21 @@ static TINA_SHARE *get_share(const char *table_name, TABLE *table)
Usually this will result in auto-repair, and we will get a good Usually this will result in auto-repair, and we will get a good
meta-file in the end. meta-file in the end.
*/ */
if (((share->meta_file= my_open(meta_file_name, if (((share->meta_file= mysql_file_open(csv_key_file_metadata,
O_RDWR|O_CREAT, MYF(MY_WME))) == -1) || meta_file_name,
O_RDWR|O_CREAT,
MYF(MY_WME))) == -1) ||
read_meta_file(share->meta_file, &share->rows_recorded)) read_meta_file(share->meta_file, &share->rows_recorded))
share->crashed= TRUE; share->crashed= TRUE;
} }
share->use_count++; share->use_count++;
pthread_mutex_unlock(&tina_mutex); mysql_mutex_unlock(&tina_mutex);
return share; return share;
error: error:
pthread_mutex_unlock(&tina_mutex); mysql_mutex_unlock(&tina_mutex);
my_free((uchar*) share, MYF(0)); my_free((uchar*) share, MYF(0));
return NULL; return NULL;
@ -236,8 +280,8 @@ static int read_meta_file(File meta_file, ha_rows *rows)
DBUG_ENTER("ha_tina::read_meta_file"); DBUG_ENTER("ha_tina::read_meta_file");
my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); mysql_file_seek(meta_file, 0, MY_SEEK_SET, MYF(0));
if (my_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0) if (mysql_file_read(meta_file, (uchar*)meta_buffer, META_BUFFER_SIZE, 0)
!= META_BUFFER_SIZE) != META_BUFFER_SIZE)
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
@ -259,7 +303,7 @@ static int read_meta_file(File meta_file, ha_rows *rows)
((bool)(*ptr)== TRUE)) ((bool)(*ptr)== TRUE))
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
my_sync(meta_file, MYF(MY_WME)); mysql_file_sync(meta_file, MYF(MY_WME));
DBUG_RETURN(0); DBUG_RETURN(0);
} }
@ -305,12 +349,12 @@ static int write_meta_file(File meta_file, ha_rows rows, bool dirty)
ptr+= 3*sizeof(ulonglong); ptr+= 3*sizeof(ulonglong);
*ptr= (uchar)dirty; *ptr= (uchar)dirty;
my_seek(meta_file, 0, MY_SEEK_SET, MYF(0)); mysql_file_seek(meta_file, 0, MY_SEEK_SET, MYF(0));
if (my_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0) if (mysql_file_write(meta_file, (uchar *)meta_buffer, META_BUFFER_SIZE, 0)
!= META_BUFFER_SIZE) != META_BUFFER_SIZE)
DBUG_RETURN(-1); DBUG_RETURN(-1);
my_sync(meta_file, MYF(MY_WME)); mysql_file_sync(meta_file, MYF(MY_WME));
DBUG_RETURN(0); DBUG_RETURN(0);
} }
@ -338,7 +382,9 @@ int ha_tina::init_tina_writer()
(void)write_meta_file(share->meta_file, share->rows_recorded, TRUE); (void)write_meta_file(share->meta_file, share->rows_recorded, TRUE);
if ((share->tina_write_filedes= if ((share->tina_write_filedes=
my_open(share->data_file_name, O_RDWR|O_APPEND, MYF(MY_WME))) == -1) mysql_file_open(csv_key_file_data,
share->data_file_name, O_RDWR|O_APPEND,
MYF(MY_WME))) == -1)
{ {
DBUG_PRINT("info", ("Could not open tina file writes")); DBUG_PRINT("info", ("Could not open tina file writes"));
share->crashed= TRUE; share->crashed= TRUE;
@ -362,27 +408,27 @@ bool ha_tina::is_crashed() const
static int free_share(TINA_SHARE *share) static int free_share(TINA_SHARE *share)
{ {
DBUG_ENTER("ha_tina::free_share"); DBUG_ENTER("ha_tina::free_share");
pthread_mutex_lock(&tina_mutex); mysql_mutex_lock(&tina_mutex);
int result_code= 0; int result_code= 0;
if (!--share->use_count){ if (!--share->use_count){
/* Write the meta file. Mark it as crashed if needed. */ /* Write the meta file. Mark it as crashed if needed. */
(void)write_meta_file(share->meta_file, share->rows_recorded, (void)write_meta_file(share->meta_file, share->rows_recorded,
share->crashed ? TRUE :FALSE); share->crashed ? TRUE :FALSE);
if (my_close(share->meta_file, MYF(0))) if (mysql_file_close(share->meta_file, MYF(0)))
result_code= 1; result_code= 1;
if (share->tina_write_opened) if (share->tina_write_opened)
{ {
if (my_close(share->tina_write_filedes, MYF(0))) if (mysql_file_close(share->tina_write_filedes, MYF(0)))
result_code= 1; result_code= 1;
share->tina_write_opened= FALSE; share->tina_write_opened= FALSE;
} }
my_hash_delete(&tina_open_tables, (uchar*) share); my_hash_delete(&tina_open_tables, (uchar*) share);
thr_lock_delete(&share->lock); thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->mutex); mysql_mutex_destroy(&share->mutex);
my_free((uchar*) share, MYF(0)); my_free((uchar*) share, MYF(0));
} }
pthread_mutex_unlock(&tina_mutex); mysql_mutex_unlock(&tina_mutex);
DBUG_RETURN(result_code); DBUG_RETURN(result_code);
} }
@ -769,9 +815,9 @@ void ha_tina::get_status()
We have to use mutex to follow pthreads memory visibility We have to use mutex to follow pthreads memory visibility
rules for share->saved_data_file_length rules for share->saved_data_file_length
*/ */
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
local_saved_data_file_length= share->saved_data_file_length; local_saved_data_file_length= share->saved_data_file_length;
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
return; return;
} }
local_saved_data_file_length= share->saved_data_file_length; local_saved_data_file_length= share->saved_data_file_length;
@ -825,8 +871,9 @@ int ha_tina::open(const char *name, int mode, uint open_options)
} }
local_data_file_version= share->data_file_version; local_data_file_version= share->data_file_version;
if ((data_file= my_open(share->data_file_name, if ((data_file= mysql_file_open(csv_key_file_data,
O_RDONLY, MYF(MY_WME))) == -1) share->data_file_name,
O_RDONLY, MYF(MY_WME))) == -1)
{ {
free_share(share); free_share(share);
DBUG_RETURN(my_errno ? my_errno : -1); DBUG_RETURN(my_errno ? my_errno : -1);
@ -856,7 +903,7 @@ int ha_tina::close(void)
{ {
int rc= 0; int rc= 0;
DBUG_ENTER("ha_tina::close"); DBUG_ENTER("ha_tina::close");
rc= my_close(data_file, MYF(0)); rc= mysql_file_close(data_file, MYF(0));
DBUG_RETURN(free_share(share) || rc); DBUG_RETURN(free_share(share) || rc);
} }
@ -885,20 +932,20 @@ int ha_tina::write_row(uchar * buf)
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* use pwrite, as concurrent reader could have changed the position */ /* use pwrite, as concurrent reader could have changed the position */
if (my_write(share->tina_write_filedes, (uchar*)buffer.ptr(), size, if (mysql_file_write(share->tina_write_filedes, (uchar*)buffer.ptr(), size,
MYF(MY_WME | MY_NABP))) MYF(MY_WME | MY_NABP)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* update local copy of the max position to see our own changes */ /* update local copy of the max position to see our own changes */
local_saved_data_file_length+= size; local_saved_data_file_length+= size;
/* update shared info */ /* update shared info */
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
share->rows_recorded++; share->rows_recorded++;
/* update status for the log tables */ /* update status for the log tables */
if (share->is_log_table) if (share->is_log_table)
update_status(); update_status();
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
stats.records++; stats.records++;
DBUG_RETURN(0); DBUG_RETURN(0);
@ -912,10 +959,11 @@ int ha_tina::open_update_temp_file_if_needed()
if (!share->update_file_opened) if (!share->update_file_opened)
{ {
if ((update_temp_file= if ((update_temp_file=
my_create(fn_format(updated_fname, share->table_name, mysql_file_create(csv_key_file_update,
"", CSN_EXT, fn_format(updated_fname, share->table_name,
MY_REPLACE_EXT | MY_UNPACK_FILENAME), "", CSN_EXT,
0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0) MY_REPLACE_EXT | MY_UNPACK_FILENAME),
0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
return 1; return 1;
share->update_file_opened= TRUE; share->update_file_opened= TRUE;
temp_file_length= 0; temp_file_length= 0;
@ -957,8 +1005,8 @@ int ha_tina::update_row(const uchar * old_data, uchar * new_data)
if (open_update_temp_file_if_needed()) if (open_update_temp_file_if_needed())
goto err; goto err;
if (my_write(update_temp_file, (uchar*)buffer.ptr(), size, if (mysql_file_write(update_temp_file, (uchar*)buffer.ptr(), size,
MYF(MY_WME | MY_NABP))) MYF(MY_WME | MY_NABP)))
goto err; goto err;
temp_file_length+= size; temp_file_length+= size;
rc= 0; rc= 0;
@ -992,9 +1040,9 @@ int ha_tina::delete_row(const uchar * buf)
stats.records--; stats.records--;
/* Update shared info */ /* Update shared info */
DBUG_ASSERT(share->rows_recorded); DBUG_ASSERT(share->rows_recorded);
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
share->rows_recorded--; share->rows_recorded--;
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
/* DELETE should never happen on the log table */ /* DELETE should never happen on the log table */
DBUG_ASSERT(!share->is_log_table); DBUG_ASSERT(!share->is_log_table);
@ -1021,8 +1069,10 @@ int ha_tina::init_data_file()
if (local_data_file_version != share->data_file_version) if (local_data_file_version != share->data_file_version)
{ {
local_data_file_version= share->data_file_version; local_data_file_version= share->data_file_version;
if (my_close(data_file, MYF(0)) || if (mysql_file_close(data_file, MYF(0)) ||
(data_file= my_open(share->data_file_name, O_RDONLY, MYF(MY_WME))) == -1) (data_file= mysql_file_open(csv_key_file_data,
share->data_file_name, O_RDONLY,
MYF(MY_WME))) == -1)
return my_errno ? my_errno : -1; return my_errno ? my_errno : -1;
} }
file_buff->init_buff(data_file); file_buff->init_buff(data_file);
@ -1184,9 +1234,9 @@ int ha_tina::extra(enum ha_extra_function operation)
DBUG_ENTER("ha_tina::extra"); DBUG_ENTER("ha_tina::extra");
if (operation == HA_EXTRA_MARK_AS_LOG_TABLE) if (operation == HA_EXTRA_MARK_AS_LOG_TABLE)
{ {
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
share->is_log_table= TRUE; share->is_log_table= TRUE;
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
@ -1255,10 +1305,10 @@ int ha_tina::rnd_end()
/* if there is something to write, write it */ /* if there is something to write, write it */
if (write_length) if (write_length)
{ {
if (my_write(update_temp_file, if (mysql_file_write(update_temp_file,
(uchar*) (file_buff->ptr() + (uchar*) (file_buff->ptr() +
(write_begin - file_buff->start())), (write_begin - file_buff->start())),
(size_t)write_length, MYF_RW)) (size_t)write_length, MYF_RW))
goto error; goto error;
temp_file_length+= write_length; temp_file_length+= write_length;
} }
@ -1279,15 +1329,15 @@ int ha_tina::rnd_end()
} }
if (my_sync(update_temp_file, MYF(MY_WME)) || if (mysql_file_sync(update_temp_file, MYF(MY_WME)) ||
my_close(update_temp_file, MYF(0))) mysql_file_close(update_temp_file, MYF(0)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
share->update_file_opened= FALSE; share->update_file_opened= FALSE;
if (share->tina_write_opened) if (share->tina_write_opened)
{ {
if (my_close(share->tina_write_filedes, MYF(0))) if (mysql_file_close(share->tina_write_filedes, MYF(0)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* /*
Mark that the writer fd is closed, so that init_tina_writer() Mark that the writer fd is closed, so that init_tina_writer()
@ -1300,15 +1350,18 @@ int ha_tina::rnd_end()
Close opened fildes's. Then move updated file in place Close opened fildes's. Then move updated file in place
of the old datafile. of the old datafile.
*/ */
if (my_close(data_file, MYF(0)) || if (mysql_file_close(data_file, MYF(0)) ||
my_rename(fn_format(updated_fname, share->table_name, "", CSN_EXT, mysql_file_rename(csv_key_file_data,
MY_REPLACE_EXT | MY_UNPACK_FILENAME), fn_format(updated_fname, share->table_name,
share->data_file_name, MYF(0))) "", CSN_EXT,
MY_REPLACE_EXT | MY_UNPACK_FILENAME),
share->data_file_name, MYF(0)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* Open the file again */ /* Open the file again */
if (((data_file= my_open(share->data_file_name, if (((data_file= mysql_file_open(csv_key_file_data,
O_RDONLY, MYF(MY_WME))) == -1)) share->data_file_name,
O_RDONLY, MYF(MY_WME))) == -1))
DBUG_RETURN(my_errno ? my_errno : -1); DBUG_RETURN(my_errno ? my_errno : -1);
/* /*
As we reopened the data file, increase share->data_file_version As we reopened the data file, increase share->data_file_version
@ -1335,7 +1388,7 @@ int ha_tina::rnd_end()
DBUG_RETURN(0); DBUG_RETURN(0);
error: error:
my_close(update_temp_file, MYF(0)); mysql_file_close(update_temp_file, MYF(0));
share->update_file_opened= FALSE; share->update_file_opened= FALSE;
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
@ -1421,10 +1474,12 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
Otherwise we've encountered a bad row => repair is needed. Otherwise we've encountered a bad row => repair is needed.
Let us create a temporary file. Let us create a temporary file.
*/ */
if ((repair_file= my_create(fn_format(repaired_fname, share->table_name, if ((repair_file= mysql_file_create(csv_key_file_update,
"", CSN_EXT, fn_format(repaired_fname,
MY_REPLACE_EXT|MY_UNPACK_FILENAME), share->table_name,
0, O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) "", CSN_EXT,
MY_REPLACE_EXT|MY_UNPACK_FILENAME),
0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
DBUG_RETURN(HA_ERR_CRASHED_ON_REPAIR); DBUG_RETURN(HA_ERR_CRASHED_ON_REPAIR);
file_buff->init_buff(data_file); file_buff->init_buff(data_file);
@ -1438,8 +1493,8 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
{ {
write_end= min(file_buff->end(), current_position); write_end= min(file_buff->end(), current_position);
if ((write_end - write_begin) && if ((write_end - write_begin) &&
(my_write(repair_file, (uchar*)file_buff->ptr(), (mysql_file_write(repair_file, (uchar*)file_buff->ptr(),
(size_t) (write_end - write_begin), MYF_RW))) (size_t) (write_end - write_begin), MYF_RW)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
write_begin= write_end; write_begin= write_end;
@ -1453,7 +1508,7 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
Close the files and rename repaired file to the datafile. Close the files and rename repaired file to the datafile.
We have to close the files, as on Windows one cannot rename We have to close the files, as on Windows one cannot rename
a file, which descriptor is still open. EACCES will be returned a file, which descriptor is still open. EACCES will be returned
when trying to delete the "to"-file in my_rename(). when trying to delete the "to"-file in mysql_file_rename().
*/ */
if (share->tina_write_opened) if (share->tina_write_opened)
{ {
@ -1462,17 +1517,20 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt)
during write_row execution. We need to close both instances during write_row execution. We need to close both instances
to satisfy Win. to satisfy Win.
*/ */
if (my_close(share->tina_write_filedes, MYF(0))) if (mysql_file_close(share->tina_write_filedes, MYF(0)))
DBUG_RETURN(my_errno ? my_errno : -1); DBUG_RETURN(my_errno ? my_errno : -1);
share->tina_write_opened= FALSE; share->tina_write_opened= FALSE;
} }
if (my_close(data_file,MYF(0)) || my_close(repair_file, MYF(0)) || if (mysql_file_close(data_file, MYF(0)) ||
my_rename(repaired_fname, share->data_file_name, MYF(0))) mysql_file_close(repair_file, MYF(0)) ||
mysql_file_rename(csv_key_file_data,
repaired_fname, share->data_file_name, MYF(0)))
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* Open the file again, it should now be repaired */ /* Open the file again, it should now be repaired */
if ((data_file= my_open(share->data_file_name, O_RDWR|O_APPEND, if ((data_file= mysql_file_open(csv_key_file_data,
MYF(MY_WME))) == -1) share->data_file_name, O_RDWR|O_APPEND,
MYF(MY_WME))) == -1)
DBUG_RETURN(my_errno ? my_errno : -1); DBUG_RETURN(my_errno ? my_errno : -1);
/* Set new file size. The file size will be updated by ::update_status() */ /* Set new file size. The file size will be updated by ::update_status() */
@ -1500,13 +1558,13 @@ int ha_tina::delete_all_rows()
DBUG_RETURN(-1); DBUG_RETURN(-1);
/* Truncate the file to zero size */ /* Truncate the file to zero size */
rc= my_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME)); rc= mysql_file_chsize(share->tina_write_filedes, 0, 0, MYF(MY_WME));
stats.records=0; stats.records=0;
/* Update shared info */ /* Update shared info */
pthread_mutex_lock(&share->mutex); mysql_mutex_lock(&share->mutex);
share->rows_recorded= 0; share->rows_recorded= 0;
pthread_mutex_unlock(&share->mutex); mysql_mutex_unlock(&share->mutex);
local_saved_data_file_length= 0; local_saved_data_file_length= 0;
DBUG_RETURN(rc); DBUG_RETURN(rc);
} }
@ -1550,20 +1608,22 @@ int ha_tina::create(const char *name, TABLE *table_arg,
} }
if ((create_file= my_create(fn_format(name_buff, name, "", CSM_EXT, if ((create_file= mysql_file_create(csv_key_file_metadata,
MY_REPLACE_EXT|MY_UNPACK_FILENAME), 0, fn_format(name_buff, name, "", CSM_EXT,
O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) MY_REPLACE_EXT|MY_UNPACK_FILENAME),
0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
DBUG_RETURN(-1); DBUG_RETURN(-1);
write_meta_file(create_file, 0, FALSE); write_meta_file(create_file, 0, FALSE);
my_close(create_file, MYF(0)); mysql_file_close(create_file, MYF(0));
if ((create_file= my_create(fn_format(name_buff, name, "", CSV_EXT, if ((create_file= mysql_file_create(csv_key_file_data,
MY_REPLACE_EXT|MY_UNPACK_FILENAME),0, fn_format(name_buff, name, "", CSV_EXT,
O_RDWR | O_TRUNC,MYF(MY_WME))) < 0) MY_REPLACE_EXT|MY_UNPACK_FILENAME),
0, O_RDWR | O_TRUNC, MYF(MY_WME))) < 0)
DBUG_RETURN(-1); DBUG_RETURN(-1);
my_close(create_file, MYF(0)); mysql_file_close(create_file, MYF(0));
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -41,7 +41,7 @@ typedef struct st_tina_share {
share initialization. share initialization.
*/ */
my_off_t saved_data_file_length; my_off_t saved_data_file_length;
pthread_mutex_t mutex; mysql_mutex_t mutex;
THR_LOCK lock; THR_LOCK lock;
bool update_file_opened; bool update_file_opened;
bool tina_write_opened; bool tina_write_opened;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -35,9 +35,9 @@ void Transparent_file::init_buff(File filedes_arg)
filedes= filedes_arg; filedes= filedes_arg;
/* read the beginning of the file */ /* read the beginning of the file */
lower_bound= 0; lower_bound= 0;
my_seek(filedes, 0, MY_SEEK_SET, MYF(0)); mysql_file_seek(filedes, 0, MY_SEEK_SET, MYF(0));
if (filedes && buff) if (filedes && buff)
upper_bound= my_read(filedes, buff, buff_size, MYF(0)); upper_bound= mysql_file_read(filedes, buff, buff_size, MYF(0));
} }
uchar *Transparent_file::ptr() uchar *Transparent_file::ptr()
@ -63,7 +63,8 @@ my_off_t Transparent_file::read_next()
No need to seek here, as the file managed by Transparent_file class No need to seek here, as the file managed by Transparent_file class
always points to upper_bound byte always points to upper_bound byte
*/ */
if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR) if ((bytes_read= mysql_file_read(filedes, buff, buff_size, MYF(0)))
== MY_FILE_ERROR)
return (my_off_t) -1; return (my_off_t) -1;
/* end of file */ /* end of file */
@ -85,10 +86,10 @@ char Transparent_file::get_value(my_off_t offset)
if ((lower_bound <= offset) && (((my_off_t) offset) < upper_bound)) if ((lower_bound <= offset) && (((my_off_t) offset) < upper_bound))
return buff[offset - lower_bound]; return buff[offset - lower_bound];
my_seek(filedes, offset, MY_SEEK_SET, MYF(0)); mysql_file_seek(filedes, offset, MY_SEEK_SET, MYF(0));
/* read appropriate portion of the file */ /* read appropriate portion of the file */
if ((bytes_read= my_read(filedes, buff, buff_size, if ((bytes_read= mysql_file_read(filedes, buff, buff_size,
MYF(0))) == MY_FILE_ERROR) MYF(0))) == MY_FILE_ERROR)
return 0; return 0;
lower_bound= offset; lower_bound= offset;

View File

@ -112,7 +112,7 @@ handlerton *example_hton;
static HASH example_open_tables; static HASH example_open_tables;
/* The mutex used to init the hash; variable for example share methods */ /* The mutex used to init the hash; variable for example share methods */
pthread_mutex_t example_mutex; mysql_mutex_t example_mutex;
/** /**
@brief @brief
@ -126,13 +126,39 @@ static uchar* example_get_key(EXAMPLE_SHARE *share, size_t *length,
return (uchar*) share->table_name; return (uchar*) share->table_name;
} }
#ifdef HAVE_PSI_INTERFACE
static PSI_mutex_key ex_key_mutex_example, ex_key_mutex_EXAMPLE_SHARE_mutex;
static PSI_mutex_info all_example_mutexes[]=
{
{ &ex_key_mutex_example, "example", PSI_FLAG_GLOBAL},
{ &ex_key_mutex_EXAMPLE_SHARE_mutex, "EXAMPLE_SHARE::mutex", 0}
};
static void init_example_psi_keys()
{
const char* category= "example";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_example_mutexes);
PSI_server->register_mutex(category, all_example_mutexes, count);
}
#endif
static int example_init_func(void *p) static int example_init_func(void *p)
{ {
DBUG_ENTER("example_init_func"); DBUG_ENTER("example_init_func");
#ifdef HAVE_PSI_INTERFACE
init_example_psi_keys();
#endif
example_hton= (handlerton *)p; example_hton= (handlerton *)p;
pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST); mysql_mutex_init(ex_key_mutex_example, &example_mutex, MY_MUTEX_INIT_FAST);
(void) my_hash_init(&example_open_tables,system_charset_info,32,0,0, (void) my_hash_init(&example_open_tables,system_charset_info,32,0,0,
(my_hash_get_key) example_get_key,0,0); (my_hash_get_key) example_get_key,0,0);
@ -152,7 +178,7 @@ static int example_done_func(void *p)
if (example_open_tables.records) if (example_open_tables.records)
error= 1; error= 1;
my_hash_free(&example_open_tables); my_hash_free(&example_open_tables);
pthread_mutex_destroy(&example_mutex); mysql_mutex_destroy(&example_mutex);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
@ -172,7 +198,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
uint length; uint length;
char *tmp_name; char *tmp_name;
pthread_mutex_lock(&example_mutex); mysql_mutex_lock(&example_mutex);
length=(uint) strlen(table_name); length=(uint) strlen(table_name);
if (!(share=(EXAMPLE_SHARE*) my_hash_search(&example_open_tables, if (!(share=(EXAMPLE_SHARE*) my_hash_search(&example_open_tables,
@ -185,7 +211,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
&tmp_name, length+1, &tmp_name, length+1,
NullS))) NullS)))
{ {
pthread_mutex_unlock(&example_mutex); mysql_mutex_unlock(&example_mutex);
return NULL; return NULL;
} }
@ -196,15 +222,16 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table)
if (my_hash_insert(&example_open_tables, (uchar*) share)) if (my_hash_insert(&example_open_tables, (uchar*) share))
goto error; goto error;
thr_lock_init(&share->lock); thr_lock_init(&share->lock);
pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); mysql_mutex_init(ex_key_mutex_EXAMPLE_SHARE_mutex,
&share->mutex, MY_MUTEX_INIT_FAST);
} }
share->use_count++; share->use_count++;
pthread_mutex_unlock(&example_mutex); mysql_mutex_unlock(&example_mutex);
return share; return share;
error: error:
pthread_mutex_destroy(&share->mutex); mysql_mutex_destroy(&share->mutex);
my_free(share, MYF(0)); my_free(share, MYF(0));
return NULL; return NULL;
@ -219,15 +246,15 @@ error:
static int free_share(EXAMPLE_SHARE *share) static int free_share(EXAMPLE_SHARE *share)
{ {
pthread_mutex_lock(&example_mutex); mysql_mutex_lock(&example_mutex);
if (!--share->use_count) if (!--share->use_count)
{ {
my_hash_delete(&example_open_tables, (uchar*) share); my_hash_delete(&example_open_tables, (uchar*) share);
thr_lock_delete(&share->lock); thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->mutex); mysql_mutex_destroy(&share->mutex);
my_free(share, MYF(0)); my_free(share, MYF(0));
} }
pthread_mutex_unlock(&example_mutex); mysql_mutex_unlock(&example_mutex);
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -42,7 +42,7 @@
typedef struct st_example_share { typedef struct st_example_share {
char *table_name; char *table_name;
uint table_name_length,use_count; uint table_name_length,use_count;
pthread_mutex_t mutex; mysql_mutex_t mutex;
THR_LOCK lock; THR_LOCK lock;
} EXAMPLE_SHARE; } EXAMPLE_SHARE;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2004 MySQL AB /* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -388,7 +388,7 @@
/* Variables for federated share methods */ /* Variables for federated share methods */
static HASH federated_open_tables; // To track open tables static HASH federated_open_tables; // To track open tables
pthread_mutex_t federated_mutex; // To init the hash mysql_mutex_t federated_mutex; // To init the hash
static char ident_quote_char= '`'; // Character for quoting static char ident_quote_char= '`'; // Character for quoting
// identifiers // identifiers
static char value_quote_char= '\''; // Character for quoting static char value_quote_char= '\''; // Character for quoting
@ -427,6 +427,28 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length,
return (uchar*) share->share_key; return (uchar*) share->share_key;
} }
#ifdef HAVE_PSI_INTERFACE
static PSI_mutex_key fe_key_mutex_federated, fe_key_mutex_FEDERATED_SHARE_mutex;
static PSI_mutex_info all_federated_mutexes[]=
{
{ &fe_key_mutex_federated, "federated", PSI_FLAG_GLOBAL},
{ &fe_key_mutex_FEDERATED_SHARE_mutex, "FEDERATED_SHARE::mutex", 0}
};
static void init_federated_psi_keys(void)
{
const char* category= "federated";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_federated_mutexes);
PSI_server->register_mutex(category, all_federated_mutexes, count);
}
#endif /* HAVE_PSI_INTERFACE */
/* /*
Initialize the federated handler. Initialize the federated handler.
@ -442,6 +464,11 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length,
int federated_db_init(void *p) int federated_db_init(void *p)
{ {
DBUG_ENTER("federated_db_init"); DBUG_ENTER("federated_db_init");
#ifdef HAVE_PSI_INTERFACE
init_federated_psi_keys();
#endif /* HAVE_PSI_INTERFACE */
handlerton *federated_hton= (handlerton *)p; handlerton *federated_hton= (handlerton *)p;
federated_hton->state= SHOW_OPTION_YES; federated_hton->state= SHOW_OPTION_YES;
federated_hton->db_type= DB_TYPE_FEDERATED_DB; federated_hton->db_type= DB_TYPE_FEDERATED_DB;
@ -457,7 +484,8 @@ int federated_db_init(void *p)
federated_hton->commit= 0; federated_hton->commit= 0;
federated_hton->rollback= 0; federated_hton->rollback= 0;
if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST)) if (mysql_mutex_init(fe_key_mutex_federated,
&federated_mutex, MY_MUTEX_INIT_FAST))
goto error; goto error;
if (!my_hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0, if (!my_hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
(my_hash_get_key) federated_get_key, 0, 0)) (my_hash_get_key) federated_get_key, 0, 0))
@ -465,7 +493,7 @@ int federated_db_init(void *p)
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
pthread_mutex_destroy(&federated_mutex); mysql_mutex_destroy(&federated_mutex);
error: error:
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
@ -484,7 +512,7 @@ error:
int federated_done(void *p) int federated_done(void *p)
{ {
my_hash_free(&federated_open_tables); my_hash_free(&federated_open_tables);
pthread_mutex_destroy(&federated_mutex); mysql_mutex_destroy(&federated_mutex);
return 0; return 0;
} }
@ -1487,7 +1515,7 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
init_alloc_root(&mem_root, 256, 0); init_alloc_root(&mem_root, 256, 0);
pthread_mutex_lock(&federated_mutex); mysql_mutex_lock(&federated_mutex);
tmp_share.share_key= table_name; tmp_share.share_key= table_name;
tmp_share.share_key_length= (uint) strlen(table_name); tmp_share.share_key_length= (uint) strlen(table_name);
@ -1529,18 +1557,19 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
if (my_hash_insert(&federated_open_tables, (uchar*) share)) if (my_hash_insert(&federated_open_tables, (uchar*) share))
goto error; goto error;
thr_lock_init(&share->lock); thr_lock_init(&share->lock);
pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); mysql_mutex_init(fe_key_mutex_FEDERATED_SHARE_mutex,
&share->mutex, MY_MUTEX_INIT_FAST);
} }
else else
free_root(&mem_root, MYF(0)); /* prevents memory leak */ free_root(&mem_root, MYF(0)); /* prevents memory leak */
share->use_count++; share->use_count++;
pthread_mutex_unlock(&federated_mutex); mysql_mutex_unlock(&federated_mutex);
DBUG_RETURN(share); DBUG_RETURN(share);
error: error:
pthread_mutex_unlock(&federated_mutex); mysql_mutex_unlock(&federated_mutex);
free_root(&mem_root, MYF(0)); free_root(&mem_root, MYF(0));
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
@ -1557,15 +1586,15 @@ static int free_share(FEDERATED_SHARE *share)
MEM_ROOT mem_root= share->mem_root; MEM_ROOT mem_root= share->mem_root;
DBUG_ENTER("free_share"); DBUG_ENTER("free_share");
pthread_mutex_lock(&federated_mutex); mysql_mutex_lock(&federated_mutex);
if (!--share->use_count) if (!--share->use_count)
{ {
my_hash_delete(&federated_open_tables, (uchar*) share); my_hash_delete(&federated_open_tables, (uchar*) share);
thr_lock_delete(&share->lock); thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->mutex); mysql_mutex_destroy(&share->mutex);
free_root(&mem_root, MYF(0)); free_root(&mem_root, MYF(0));
} }
pthread_mutex_unlock(&federated_mutex); mysql_mutex_unlock(&federated_mutex);
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -71,7 +71,7 @@ typedef struct st_federated_share {
ushort port; ushort port;
size_t table_name_length, server_name_length, connect_string_length, use_count; size_t table_name_length, server_name_length, connect_string_length, use_count;
pthread_mutex_t mutex; mysql_mutex_t mutex;
THR_LOCK lock; THR_LOCK lock;
} FEDERATED_SHARE; } FEDERATED_SHARE;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -39,6 +39,10 @@ int heap_init(void *p)
{ {
handlerton *heap_hton; handlerton *heap_hton;
#ifdef HAVE_PSI_INTERFACE
init_heap_psi_keys();
#endif
heap_hton= (handlerton *)p; heap_hton= (handlerton *)p;
heap_hton->state= SHOW_OPTION_YES; heap_hton->state= SHOW_OPTION_YES;
heap_hton->db_type= DB_TYPE_HEAP; heap_hton->db_type= DB_TYPE_HEAP;
@ -106,9 +110,9 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked)
if (!file) if (!file)
{ {
/* Couldn't open table; Remove the newly created table */ /* Couldn't open table; Remove the newly created table */
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
hp_free(internal_share); hp_free(internal_share);
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
} }
implicit_emptied= 1; implicit_emptied= 1;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2002, 2004 MySQL AB /* Copyright (C) 2000-2002, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -103,9 +103,14 @@ extern void hp_clear_keys(HP_SHARE *info);
extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old, extern uint hp_rb_pack_key(HP_KEYDEF *keydef, uchar *key, const uchar *old,
key_part_map keypart_map); key_part_map keypart_map);
#ifdef THREAD #ifdef THREAD
extern pthread_mutex_t THR_LOCK_heap; extern mysql_mutex_t THR_LOCK_heap;
#else
#define pthread_mutex_lock(A)
#define pthread_mutex_unlock(A)
#endif #endif
#ifdef HAVE_PSI_INTERFACE
#ifdef THREAD
extern PSI_mutex_key hp_key_mutex_HP_SHARE_intern_lock;
#endif /* THREAD */
void init_heap_psi_keys();
#endif /* HAVE_PSI_INTERFACE */
C_MODE_END C_MODE_END

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2002 MySQL AB /* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -24,9 +24,9 @@ int heap_close(HP_INFO *info)
{ {
int tmp; int tmp;
DBUG_ENTER("heap_close"); DBUG_ENTER("heap_close");
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
tmp= hp_close(info); tmp= hp_close(info);
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(tmp); DBUG_RETURN(tmp);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -32,7 +32,7 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
if (!create_info->internal_table) if (!create_info->internal_table)
{ {
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
if ((share= hp_find_named_heap(name)) && share->open_count == 0) if ((share= hp_find_named_heap(name)) && share->open_count == 0)
{ {
hp_free(share); hp_free(share);
@ -194,7 +194,8 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
} }
#ifdef THREAD #ifdef THREAD
thr_lock_init(&share->lock); thr_lock_init(&share->lock);
pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST); mysql_mutex_init(hp_key_mutex_HP_SHARE_intern_lock,
&share->intern_lock, MY_MUTEX_INIT_FAST);
#endif #endif
if (!create_info->internal_table) if (!create_info->internal_table)
{ {
@ -205,14 +206,14 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
share->delete_on_close= 1; share->delete_on_close= 1;
} }
if (!create_info->internal_table) if (!create_info->internal_table)
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
*res= share; *res= share;
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
if (!create_info->internal_table) if (!create_info->internal_table)
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(1); DBUG_RETURN(1);
} /* heap_create */ } /* heap_create */
@ -266,7 +267,7 @@ int heap_delete_table(const char *name)
reg1 HP_SHARE *share; reg1 HP_SHARE *share;
DBUG_ENTER("heap_delete_table"); DBUG_ENTER("heap_delete_table");
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
if ((share= hp_find_named_heap(name))) if ((share= hp_find_named_heap(name)))
{ {
heap_try_free(share); heap_try_free(share);
@ -276,7 +277,7 @@ int heap_delete_table(const char *name)
{ {
result= my_errno=ENOENT; result= my_errno=ENOENT;
} }
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(result); DBUG_RETURN(result);
} }
@ -284,9 +285,9 @@ int heap_delete_table(const char *name)
void heap_drop_table(HP_INFO *info) void heap_drop_table(HP_INFO *info)
{ {
DBUG_ENTER("heap_drop_table"); DBUG_ENTER("heap_drop_table");
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
heap_try_free(info->s); heap_try_free(info->s);
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
@ -298,7 +299,7 @@ void hp_free(HP_SHARE *share)
hp_clear(share); /* Remove blocks from memory */ hp_clear(share); /* Remove blocks from memory */
#ifdef THREAD #ifdef THREAD
thr_lock_delete(&share->lock); thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->intern_lock); mysql_mutex_destroy(&share->intern_lock);
#endif #endif
my_free((uchar*) share->name, MYF(0)); my_free((uchar*) share->name, MYF(0));
my_free((uchar*) share, MYF(0)); my_free((uchar*) share, MYF(0));

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2004, 2006 MySQL AB /* Copyright (C) 2000-2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -69,13 +69,13 @@ HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
HP_INFO *info; HP_INFO *info;
DBUG_ENTER("heap_open_from_share_and_register"); DBUG_ENTER("heap_open_from_share_and_register");
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
if ((info= heap_open_from_share(share, mode))) if ((info= heap_open_from_share(share, mode)))
{ {
info->open_list.data= (void*) info; info->open_list.data= (void*) info;
heap_open_list= list_add(heap_open_list,&info->open_list); heap_open_list= list_add(heap_open_list,&info->open_list);
} }
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(info); DBUG_RETURN(info);
} }
@ -94,11 +94,11 @@ HP_INFO *heap_open(const char *name, int mode)
HP_SHARE *share; HP_SHARE *share;
DBUG_ENTER("heap_open"); DBUG_ENTER("heap_open");
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
if (!(share= hp_find_named_heap(name))) if (!(share= hp_find_named_heap(name)))
{ {
my_errno= ENOENT; my_errno= ENOENT;
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
if ((info= heap_open_from_share(share, mode))) if ((info= heap_open_from_share(share, mode)))
@ -106,7 +106,7 @@ HP_INFO *heap_open(const char *name, int mode)
info->open_list.data= (void*) info; info->open_list.data= (void*) info;
heap_open_list= list_add(heap_open_list,&info->open_list); heap_open_list= list_add(heap_open_list,&info->open_list);
} }
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(info); DBUG_RETURN(info);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2002 MySQL AB /* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -23,7 +23,7 @@ int hp_panic(enum ha_panic_function flag)
LIST *element,*next_open; LIST *element,*next_open;
DBUG_ENTER("hp_panic"); DBUG_ENTER("hp_panic");
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
for (element=heap_open_list ; element ; element=next_open) for (element=heap_open_list ; element ; element=next_open)
{ {
HP_INFO *info=(HP_INFO*) element->data; HP_INFO *info=(HP_INFO*) element->data;
@ -51,6 +51,6 @@ int hp_panic(enum ha_panic_function flag)
break; break;
} }
} }
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(0); DBUG_RETURN(0);
} /* hp_panic */ } /* hp_panic */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2002 MySQL AB /* Copyright (C) 2000-2002 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -25,17 +25,17 @@ int heap_rename(const char *old_name, const char *new_name)
char *name_buff; char *name_buff;
DBUG_ENTER("heap_rename"); DBUG_ENTER("heap_rename");
pthread_mutex_lock(&THR_LOCK_heap); mysql_mutex_lock(&THR_LOCK_heap);
if ((info = hp_find_named_heap(old_name))) if ((info = hp_find_named_heap(old_name)))
{ {
if (!(name_buff=(char*) my_strdup(new_name,MYF(MY_WME)))) if (!(name_buff=(char*) my_strdup(new_name,MYF(MY_WME))))
{ {
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
} }
my_free(info->name,MYF(0)); my_free(info->name,MYF(0));
info->name=name_buff; info->name=name_buff;
} }
pthread_mutex_unlock(&THR_LOCK_heap); mysql_mutex_unlock(&THR_LOCK_heap);
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001 MySQL AB /* Copyright (C) 2000-2001 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -23,3 +23,34 @@
#endif #endif
LIST *heap_open_list=0,*heap_share_list=0; LIST *heap_open_list=0,*heap_share_list=0;
#ifdef HAVE_PSI_INTERFACE
#ifdef THREAD
PSI_mutex_key hp_key_mutex_HP_SHARE_intern_lock;
static PSI_mutex_info all_heap_mutexes[]=
{
{ & hp_key_mutex_HP_SHARE_intern_lock, "HP_SHARE::intern_lock", 0}
/*
Note:
THR_LOCK_heap is part of mysys, not storage/heap.
*/
};
#endif /* THREAD */
void init_heap_psi_keys()
{
#ifdef THREAD
const char* category= "memory";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_heap_mutexes);
PSI_server->register_mutex(category, all_heap_mutexes, count);
#endif /* THREAD */
}
#endif /* HAVE_PSI_INTERFACE */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -118,7 +118,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
*/ */
#ifdef THREAD #ifdef THREAD
if (param->need_print_msg_lock) if (param->need_print_msg_lock)
pthread_mutex_lock(&param->print_msg_mutex); mysql_mutex_lock(&param->print_msg_mutex);
#endif #endif
protocol->prepare_for_resend(); protocol->prepare_for_resend();
protocol->store(name, length, system_charset_info); protocol->store(name, length, system_charset_info);
@ -130,7 +130,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
msgbuf); msgbuf);
#ifdef THREAD #ifdef THREAD
if (param->need_print_msg_lock) if (param->need_print_msg_lock)
pthread_mutex_unlock(&param->print_msg_mutex); mysql_mutex_unlock(&param->print_msg_mutex);
#endif #endif
return; return;
} }
@ -762,13 +762,13 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
mi_is_crashed(file)) mi_is_crashed(file))
{ {
file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED |
STATE_CRASHED_ON_REPAIR); STATE_CRASHED_ON_REPAIR);
if (!(table->db_stat & HA_READ_ONLY)) if (!(table->db_stat & HA_READ_ONLY))
error=update_state_info(&param,file,UPDATE_TIME | UPDATE_OPEN_COUNT | error=update_state_info(&param,file,UPDATE_TIME | UPDATE_OPEN_COUNT |
UPDATE_STAT); UPDATE_STAT);
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE |
HA_STATUS_CONST); HA_STATUS_CONST);
} }
@ -812,9 +812,9 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
error = chk_key(&param, file); error = chk_key(&param, file);
if (!error) if (!error)
{ {
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
error=update_state_info(&param,file,UPDATE_STAT); error=update_state_info(&param,file,UPDATE_STAT);
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
} }
else if (!mi_is_crashed(file) && !thd->killed) else if (!mi_is_crashed(file) && !thd->killed)
mi_mark_crashed(file); mi_mark_crashed(file);
@ -1926,6 +1926,10 @@ static int myisam_init(void *p)
{ {
handlerton *myisam_hton; handlerton *myisam_hton;
#ifdef HAVE_PSI_INTERFACE
init_myisam_psi_keys();
#endif
myisam_hton= (handlerton *)p; myisam_hton= (handlerton *)p;
myisam_hton->state= SHOW_OPTION_YES; myisam_hton->state= SHOW_OPTION_YES;
myisam_hton->db_type= DB_TYPE_MYISAM; myisam_hton->db_type= DB_TYPE_MYISAM;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2003 MySQL AB /* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -29,7 +29,7 @@
is set) - unread part is bzero'ed is set) - unread part is bzero'ed
Note: out-of-cache reads are enabled for shared IO_CACHE's too, Note: out-of-cache reads are enabled for shared IO_CACHE's too,
as these reads will be cached by OS cache (and my_pread is always atomic) as these reads will be cached by OS cache (and mysql_file_pread is always atomic)
*/ */
@ -49,7 +49,7 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length,
if ((my_off_t) read_length > (my_off_t) (info->pos_in_file-pos)) if ((my_off_t) read_length > (my_off_t) (info->pos_in_file-pos))
read_length=(uint) (info->pos_in_file-pos); read_length=(uint) (info->pos_in_file-pos);
info->seek_not_done=1; info->seek_not_done=1;
if (my_pread(info->file,buff,read_length,pos,MYF(MY_NABP))) if (mysql_file_pread(info->file, buff, read_length, pos, MYF(MY_NABP)))
DBUG_RETURN(1); DBUG_RETURN(1);
if (!(length-=read_length)) if (!(length-=read_length))
DBUG_RETURN(0); DBUG_RETURN(0);
@ -88,7 +88,8 @@ int _mi_read_cache(IO_CACHE *info, uchar *buff, my_off_t pos, uint length,
else else
{ {
info->seek_not_done=1; info->seek_not_done=1;
if ((read_length=my_pread(info->file,buff,length,pos,MYF(0))) == length) if ((read_length= mysql_file_pread(info->file, buff, length, pos,
MYF(0))) == length)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
if (!(flag & READING_HEADER) || (int) read_length == -1 || if (!(flag & READING_HEADER) || (int) read_length == -1 ||

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -53,8 +53,8 @@
#include "rt_index.h" #include "rt_index.h"
#ifndef USE_RAID #ifndef USE_RAID
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G) #define my_raid_create(K, A, B, C, D, E, F, G) mysql_file_create(K, A, B, C, G)
#define my_raid_delete(A,B,C) my_delete(A,B) #define my_raid_delete(K, A, B, C) mysql_file_delete(K, A, B)
#endif #endif
/* Functions defined in this file */ /* Functions defined in this file */
@ -175,8 +175,8 @@ int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag)
printf(" %9s",llstr(next_link,buff)); printf(" %9s",llstr(next_link,buff));
if (next_link >= info->state->data_file_length) if (next_link >= info->state->data_file_length)
goto wrong; goto wrong;
if (my_pread(info->dfile, (uchar*) buff,delete_link_length, if (mysql_file_pread(info->dfile, (uchar*) buff, delete_link_length,
next_link,MYF(MY_NABP))) next_link, MYF(MY_NABP)))
{ {
if (test_flag & T_VERBOSE) puts(""); if (test_flag & T_VERBOSE) puts("");
mi_check_print_error(param,"Can't read delete-link at filepos: %s", mi_check_print_error(param,"Can't read delete-link at filepos: %s",
@ -338,7 +338,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info)
flush_key_blocks(info->s->key_cache, flush_key_blocks(info->s->key_cache,
info->s->kfile, FLUSH_FORCE_WRITE); info->s->kfile, FLUSH_FORCE_WRITE);
size= my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)); size= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE));
if ((skr=(my_off_t) info->state->key_file_length) != size) if ((skr=(my_off_t) info->state->key_file_length) != size)
{ {
/* Don't give error if file generated by myisampack */ /* Don't give error if file generated by myisampack */
@ -362,7 +362,7 @@ int chk_size(MI_CHECK *param, register MI_INFO *info)
llstr(info->state->key_file_length,buff), llstr(info->state->key_file_length,buff),
llstr(info->s->base.max_key_file_length-1,buff)); llstr(info->s->base.max_key_file_length-1,buff));
size=my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)); size= mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0));
skr=(my_off_t) info->state->data_file_length; skr=(my_off_t) info->state->data_file_length;
if (info->s->options & HA_OPTION_COMPRESS_RECORD) if (info->s->options & HA_OPTION_COMPRESS_RECORD)
skr+= MEMMAP_EXTRA_MARGIN; skr+= MEMMAP_EXTRA_MARGIN;
@ -598,8 +598,8 @@ static int chk_index_down(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
{ {
/* purecov: begin tested */ /* purecov: begin tested */
/* Give it a chance to fit in the real file size. */ /* Give it a chance to fit in the real file size. */
my_off_t max_length= my_seek(info->s->kfile, 0L, MY_SEEK_END, my_off_t max_length= mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END,
MYF(MY_THREADSAFE)); MYF(MY_THREADSAFE));
mi_check_print_error(param, "Invalid key block position: %s " mi_check_print_error(param, "Invalid key block position: %s "
"key block size: %u file_length: %s", "key block size: %u file_length: %s",
llstr(page, llbuff), keyinfo->block_length, llstr(page, llbuff), keyinfo->block_length,
@ -1577,14 +1577,15 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick) if (!rep_quick)
{ {
/* Get real path for data file */ /* Get real path for data file */
if ((new_file=my_raid_create(fn_format(param->temp_filename, if ((new_file= my_raid_create(mi_key_file_datatmp,
share->data_file_name, "", fn_format(param->temp_filename,
DATA_TMP_EXT, 2+4), share->data_file_name, "",
0,param->tmpfile_createflag, DATA_TMP_EXT, 2+4),
share->base.raid_type, 0, param->tmpfile_createflag,
share->base.raid_chunks, share->base.raid_type,
share->base.raid_chunksize, share->base.raid_chunks,
MYF(0))) < 0) share->base.raid_chunksize,
MYF(0))) < 0)
{ {
mi_check_print_error(param,"Can't create new tempfile: '%s'", mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename); param->temp_filename);
@ -1608,7 +1609,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
sort_param.pos=sort_param.max_pos=share->pack.header_length; sort_param.pos=sort_param.max_pos=share->pack.header_length;
sort_param.filepos=new_header_length; sort_param.filepos=new_header_length;
param->read_cache.end_of_file=sort_info.filelength= param->read_cache.end_of_file=sort_info.filelength=
my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)); mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0));
sort_info.dupp=0; sort_info.dupp=0;
sort_param.fix_datafile= (my_bool) (! rep_quick); sort_param.fix_datafile= (my_bool) (! rep_quick);
sort_param.master=1; sort_param.master=1;
@ -1670,7 +1671,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
{ {
(void) fputs(" \r",stdout); (void) fflush(stdout); (void) fputs(" \r",stdout); (void) fflush(stdout);
} }
if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0)))
{ {
mi_check_print_warning(param, mi_check_print_warning(param,
"Can't change size of indexfile, error: %d", "Can't change size of indexfile, error: %d",
@ -1700,7 +1701,7 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick) if (!rep_quick)
{ {
my_close(info->dfile,MYF(0)); mysql_file_close(info->dfile, MYF(0));
info->dfile=new_file; info->dfile=new_file;
info->state->data_file_length=sort_param.filepos; info->state->data_file_length=sort_param.filepos;
share->state.version=(ulong) time((time_t*) 0); /* Force reopen */ share->state.version=(ulong) time((time_t*) 0); /* Force reopen */
@ -1733,7 +1734,7 @@ err:
/* Replace the actual file with the temporary file */ /* Replace the actual file with the temporary file */
if (new_file >= 0) if (new_file >= 0)
{ {
my_close(new_file,MYF(0)); mysql_file_close(new_file, MYF(0));
info->dfile=new_file= -1; info->dfile=new_file= -1;
if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
DATA_TMP_EXT, share->base.raid_chunks, DATA_TMP_EXT, share->base.raid_chunks,
@ -1750,9 +1751,10 @@ err:
llstr(sort_param.start_recpos,llbuff)); llstr(sort_param.start_recpos,llbuff));
if (new_file >= 0) if (new_file >= 0)
{ {
(void) my_close(new_file,MYF(0)); (void) mysql_file_close(new_file, MYF(0));
(void) my_raid_delete(param->temp_filename,info->s->base.raid_chunks, (void) my_raid_delete(mi_key_file_datatmp,
MYF(MY_WME)); param->temp_filename, info->s->base.raid_chunks,
MYF(MY_WME));
info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */ info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */
} }
mi_mark_crashed_on_repair(info); mi_mark_crashed_on_repair(info);
@ -1949,9 +1951,11 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name)
/* Get real path for index file */ /* Get real path for index file */
fn_format(param->temp_filename,name,"", MI_NAME_IEXT,2+4+32); fn_format(param->temp_filename,name,"", MI_NAME_IEXT,2+4+32);
if ((new_file=my_create(fn_format(param->temp_filename,param->temp_filename, if ((new_file= mysql_file_create(mi_key_file_datatmp,
"", INDEX_TMP_EXT,2+4), fn_format(param->temp_filename,
0,param->tmpfile_createflag,MYF(0))) <= 0) param->temp_filename,
"", INDEX_TMP_EXT, 2+4),
0, param->tmpfile_createflag, MYF(0))) <= 0)
{ {
mi_check_print_error(param,"Can't create new tempfile: '%s'", mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename); param->temp_filename);
@ -1991,9 +1995,9 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name)
/* Put same locks as old file */ /* Put same locks as old file */
share->r_locks= share->w_locks= share->tot_locks= 0; share->r_locks= share->w_locks= share->tot_locks= 0;
(void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
(void) my_close(share->kfile,MYF(MY_WME)); (void) mysql_file_close(share->kfile, MYF(MY_WME));
share->kfile = -1; share->kfile = -1;
(void) my_close(new_file,MYF(MY_WME)); (void) mysql_file_close(new_file, MYF(MY_WME));
if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0, if (change_to_newfile(share->index_file_name,MI_NAME_IEXT,INDEX_TMP_EXT,0,
MYF(0)) || MYF(0)) ||
mi_open_keyfile(share)) mi_open_keyfile(share))
@ -2017,9 +2021,10 @@ int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name)
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
(void) my_close(new_file,MYF(MY_WME)); (void) mysql_file_close(new_file, MYF(MY_WME));
err2: err2:
(void) my_delete(param->temp_filename,MYF(MY_WME)); (void) mysql_file_delete(mi_key_file_datatmp,
param->temp_filename, MYF(MY_WME));
DBUG_RETURN(-1); DBUG_RETURN(-1);
} /* mi_sort_index */ } /* mi_sort_index */
@ -2099,8 +2104,8 @@ static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
/* Fill block with zero and write it to the new index file */ /* Fill block with zero and write it to the new index file */
length=mi_getint(buff); length=mi_getint(buff);
bzero((uchar*) buff+length,keyinfo->block_length-length); bzero((uchar*) buff+length,keyinfo->block_length-length);
if (my_pwrite(new_file,(uchar*) buff,(uint) keyinfo->block_length, if (mysql_file_pwrite(new_file, (uchar*) buff, (uint) keyinfo->block_length,
new_page_pos,MYF(MY_NABP | MY_WAIT_IF_FULL))) new_page_pos, MYF(MY_NABP | MY_WAIT_IF_FULL)))
{ {
mi_check_print_error(param,"Can't write indexblock, error: %d",my_errno); mi_check_print_error(param,"Can't write indexblock, error: %d",my_errno);
goto err; goto err;
@ -2176,16 +2181,16 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
buff=tmp_buff; buff_length=IO_SIZE; buff=tmp_buff; buff_length=IO_SIZE;
} }
my_seek(from,start,MY_SEEK_SET,MYF(0)); mysql_file_seek(from, start, MY_SEEK_SET, MYF(0));
while (length > buff_length) while (length > buff_length)
{ {
if (my_read(from,(uchar*) buff,buff_length,MYF(MY_NABP)) || if (mysql_file_read(from, (uchar*) buff, buff_length, MYF(MY_NABP)) ||
my_write(to,(uchar*) buff,buff_length,param->myf_rw)) mysql_file_write(to, (uchar*) buff, buff_length, param->myf_rw))
goto err; goto err;
length-= buff_length; length-= buff_length;
} }
if (my_read(from,(uchar*) buff,(uint) length,MYF(MY_NABP)) || if (mysql_file_read(from, (uchar*) buff, (uint) length, MYF(MY_NABP)) ||
my_write(to,(uchar*) buff,(uint) length,param->myf_rw)) mysql_file_write(to, (uchar*) buff, (uint) length, param->myf_rw))
goto err; goto err;
if (buff != tmp_buff) if (buff != tmp_buff)
my_free(buff,MYF(0)); my_free(buff,MYF(0));
@ -2275,14 +2280,15 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick) if (!rep_quick)
{ {
/* Get real path for data file */ /* Get real path for data file */
if ((new_file=my_raid_create(fn_format(param->temp_filename, if ((new_file= my_raid_create(mi_key_file_datatmp,
share->data_file_name, "", fn_format(param->temp_filename,
DATA_TMP_EXT, 2+4), share->data_file_name, "",
0,param->tmpfile_createflag, DATA_TMP_EXT, 2+4),
share->base.raid_type, 0, param->tmpfile_createflag,
share->base.raid_chunks, share->base.raid_type,
share->base.raid_chunksize, share->base.raid_chunks,
MYF(0))) < 0) share->base.raid_chunksize,
MYF(0))) < 0)
{ {
mi_check_print_error(param,"Can't create new tempfile: '%s'", mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename); param->temp_filename);
@ -2320,7 +2326,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
sort_info.dupp=0; sort_info.dupp=0;
sort_info.buff=0; sort_info.buff=0;
param->read_cache.end_of_file=sort_info.filelength= param->read_cache.end_of_file=sort_info.filelength=
my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0));
sort_param.wordlist=NULL; sort_param.wordlist=NULL;
init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0); init_alloc_root(&sort_param.wordroot, FTPARSER_MEMROOT_ALLOC_SIZE, 0);
@ -2470,7 +2476,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
sort_param.filepos; sort_param.filepos;
/* Only whole records */ /* Only whole records */
share->state.version=(ulong) time((time_t*) 0); share->state.version=(ulong) time((time_t*) 0);
my_close(info->dfile,MYF(0)); mysql_file_close(info->dfile, MYF(0));
info->dfile=new_file; info->dfile=new_file;
share->data_file_type=sort_info.new_data_file_type; share->data_file_type=sort_info.new_data_file_type;
share->pack.header_length=(ulong) new_header_length; share->pack.header_length=(ulong) new_header_length;
@ -2510,7 +2516,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
skr=share->base.reloc*share->base.min_pack_length; skr=share->base.reloc*share->base.min_pack_length;
#endif #endif
if (skr != sort_info.filelength && !info->s->base.raid_type) if (skr != sort_info.filelength && !info->s->base.raid_type)
if (my_chsize(info->dfile,skr,0,MYF(0))) if (mysql_file_chsize(info->dfile, skr, 0, MYF(0)))
mi_check_print_warning(param, mi_check_print_warning(param,
"Can't change size of datafile, error: %d", "Can't change size of datafile, error: %d",
my_errno); my_errno);
@ -2518,7 +2524,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
if (param->testflag & T_CALC_CHECKSUM) if (param->testflag & T_CALC_CHECKSUM)
info->state->checksum=param->glob_crc; info->state->checksum=param->glob_crc;
if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0)))
mi_check_print_warning(param, mi_check_print_warning(param,
"Can't change size of indexfile, error: %d", "Can't change size of indexfile, error: %d",
my_errno); my_errno);
@ -2545,7 +2551,7 @@ err:
/* Replace the actual file with the temporary file */ /* Replace the actual file with the temporary file */
if (new_file >= 0) if (new_file >= 0)
{ {
my_close(new_file,MYF(0)); mysql_file_close(new_file, MYF(0));
info->dfile=new_file= -1; info->dfile=new_file= -1;
if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
DATA_TMP_EXT, share->base.raid_chunks, DATA_TMP_EXT, share->base.raid_chunks,
@ -2561,9 +2567,10 @@ err:
mi_check_print_error(param,"%d when fixing table",my_errno); mi_check_print_error(param,"%d when fixing table",my_errno);
if (new_file >= 0) if (new_file >= 0)
{ {
(void) my_close(new_file,MYF(0)); (void) mysql_file_close(new_file, MYF(0));
(void) my_raid_delete(param->temp_filename,share->base.raid_chunks, (void) my_raid_delete(mi_key_file_datatmp,
MYF(MY_WME)); param->temp_filename, share->base.raid_chunks,
MYF(MY_WME));
if (info->dfile == new_file) /* Retry with key cache */ if (info->dfile == new_file) /* Retry with key cache */
if (unlikely(mi_open_datafile(info, share, name, -1))) if (unlikely(mi_open_datafile(info, share, name, -1)))
param->retry_repair= 0; /* Safety */ param->retry_repair= 0; /* Safety */
@ -2704,9 +2711,11 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
DBUG_PRINT("info", ("is quick repair: %d", rep_quick)); DBUG_PRINT("info", ("is quick repair: %d", rep_quick));
bzero((char*)&sort_info,sizeof(sort_info)); bzero((char*)&sort_info,sizeof(sort_info));
/* Initialize pthread structures before goto err. */ /* Initialize pthread structures before goto err. */
pthread_mutex_init(&sort_info.mutex, MY_MUTEX_INIT_FAST); mysql_mutex_init(mi_key_mutex_MI_SORT_INFO_mutex,
pthread_cond_init(&sort_info.cond, 0); &sort_info.mutex, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&param->print_msg_mutex, MY_MUTEX_INIT_FAST); mysql_cond_init(mi_key_cond_MI_SORT_INFO_cond, &sort_info.cond, 0);
mysql_mutex_init(mi_key_mutex_MI_CHECK_print_msg,
&param->print_msg_mutex, MY_MUTEX_INIT_FAST);
param->need_print_msg_lock= 1; param->need_print_msg_lock= 1;
if (!(sort_info.key_block= if (!(sort_info.key_block=
@ -2732,15 +2741,16 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
if (!rep_quick) if (!rep_quick)
{ {
/* Get real path for data file */ /* Get real path for data file */
if ((new_file=my_raid_create(fn_format(param->temp_filename, if ((new_file= my_raid_create(mi_key_file_datatmp,
share->data_file_name, "", fn_format(param->temp_filename,
DATA_TMP_EXT, share->data_file_name, "",
2+4), DATA_TMP_EXT,
0,param->tmpfile_createflag, 2+4),
share->base.raid_type, 0, param->tmpfile_createflag,
share->base.raid_chunks, share->base.raid_type,
share->base.raid_chunksize, share->base.raid_chunks,
MYF(0))) < 0) share->base.raid_chunksize,
MYF(0))) < 0)
{ {
mi_check_print_error(param,"Can't create new tempfile: '%s'", mi_check_print_error(param,"Can't create new tempfile: '%s'",
param->temp_filename); param->temp_filename);
@ -2777,7 +2787,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
sort_info.dupp=0; sort_info.dupp=0;
sort_info.buff=0; sort_info.buff=0;
param->read_cache.end_of_file=sort_info.filelength= param->read_cache.end_of_file=sort_info.filelength=
my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); mysql_file_seek(param->read_cache.file, 0L, MY_SEEK_END, MYF(0));
if (share->data_file_type == DYNAMIC_RECORD) if (share->data_file_type == DYNAMIC_RECORD)
rec_length=max(share->base.min_pack_length+1,share->base.min_block_length); rec_length=max(share->base.min_pack_length+1,share->base.min_block_length);
@ -2903,7 +2913,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
goto err; goto err;
sort_info.got_error=0; sort_info.got_error=0;
pthread_mutex_lock(&sort_info.mutex); mysql_mutex_lock(&sort_info.mutex);
/* /*
Initialize the I/O cache share for use with the read caches and, in Initialize the I/O cache share for use with the read caches and, in
@ -2951,9 +2961,10 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
#else #else
param->sort_buffer_length*sort_param[i].key_length/total_key_length; param->sort_buffer_length*sort_param[i].key_length/total_key_length;
#endif #endif
if (pthread_create(&sort_param[i].thr, &thr_attr, if (mysql_thread_create(mi_key_thread_find_all_keys,
thr_find_all_keys, &sort_param[i].thr, &thr_attr,
(void *) (sort_param+i))) thr_find_all_keys,
(void *) (sort_param+i)))
{ {
mi_check_print_error(param,"Cannot start a repair thread"); mi_check_print_error(param,"Cannot start a repair thread");
/* Cleanup: Detach from the share. Avoid others to be blocked. */ /* Cleanup: Detach from the share. Avoid others to be blocked. */
@ -2969,8 +2980,8 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
/* waiting for all threads to finish */ /* waiting for all threads to finish */
while (sort_info.threads_running) while (sort_info.threads_running)
pthread_cond_wait(&sort_info.cond, &sort_info.mutex); mysql_cond_wait(&sort_info.cond, &sort_info.mutex);
pthread_mutex_unlock(&sort_info.mutex); mysql_mutex_unlock(&sort_info.mutex);
if ((got_error= thr_write_keys(sort_param))) if ((got_error= thr_write_keys(sort_param)))
{ {
@ -3006,7 +3017,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
Exchange the data file descriptor of the table, so that we use the Exchange the data file descriptor of the table, so that we use the
new file from now on. new file from now on.
*/ */
my_close(info->dfile,MYF(0)); mysql_file_close(info->dfile, MYF(0));
info->dfile=new_file; info->dfile=new_file;
share->data_file_type=sort_info.new_data_file_type; share->data_file_type=sort_info.new_data_file_type;
@ -3035,7 +3046,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
skr=share->base.reloc*share->base.min_pack_length; skr=share->base.reloc*share->base.min_pack_length;
#endif #endif
if (skr != sort_info.filelength && !info->s->base.raid_type) if (skr != sort_info.filelength && !info->s->base.raid_type)
if (my_chsize(info->dfile,skr,0,MYF(0))) if (mysql_file_chsize(info->dfile, skr, 0, MYF(0)))
mi_check_print_warning(param, mi_check_print_warning(param,
"Can't change size of datafile, error: %d", "Can't change size of datafile, error: %d",
my_errno); my_errno);
@ -3043,7 +3054,7 @@ int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
if (param->testflag & T_CALC_CHECKSUM) if (param->testflag & T_CALC_CHECKSUM)
info->state->checksum=param->glob_crc; info->state->checksum=param->glob_crc;
if (my_chsize(share->kfile,info->state->key_file_length,0,MYF(0))) if (mysql_file_chsize(share->kfile, info->state->key_file_length, 0, MYF(0)))
mi_check_print_warning(param, mi_check_print_warning(param,
"Can't change size of indexfile, error: %d", my_errno); "Can't change size of indexfile, error: %d", my_errno);
@ -3082,7 +3093,7 @@ err:
/* Replace the actual file with the temporary file */ /* Replace the actual file with the temporary file */
if (new_file >= 0) if (new_file >= 0)
{ {
my_close(new_file,MYF(0)); mysql_file_close(new_file, MYF(0));
info->dfile=new_file= -1; info->dfile=new_file= -1;
if (change_to_newfile(share->data_file_name,MI_NAME_DEXT, if (change_to_newfile(share->data_file_name,MI_NAME_DEXT,
DATA_TMP_EXT, share->base.raid_chunks, DATA_TMP_EXT, share->base.raid_chunks,
@ -3098,9 +3109,10 @@ err:
mi_check_print_error(param,"%d when fixing table",my_errno); mi_check_print_error(param,"%d when fixing table",my_errno);
if (new_file >= 0) if (new_file >= 0)
{ {
(void) my_close(new_file,MYF(0)); (void) mysql_file_close(new_file, MYF(0));
(void) my_raid_delete(param->temp_filename,share->base.raid_chunks, (void) my_raid_delete(mi_key_file_datatmp,
MYF(MY_WME)); param->temp_filename, share->base.raid_chunks,
MYF(MY_WME));
if (info->dfile == new_file) /* Retry with key cache */ if (info->dfile == new_file) /* Retry with key cache */
if (unlikely(mi_open_datafile(info, share, name, -1))) if (unlikely(mi_open_datafile(info, share, name, -1)))
param->retry_repair= 0; /* Safety */ param->retry_repair= 0; /* Safety */
@ -3111,9 +3123,9 @@ err:
share->state.changed&= ~STATE_NOT_OPTIMIZED_KEYS; share->state.changed&= ~STATE_NOT_OPTIMIZED_KEYS;
share->state.changed|=STATE_NOT_SORTED_PAGES; share->state.changed|=STATE_NOT_SORTED_PAGES;
pthread_cond_destroy (&sort_info.cond); mysql_cond_destroy(&sort_info.cond);
pthread_mutex_destroy(&sort_info.mutex); mysql_mutex_destroy(&sort_info.mutex);
pthread_mutex_destroy(&param->print_msg_mutex); mysql_mutex_destroy(&param->print_msg_mutex);
param->need_print_msg_lock= 0; param->need_print_msg_lock= 0;
my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR)); my_free((uchar*) sort_info.ft_buf, MYF(MY_ALLOW_ZERO_PTR));
@ -4067,8 +4079,9 @@ static int sort_insert_key(MI_SORT_PARAM *sort_param,
if (_mi_write_keypage(info, keyinfo, filepos, DFLT_INIT_HITS, anc_buff)) if (_mi_write_keypage(info, keyinfo, filepos, DFLT_INIT_HITS, anc_buff))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else if (my_pwrite(info->s->kfile,(uchar*) anc_buff, else if (mysql_file_pwrite(info->s->kfile, (uchar*) anc_buff,
(uint) keyinfo->block_length,filepos, param->myf_rw)) (uint) keyinfo->block_length, filepos,
param->myf_rw))
DBUG_RETURN(1); DBUG_RETURN(1);
DBUG_DUMP("buff",(uchar*) anc_buff,mi_getint(anc_buff)); DBUG_DUMP("buff",(uchar*) anc_buff,mi_getint(anc_buff));
@ -4172,8 +4185,8 @@ int flush_pending_blocks(MI_SORT_PARAM *sort_param)
DFLT_INIT_HITS, key_block->buff)) DFLT_INIT_HITS, key_block->buff))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
else if (my_pwrite(info->s->kfile,(uchar*) key_block->buff, else if (mysql_file_pwrite(info->s->kfile, (uchar*) key_block->buff,
(uint) keyinfo->block_length,filepos, myf_rw)) (uint) keyinfo->block_length, filepos, myf_rw))
DBUG_RETURN(1); DBUG_RETURN(1);
DBUG_DUMP("buff",(uchar*) key_block->buff,length); DBUG_DUMP("buff",(uchar*) key_block->buff,length);
nod_flag=1; nod_flag=1;
@ -4213,9 +4226,11 @@ int test_if_almost_full(MI_INFO *info)
{ {
if (info->s->options & HA_OPTION_COMPRESS_RECORD) if (info->s->options & HA_OPTION_COMPRESS_RECORD)
return 0; return 0;
return my_seek(info->s->kfile, 0L, MY_SEEK_END, MYF(MY_THREADSAFE)) / 10 * 9 > return mysql_file_seek(info->s->kfile, 0L, MY_SEEK_END,
MYF(MY_THREADSAFE)) / 10 * 9 >
(my_off_t) info->s->base.max_key_file_length || (my_off_t) info->s->base.max_key_file_length ||
my_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) / 10 * 9 > mysql_file_seek(info->dfile, 0L, MY_SEEK_END,
MYF(0)) / 10 * 9 >
(my_off_t) info->s->base.max_data_file_length; (my_off_t) info->s->base.max_data_file_length;
} }
@ -4313,7 +4328,8 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename)
if (share.options & HA_OPTION_COMPRESS_RECORD) if (share.options & HA_OPTION_COMPRESS_RECORD)
share.base.records=max_records=info.state->records; share.base.records=max_records=info.state->records;
else if (share.base.min_pack_length) else if (share.base.min_pack_length)
max_records=(ha_rows) (my_seek(info.dfile,0L,MY_SEEK_END,MYF(0)) / max_records=(ha_rows) (mysql_file_seek(info.dfile, 0L, MY_SEEK_END,
MYF(0)) /
(ulong) share.base.min_pack_length); (ulong) share.base.min_pack_length);
else else
max_records=0; max_records=0;
@ -4321,7 +4337,7 @@ int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename)
(param->testflag & T_UNPACK); (param->testflag & T_UNPACK);
share.options&= ~HA_OPTION_TEMP_COMPRESS_RECORD; share.options&= ~HA_OPTION_TEMP_COMPRESS_RECORD;
file_length=(ulonglong) my_seek(info.dfile,0L,MY_SEEK_END,MYF(0)); file_length=(ulonglong) mysql_file_seek(info.dfile, 0L, MY_SEEK_END, MYF(0));
tmp_length= file_length+file_length/10; tmp_length= file_length+file_length/10;
set_if_bigger(file_length,param->max_data_file_length); set_if_bigger(file_length,param->max_data_file_length);
set_if_bigger(file_length,tmp_length); set_if_bigger(file_length,tmp_length);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2004 MySQL AB /* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -31,7 +31,7 @@ int mi_close(register MI_INFO *info)
(long) info, (uint) share->reopen, (long) info, (uint) share->reopen,
(uint) share->tot_locks)); (uint) share->tot_locks));
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
if (info->lock_type == F_EXTRA_LCK) if (info->lock_type == F_EXTRA_LCK)
info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */ info->lock_type=F_UNLCK; /* HA_EXTRA_NO_USER_CHANGE */
@ -40,7 +40,7 @@ int mi_close(register MI_INFO *info)
if (mi_lock_database(info,F_UNLCK)) if (mi_lock_database(info,F_UNLCK))
error=my_errno; error=my_errno;
} }
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
if (share->options & HA_OPTION_READ_ONLY_DATA) if (share->options & HA_OPTION_READ_ONLY_DATA)
{ {
@ -55,7 +55,7 @@ int mi_close(register MI_INFO *info)
} }
flag= !--share->reopen; flag= !--share->reopen;
myisam_open_list=list_delete(myisam_open_list,&info->open_list); myisam_open_list=list_delete(myisam_open_list,&info->open_list);
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR)); my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
if (flag) if (flag)
@ -79,7 +79,7 @@ int mi_close(register MI_INFO *info)
mi_state_info_write(share->kfile, &share->state, 1); mi_state_info_write(share->kfile, &share->state, 1);
/* Decrement open count must be last I/O on this file. */ /* Decrement open count must be last I/O on this file. */
_mi_decrement_open_count(info); _mi_decrement_open_count(info);
if (my_close(share->kfile,MYF(0))) if (mysql_file_close(share->kfile, MYF(0)))
error = my_errno; error = my_errno;
} }
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
@ -93,25 +93,25 @@ int mi_close(register MI_INFO *info)
} }
#ifdef THREAD #ifdef THREAD
thr_lock_delete(&share->lock); thr_lock_delete(&share->lock);
pthread_mutex_destroy(&share->intern_lock); mysql_mutex_destroy(&share->intern_lock);
{ {
int i,keys; int i,keys;
keys = share->state.header.keys; keys = share->state.header.keys;
(void) rwlock_destroy(&share->mmap_lock); mysql_rwlock_destroy(&share->mmap_lock);
for(i=0; i<keys; i++) { for(i=0; i<keys; i++) {
(void) rwlock_destroy(&share->key_root_lock[i]); mysql_rwlock_destroy(&share->key_root_lock[i]);
} }
} }
#endif #endif
my_free((uchar*) info->s,MYF(0)); my_free((uchar*) info->s,MYF(0));
} }
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
if (info->ftparser_param) if (info->ftparser_param)
{ {
my_free((uchar*)info->ftparser_param, MYF(0)); my_free((uchar*)info->ftparser_param, MYF(0));
info->ftparser_param= 0; info->ftparser_param= 0;
} }
if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0)))
error = my_errno; error = my_errno;
myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error); myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -572,7 +572,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
if (! (flags & HA_DONT_TOUCH_DATA)) if (! (flags & HA_DONT_TOUCH_DATA))
share.state.create_time= (long) time((time_t*) 0); share.state.create_time= (long) time((time_t*) 0);
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
/* /*
NOTE: For test_if_reopen() we need a real path name. Hence we need NOTE: For test_if_reopen() we need a real path name. Hence we need
@ -638,8 +638,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
goto err; goto err;
} }
if ((file= my_create_with_symlink(linkname_ptr, filename, 0, create_mode, if ((file= mysql_file_create_with_symlink(mi_key_file_kfile,
MYF(MY_WME | create_flag))) < 0) linkname_ptr, filename, 0,
create_mode,
MYF(MY_WME | create_flag))) < 0)
goto err; goto err;
errpos=1; errpos=1;
@ -694,8 +696,10 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD; create_flag=(flags & HA_CREATE_KEEP_FILES) ? 0 : MY_DELETE_OLD;
} }
if ((dfile= if ((dfile=
my_create_with_symlink(linkname_ptr, filename, 0, create_mode, mysql_file_create_with_symlink(mi_key_file_dfile,
MYF(MY_WME | create_flag))) < 0) linkname_ptr, filename, 0,
create_mode,
MYF(MY_WME | create_flag))) < 0)
goto err; goto err;
} }
errpos=3; errpos=3;
@ -706,9 +710,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
mi_base_info_write(file, &share.base)) mi_base_info_write(file, &share.base))
goto err; goto err;
#ifndef DBUG_OFF #ifndef DBUG_OFF
if ((uint) my_tell(file,MYF(0)) != base_pos+ MI_BASE_INFO_SIZE) if ((uint) mysql_file_tell(file, MYF(0)) != base_pos + MI_BASE_INFO_SIZE)
{ {
uint pos=(uint) my_tell(file,MYF(0)); uint pos=(uint) mysql_file_tell(file, MYF(0));
DBUG_PRINT("warning",("base_length: %d != used_length: %d", DBUG_PRINT("warning",("base_length: %d != used_length: %d",
base_pos+ MI_BASE_INFO_SIZE, pos)); base_pos+ MI_BASE_INFO_SIZE, pos));
} }
@ -803,9 +807,9 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
goto err; goto err;
#ifndef DBUG_OFF #ifndef DBUG_OFF
if ((uint) my_tell(file,MYF(0)) != info_length) if ((uint) mysql_file_tell(file, MYF(0)) != info_length)
{ {
uint pos= (uint) my_tell(file,MYF(0)); uint pos= (uint) mysql_file_tell(file, MYF(0));
DBUG_PRINT("warning",("info_length: %d != used_length: %d", DBUG_PRINT("warning",("info_length: %d != used_length: %d",
info_length, pos)); info_length, pos));
} }
@ -813,46 +817,49 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
/* Enlarge files */ /* Enlarge files */
DBUG_PRINT("info", ("enlarge to keystart: %lu", (ulong) share.base.keystart)); DBUG_PRINT("info", ("enlarge to keystart: %lu", (ulong) share.base.keystart));
if (my_chsize(file,(ulong) share.base.keystart,0,MYF(0))) if (mysql_file_chsize(file, (ulong) share.base.keystart, 0, MYF(0)))
goto err; goto err;
if (! (flags & HA_DONT_TOUCH_DATA)) if (! (flags & HA_DONT_TOUCH_DATA))
{ {
#ifdef USE_RELOC #ifdef USE_RELOC
if (my_chsize(dfile,share.base.min_pack_length*ci->reloc_rows,0,MYF(0))) if (mysql_file_chsize(dfile, share.base.min_pack_length*ci->reloc_rows,
0, MYF(0)))
goto err; goto err;
#endif #endif
errpos=2; errpos=2;
if (my_close(dfile,MYF(0))) if (mysql_file_close(dfile, MYF(0)))
goto err; goto err;
} }
errpos=0; errpos=0;
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
if (my_close(file,MYF(0))) if (mysql_file_close(file, MYF(0)))
goto err; goto err;
my_free((char*) rec_per_key_part,MYF(0)); my_free((char*) rec_per_key_part,MYF(0));
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
save_errno=my_errno; save_errno=my_errno;
switch (errpos) { switch (errpos) {
case 3: case 3:
(void) my_close(dfile,MYF(0)); (void) mysql_file_close(dfile, MYF(0));
/* fall through */ /* fall through */
case 2: case 2:
/* QQ: Tõnu should add a call to my_raid_delete() here */ /* QQ: Tõnu should add a call to my_raid_delete() here */
if (! (flags & HA_DONT_TOUCH_DATA)) if (! (flags & HA_DONT_TOUCH_DATA))
my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_DEXT, mysql_file_delete_with_symlink(mi_key_file_dfile,
MY_UNPACK_FILENAME | MY_APPEND_EXT), fn_format(filename, name, "", MI_NAME_DEXT,
MYF(0)); MY_UNPACK_FILENAME | MY_APPEND_EXT),
MYF(0));
/* fall through */ /* fall through */
case 1: case 1:
(void) my_close(file,MYF(0)); (void) mysql_file_close(file, MYF(0));
if (! (flags & HA_DONT_TOUCH_DATA)) if (! (flags & HA_DONT_TOUCH_DATA))
my_delete_with_symlink(fn_format(filename,name,"",MI_NAME_IEXT, mysql_file_delete_with_symlink(mi_key_file_kfile,
MY_UNPACK_FILENAME | MY_APPEND_EXT), fn_format(filename, name, "", MI_NAME_IEXT,
MYF(0)); MY_UNPACK_FILENAME | MY_APPEND_EXT),
MYF(0));
} }
my_free((char*) rec_per_key_part, MYF(0)); my_free((char*) rec_per_key_part, MYF(0));
DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */ DBUG_RETURN(my_errno=save_errno); /* return the fatal errno */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2003, 2005 MySQL AB /* Copyright (C) 2000-2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -57,8 +57,8 @@ int mi_delete_all_rows(MI_INFO *info)
if (share->file_map) if (share->file_map)
_mi_unmap_file(info); _mi_unmap_file(info);
#endif #endif
if (my_chsize(info->dfile, 0, 0, MYF(MY_WME)) || if (mysql_file_chsize(info->dfile, 0, 0, MYF(MY_WME)) ||
my_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)) ) mysql_file_chsize(share->kfile, share->base.keystart, 0, MYF(MY_WME)))
goto err; goto err;
(void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE); (void) _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
#ifdef HAVE_MMAP #ifdef HAVE_MMAP

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2004, 2006 MySQL AB /* Copyright (C) 2000-2001, 2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -58,12 +58,13 @@ int mi_delete_table(const char *name)
#endif /* USE_RAID */ #endif /* USE_RAID */
fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
if (my_delete_with_symlink(from, MYF(MY_WME))) if (mysql_file_delete_with_symlink(mi_key_file_kfile, from, MYF(MY_WME)))
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
#ifdef USE_RAID #ifdef USE_RAID
if (raid_type) if (raid_type)
DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME)) ? my_errno : 0); DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME)) ? my_errno : 0);
#endif #endif
DBUG_RETURN(my_delete_with_symlink(from, MYF(MY_WME)) ? my_errno : 0); DBUG_RETURN(mysql_file_delete_with_symlink(mi_key_file_dfile,
from, MYF(MY_WME)) ? my_errno : 0);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -143,7 +143,7 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer,
{ {
DBUG_PRINT("info", ("mi_read with mmap %d\n", info->dfile)); DBUG_PRINT("info", ("mi_read with mmap %d\n", info->dfile));
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_rdlock(&info->s->mmap_lock); mysql_rwlock_rdlock(&info->s->mmap_lock);
/* /*
The following test may fail in the following cases: The following test may fail in the following cases:
@ -156,24 +156,24 @@ size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer,
{ {
memcpy(Buffer, info->s->file_map + offset, Count); memcpy(Buffer, info->s->file_map + offset, Count);
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->mmap_lock); mysql_rwlock_unlock(&info->s->mmap_lock);
return 0; return 0;
} }
else else
{ {
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->mmap_lock); mysql_rwlock_unlock(&info->s->mmap_lock);
return my_pread(info->dfile, Buffer, Count, offset, MyFlags); return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags);
} }
} }
/* wrapper for my_pread in case if mmap isn't used */ /* wrapper for mysql_file_pread in case if mmap isn't used */
size_t mi_nommap_pread(MI_INFO *info, uchar *Buffer, size_t mi_nommap_pread(MI_INFO *info, uchar *Buffer,
size_t Count, my_off_t offset, myf MyFlags) size_t Count, my_off_t offset, myf MyFlags)
{ {
return my_pread(info->dfile, Buffer, Count, offset, MyFlags); return mysql_file_pread(info->dfile, Buffer, Count, offset, MyFlags);
} }
@ -198,7 +198,7 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer,
{ {
DBUG_PRINT("info", ("mi_write with mmap %d\n", info->dfile)); DBUG_PRINT("info", ("mi_write with mmap %d\n", info->dfile));
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_rdlock(&info->s->mmap_lock); mysql_rwlock_rdlock(&info->s->mmap_lock);
/* /*
The following test may fail in the following cases: The following test may fail in the following cases:
@ -211,26 +211,26 @@ size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer,
{ {
memcpy(info->s->file_map + offset, Buffer, Count); memcpy(info->s->file_map + offset, Buffer, Count);
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->mmap_lock); mysql_rwlock_unlock(&info->s->mmap_lock);
return 0; return 0;
} }
else else
{ {
info->s->nonmmaped_inserts++; info->s->nonmmaped_inserts++;
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->mmap_lock); mysql_rwlock_unlock(&info->s->mmap_lock);
return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags); return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
} }
} }
/* wrapper for my_pwrite in case if mmap isn't used */ /* wrapper for mysql_file_pwrite in case if mmap isn't used */
size_t mi_nommap_pwrite(MI_INFO *info, const uchar *Buffer, size_t mi_nommap_pwrite(MI_INFO *info, const uchar *Buffer,
size_t Count, my_off_t offset, myf MyFlags) size_t Count, my_off_t offset, myf MyFlags)
{ {
return my_pwrite(info->dfile, Buffer, Count, offset, MyFlags); return mysql_file_pwrite(info->dfile, Buffer, Count, offset, MyFlags);
} }
@ -1642,7 +1642,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
while (length > IO_SIZE*2) while (length > IO_SIZE*2)
{ {
if (my_pread(file,temp_buff,next_length,filepos, MYF(MY_NABP)) || if (mysql_file_pread(file, temp_buff, next_length, filepos, MYF(MY_NABP)) ||
memcmp(buff, temp_buff, next_length)) memcmp(buff, temp_buff, next_length))
goto err; goto err;
filepos+=next_length; filepos+=next_length;
@ -1650,7 +1650,7 @@ static int _mi_cmp_buffer(File file, const uchar *buff, my_off_t filepos,
length-= next_length; length-= next_length;
next_length=IO_SIZE*2; next_length=IO_SIZE*2;
} }
if (my_pread(file,temp_buff,length,filepos,MYF(MY_NABP))) if (mysql_file_pread(file, temp_buff, length, filepos, MYF(MY_NABP)))
goto err; goto err;
DBUG_RETURN(memcmp(buff,temp_buff,length)); DBUG_RETURN(memcmp(buff,temp_buff,length));
err: err:
@ -1831,8 +1831,9 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, uchar *buf,
block_info.filepos + block_info.data_len && block_info.filepos + block_info.data_len &&
flush_io_cache(&info->rec_cache)) flush_io_cache(&info->rec_cache))
goto err; goto err;
/* my_seek(info->dfile,filepos,MY_SEEK_SET,MYF(0)); */ /* mysql_file_seek(info->dfile, filepos, MY_SEEK_SET, MYF(0)); */
if (my_read(info->dfile,(uchar*) to,block_info.data_len,MYF(MY_NABP))) if (mysql_file_read(info->dfile, (uchar*) to, block_info.data_len,
MYF(MY_NABP)))
{ {
if (my_errno == -1) if (my_errno == -1)
my_errno= HA_ERR_WRONG_IN_RECORD; /* Unexpected end of file */ my_errno= HA_ERR_WRONG_IN_RECORD; /* Unexpected end of file */
@ -1880,12 +1881,12 @@ uint _mi_get_block_info(MI_BLOCK_INFO *info, File file, my_off_t filepos)
if (file >= 0) if (file >= 0)
{ {
/* /*
We do not use my_pread() here because we want to have the file We do not use mysql_file_pread() here because we want to have the file
pointer set to the end of the header after this function. pointer set to the end of the header after this function.
my_pread() may leave the file pointer untouched. mysql_file_pread() may leave the file pointer untouched.
*/ */
my_seek(file,filepos,MY_SEEK_SET,MYF(0)); mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0));
if (my_read(file, header, sizeof(info->header),MYF(0)) != if (mysql_file_read(file, header, sizeof(info->header), MYF(0)) !=
sizeof(info->header)) sizeof(info->header))
goto err; goto err;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2005 MySQL AB /* Copyright (C) 2000-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -74,17 +74,17 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
#if defined(HAVE_MMAP) && defined(HAVE_MADVISE) #if defined(HAVE_MMAP) && defined(HAVE_MADVISE)
if ((share->options & HA_OPTION_COMPRESS_RECORD)) if ((share->options & HA_OPTION_COMPRESS_RECORD))
{ {
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
if (_mi_memmap_file(info)) if (_mi_memmap_file(info))
{ {
/* We don't nead MADV_SEQUENTIAL if small file */ /* We don't nead MADV_SEQUENTIAL if small file */
madvise((char*) share->file_map, share->state.state.data_file_length, madvise((char*) share->file_map, share->state.state.data_file_length,
share->state.state.data_file_length <= RECORD_CACHE_SIZE*16 ? share->state.state.data_file_length <= RECORD_CACHE_SIZE*16 ?
MADV_RANDOM : MADV_SEQUENTIAL); MADV_RANDOM : MADV_SEQUENTIAL);
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
break; break;
} }
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
} }
#endif #endif
if (info->opt_flag & WRITE_CACHE_USED) if (info->opt_flag & WRITE_CACHE_USED)
@ -252,16 +252,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
} }
break; break;
case HA_EXTRA_FORCE_REOPEN: case HA_EXTRA_FORCE_REOPEN:
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
share->last_version= 0L; /* Impossible version */ share->last_version= 0L; /* Impossible version */
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
break; break;
case HA_EXTRA_PREPARE_FOR_DROP: case HA_EXTRA_PREPARE_FOR_DROP:
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
share->last_version= 0L; /* Impossible version */ share->last_version= 0L; /* Impossible version */
#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND #ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
/* Close the isam and data files as Win32 can't drop an open table */ /* Close the isam and data files as Win32 can't drop an open table */
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
if (flush_key_blocks(share->key_cache, share->kfile, if (flush_key_blocks(share->key_cache, share->kfile,
(function == HA_EXTRA_FORCE_REOPEN ? (function == HA_EXTRA_FORCE_REOPEN ?
FLUSH_RELEASE : FLUSH_IGNORE_CHANGED))) FLUSH_RELEASE : FLUSH_IGNORE_CHANGED)))
@ -285,7 +285,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
} }
if (share->kfile >= 0) if (share->kfile >= 0)
_mi_decrement_open_count(info); _mi_decrement_open_count(info);
if (share->kfile >= 0 && my_close(share->kfile,MYF(0))) if (share->kfile >= 0 && mysql_file_close(share->kfile, MYF(0)))
error=my_errno; error=my_errno;
{ {
LIST *list_element ; LIST *list_element ;
@ -296,16 +296,16 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
MI_INFO *tmpinfo=(MI_INFO*) list_element->data; MI_INFO *tmpinfo=(MI_INFO*) list_element->data;
if (tmpinfo->s == info->s) if (tmpinfo->s == info->s)
{ {
if (tmpinfo->dfile >= 0 && my_close(tmpinfo->dfile,MYF(0))) if (tmpinfo->dfile >= 0 && mysql_file_close(tmpinfo->dfile, MYF(0)))
error = my_errno; error = my_errno;
tmpinfo->dfile= -1; tmpinfo->dfile= -1;
} }
} }
} }
share->kfile= -1; /* Files aren't open anymore */ share->kfile= -1; /* Files aren't open anymore */
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
#endif #endif
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
break; break;
case HA_EXTRA_FLUSH: case HA_EXTRA_FLUSH:
if (!share->temporary) if (!share->temporary)
@ -316,9 +316,9 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
if (share->not_flushed) if (share->not_flushed)
{ {
share->not_flushed=0; share->not_flushed=0;
if (my_sync(share->kfile, MYF(0))) if (mysql_file_sync(share->kfile, MYF(0)))
error= my_errno; error= my_errno;
if (my_sync(info->dfile, MYF(0))) if (mysql_file_sync(info->dfile, MYF(0)))
error= my_errno; error= my_errno;
if (error) if (error)
{ {
@ -349,7 +349,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
break; break;
case HA_EXTRA_MMAP: case HA_EXTRA_MMAP:
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
/* /*
Memory map the data file if it is not already mapped. It is safe Memory map the data file if it is not already mapped. It is safe
to memory map a file while other threads are using file I/O on it. to memory map a file while other threads are using file I/O on it.
@ -370,13 +370,13 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
share->file_write= mi_mmap_pwrite; share->file_write= mi_mmap_pwrite;
} }
} }
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
#endif #endif
break; break;
case HA_EXTRA_MARK_AS_LOG_TABLE: case HA_EXTRA_MARK_AS_LOG_TABLE:
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
share->is_log_table= TRUE; share->is_log_table= TRUE;
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
break; break;
case HA_EXTRA_KEY_CACHE: case HA_EXTRA_KEY_CACHE:
case HA_EXTRA_NO_KEY_CACHE: case HA_EXTRA_NO_KEY_CACHE:

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2003-2004 MySQL AB /* Copyright (C) 2000-2001, 2003-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -42,10 +42,10 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag)
DBUG_RETURN(0); /* Compatible with ISAM */ DBUG_RETURN(0); /* Compatible with ISAM */
if (!(flag & HA_STATUS_NO_LOCK)) if (!(flag & HA_STATUS_NO_LOCK))
{ {
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
(void) _mi_readinfo(info,F_RDLCK,0); (void) _mi_readinfo(info,F_RDLCK,0);
fast_mi_writeinfo(info); fast_mi_writeinfo(info);
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
} }
if (flag & HA_STATUS_VARIABLE) if (flag & HA_STATUS_VARIABLE)
{ {
@ -85,7 +85,7 @@ int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint flag)
x->data_file_name = share->data_file_name; x->data_file_name = share->data_file_name;
x->index_file_name = share->index_file_name; x->index_file_name = share->index_file_name;
} }
if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile,&state,MYF(0))) if ((flag & HA_STATUS_TIME) && !mysql_file_fstat(info->dfile, &state, MYF(0)))
x->update_time=state.st_mtime; x->update_time=state.st_mtime;
else else
x->update_time=0; x->update_time=0;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003 MySQL AB /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -96,7 +96,7 @@ int mi_assign_to_key_cache(MI_INFO *info,
ensure that setting the key cache and changing the multi_key_cache ensure that setting the key cache and changing the multi_key_cache
is done atomicly is done atomicly
*/ */
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
/* /*
Tell all threads to use the new key cache Tell all threads to use the new key cache
This should be seen at the lastes for the next call to an myisam function. This should be seen at the lastes for the next call to an myisam function.
@ -108,7 +108,7 @@ int mi_assign_to_key_cache(MI_INFO *info,
share->unique_name_length, share->unique_name_length,
share->key_cache)) share->key_cache))
error= my_errno; error= my_errno;
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
DBUG_RETURN(error); DBUG_RETURN(error);
} }
@ -143,7 +143,7 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache,
/* /*
Lock list to ensure that no one can close the table while we manipulate it Lock list to ensure that no one can close the table while we manipulate it
*/ */
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
for (pos=myisam_open_list ; pos ; pos=pos->next) for (pos=myisam_open_list ; pos ; pos=pos->next)
{ {
MI_INFO *info= (MI_INFO*) pos->data; MI_INFO *info= (MI_INFO*) pos->data;
@ -158,6 +158,6 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache,
open a new table that will be associted with the old key cache open a new table that will be associted with the old key cache
*/ */
multi_key_cache_change(old_key_cache, new_key_cache); multi_key_cache_change(old_key_cache, new_key_cache);
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -49,7 +49,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
} }
flag=error=0; flag=error=0;
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
if (share->kfile >= 0) /* May only be false on windows */ if (share->kfile >= 0) /* May only be false on windows */
{ {
switch (lock_type) { switch (lock_type) {
@ -88,11 +88,11 @@ int mi_lock_database(MI_INFO *info, int lock_type)
(info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS)) (info->s->nonmmaped_inserts > MAX_NONMAPPED_INSERTS))
{ {
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_wrlock(&info->s->mmap_lock); mysql_rwlock_wrlock(&info->s->mmap_lock);
mi_remap_file(info, info->s->state.state.data_file_length); mi_remap_file(info, info->s->state.state.data_file_length);
info->s->nonmmaped_inserts= 0; info->s->nonmmaped_inserts= 0;
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->mmap_lock); mysql_rwlock_unlock(&info->s->mmap_lock);
} }
#endif #endif
share->state.process= share->last_process=share->this_process; share->state.process= share->last_process=share->this_process;
@ -103,9 +103,9 @@ int mi_lock_database(MI_INFO *info, int lock_type)
share->changed=0; share->changed=0;
if (myisam_flush) if (myisam_flush)
{ {
if (my_sync(share->kfile, MYF(0))) if (mysql_file_sync(share->kfile, MYF(0)))
error= my_errno; error= my_errno;
if (my_sync(info->dfile, MYF(0))) if (mysql_file_sync(info->dfile, MYF(0)))
error= my_errno; error= my_errno;
} }
else else
@ -251,7 +251,7 @@ int mi_lock_database(MI_INFO *info, int lock_type)
} }
} }
#endif #endif
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
#if defined(FULL_LOG) || defined(_lint) #if defined(FULL_LOG) || defined(_lint)
lock_type|=(int) (flag << 8); /* Set bit to set if real lock */ lock_type|=(int) (flag << 8); /* Set bit to set if real lock */
myisam_log_command(MI_LOG_LOCK,info,(uchar*) &lock_type,sizeof(lock_type), myisam_log_command(MI_LOG_LOCK,info,(uchar*) &lock_type,sizeof(lock_type),
@ -458,8 +458,8 @@ int _mi_writeinfo(register MI_INFO *info, uint operation)
#ifdef _WIN32 #ifdef _WIN32
if (myisam_flush) if (myisam_flush)
{ {
my_sync(share->kfile,0); mysql_file_sync(share->kfile, 0);
my_sync(info->dfile,0); mysql_file_sync(info->dfile, 0);
} }
#endif #endif
} }
@ -539,9 +539,9 @@ int _mi_mark_file_changed(MI_INFO *info)
{ {
mi_int2store(buff,share->state.open_count); mi_int2store(buff,share->state.open_count);
buff[2]=1; /* Mark that it's changed */ buff[2]=1; /* Mark that it's changed */
DBUG_RETURN(my_pwrite(share->kfile,buff,sizeof(buff), DBUG_RETURN(mysql_file_pwrite(share->kfile, buff, sizeof(buff),
sizeof(share->state.header), sizeof(share->state.header),
MYF(MY_NABP))); MYF(MY_NABP)));
} }
} }
DBUG_RETURN(0); DBUG_RETURN(0);
@ -568,9 +568,9 @@ int _mi_decrement_open_count(MI_INFO *info)
{ {
share->state.open_count--; share->state.open_count--;
mi_int2store(buff,share->state.open_count); mi_int2store(buff,share->state.open_count);
write_error=my_pwrite(share->kfile,buff,sizeof(buff), write_error= mysql_file_pwrite(share->kfile, buff, sizeof(buff),
sizeof(share->state.header), sizeof(share->state.header),
MYF(MY_NABP)); MYF(MY_NABP));
} }
if (!lock_error) if (!lock_error)
lock_error=mi_lock_database(info,old_lock); lock_error=mi_lock_database(info,old_lock);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2004 MySQL AB /* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -54,16 +54,19 @@ int mi_log(int activate_log)
myisam_pid=(ulong) getpid(); myisam_pid=(ulong) getpid();
if (myisam_log_file < 0) if (myisam_log_file < 0)
{ {
if ((myisam_log_file = my_create(fn_format(buff,myisam_log_filename, if ((myisam_log_file= mysql_file_create(mi_key_file_log,
"",".log",4), fn_format(buff,
0,(O_RDWR | O_BINARY | O_APPEND),MYF(0))) myisam_log_filename,
< 0) "", ".log", 4),
0,
(O_RDWR | O_BINARY | O_APPEND),
MYF(0))) < 0)
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
} }
} }
else if (myisam_log_file >= 0) else if (myisam_log_file >= 0)
{ {
error=my_close(myisam_log_file,MYF(0)) ? my_errno : 0 ; error= mysql_file_close(myisam_log_file, MYF(0)) ? my_errno : 0 ;
myisam_log_file= -1; myisam_log_file= -1;
} }
DBUG_RETURN(error); DBUG_RETURN(error);
@ -86,13 +89,13 @@ void _myisam_log(enum myisam_log_commands command, MI_INFO *info,
mi_int4store(buff+3,pid); mi_int4store(buff+3,pid);
mi_int2store(buff+9,length); mi_int2store(buff+9,length);
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
(void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
(void) my_write(myisam_log_file,buffert,length,MYF(0)); (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0));
if (!error) if (!error)
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=old_errno; my_errno=old_errno;
} }
@ -109,14 +112,14 @@ void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info,
mi_int2store(buff+1,info->dfile); mi_int2store(buff+1,info->dfile);
mi_int4store(buff+3,pid); mi_int4store(buff+3,pid);
mi_int2store(buff+7,result); mi_int2store(buff+7,result);
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
(void) my_write(myisam_log_file,buff,sizeof(buff),MYF(0)); (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
if (buffert) if (buffert)
(void) my_write(myisam_log_file,buffert,length,MYF(0)); (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0));
if (!error) if (!error)
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=old_errno; my_errno=old_errno;
} }
@ -140,10 +143,10 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
mi_int2store(buff+7,result); mi_int2store(buff+7,result);
mi_sizestore(buff+9,filepos); mi_sizestore(buff+9,filepos);
mi_int4store(buff+17,length); mi_int4store(buff+17,length);
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
(void) my_write(myisam_log_file, buff,sizeof(buff),MYF(0)); (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
(void) my_write(myisam_log_file, record,info->s->base.reclength,MYF(0)); (void) mysql_file_write(myisam_log_file, record, info->s->base.reclength, MYF(0));
if (info->s->base.blobs) if (info->s->base.blobs)
{ {
MI_BLOB *blob,*end; MI_BLOB *blob,*end;
@ -154,11 +157,11 @@ void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
{ {
memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length, memcpy_fixed((uchar*) &pos, record+blob->offset+blob->pack_length,
sizeof(char*)); sizeof(char*));
(void) my_write(myisam_log_file,pos,blob->length,MYF(0)); (void) mysql_file_write(myisam_log_file, pos, blob->length, MYF(0));
} }
} }
if (!error) if (!error)
error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE)); error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=old_errno; my_errno=old_errno;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -103,7 +103,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
DBUG_RETURN (NULL); DBUG_RETURN (NULL);
} }
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
if (!(old_info=test_if_reopen(name_buff))) if (!(old_info=test_if_reopen(name_buff)))
{ {
share= &share_buff; share= &share_buff;
@ -120,17 +120,21 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
my_errno= HA_ERR_CRASHED; my_errno= HA_ERR_CRASHED;
goto err; goto err;
}); });
if ((kfile=my_open(name_buff,(open_mode=O_RDWR) | O_SHARE,MYF(0))) < 0) if ((kfile= mysql_file_open(mi_key_file_kfile,
name_buff,
(open_mode= O_RDWR) | O_SHARE, MYF(0))) < 0)
{ {
if ((errno != EROFS && errno != EACCES) || if ((errno != EROFS && errno != EACCES) ||
mode != O_RDONLY || mode != O_RDONLY ||
(kfile=my_open(name_buff,(open_mode=O_RDONLY) | O_SHARE,MYF(0))) < 0) (kfile= mysql_file_open(mi_key_file_kfile,
name_buff,
(open_mode= O_RDONLY) | O_SHARE, MYF(0))) < 0)
goto err; goto err;
} }
share->mode=open_mode; share->mode=open_mode;
errpos=1; errpos=1;
if (my_read(kfile, share->state.header.file_version, head_length, if (mysql_file_read(kfile, share->state.header.file_version, head_length,
MYF(MY_NABP))) MYF(MY_NABP)))
{ {
my_errno= HA_ERR_NOT_A_TABLE; my_errno= HA_ERR_NOT_A_TABLE;
goto err; goto err;
@ -181,7 +185,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
end_pos=disk_cache+info_length; end_pos=disk_cache+info_length;
errpos=2; errpos=2;
my_seek(kfile,0L,MY_SEEK_SET,MYF(0)); mysql_file_seek(kfile, 0L, MY_SEEK_SET, MYF(0));
if (!(open_flags & HA_OPEN_TMP_TABLE)) if (!(open_flags & HA_OPEN_TMP_TABLE))
{ {
if ((lock_error=my_lock(kfile,F_RDLCK,0L,F_TO_EOF, if ((lock_error=my_lock(kfile,F_RDLCK,0L,F_TO_EOF,
@ -191,7 +195,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
goto err; goto err;
} }
errpos=3; errpos=3;
if (my_read(kfile,disk_cache,info_length,MYF(MY_NABP))) if (mysql_file_read(kfile, disk_cache, info_length, MYF(MY_NABP)))
{ {
my_errno=HA_ERR_CRASHED; my_errno=HA_ERR_CRASHED;
goto err; goto err;
@ -309,9 +313,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
&share->state.key_del, &share->state.key_del,
(share->state.header.max_block_size_index*sizeof(my_off_t)), (share->state.header.max_block_size_index*sizeof(my_off_t)),
#ifdef THREAD #ifdef THREAD
&share->key_root_lock,sizeof(rw_lock_t)*keys, &share->key_root_lock, sizeof(mysql_rwlock_t)*keys,
#endif #endif
&share->mmap_lock,sizeof(rw_lock_t), &share->mmap_lock, sizeof(mysql_rwlock_t),
NullS)) NullS))
goto err; goto err;
errpos=4; errpos=4;
@ -522,10 +526,12 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
share->is_log_table= FALSE; share->is_log_table= FALSE;
#ifdef THREAD #ifdef THREAD
thr_lock_init(&share->lock); thr_lock_init(&share->lock);
pthread_mutex_init(&share->intern_lock,MY_MUTEX_INIT_FAST); mysql_mutex_init(mi_key_mutex_MYISAM_SHARE_intern_lock,
&share->intern_lock, MY_MUTEX_INIT_FAST);
for (i=0; i<keys; i++) for (i=0; i<keys; i++)
(void) my_rwlock_init(&share->key_root_lock[i], NULL); mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_key_root_lock,
(void) my_rwlock_init(&share->mmap_lock, NULL); &share->key_root_lock[i]);
mysql_rwlock_init(mi_key_rwlock_MYISAM_SHARE_mmap_lock, &share->mmap_lock);
if (!thr_lock_inited) if (!thr_lock_inited)
{ {
/* Probably a single threaded program; Don't use concurrent inserts */ /* Probably a single threaded program; Don't use concurrent inserts */
@ -611,7 +617,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
info.ft1_to_ft2=0; info.ft1_to_ft2=0;
info.errkey= -1; info.errkey= -1;
info.page_changed=1; info.page_changed=1;
pthread_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
info.read_record=share->read_record; info.read_record=share->read_record;
share->reopen++; share->reopen++;
share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL); share->write_flag=MYF(MY_NABP | MY_WAIT_IF_FULL);
@ -635,7 +641,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
myisam_delay_key_write) myisam_delay_key_write)
share->delay_key_write=1; share->delay_key_write=1;
info.state= &share->state.state; /* Change global values by default */ info.state= &share->state.state; /* Change global values by default */
pthread_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
/* Allocate buffer for one record */ /* Allocate buffer for one record */
@ -651,7 +657,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
m_info->open_list.data=(void*) m_info; m_info->open_list.data=(void*) m_info;
myisam_open_list=list_add(myisam_open_list,&m_info->open_list); myisam_open_list=list_add(myisam_open_list,&m_info->open_list);
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
if (myisam_log_file >= 0) if (myisam_log_file >= 0)
{ {
intern_filename(name_buff,share->index_file_name); intern_filename(name_buff,share->index_file_name);
@ -670,7 +676,7 @@ err:
my_free((uchar*) m_info,MYF(0)); my_free((uchar*) m_info,MYF(0));
/* fall through */ /* fall through */
case 5: case 5:
(void) my_close(info.dfile,MYF(0)); (void) mysql_file_close(info.dfile, MYF(0));
if (old_info) if (old_info)
break; /* Don't remove open table */ break; /* Don't remove open table */
/* fall through */ /* fall through */
@ -685,13 +691,13 @@ err:
my_afree(disk_cache); my_afree(disk_cache);
/* fall through */ /* fall through */
case 1: case 1:
(void) my_close(kfile,MYF(0)); (void) mysql_file_close(kfile, MYF(0));
/* fall through */ /* fall through */
case 0: case 0:
default: default:
break; break;
} }
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
my_errno=save_errno; my_errno=save_errno;
DBUG_RETURN (NULL); DBUG_RETURN (NULL);
} /* mi_open */ } /* mi_open */
@ -924,10 +930,10 @@ uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite)
} }
if (pWrite & 1) if (pWrite & 1)
DBUG_RETURN(my_pwrite(file, buff, (size_t) (ptr-buff), 0L, DBUG_RETURN(mysql_file_pwrite(file, buff, (size_t) (ptr-buff), 0L,
MYF(MY_NABP | MY_THREADSAFE)) != 0); MYF(MY_NABP | MY_THREADSAFE)) != 0);
DBUG_RETURN(my_write(file, buff, (size_t) (ptr-buff), DBUG_RETURN(mysql_file_write(file, buff, (size_t) (ptr-buff),
MYF(MY_NABP)) != 0); MYF(MY_NABP)) != 0);
} }
@ -992,10 +998,10 @@ uint mi_state_info_read_dsk(File file, MI_STATE_INFO *state, my_bool pRead)
{ {
if (pRead) if (pRead)
{ {
if (my_pread(file, buff, state->state_length,0L, MYF(MY_NABP))) if (mysql_file_pread(file, buff, state->state_length, 0L, MYF(MY_NABP)))
return 1; return 1;
} }
else if (my_read(file, buff, state->state_length,MYF(MY_NABP))) else if (mysql_file_read(file, buff, state->state_length, MYF(MY_NABP)))
return 1; return 1;
mi_state_info_read(buff, state); mi_state_info_read(buff, state);
} }
@ -1038,7 +1044,7 @@ uint mi_base_info_write(File file, MI_BASE_INFO *base)
mi_int2store(ptr,base->raid_chunks); ptr +=2; mi_int2store(ptr,base->raid_chunks); ptr +=2;
mi_int4store(ptr,base->raid_chunksize); ptr +=4; mi_int4store(ptr,base->raid_chunksize); ptr +=4;
bzero(ptr,6); ptr +=6; /* extra */ bzero(ptr,6); ptr +=6; /* extra */
return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
} }
@ -1098,7 +1104,7 @@ uint mi_keydef_write(File file, MI_KEYDEF *keydef)
mi_int2store(ptr,keydef->keylength); ptr +=2; mi_int2store(ptr,keydef->keylength); ptr +=2;
mi_int2store(ptr,keydef->minlength); ptr +=2; mi_int2store(ptr,keydef->minlength); ptr +=2;
mi_int2store(ptr,keydef->maxlength); ptr +=2; mi_int2store(ptr,keydef->maxlength); ptr +=2;
return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
} }
uchar *mi_keydef_read(uchar *ptr, MI_KEYDEF *keydef) uchar *mi_keydef_read(uchar *ptr, MI_KEYDEF *keydef)
@ -1142,7 +1148,7 @@ int mi_keyseg_write(File file, const HA_KEYSEG *keyseg)
mi_int4store(ptr, pos); mi_int4store(ptr, pos);
ptr+=4; ptr+=4;
return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
} }
@ -1184,7 +1190,7 @@ uint mi_uniquedef_write(File file, MI_UNIQUEDEF *def)
*ptr++= (uchar) def->key; *ptr++= (uchar) def->key;
*ptr++ = (uchar) def->null_are_equal; *ptr++ = (uchar) def->null_are_equal;
return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
} }
uchar *mi_uniquedef_read(uchar *ptr, MI_UNIQUEDEF *def) uchar *mi_uniquedef_read(uchar *ptr, MI_UNIQUEDEF *def)
@ -1208,7 +1214,7 @@ uint mi_recinfo_write(File file, MI_COLUMNDEF *recinfo)
mi_int2store(ptr,recinfo->length); ptr +=2; mi_int2store(ptr,recinfo->length); ptr +=2;
*ptr++ = recinfo->null_bit; *ptr++ = recinfo->null_bit;
mi_int2store(ptr,recinfo->null_pos); ptr+= 2; mi_int2store(ptr,recinfo->null_pos); ptr+= 2;
return my_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0; return mysql_file_write(file, buff, (size_t) (ptr-buff), MYF(MY_NABP)) != 0;
} }
uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo) uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo)
@ -1261,15 +1267,18 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name,
} }
else else
#endif #endif
info->dfile=my_open(data_name, share->mode | O_SHARE, MYF(MY_WME)); info->dfile= mysql_file_open(mi_key_file_dfile,
data_name, share->mode | O_SHARE, MYF(MY_WME));
return info->dfile >= 0 ? 0 : 1; return info->dfile >= 0 ? 0 : 1;
} }
int mi_open_keyfile(MYISAM_SHARE *share) int mi_open_keyfile(MYISAM_SHARE *share)
{ {
if ((share->kfile=my_open(share->unique_file_name, share->mode | O_SHARE, if ((share->kfile= mysql_file_open(mi_key_file_kfile,
MYF(MY_WME))) < 0) share->unique_file_name,
share->mode | O_SHARE,
MYF(MY_WME))) < 0)
return 1; return 1;
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -150,7 +150,7 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys)
file=info->dfile; file=info->dfile;
my_errno=0; my_errno=0;
if (my_read(file,(uchar*) header,sizeof(header),MYF(MY_NABP))) if (mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP)))
{ {
if (!my_errno) if (!my_errno)
my_errno=HA_ERR_END_OF_FILE; my_errno=HA_ERR_END_OF_FILE;
@ -224,9 +224,9 @@ my_bool _mi_read_pack_info(MI_INFO *info, pbool fix_keys)
tmp_buff=share->decode_tables+length; tmp_buff=share->decode_tables+length;
disk_cache= (uchar*) (tmp_buff+OFFSET_TABLE_SIZE); disk_cache= (uchar*) (tmp_buff+OFFSET_TABLE_SIZE);
if (my_read(file,disk_cache, if (mysql_file_read(file, disk_cache,
(uint) (share->pack.header_length-sizeof(header)), (uint) (share->pack.header_length-sizeof(header)),
MYF(MY_NABP))) MYF(MY_NABP)))
goto err2; goto err2;
huff_tree_bits=max_bit(trees ? trees-1 : 0); huff_tree_bits=max_bit(trees ? trees-1 : 0);
@ -717,8 +717,8 @@ int _mi_read_pack_record(MI_INFO *info, my_off_t filepos, uchar *buf)
if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info, if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
&info->rec_buff, file, filepos)) &info->rec_buff, file, filepos))
goto err; goto err;
if (my_read(file,(uchar*) info->rec_buff + block_info.offset , if (mysql_file_read(file, (uchar*) info->rec_buff + block_info.offset,
block_info.rec_len - block_info.offset, MYF(MY_NABP))) block_info.rec_len - block_info.offset, MYF(MY_NABP)))
goto panic; goto panic;
info->update|= HA_STATE_AKTIV; info->update|= HA_STATE_AKTIV;
DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf, DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
@ -1339,9 +1339,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, uchar *buf,
} }
else else
{ {
if (my_read(info->dfile,(uchar*) info->rec_buff + block_info.offset, if (mysql_file_read(info->dfile,
block_info.rec_len-block_info.offset, (uchar*) info->rec_buff + block_info.offset,
MYF(MY_NABP))) block_info.rec_len-block_info.offset, MYF(MY_NABP)))
goto err; goto err;
} }
info->packed_length=block_info.rec_len; info->packed_length=block_info.rec_len;
@ -1370,11 +1370,11 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
{ {
ref_length=myisam->s->pack.ref_length; ref_length=myisam->s->pack.ref_length;
/* /*
We can't use my_pread() here because mi_read_rnd_pack_record assumes We can't use mysql_file_pread() here because mi_read_rnd_pack_record assumes
position is ok position is ok
*/ */
my_seek(file,filepos,MY_SEEK_SET,MYF(0)); mysql_file_seek(file, filepos, MY_SEEK_SET, MYF(0));
if (my_read(file, header,ref_length,MYF(MY_NABP))) if (mysql_file_read(file, header, ref_length, MYF(MY_NABP)))
return BLOCK_FATAL_ERROR; return BLOCK_FATAL_ERROR;
DBUG_DUMP("header",(uchar*) header,ref_length); DBUG_DUMP("header",(uchar*) header,ref_length);
} }
@ -1496,7 +1496,7 @@ my_bool _mi_memmap_file(MI_INFO *info)
if (!info->s->file_map) if (!info->s->file_map)
{ {
if (my_seek(info->dfile,0L,MY_SEEK_END,MYF(0)) < if (mysql_file_seek(info->dfile, 0L, MY_SEEK_END, MYF(0)) <
share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN) share->state.state.data_file_length+MEMMAP_EXTRA_MARGIN)
{ {
DBUG_PRINT("warning",("File isn't extended for memmap")); DBUG_PRINT("warning",("File isn't extended for memmap"));

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2003 MySQL AB /* Copyright (C) 2000-2001, 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -30,17 +30,17 @@ int mi_panic(enum ha_panic_function flag)
MI_INFO *info; MI_INFO *info;
DBUG_ENTER("mi_panic"); DBUG_ENTER("mi_panic");
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
for (list_element=myisam_open_list ; list_element ; list_element=next_open) for (list_element=myisam_open_list ; list_element ; list_element=next_open)
{ {
next_open=list_element->next; /* Save if close */ next_open=list_element->next; /* Save if close */
info=(MI_INFO*) list_element->data; info=(MI_INFO*) list_element->data;
switch (flag) { switch (flag) {
case HA_PANIC_CLOSE: case HA_PANIC_CLOSE:
pthread_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */ mysql_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */
if (mi_close(info)) if (mi_close(info))
error=my_errno; error=my_errno;
pthread_mutex_lock(&THR_LOCK_myisam); mysql_mutex_lock(&THR_LOCK_myisam);
break; break;
case HA_PANIC_WRITE: /* Do this to free databases */ case HA_PANIC_WRITE: /* Do this to free databases */
#ifdef CANT_OPEN_FILES_TWICE #ifdef CANT_OPEN_FILES_TWICE
@ -66,9 +66,9 @@ int mi_panic(enum ha_panic_function flag)
error=my_errno; error=my_errno;
} }
#ifdef CANT_OPEN_FILES_TWICE #ifdef CANT_OPEN_FILES_TWICE
if (info->s->kfile >= 0 && my_close(info->s->kfile,MYF(0))) if (info->s->kfile >= 0 && mysql_file_close(info->s->kfile, MYF(0)))
error = my_errno; error = my_errno;
if (info->dfile >= 0 && my_close(info->dfile,MYF(0))) if (info->dfile >= 0 && mysql_file_close(info->dfile, MYF(0)))
error = my_errno; error = my_errno;
info->s->kfile=info->dfile= -1; /* Files aren't open anymore */ info->s->kfile=info->dfile= -1; /* Files aren't open anymore */
break; break;
@ -78,15 +78,19 @@ int mi_panic(enum ha_panic_function flag)
{ /* Open closed files */ { /* Open closed files */
char name_buff[FN_REFLEN]; char name_buff[FN_REFLEN];
if (info->s->kfile < 0) if (info->s->kfile < 0)
if ((info->s->kfile= my_open(fn_format(name_buff,info->filename,"", if ((info->s->kfile= mysql_file_open(mi_key_file_kfile,
N_NAME_IEXT,4),info->mode, fn_format(name_buff,
MYF(MY_WME))) < 0) info->filename, "",
N_NAME_IEXT, 4),
info->mode, MYF(MY_WME))) < 0)
error = my_errno; error = my_errno;
if (info->dfile < 0) if (info->dfile < 0)
{ {
if ((info->dfile= my_open(fn_format(name_buff,info->filename,"", if ((info->dfile= mysql_file_open(mi_key_file_dfile,
N_NAME_DEXT,4),info->mode, fn_format(name_buff,
MYF(MY_WME))) < 0) info->filename, "",
N_NAME_DEXT, 4),
info->mode, MYF(MY_WME))) < 0)
error = my_errno; error = my_errno;
info->rec_cache.file=info->dfile; info->rec_cache.file=info->dfile;
} }
@ -106,7 +110,7 @@ int mi_panic(enum ha_panic_function flag)
(void) mi_log(0); /* Close log if neaded */ (void) mi_log(0); /* Close log if neaded */
ft_free_stopwords(); ft_free_stopwords();
} }
pthread_mutex_unlock(&THR_LOCK_myisam); mysql_mutex_unlock(&THR_LOCK_myisam);
if (!error) if (!error)
DBUG_RETURN(0); DBUG_RETURN(0);
DBUG_RETURN(my_errno=error); DBUG_RETURN(my_errno=error);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2003, 2005 MySQL AB /* Copyright (C) 2003, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -81,7 +81,8 @@ int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves)
/* Read the next block of index file into the preload buffer */ /* Read the next block of index file into the preload buffer */
if ((my_off_t) length > (key_file_length-pos)) if ((my_off_t) length > (key_file_length-pos))
length= (ulong) (key_file_length-pos); length= (ulong) (key_file_length-pos);
if (my_pread(share->kfile, (uchar*) buff, length, pos, MYF(MY_FAE|MY_FNABP))) if (mysql_file_pread(share->kfile, (uchar*) buff, length, pos,
MYF(MY_FAE|MY_FNABP)))
goto err; goto err;
if (ignore_leaves) if (ignore_leaves)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2004, 2006 MySQL AB /* Copyright (C) 2000-2004, 2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -57,7 +57,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx,
DBUG_RETURN(HA_POS_ERROR); DBUG_RETURN(HA_POS_ERROR);
info->update&= (HA_STATE_CHANGED+HA_STATE_ROW_CHANGED); info->update&= (HA_STATE_CHANGED+HA_STATE_ROW_CHANGED);
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_rdlock(&info->s->key_root_lock[inx]); mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
switch(info->s->keyinfo[inx].key_alg){ switch(info->s->keyinfo[inx].key_alg){
#ifdef HAVE_RTREE_KEYS #ifdef HAVE_RTREE_KEYS
@ -106,7 +106,7 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx,
} }
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->key_root_lock[inx]); mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
fast_mi_writeinfo(info); fast_mi_writeinfo(info);
DBUG_PRINT("info",("records: %ld",(ulong) (res))); DBUG_PRINT("info",("records: %ld",(ulong) (res)));

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2004 MySQL AB /* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -47,7 +47,7 @@ int mi_rename(const char *old_name, const char *new_name)
fn_format(from,old_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(from,old_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
fn_format(to,new_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(to,new_name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
if (my_rename_with_symlink(from, to, MYF(MY_WME))) if (mysql_file_rename_with_symlink(mi_key_file_kfile, from, to, MYF(MY_WME)))
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
fn_format(from,old_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(from,old_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
fn_format(to,new_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT); fn_format(to,new_name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
@ -56,5 +56,7 @@ int mi_rename(const char *old_name, const char *new_name)
DBUG_RETURN(my_raid_rename(from, to, raid_chunks, MYF(MY_WME)) ? my_errno : DBUG_RETURN(my_raid_rename(from, to, raid_chunks, MYF(MY_WME)) ? my_errno :
0); 0);
#endif #endif
DBUG_RETURN(my_rename_with_symlink(from, to,MYF(MY_WME)) ? my_errno : 0); DBUG_RETURN(mysql_file_rename_with_symlink(mi_key_file_dfile,
from, to,
MYF(MY_WME)) ? my_errno : 0);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -71,7 +71,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
goto err; goto err;
if (share->concurrent_insert) if (share->concurrent_insert)
rw_rdlock(&share->key_root_lock[inx]); mysql_rwlock_rdlock(&share->key_root_lock[inx]);
nextflag=myisam_read_vec[search_flag]; nextflag=myisam_read_vec[search_flag];
use_key_length=pack_key_length; use_key_length=pack_key_length;
@ -156,7 +156,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
} }
} }
if (share->concurrent_insert) if (share->concurrent_insert)
rw_unlock(&share->key_root_lock[inx]); mysql_rwlock_unlock(&share->key_root_lock[inx]);
/* Calculate length of the found key; Used by mi_rnext_same */ /* Calculate length of the found key; Used by mi_rnext_same */
if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg && if ((keyinfo->flag & HA_VAR_LENGTH_KEY) && last_used_keyseg &&

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2004 MySQL AB /* Copyright (C) 2000-2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -39,7 +39,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx)
if (fast_mi_readinfo(info)) if (fast_mi_readinfo(info))
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_rdlock(&info->s->key_root_lock[inx]); mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
changed=_mi_test_if_changed(info); changed=_mi_test_if_changed(info);
if (!flag) if (!flag)
{ {
@ -96,7 +96,7 @@ int mi_rnext(MI_INFO *info, uchar *buf, int inx)
break; break;
} }
} }
rw_unlock(&info->s->key_root_lock[inx]); mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
} }
/* Don't clear if database-changed */ /* Don't clear if database-changed */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -38,7 +38,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf)
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_rdlock(&info->s->key_root_lock[inx]); mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
switch (keyinfo->key_alg) switch (keyinfo->key_alg)
{ {
@ -81,7 +81,7 @@ int mi_rnext_same(MI_INFO *info, uchar *buf)
} }
} }
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->key_root_lock[inx]); mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
/* Don't clear if database-changed */ /* Don't clear if database-changed */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME; info->update|= HA_STATE_NEXT_FOUND | HA_STATE_RNEXT_SAME;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2004 MySQL AB /* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -39,7 +39,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx)
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
changed=_mi_test_if_changed(info); changed=_mi_test_if_changed(info);
if (share->concurrent_insert) if (share->concurrent_insert)
rw_rdlock(&share->key_root_lock[inx]); mysql_rwlock_rdlock(&share->key_root_lock[inx]);
if (!flag) if (!flag)
error=_mi_search_last(info, share->keyinfo+inx, error=_mi_search_last(info, share->keyinfo+inx,
share->state.key_root[inx]); share->state.key_root[inx]);
@ -65,7 +65,7 @@ int mi_rprev(MI_INFO *info, uchar *buf, int inx)
break; break;
} }
} }
rw_unlock(&share->key_root_lock[inx]); mysql_rwlock_unlock(&share->key_root_lock[inx]);
} }
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
info->update|= HA_STATE_PREV_FOUND; info->update|= HA_STATE_PREV_FOUND;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2005 MySQL AB /* Copyright (C) 2000-2001, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -49,12 +49,12 @@ int mi_rsame(MI_INFO *info, uchar *record, int inx)
info->lastkey_length=_mi_make_key(info,(uint) inx,info->lastkey,record, info->lastkey_length=_mi_make_key(info,(uint) inx,info->lastkey,record,
info->lastpos); info->lastpos);
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_rdlock(&info->s->key_root_lock[inx]); mysql_rwlock_rdlock(&info->s->key_root_lock[inx]);
(void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY, (void) _mi_search(info,info->s->keyinfo+inx,info->lastkey, USE_WHOLE_KEY,
SEARCH_SAME, SEARCH_SAME,
info->s->state.key_root[inx]); info->s->state.key_root[inx]);
if (info->s->concurrent_insert) if (info->s->concurrent_insert)
rw_unlock(&info->s->key_root_lock[inx]); mysql_rwlock_unlock(&info->s->key_root_lock[inx]);
} }
if (!(*info->read_record)(info,info->lastpos,record)) if (!(*info->read_record)(info,info->lastpos,record))

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2002, 2004-2005 MySQL AB /* Copyright (C) 2000-2002, 2004-2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -68,3 +68,74 @@ uint NEAR myisam_readnext_vec[]=
SEARCH_BIGGER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_BIGGER, SEARCH_SMALLER,
SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_SMALLER SEARCH_BIGGER, SEARCH_SMALLER, SEARCH_SMALLER
}; };
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock,
mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg;
static PSI_mutex_info all_myisam_mutexes[]=
{
{ &mi_key_mutex_MI_SORT_INFO_mutex, "MI_SORT_INFO::mutex", 0},
{ &mi_key_mutex_MYISAM_SHARE_intern_lock, "MYISAM_SHARE::intern_lock", 0},
{ &mi_key_mutex_MI_CHECK_print_msg, "MI_CHECK::print_msg", 0}
};
PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock,
mi_key_rwlock_MYISAM_SHARE_mmap_lock;
static PSI_rwlock_info all_myisam_rwlocks[]=
{
{ &mi_key_rwlock_MYISAM_SHARE_key_root_lock, "MYISAM_SHARE::key_root_lock", 0},
{ &mi_key_rwlock_MYISAM_SHARE_mmap_lock, "MYISAM_SHARE::mmap_lock", 0}
};
PSI_cond_key mi_key_cond_MI_SORT_INFO_cond;
static PSI_cond_info all_myisam_conds[]=
{
{ &mi_key_cond_MI_SORT_INFO_cond, "MI_SORT_INFO::cond", 0}
};
PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile,
mi_key_file_log;
static PSI_file_info all_myisam_files[]=
{
{ & mi_key_file_datatmp, "data_tmp", 0},
{ & mi_key_file_dfile, "dfile", 0},
{ & mi_key_file_kfile, "kfile", 0},
{ & mi_key_file_log, "log", 0}
};
PSI_thread_key mi_key_thread_find_all_keys;
static PSI_thread_info all_myisam_threads[]=
{
{ &mi_key_thread_find_all_keys, "find_all_keys", 0},
};
void init_myisam_psi_keys()
{
const char* category= "myisam";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_myisam_mutexes);
PSI_server->register_mutex(category, all_myisam_mutexes, count);
count= array_elements(all_myisam_rwlocks);
PSI_server->register_rwlock(category, all_myisam_rwlocks, count);
count= array_elements(all_myisam_conds);
PSI_server->register_cond(category, all_myisam_conds, count);
count= array_elements(all_myisam_files);
PSI_server->register_file(category, all_myisam_files, count);
count= array_elements(all_myisam_threads);
PSI_server->register_thread(category, all_myisam_threads, count);
}
#endif /* HAVE_PSI_INTERFACE */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -107,7 +107,7 @@ int mi_write(MI_INFO *info, uchar *record)
is_tree_inited(&info->bulk_insert[i]))); is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree) if (local_lock_tree)
{ {
rw_wrlock(&share->key_root_lock[i]); mysql_rwlock_wrlock(&share->key_root_lock[i]);
share->keyinfo[i].version++; share->keyinfo[i].version++;
} }
if (share->keyinfo[i].flag & HA_FULLTEXT ) if (share->keyinfo[i].flag & HA_FULLTEXT )
@ -115,7 +115,7 @@ int mi_write(MI_INFO *info, uchar *record)
if (_mi_ft_add(info,i, buff, record, filepos)) if (_mi_ft_add(info,i, buff, record, filepos))
{ {
if (local_lock_tree) if (local_lock_tree)
rw_unlock(&share->key_root_lock[i]); mysql_rwlock_unlock(&share->key_root_lock[i]);
DBUG_PRINT("error",("Got error: %d on write",my_errno)); DBUG_PRINT("error",("Got error: %d on write",my_errno));
goto err; goto err;
} }
@ -126,7 +126,7 @@ int mi_write(MI_INFO *info, uchar *record)
_mi_make_key(info,i,buff,record,filepos))) _mi_make_key(info,i,buff,record,filepos)))
{ {
if (local_lock_tree) if (local_lock_tree)
rw_unlock(&share->key_root_lock[i]); mysql_rwlock_unlock(&share->key_root_lock[i]);
DBUG_PRINT("error",("Got error: %d on write",my_errno)); DBUG_PRINT("error",("Got error: %d on write",my_errno));
goto err; goto err;
} }
@ -136,7 +136,7 @@ int mi_write(MI_INFO *info, uchar *record)
info->update&= ~HA_STATE_RNEXT_SAME; info->update&= ~HA_STATE_RNEXT_SAME;
if (local_lock_tree) if (local_lock_tree)
rw_unlock(&share->key_root_lock[i]); mysql_rwlock_unlock(&share->key_root_lock[i]);
} }
} }
if (share->calc_checksum) if (share->calc_checksum)
@ -197,13 +197,13 @@ err:
!(info->bulk_insert && !(info->bulk_insert &&
is_tree_inited(&info->bulk_insert[i]))); is_tree_inited(&info->bulk_insert[i])));
if (local_lock_tree) if (local_lock_tree)
rw_wrlock(&share->key_root_lock[i]); mysql_rwlock_wrlock(&share->key_root_lock[i]);
if (share->keyinfo[i].flag & HA_FULLTEXT) if (share->keyinfo[i].flag & HA_FULLTEXT)
{ {
if (_mi_ft_del(info,i, buff,record,filepos)) if (_mi_ft_del(info,i, buff,record,filepos))
{ {
if (local_lock_tree) if (local_lock_tree)
rw_unlock(&share->key_root_lock[i]); mysql_rwlock_unlock(&share->key_root_lock[i]);
break; break;
} }
} }
@ -213,12 +213,12 @@ err:
if (_mi_ck_delete(info,i,buff,key_length)) if (_mi_ck_delete(info,i,buff,key_length))
{ {
if (local_lock_tree) if (local_lock_tree)
rw_unlock(&share->key_root_lock[i]); mysql_rwlock_unlock(&share->key_root_lock[i]);
break; break;
} }
} }
if (local_lock_tree) if (local_lock_tree)
rw_unlock(&share->key_root_lock[i]); mysql_rwlock_unlock(&share->key_root_lock[i]);
} }
} }
} }
@ -943,7 +943,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
case free_init: case free_init:
if (param->info->s->concurrent_insert) if (param->info->s->concurrent_insert)
{ {
rw_wrlock(&param->info->s->key_root_lock[param->keynr]); mysql_rwlock_wrlock(&param->info->s->key_root_lock[param->keynr]);
param->info->s->keyinfo[param->keynr].version++; param->info->s->keyinfo[param->keynr].version++;
} }
return 0; return 0;
@ -955,7 +955,7 @@ static int keys_free(uchar *key, TREE_FREE mode, bulk_insert_param *param)
keylen - param->info->s->rec_reflength); keylen - param->info->s->rec_reflength);
case free_end: case free_end:
if (param->info->s->concurrent_insert) if (param->info->s->concurrent_insert)
rw_unlock(&param->info->s->key_root_lock[param->keynr]); mysql_rwlock_unlock(&param->info->s->key_root_lock[param->keynr]);
return 0; return 0;
} }
return -1; return -1;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -24,6 +24,7 @@
#else #else
#include <my_no_pthread.h> #include <my_no_pthread.h>
#endif #endif
#include <mysql/psi/mysql_file.h>
#if defined(my_write) && !defined(MAP_TO_USE_RAID) #if defined(my_write) && !defined(MAP_TO_USE_RAID)
#undef my_write /* undef map from my_nosys; We need test-if-disk full */ #undef my_write /* undef map from my_nosys; We need test-if-disk full */
@ -213,13 +214,13 @@ typedef struct st_mi_isam_share { /* Shared between opens */
concurrent_insert; concurrent_insert;
#ifdef THREAD #ifdef THREAD
THR_LOCK lock; THR_LOCK lock;
pthread_mutex_t intern_lock; /* Locking for use with _locking */ mysql_mutex_t intern_lock; /* Locking for use with _locking */
rw_lock_t *key_root_lock; mysql_rwlock_t *key_root_lock;
#endif #endif
my_off_t mmaped_length; my_off_t mmaped_length;
uint nonmmaped_inserts; /* counter of writing in non-mmaped uint nonmmaped_inserts; /* counter of writing in non-mmaped
area */ area */
rw_lock_t mmap_lock; mysql_rwlock_t mmap_lock;
} MYISAM_SHARE; } MYISAM_SHARE;
@ -460,12 +461,12 @@ typedef struct st_mi_sort_param
#define mi_unique_store(A,B) mi_int4store((A),(B)) #define mi_unique_store(A,B) mi_int4store((A),(B))
#ifdef THREAD #ifdef THREAD
extern pthread_mutex_t THR_LOCK_myisam; extern mysql_mutex_t THR_LOCK_myisam;
#endif #endif
#if !defined(THREAD) || defined(DONT_USE_RW_LOCKS) #if !defined(THREAD) || defined(DONT_USE_RW_LOCKS)
#define rw_wrlock(A) {} #define mysql_rwlock_wrlock(A) {}
#define rw_rdlock(A) {} #define mysql_rwlock_rdlock(A) {}
#define rw_unlock(A) {} #define mysql_rwlock_unlock(A) {}
#endif #endif
/* Some extern variables */ /* Some extern variables */
@ -785,3 +786,22 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong);
} }
#endif #endif
#ifdef HAVE_PSI_INTERFACE
C_MODE_START
extern PSI_mutex_key mi_key_mutex_MYISAM_SHARE_intern_lock,
mi_key_mutex_MI_SORT_INFO_mutex, mi_key_mutex_MI_CHECK_print_msg;
extern PSI_rwlock_key mi_key_rwlock_MYISAM_SHARE_key_root_lock,
mi_key_rwlock_MYISAM_SHARE_mmap_lock;
extern PSI_cond_key mi_key_cond_MI_SORT_INFO_cond;
extern PSI_file_key mi_key_file_datatmp, mi_key_file_dfile, mi_key_file_kfile,
mi_key_file_log;
extern PSI_thread_key mi_key_thread_find_all_keys;
void init_myisam_psi_keys();
C_MODE_END
#endif /* HAVE_PSI_INTERFACE */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -478,10 +478,10 @@ ok:
if (sort_param->read_cache.share) if (sort_param->read_cache.share)
remove_io_thread(&sort_param->read_cache); remove_io_thread(&sort_param->read_cache);
pthread_mutex_lock(&sort_param->sort_info->mutex); mysql_mutex_lock(&sort_param->sort_info->mutex);
if (!--sort_param->sort_info->threads_running) if (!--sort_param->sort_info->threads_running)
pthread_cond_signal(&sort_param->sort_info->cond); mysql_cond_signal(&sort_param->sort_info->cond);
pthread_mutex_unlock(&sort_param->sort_info->mutex); mysql_mutex_unlock(&sort_param->sort_info->mutex);
DBUG_PRINT("exit", ("======== ending thread ========")); DBUG_PRINT("exit", ("======== ending thread ========"));
} }
my_thread_end(); my_thread_end();
@ -824,8 +824,9 @@ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek,
if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count))) if ((count=(uint) min((ha_rows) buffpek->max_keys,buffpek->count)))
{ {
if (my_pread(fromfile->file,(uchar*) buffpek->base, if (mysql_file_pread(fromfile->file, (uchar*) buffpek->base,
(length= sort_length*count),buffpek->file_pos,MYF_RW)) (length= sort_length*count),
buffpek->file_pos, MYF_RW))
return((uint) -1); /* purecov: inspected */ return((uint) -1); /* purecov: inspected */
buffpek->key=buffpek->base; buffpek->key=buffpek->base;
buffpek->file_pos+= length; /* New filepos */ buffpek->file_pos+= length; /* New filepos */
@ -849,12 +850,12 @@ static uint NEAR_F read_to_buffer_varlen(IO_CACHE *fromfile, BUFFPEK *buffpek,
for (idx=1;idx<=count;idx++) for (idx=1;idx<=count;idx++)
{ {
if (my_pread(fromfile->file,(uchar*)&length_of_key,sizeof(length_of_key), if (mysql_file_pread(fromfile->file, (uchar*)&length_of_key,
buffpek->file_pos,MYF_RW)) sizeof(length_of_key), buffpek->file_pos, MYF_RW))
return((uint) -1); return((uint) -1);
buffpek->file_pos+=sizeof(length_of_key); buffpek->file_pos+=sizeof(length_of_key);
if (my_pread(fromfile->file,(uchar*) buffp,length_of_key, if (mysql_file_pread(fromfile->file, (uchar*) buffp,
buffpek->file_pos,MYF_RW)) length_of_key, buffpek->file_pos, MYF_RW))
return((uint) -1); return((uint) -1);
buffpek->file_pos+=length_of_key; buffpek->file_pos+=length_of_key;
buffp = buffp + sort_length; buffp = buffp + sort_length;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -1513,6 +1513,10 @@ static int myisammrg_init(void *p)
myisammrg_hton= (handlerton *)p; myisammrg_hton= (handlerton *)p;
#ifdef HAVE_PSI_INTERFACE
init_myisammrg_psi_keys();
#endif
myisammrg_hton->db_type= DB_TYPE_MRG_MYISAM; myisammrg_hton->db_type= DB_TYPE_MRG_MYISAM;
myisammrg_hton->create= myisammrg_create_handler; myisammrg_hton->create= myisammrg_create_handler;
myisammrg_hton->panic= myisammrg_panic; myisammrg_hton->panic= myisammrg_panic;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001 MySQL AB /* Copyright (C) 2000-2001 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -55,10 +55,10 @@ int myrg_close(MYRG_INFO *info)
else else
my_free((uchar*) info->rec_per_key_part, MYF(MY_ALLOW_ZERO_PTR)); my_free((uchar*) info->rec_per_key_part, MYF(MY_ALLOW_ZERO_PTR));
delete_queue(&info->by_key); delete_queue(&info->by_key);
pthread_mutex_lock(&THR_LOCK_open); mysql_mutex_lock(&THR_LOCK_open);
myrg_open_list=list_delete(myrg_open_list,&info->open_list); myrg_open_list=list_delete(myrg_open_list,&info->open_list);
pthread_mutex_unlock(&THR_LOCK_open); mysql_mutex_unlock(&THR_LOCK_open);
pthread_mutex_destroy(&info->mutex); mysql_mutex_destroy(&info->mutex);
my_free((uchar*) info,MYF(0)); my_free((uchar*) info,MYF(0));
if (error) if (error)
{ {

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2005 MySQL AB /* Copyright (C) 2000-2001, 2005 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -32,9 +32,10 @@ int myrg_create(const char *name, const char **table_names,
DBUG_ENTER("myrg_create"); DBUG_ENTER("myrg_create");
errpos=0; errpos=0;
if ((file = my_create(fn_format(buff,name,"",MYRG_NAME_EXT, if ((file= mysql_file_create(rg_key_file_MRG,
MY_UNPACK_FILENAME|MY_APPEND_EXT),0, fn_format(buff, name, "", MYRG_NAME_EXT,
O_RDWR | O_EXCL | O_NOFOLLOW,MYF(MY_WME))) < 0) MY_UNPACK_FILENAME|MY_APPEND_EXT), 0,
O_RDWR | O_EXCL | O_NOFOLLOW, MYF(MY_WME))) < 0)
goto err; goto err;
errpos=1; errpos=1;
if (table_names) if (table_names)
@ -46,8 +47,8 @@ int myrg_create(const char *name, const char **table_names,
fn_same(buff,name,4); fn_same(buff,name,4);
*(end=strend(buff))='\n'; *(end=strend(buff))='\n';
end[1]=0; end[1]=0;
if (my_write(file,(uchar*) buff,(uint) (end-buff+1), if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff+1),
MYF(MY_WME | MY_NABP))) MYF(MY_WME | MY_NABP)))
goto err; goto err;
} }
} }
@ -55,10 +56,11 @@ int myrg_create(const char *name, const char **table_names,
{ {
end=strxmov(buff,"#INSERT_METHOD=", end=strxmov(buff,"#INSERT_METHOD=",
get_type(&merge_insert_method,insert_method-1),"\n",NullS); get_type(&merge_insert_method,insert_method-1),"\n",NullS);
if (my_write(file, (uchar*) buff,(uint) (end-buff),MYF(MY_WME | MY_NABP))) if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff),
MYF(MY_WME | MY_NABP)))
goto err; goto err;
} }
if (my_close(file,MYF(0))) if (mysql_file_close(file, MYF(0)))
goto err; goto err;
DBUG_RETURN(0); DBUG_RETURN(0);
@ -66,7 +68,7 @@ err:
save_errno=my_errno ? my_errno : -1; save_errno=my_errno ? my_errno : -1;
switch (errpos) { switch (errpos) {
case 1: case 1:
(void) my_close(file,MYF(0)); (void) mysql_file_close(file, MYF(0));
} }
DBUG_RETURN(my_errno=save_errno); DBUG_RETURN(my_errno=save_errno);
} /* myrg_create */ } /* myrg_create */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2003 MySQL AB /* Copyright (C) 2000-2001, 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -24,7 +24,7 @@
extern LIST *myrg_open_list; extern LIST *myrg_open_list;
#ifdef THREAD #ifdef THREAD
extern pthread_mutex_t THR_LOCK_open; extern mysql_mutex_t THR_LOCK_open;
#endif #endif
int _myrg_init_queue(MYRG_INFO *info,int inx,enum ha_rkey_function search_flag); int _myrg_init_queue(MYRG_INFO *info,int inx,enum ha_rkey_function search_flag);
@ -33,3 +33,14 @@ int _myrg_mi_read_record(MI_INFO *info, uchar *buf);
extern "C" extern "C"
#endif #endif
void myrg_print_wrong_table(const char *table_name); void myrg_print_wrong_table(const char *table_name);
#ifdef HAVE_PSI_INTERFACE
extern PSI_mutex_key rg_key_mutex_MYRG_INFO_mutex;
extern PSI_file_key rg_key_file_MRG;
C_MODE_START
void init_myisammrg_psi_keys();
C_MODE_END
#endif /* HAVE_PSI_INTERFACE */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2006 MySQL AB /* Copyright (C) 2000-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -50,9 +50,10 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
DBUG_ENTER("myrg_open"); DBUG_ENTER("myrg_open");
bzero((char*) &file,sizeof(file)); bzero((char*) &file,sizeof(file));
if ((fd=my_open(fn_format(name_buff,name,"",MYRG_NAME_EXT, if ((fd= mysql_file_open(rg_key_file_MRG,
MY_UNPACK_FILENAME|MY_APPEND_EXT), fn_format(name_buff, name, "", MYRG_NAME_EXT,
O_RDONLY | O_SHARE,MYF(0))) < 0) MY_UNPACK_FILENAME|MY_APPEND_EXT),
O_RDONLY | O_SHARE, MYF(0))) < 0)
goto err; goto err;
errpos=1; errpos=1;
if (init_io_cache(&file, fd, 4*IO_SIZE, READ_CACHE, 0, 0, if (init_io_cache(&file, fd, 4*IO_SIZE, READ_CACHE, 0, 0,
@ -167,13 +168,14 @@ MYRG_INFO *myrg_open(const char *name, int mode, int handle_locking)
m_info->last_used_table=m_info->open_tables; m_info->last_used_table=m_info->open_tables;
m_info->children_attached= TRUE; m_info->children_attached= TRUE;
(void) my_close(fd,MYF(0)); (void) mysql_file_close(fd, MYF(0));
end_io_cache(&file); end_io_cache(&file);
pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST); mysql_mutex_init(rg_key_mutex_MYRG_INFO_mutex,
&m_info->mutex, MY_MUTEX_INIT_FAST);
m_info->open_list.data=(void*) m_info; m_info->open_list.data=(void*) m_info;
pthread_mutex_lock(&THR_LOCK_open); mysql_mutex_lock(&THR_LOCK_open);
myrg_open_list=list_add(myrg_open_list,&m_info->open_list); myrg_open_list=list_add(myrg_open_list,&m_info->open_list);
pthread_mutex_unlock(&THR_LOCK_open); mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(m_info); DBUG_RETURN(m_info);
bad_children: bad_children:
@ -190,7 +192,7 @@ err:
end_io_cache(&file); end_io_cache(&file);
/* Fall through */ /* Fall through */
case 1: case 1:
(void) my_close(fd,MYF(0)); (void) mysql_file_close(fd, MYF(0));
} }
my_errno=save_errno; my_errno=save_errno;
DBUG_RETURN (NULL); DBUG_RETURN (NULL);
@ -241,9 +243,11 @@ MYRG_INFO *myrg_parent_open(const char *parent_name,
bzero((char*) &file_cache, sizeof(file_cache)); bzero((char*) &file_cache, sizeof(file_cache));
/* Open MERGE meta file. */ /* Open MERGE meta file. */
if ((fd= my_open(fn_format(parent_name_buff, parent_name, "", MYRG_NAME_EXT, if ((fd= mysql_file_open(rg_key_file_MRG,
MY_UNPACK_FILENAME|MY_APPEND_EXT), fn_format(parent_name_buff, parent_name,
O_RDONLY | O_SHARE, MYF(0))) < 0) "", MYRG_NAME_EXT,
MY_UNPACK_FILENAME|MY_APPEND_EXT),
O_RDONLY | O_SHARE, MYF(0))) < 0)
goto err; /* purecov: inspected */ goto err; /* purecov: inspected */
errpos= 1; errpos= 1;
@ -327,13 +331,14 @@ MYRG_INFO *myrg_parent_open(const char *parent_name,
} }
end_io_cache(&file_cache); end_io_cache(&file_cache);
(void) my_close(fd, MYF(0)); (void) mysql_file_close(fd, MYF(0));
pthread_mutex_init(&m_info->mutex, MY_MUTEX_INIT_FAST); mysql_mutex_init(rg_key_mutex_MYRG_INFO_mutex,
&m_info->mutex, MY_MUTEX_INIT_FAST);
m_info->open_list.data= (void*) m_info; m_info->open_list.data= (void*) m_info;
pthread_mutex_lock(&THR_LOCK_open); mysql_mutex_lock(&THR_LOCK_open);
myrg_open_list= list_add(myrg_open_list, &m_info->open_list); myrg_open_list= list_add(myrg_open_list, &m_info->open_list);
pthread_mutex_unlock(&THR_LOCK_open); mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(m_info); DBUG_RETURN(m_info);
@ -348,7 +353,7 @@ MYRG_INFO *myrg_parent_open(const char *parent_name,
end_io_cache(&file_cache); end_io_cache(&file_cache);
/* Fall through */ /* Fall through */
case 1: case 1:
(void) my_close(fd, MYF(0)); (void) mysql_file_close(fd, MYF(0));
} }
my_errno= save_errno; my_errno= save_errno;
DBUG_RETURN (NULL); DBUG_RETURN (NULL);
@ -405,7 +410,7 @@ int myrg_attach_children(MYRG_INFO *m_info, int handle_locking,
'open_tables' has all the pointers to the children. Use of a mutex 'open_tables' has all the pointers to the children. Use of a mutex
here and in ha_myisammrg::store_lock() forces consistent data. here and in ha_myisammrg::store_lock() forces consistent data.
*/ */
pthread_mutex_lock(&m_info->mutex); mysql_mutex_lock(&m_info->mutex);
rc= 1; rc= 1;
errpos= 0; errpos= 0;
file_offset= 0; file_offset= 0;
@ -485,7 +490,7 @@ int myrg_attach_children(MYRG_INFO *m_info, int handle_locking,
m_info->keys= min_keys; m_info->keys= min_keys;
m_info->last_used_table= m_info->open_tables; m_info->last_used_table= m_info->open_tables;
m_info->children_attached= TRUE; m_info->children_attached= TRUE;
pthread_mutex_unlock(&m_info->mutex); mysql_mutex_unlock(&m_info->mutex);
DBUG_RETURN(0); DBUG_RETURN(0);
bad_children: bad_children:
@ -497,7 +502,7 @@ err:
my_free((char*) m_info->rec_per_key_part, MYF(0)); my_free((char*) m_info->rec_per_key_part, MYF(0));
m_info->rec_per_key_part= NULL; m_info->rec_per_key_part= NULL;
} }
pthread_mutex_unlock(&m_info->mutex); mysql_mutex_unlock(&m_info->mutex);
my_errno= save_errno; my_errno= save_errno;
DBUG_RETURN(1); DBUG_RETURN(1);
} }
@ -520,7 +525,7 @@ int myrg_detach_children(MYRG_INFO *m_info)
{ {
DBUG_ENTER("myrg_detach_children"); DBUG_ENTER("myrg_detach_children");
/* For symmetry with myrg_attach_children() we use the mutex here. */ /* For symmetry with myrg_attach_children() we use the mutex here. */
pthread_mutex_lock(&m_info->mutex); mysql_mutex_lock(&m_info->mutex);
if (m_info->tables) if (m_info->tables)
{ {
/* Do not attach/detach an empty child list. */ /* Do not attach/detach an empty child list. */
@ -531,7 +536,7 @@ int myrg_detach_children(MYRG_INFO *m_info)
m_info->del= 0; m_info->del= 0;
m_info->data_file_length= 0; m_info->data_file_length= 0;
m_info->options= 0; m_info->options= 0;
pthread_mutex_unlock(&m_info->mutex); mysql_mutex_unlock(&m_info->mutex);
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000-2001, 2004 MySQL AB /* Copyright (C) 2000-2001, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@ -27,3 +27,35 @@ static const char *merge_insert_methods[] =
{ "FIRST", "LAST", NullS }; { "FIRST", "LAST", NullS };
TYPELIB merge_insert_method= { array_elements(merge_insert_methods)-1,"", TYPELIB merge_insert_method= { array_elements(merge_insert_methods)-1,"",
merge_insert_methods, 0}; merge_insert_methods, 0};
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key rg_key_mutex_MYRG_INFO_mutex;
static PSI_mutex_info all_myisammrg_mutexes[]=
{
{ &rg_key_mutex_MYRG_INFO_mutex, "MYRG_INFO::mutex", 0}
};
PSI_file_key rg_key_file_MRG;
static PSI_file_info all_myisammrg_files[]=
{
{ &rg_key_file_MRG, "MRG", 0}
};
void init_myisammrg_psi_keys()
{
const char* category= "myisammrg";
int count;
if (PSI_server == NULL)
return;
count= array_elements(all_myisammrg_mutexes);
PSI_server->register_mutex(category, all_myisammrg_mutexes, count);
count= array_elements(all_myisammrg_files);
PSI_server->register_file(category, all_myisammrg_files, count);
}
#endif /* HAVE_PSI_INTERFACE */

View File

@ -1,4 +1,4 @@
# Copyright (C) 2000-2006 MySQL AB # Copyright (C) 2000-2006 MySQL AB, 2009 Sun Microsystems, Inc.
# #
# 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
@ -15,7 +15,16 @@
# This file is public domain and comes with NO WARRANTY of any kind # This file is public domain and comes with NO WARRANTY of any kind
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include #
# Note that the string library is built with #define THREAD,
# which by default cause all the thread related code (my_pthread.h)
# and therefore the associated instrumentation (mysql/psi/mysql_thread.h)
# to be used.
# Since the string code itself is not instrumented, we use
# #define DISABLE_MYSQL_THREAD_H here to avoid unneeded dependencies.
#
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -DDISABLE_MYSQL_THREAD_H
pkglib_LIBRARIES = libmystrings.a pkglib_LIBRARIES = libmystrings.a
# Exact one of ASSEMBLER_X # Exact one of ASSEMBLER_X