diff options
Diffstat (limited to 'include')
52 files changed, 2600 insertions, 647 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index bd5d2a42b6d..3f60ffaf74b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2011, Oracle and/or its affiliates. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public @@ -23,22 +23,27 @@ HEADERS_ABI = mysql.h mysql_com.h mysql_time.h \ pkginclude_HEADERS = $(HEADERS_ABI) my_dbug.h m_string.h my_sys.h \ my_xml.h mysql_embed.h \ my_pthread.h my_no_pthread.h \ - decimal.h errmsg.h my_global.h my_net.h \ + decimal.h errmsg.h my_global.h my_valgrind.h my_net.h \ my_getopt.h sslopt-longopts.h my_dir.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ m_ctype.h my_attribute.h my_compiler.h \ $(HEADERS_GEN_CONFIGURE) \ $(HEADERS_GEN_MAKE) -noinst_HEADERS = config-win.h config-netware.h my_bit.h \ - heap.h my_bitmap.h my_uctype.h \ +noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \ + heap.h maria.h myisamchk.h my_bitmap.h my_uctype.h \ myisam.h myisampack.h myisammrg.h ft_global.h\ mysys_err.h my_base.h help_start.h help_end.h \ my_nosys.h my_alarm.h queues.h rijndael.h sha1.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 \ - my_compare.h my_time.h my_vle.h my_user.h \ - my_libwrap.h my_stacktrace.h welcome_copyright_notice.h + my_compare.h my_handler.h my_time.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/gcc_builtins.h \ + my_libwrap.h my_stacktrace.h \ + wqueue.h waiting_threads.h \ + welcome_copyright_notice.h EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp @@ -58,6 +63,8 @@ link_sources: # We want both "my_config.h" and "config.h" that are identical, as # MySQL sources assumes the name "my_config.h", and 3rd party sources # assumes the name "config.h". +# Normally this is generated by configure; This rule is left here in case +# someone deletes my_config.h and expect it to be generated by make my_config.h: config.h $(CP) config.h my_config.h @@ -65,6 +72,3 @@ my_config.h: config.h # generated by configure from the .h.in files dist-hook: $(RM) -f $(distdir)/mysql_version.h $(distdir)/my_config.h - -# Don't update the files from bitkeeper -%::SCCS/s.% diff --git a/include/atomic/gcc_builtins.h b/include/atomic/gcc_builtins.h new file mode 100644 index 00000000000..3eba2fff984 --- /dev/null +++ b/include/atomic/gcc_builtins.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2008 MySQL AB + + 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 */ + +#define make_atomic_add_body(S) \ + v= __sync_fetch_and_add(a, v); +#define make_atomic_swap_body(S) \ + v= __sync_lock_test_and_set(a, v); +#define make_atomic_cas_body(S) \ + int ## S sav; \ + sav= __sync_val_compare_and_swap(a, *cmp, set); \ + if (!(ret= (sav == *cmp))) *cmp= sav; + +#ifdef MY_ATOMIC_MODE_DUMMY +#define make_atomic_load_body(S) ret= *a +#define make_atomic_store_body(S) *a= v +#define MY_ATOMIC_MODE "gcc-builtins-up" + +#else +#define MY_ATOMIC_MODE "gcc-builtins-smp" +#define make_atomic_load_body(S) \ + ret= __sync_fetch_and_or(a, 0); +#define make_atomic_store_body(S) \ + (void) __sync_lock_test_and_set(a, v); +#endif diff --git a/include/atomic/generic-msvc.h b/include/atomic/generic-msvc.h new file mode 100644 index 00000000000..58c6e7d8b9a --- /dev/null +++ b/include/atomic/generic-msvc.h @@ -0,0 +1,108 @@ +/* Copyright (C) 2006-2008 MySQL AB, 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 _atomic_h_cleanup_ +#define _atomic_h_cleanup_ "atomic/generic-msvc.h" +/* + We don't implement anything specific for MY_ATOMIC_MODE_DUMMY, always use + intrinsics. + 8 and 16-bit atomics are not implemented, but it can be done if necessary. +*/ + +/* + x86 compilers (both VS2003 or VS2005) never use instrinsics, but generate + function calls to kernel32 instead, even in the optimized build. + We force intrinsics as described in MSDN documentation for + _InterlockedCompareExchange. +*/ +#ifdef _M_IX86 + +#if (_MSC_VER >= 1400) +#include <intrin.h> +#else +/*Visual Studio 2003 and earlier do not have prototypes for atomic intrinsics*/ +LONG _InterlockedExchange (LONG volatile *Target,LONG Value); +LONG _InterlockedCompareExchange (LONG volatile *Target, LONG Value, LONG Comp); +LONG _InterlockedExchangeAdd (LONG volatile *Addend, LONG Value); +#pragma intrinsic(_InterlockedExchangeAdd) +#pragma intrinsic(_InterlockedCompareExchange) +#pragma intrinsic(_InterlockedExchange) +#endif + +#define InterlockedExchange _InterlockedExchange +#define InterlockedExchangeAdd _InterlockedExchangeAdd +#define InterlockedCompareExchange _InterlockedCompareExchange +/* + No need to do something special for InterlockedCompareExchangePointer + as it is a #define to InterlockedCompareExchange. The same applies to + InterlockedExchangePointer. +*/ +#endif /*_M_IX86*/ + +#define MY_ATOMIC_MODE "msvc-intrinsics" +#define IL_EXCHG_ADD32(X,Y) InterlockedExchangeAdd((volatile LONG *)(X),(Y)) +#define IL_COMP_EXCHG32(X,Y,Z) InterlockedCompareExchange((volatile LONG *)(X),(Y),(Z)) +#define IL_COMP_EXCHGptr InterlockedCompareExchangePointer +#define IL_EXCHG32(X,Y) InterlockedExchange((volatile LONG *)(X),(Y)) +#define IL_EXCHGptr InterlockedExchangePointer +#define make_atomic_add_body(S) \ + v= IL_EXCHG_ADD ## S (a, v) +#define make_atomic_cas_body(S) \ + int ## S initial_cmp= *cmp; \ + int ## S initial_a= IL_COMP_EXCHG ## S (a, set, initial_cmp); \ + if (!(ret= (initial_a == initial_cmp))) *cmp= initial_a; +#define make_atomic_swap_body(S) \ + v= IL_EXCHG ## S (a, v) + +/* + my_yield_processor (equivalent of x86 PAUSE instruction) should be used + to improve performance on hyperthreaded CPUs. Intel recommends to use it in + spin loops also on non-HT machines to reduce power consumption (see e.g + http://softwarecommunity.intel.com/articles/eng/2004.htm) + + Running benchmarks for spinlocks implemented with InterlockedCompareExchange + and YieldProcessor shows that much better performance is achieved by calling + YieldProcessor in a loop - that is, yielding longer. On Intel boxes setting + loop count in the range 200-300 brought best results. + */ +#ifndef YIELD_LOOPS +#define YIELD_LOOPS 200 +#endif + +static __inline int my_yield_processor() +{ + int i; + for(i=0; i<YIELD_LOOPS; i++) + { +#if (_MSC_VER <= 1310) + /* On older compilers YieldProcessor is not available, use inline assembly*/ + __asm { rep nop } +#else + YieldProcessor(); +#endif + } + return 1; +} + +#define LF_BACKOFF my_yield_processor() +#else /* cleanup */ + +#undef IL_EXCHG_ADD32 +#undef IL_COMP_EXCHG32 +#undef IL_COMP_EXCHGptr +#undef IL_EXCHG32 +#undef IL_EXCHGptr + +#endif diff --git a/include/atomic/nolock.h b/include/atomic/nolock.h new file mode 100644 index 00000000000..550b53adcd9 --- /dev/null +++ b/include/atomic/nolock.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2006 MySQL AB + + 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 */ + +#if defined(__i386__) || defined(_MSC_VER) || \ + defined(__x86_64__) || defined(MY_ATOMIC_MODE_GCC_BUILTINS) + +# ifdef MY_ATOMIC_MODE_DUMMY +# define LOCK_prefix "" +# else +# define LOCK_prefix "lock" +# endif + +# ifdef MY_ATOMIC_MODE_GCC_BUILTINS +# include "gcc_builtins.h" +# elif __GNUC__ +# include "x86-gcc.h" +# elif defined(_MSC_VER) +# include "generic-msvc.h" +# endif +#endif + +#ifdef make_atomic_cas_body + +typedef char my_atomic_rwlock_t __attribute__ ((unused)); +#define my_atomic_rwlock_destroy(name) +#define my_atomic_rwlock_init(name) +#define my_atomic_rwlock_rdlock(name) +#define my_atomic_rwlock_wrlock(name) +#define my_atomic_rwlock_rdunlock(name) +#define my_atomic_rwlock_wrunlock(name) + +#endif + diff --git a/include/atomic/rwlock.h b/include/atomic/rwlock.h new file mode 100644 index 00000000000..57fbf35d18b --- /dev/null +++ b/include/atomic/rwlock.h @@ -0,0 +1,54 @@ +/* Copyright (C) 2006 MySQL AB + + 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 */ + +typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t; +#define MY_ATOMIC_MODE_RWLOCKS 1 + +#ifdef MY_ATOMIC_MODE_DUMMY +/* + the following can never be enabled by ./configure, one need to put #define in + a source to trigger the following warning. The resulting code will be broken, + it only makes sense to do it to see now test_atomic detects broken + implementations (another way is to run a UP build on an SMP box). +*/ +#warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible +#define my_atomic_rwlock_destroy(name) +#define my_atomic_rwlock_init(name) +#define my_atomic_rwlock_rdlock(name) +#define my_atomic_rwlock_wrlock(name) +#define my_atomic_rwlock_rdunlock(name) +#define my_atomic_rwlock_wrunlock(name) +#define MY_ATOMIC_MODE "dummy (non-atomic)" +#else +/* + we're using read-write lock macros but map them to mutex locks, and they're + faster. Still, having semantically rich API we can change the + underlying implementation, if necessary. +*/ +#define my_atomic_rwlock_destroy(name) pthread_mutex_destroy(& (name)->rw) +#define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw, 0) +#define my_atomic_rwlock_rdlock(name) pthread_mutex_lock(& (name)->rw) +#define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw) +#define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw) +#define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw) +#define MY_ATOMIC_MODE "mutex" +#endif + +#define make_atomic_add_body(S) int ## S sav; sav= *a; *a+= v; v=sav; +#define make_atomic_fas_body(S) int ## S sav; sav= *a; *a= v; v=sav; +#define make_atomic_cas_body(S) if ((ret= (*a == *cmp))) *a= set; else *cmp=*a; +#define make_atomic_load_body(S) ret= *a; +#define make_atomic_store_body(S) *a= v; + diff --git a/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h new file mode 100644 index 00000000000..5a34bc22f9e --- /dev/null +++ b/include/atomic/x86-gcc.h @@ -0,0 +1,69 @@ +/* Copyright (C) 2006 MySQL AB + + 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 */ + +/* + XXX 64-bit atomic operations can be implemented using + cmpxchg8b, if necessary. Though I've heard that not all 64-bit + architectures support double-word (128-bit) cas. +*/ + +#ifdef __x86_64__ +# ifdef MY_ATOMIC_NO_XADD +# define MY_ATOMIC_MODE "gcc-amd64" LOCK_prefix "-no-xadd" +# else +# define MY_ATOMIC_MODE "gcc-amd64" LOCK_prefix +# endif +#else +# ifdef MY_ATOMIC_NO_XADD +# define MY_ATOMIC_MODE "gcc-x86" LOCK_prefix "-no-xadd" +# else +# define MY_ATOMIC_MODE "gcc-x86" LOCK_prefix +# endif +#endif + +/* fix -ansi errors while maintaining readability */ +#ifndef asm +#define asm __asm__ +#endif + +#ifndef MY_ATOMIC_NO_XADD +#define make_atomic_add_body(S) \ + asm volatile (LOCK_prefix "; xadd %0, %1;" : "+r" (v) , "+m" (*a)) +#endif +#define make_atomic_fas_body(S) \ + asm volatile ("xchg %0, %1;" : "+r" (v) , "+m" (*a)) +#define make_atomic_cas_body(S) \ + asm volatile (LOCK_prefix "; cmpxchg %3, %0; setz %2;" \ + : "+m" (*a), "+a" (*cmp), "=q" (ret): "r" (set)) + +#ifdef MY_ATOMIC_MODE_DUMMY +#define make_atomic_load_body(S) ret=*a +#define make_atomic_store_body(S) *a=v +#else +/* + Actually 32-bit reads/writes are always atomic on x86 + But we add LOCK_prefix here anyway to force memory barriers +*/ +#define make_atomic_load_body(S) \ + ret=0; \ + asm volatile (LOCK_prefix "; cmpxchg %2, %0" \ + : "+m" (*a), "+a" (ret): "r" (ret)) +#define make_atomic_store_body(S) \ + asm volatile ("; xchg %0, %1;" : "+m" (*a), "+r" (v)) +#endif + +/* TODO test on intel whether the below helps. on AMD it makes no difference */ +//#define LF_BACKOFF ({asm volatile ("rep; nop"); 1; }) + diff --git a/include/config-netware.h b/include/config-netware.h index 68a67e800ef..4759d144040 100644 --- a/include/config-netware.h +++ b/include/config-netware.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2003, 2010, Oracle and/or its affiliates. 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 diff --git a/include/config-win.h b/include/config-win.h index 63624840dd1..9369c72e83d 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2011, Oracle and/or its affiliates. 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 @@ -25,6 +25,7 @@ #endif #include <sys/locking.h> +#include <sys/stat.h> /* chmod() constants*/ #include <winsock2.h> #include <fcntl.h> #include <io.h> @@ -85,6 +86,26 @@ #define S_IROTH S_IREAD /* for my_lib */ +/* for MY_S_ISFIFO() macro from my_lib */ +#if defined (_S_IFIFO) && !defined (S_IFIFO) +#define S_IFIFO _S_IFIFO +#endif + +/* Winsock2 constant (Vista SDK and later)*/ +#define IPPROTO_IPV6 41 +#ifndef IPV6_V6ONLY +#define IPV6_V6ONLY 27 +#endif + +/* + Constants used by chmod. Note, that group/others is ignored + - because unsupported by Windows due to different access control model. +*/ +#define S_IRWXU S_IREAD|S_IWRITE +#define S_IRWXG 0 +#define S_IRWXO 0 +typedef int mode_t; + #ifdef __BORLANDC__ #define FILE_BINARY O_BINARY /* my_fopen in binary mode */ #define O_TEMPORARY 0 @@ -142,10 +163,21 @@ typedef __int64 os_off_t; #ifdef _WIN64 typedef UINT_PTR rf_SetTimer; #else +typedef uint rf_SetTimer; +#endif + #ifndef HAVE_SIZE_T -typedef unsigned int size_t; +#ifndef _SIZE_T_DEFINED +typedef SIZE_T size_t; +#define _SIZE_T_DEFINED +#endif +#endif + +#ifndef HAVE_SSIZE_T +#ifndef _SSIZE_T_DEFINED +typedef SSIZE_T ssize_t; +#define _SSIZE_T_DEFINED #endif -typedef uint rf_SetTimer; #endif #define Socket_defined @@ -182,7 +214,7 @@ typedef uint rf_SetTimer; #define SIZEOF_CHARP 4 #endif #define HAVE_BROKEN_NETINET_INCLUDES -#ifdef __NT__ +#ifdef _WIN32 #define HAVE_NAMED_PIPE /* We can only create pipes on NT */ #endif @@ -295,7 +327,7 @@ inline ulonglong double2ulonglong(double d) #define strcasecmp stricmp #define strncasecmp strnicmp -#ifndef __NT__ +#ifndef _WIN32 #undef FILE_SHARE_DELETE #define FILE_SHARE_DELETE 0 /* Not implemented on Win 98/ME */ #endif @@ -350,7 +382,7 @@ inline ulonglong double2ulonglong(double d) #define thread_safe_increment(V,L) InterlockedIncrement((long*) &(V)) #define thread_safe_decrement(V,L) InterlockedDecrement((long*) &(V)) /* The following is only used for statistics, so it should be good enough */ -#ifdef __NT__ /* This should also work on Win98 but .. */ +#ifdef _WIN32 /* This should also work on Win98 but .. */ #define thread_safe_add(V,C,L) InterlockedExchangeAdd((long*) &(V),(C)) #define thread_safe_sub(V,C,L) InterlockedExchangeAdd((long*) &(V),-(long) (C)) #endif @@ -418,3 +450,7 @@ inline ulonglong double2ulonglong(double d) #define HAVE_UCA_COLLATIONS 1 #define HAVE_BOOL 1 +#ifndef EMBEDDED_LIBRARY +#define HAVE_LIBEVENT 1 +#define HAVE_POOL_OF_THREADS 1 +#endif diff --git a/include/ft_global.h b/include/ft_global.h index 752371d6bc6..e16b77422d1 100644 --- a/include/ft_global.h +++ b/include/ft_global.h @@ -25,6 +25,8 @@ extern "C" { #endif +#include <my_compare.h> + #define HA_FT_MAXBYTELEN 254 #define HA_FT_MAXCHARLEN (HA_FT_MAXBYTELEN/3) @@ -62,9 +64,23 @@ void ft_free_stopwords(void); #define FT_SORTED 2 #define FT_EXPAND 4 /* query expansion */ -FT_INFO *ft_init_search(uint,void *, uint, uchar *, uint,CHARSET_INFO *, uchar *); +FT_INFO *ft_init_search(uint,void *, uint, uchar *, size_t, + CHARSET_INFO *, uchar *); my_bool ft_boolean_check_syntax_string(const uchar *); +/* Internal symbols for fulltext between maria and MyISAM */ + +#define HA_FT_WTYPE HA_KEYTYPE_FLOAT +#define HA_FT_WLEN 4 +#define FT_SEGS 2 + +#define ft_sintXkorr(A) mi_sint4korr(A) +#define ft_intXstore(T,A) mi_int4store(T,A) + +extern const HA_KEYSEG ft_keysegs[FT_SEGS]; + +typedef union {int32 i; float f;} FT_WEIGTH; + #ifdef __cplusplus } #endif diff --git a/include/hash.h b/include/hash.h index 7e0b9b7393e..d997b207a90 100644 --- a/include/hash.h +++ b/include/hash.h @@ -69,6 +69,7 @@ extern "C" { typedef uchar *(*my_hash_get_key)(const uchar *,size_t*,my_bool); typedef void (*my_hash_free_key)(void *); +typedef my_bool (*my_hash_walk_action)(void *,void *); typedef struct st_hash { size_t key_offset,key_length; /* Length of key if const length */ @@ -107,6 +108,7 @@ my_bool my_hash_update(HASH *hash, uchar *record, uchar *old_key, size_t old_key_length); void my_hash_replace(HASH *hash, HASH_SEARCH_STATE *state, uchar *new_row); my_bool my_hash_check(HASH *hash); /* Only in debug library */ +my_bool my_hash_iterate(HASH *hash, my_hash_walk_action action, void *argument); #define my_hash_clear(H) bzero((char*) (H), sizeof(*(H))) #define my_hash_inited(H) ((H)->blength != 0) diff --git a/include/heap.h b/include/heap.h index 7adaac33096..b41f1a2519c 100644 --- a/include/heap.h +++ b/include/heap.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. 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 diff --git a/include/keycache.h b/include/keycache.h index 1307e869717..1dc30c5567e 100644 --- a/include/keycache.h +++ b/include/keycache.h @@ -135,7 +135,8 @@ extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup); /* Functions to handle multiple key caches */ extern my_bool multi_keycache_init(void); extern void multi_keycache_free(void); -extern KEY_CACHE *multi_key_cache_search(uchar *key, uint length); +extern KEY_CACHE *multi_key_cache_search(uchar *key, uint length, + KEY_CACHE *def); extern my_bool multi_key_cache_set(const uchar *key, uint length, KEY_CACHE *key_cache); extern void multi_key_cache_change(KEY_CACHE *old_data, diff --git a/include/lf.h b/include/lf.h new file mode 100644 index 00000000000..11c06099399 --- /dev/null +++ b/include/lf.h @@ -0,0 +1,262 @@ +/* Copyright (C) 2007-2008 MySQL AB, 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; either version 2 of the License, or + (at your option) any later version. + + 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 _lf_h +#define _lf_h + +#include <my_atomic.h> + +/* + Helpers to define both func() and _func(), where + func() is a _func() protected by my_atomic_rwlock_wrlock() +*/ + +#define lock_wrap(f, t, proto_args, args, lock) \ +t _ ## f proto_args; \ +static inline t f proto_args \ +{ \ + t ret; \ + my_atomic_rwlock_wrlock(lock); \ + ret= _ ## f args; \ + my_atomic_rwlock_wrunlock(lock); \ + return ret; \ +} + +#define lock_wrap_void(f, proto_args, args, lock) \ +void _ ## f proto_args; \ +static inline void f proto_args \ +{ \ + my_atomic_rwlock_wrlock(lock); \ + _ ## f args; \ + my_atomic_rwlock_wrunlock(lock); \ +} + +#define nolock_wrap(f, t, proto_args, args) \ +t _ ## f proto_args; \ +static inline t f proto_args \ +{ \ + return _ ## f args; \ +} + +#define nolock_wrap_void(f, proto_args, args) \ +void _ ## f proto_args; \ +static inline void f proto_args \ +{ \ + _ ## f args; \ +} + +/* + wait-free dynamic array, see lf_dynarray.c + + 4 levels of 256 elements each mean 4311810304 elements in an array - it + should be enough for a while +*/ +#define LF_DYNARRAY_LEVEL_LENGTH 256 +#define LF_DYNARRAY_LEVELS 4 + +typedef struct { + void * volatile level[LF_DYNARRAY_LEVELS]; + uint size_of_element; + my_atomic_rwlock_t lock; +} LF_DYNARRAY; + +typedef int (*lf_dynarray_func)(void *, void *); + +void lf_dynarray_init(LF_DYNARRAY *array, uint element_size); +void lf_dynarray_destroy(LF_DYNARRAY *array); + +nolock_wrap(lf_dynarray_value, void *, + (LF_DYNARRAY *array, uint idx), + (array, idx)) +lock_wrap(lf_dynarray_lvalue, void *, + (LF_DYNARRAY *array, uint idx), + (array, idx), + &array->lock) +nolock_wrap(lf_dynarray_iterate, int, + (LF_DYNARRAY *array, lf_dynarray_func func, void *arg), + (array, func, arg)) + +/* + pin manager for memory allocator, lf_alloc-pin.c +*/ + +#define LF_PINBOX_PINS 4 +#define LF_PURGATORY_SIZE 10 + +typedef void lf_pinbox_free_func(void *, void *, void*); + +typedef struct { + LF_DYNARRAY pinarray; + lf_pinbox_free_func *free_func; + void *free_func_arg; + uint free_ptr_offset; + uint32 volatile pinstack_top_ver; /* this is a versioned pointer */ + uint32 volatile pins_in_array; /* number of elements in array */ +} LF_PINBOX; + +typedef struct { + void * volatile pin[LF_PINBOX_PINS]; + LF_PINBOX *pinbox; + void **stack_ends_here; + void *purgatory; + uint32 purgatory_count; + uint32 volatile link; +/* we want sizeof(LF_PINS) to be 128 to avoid false sharing */ + char pad[128-sizeof(uint32)*2 + -sizeof(LF_PINBOX *) + -sizeof(void*) + -sizeof(void *)*(LF_PINBOX_PINS+1)]; +} LF_PINS; + +/* + shortcut macros to do an atomic_wrlock on a structure that uses pins + (e.g. lf_hash). +*/ +#define lf_rwlock_by_pins(PINS) \ + my_atomic_rwlock_wrlock(&(PINS)->pinbox->pinarray.lock) +#define lf_rwunlock_by_pins(PINS) \ + my_atomic_rwlock_wrunlock(&(PINS)->pinbox->pinarray.lock) + +/* + compile-time assert, to require "no less than N" pins + it's enough if it'll fail on at least one compiler, so + we'll enable it on GCC only, which supports zero-length arrays. +*/ +#if defined(__GNUC__) && defined(MY_LF_EXTRA_DEBUG) +#define LF_REQUIRE_PINS(N) \ + static const char require_pins[LF_PINBOX_PINS-N] \ + __attribute__ ((unused)); \ + static const int LF_NUM_PINS_IN_THIS_FILE= N; +#define _lf_pin(PINS, PIN, ADDR) \ + ( \ + assert(PIN < LF_NUM_PINS_IN_THIS_FILE), \ + my_atomic_storeptr(&(PINS)->pin[PIN], (ADDR)) \ + ) +#else +#define LF_REQUIRE_PINS(N) +#define _lf_pin(PINS, PIN, ADDR) my_atomic_storeptr(&(PINS)->pin[PIN], (ADDR)) +#endif + +#define _lf_unpin(PINS, PIN) _lf_pin(PINS, PIN, NULL) +#define lf_pin(PINS, PIN, ADDR) \ + do { \ + lf_rwlock_by_pins(PINS); \ + _lf_pin(PINS, PIN, ADDR); \ + lf_rwunlock_by_pins(PINS); \ + } while (0) +#define lf_unpin(PINS, PIN) lf_pin(PINS, PIN, NULL) +#define _lf_assert_pin(PINS, PIN) assert((PINS)->pin[PIN] != 0) +#define _lf_assert_unpin(PINS, PIN) assert((PINS)->pin[PIN] == 0) + +void lf_pinbox_init(LF_PINBOX *pinbox, uint free_ptr_offset, + lf_pinbox_free_func *free_func, void * free_func_arg); +void lf_pinbox_destroy(LF_PINBOX *pinbox); + +lock_wrap(lf_pinbox_get_pins, LF_PINS *, + (LF_PINBOX *pinbox), + (pinbox), + &pinbox->pinarray.lock) +lock_wrap_void(lf_pinbox_put_pins, + (LF_PINS *pins), + (pins), + &pins->pinbox->pinarray.lock) +lock_wrap_void(lf_pinbox_free, + (LF_PINS *pins, void *addr), + (pins, addr), + &pins->pinbox->pinarray.lock) + +/* + memory allocator, lf_alloc-pin.c +*/ + +typedef struct st_lf_allocator { + LF_PINBOX pinbox; + uchar * volatile top; + uint element_size; + uint32 volatile mallocs; + void (*constructor)(uchar *); /* called, when an object is malloc()'ed */ + void (*destructor)(uchar *); /* called, when an object is free()'d */ +} LF_ALLOCATOR; + +void lf_alloc_init(LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset); +void lf_alloc_destroy(LF_ALLOCATOR *allocator); +uint lf_alloc_pool_count(LF_ALLOCATOR *allocator); +/* + shortcut macros to access underlying pinbox functions from an LF_ALLOCATOR + see _lf_pinbox_get_pins() and _lf_pinbox_put_pins() +*/ +#define _lf_alloc_free(PINS, PTR) _lf_pinbox_free((PINS), (PTR)) +#define lf_alloc_free(PINS, PTR) lf_pinbox_free((PINS), (PTR)) +#define _lf_alloc_get_pins(A) _lf_pinbox_get_pins(&(A)->pinbox) +#define lf_alloc_get_pins(A) lf_pinbox_get_pins(&(A)->pinbox) +#define _lf_alloc_put_pins(PINS) _lf_pinbox_put_pins(PINS) +#define lf_alloc_put_pins(PINS) lf_pinbox_put_pins(PINS) +#define lf_alloc_direct_free(ALLOC, ADDR) my_free((uchar*)(ADDR), MYF(0)) + +lock_wrap(lf_alloc_new, void *, + (LF_PINS *pins), + (pins), + &pins->pinbox->pinarray.lock) + +/* + extendible hash, lf_hash.c +*/ +#include <hash.h> + +#define LF_HASH_UNIQUE 1 + +/* lf_hash overhead per element (that is, sizeof(LF_SLIST) */ +extern const int LF_HASH_OVERHEAD; + +typedef struct { + LF_DYNARRAY array; /* hash itself */ + LF_ALLOCATOR alloc; /* allocator for elements */ + hash_get_key get_key; /* see HASH */ + CHARSET_INFO *charset; /* see HASH */ + uint key_offset, key_length; /* see HASH */ + uint element_size; /* size of memcpy'ed area on insert */ + uint flags; /* LF_HASH_UNIQUE, etc */ + int32 volatile size; /* size of array */ + int32 volatile count; /* number of elements in the hash */ +} LF_HASH; + +void lf_hash_init(LF_HASH *hash, uint element_size, uint flags, + uint key_offset, uint key_length, hash_get_key get_key, + CHARSET_INFO *charset); +void lf_hash_destroy(LF_HASH *hash); +int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data); +void *lf_hash_search(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen); +int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen); +/* + shortcut macros to access underlying pinbox functions from an LF_HASH + see _lf_pinbox_get_pins() and _lf_pinbox_put_pins() +*/ +#define _lf_hash_get_pins(HASH) _lf_alloc_get_pins(&(HASH)->alloc) +#define lf_hash_get_pins(HASH) lf_alloc_get_pins(&(HASH)->alloc) +#define _lf_hash_put_pins(PINS) _lf_pinbox_put_pins(PINS) +#define lf_hash_put_pins(PINS) lf_pinbox_put_pins(PINS) +#define lf_hash_search_unpin(PINS) lf_unpin((PINS), 2) +/* + cleanup +*/ + +#undef lock_wrap_void +#undef lock_wrap +#undef nolock_wrap_void +#undef nolock_wrap + +#endif + diff --git a/include/m_ctype.h b/include/m_ctype.h index 3b836dfbaf3..216e03bfcac 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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 @@ -51,6 +51,24 @@ typedef struct unicase_info_st extern MY_UNICASE_INFO *my_unicase_default[256]; extern MY_UNICASE_INFO *my_unicase_turkish[256]; +#define MY_UCA_MAX_CONTRACTION 4 +#define MY_UCA_MAX_WEIGHT_SIZE 8 + +typedef struct my_contraction_t +{ + my_wc_t ch[MY_UCA_MAX_CONTRACTION]; /* Character sequence */ + uint16 weight[MY_UCA_MAX_WEIGHT_SIZE];/* Its weight string, 0-terminated */ +} MY_CONTRACTION; + + +typedef struct my_contraction_list_t +{ + size_t nitems; /* Number of items in the list */ + MY_CONTRACTION *item; /* List of contractions */ + char *flags; /* Character flags, e.g. "is contraction head") */ +} MY_CONTRACTIONS; + + typedef struct uni_ctype_st { uchar pctype; @@ -89,6 +107,7 @@ extern MY_UNI_CTYPE my_uni_ctype[256]; #define MY_CS_CSSORT 1024 /* if case sensitive sort order */ #define MY_CS_HIDDEN 2048 /* don't display in SHOW */ #define MY_CS_PUREASCII 4096 /* if a charset is pure ascii */ +#define MY_CS_NONASCII 8192 /* if not ASCII-compatible */ #define MY_CHARSET_UNDEFINED 0 /* Character repertoire flags */ @@ -263,7 +282,7 @@ typedef struct charset_info_st uchar *to_lower; uchar *to_upper; uchar *sort_order; - uint16 *contractions; + MY_CONTRACTIONS *contractions; uint16 **sort_order_big; uint16 *tab_to_uni; MY_UNI_IDX *tab_from_uni; @@ -478,6 +497,13 @@ my_bool my_charset_is_ascii_based(CHARSET_INFO *cs); my_bool my_charset_is_8bit_pure_ascii(CHARSET_INFO *cs); uint my_charset_repertoire(CHARSET_INFO *cs); +my_bool my_uca_have_contractions(CHARSET_INFO *cs); +my_bool my_uca_can_be_contraction_head(CHARSET_INFO *cs, my_wc_t wc); +my_bool my_uca_can_be_contraction_tail(CHARSET_INFO *cs, my_wc_t wc); +uint16 *my_uca_contraction2_weight(CHARSET_INFO *cs, my_wc_t wc1, my_wc_t wc2); + + + #define _MY_U 01 /* Upper case */ #define _MY_L 02 /* Lower case */ @@ -521,6 +547,7 @@ uint my_charset_repertoire(CHARSET_INFO *cs); #define my_strcasecmp(s, a, b) ((s)->coll->strcasecmp((s), (a), (b))) #define my_charpos(cs, b, e, num) (cs)->cset->charpos((cs), (const char*) (b), (const char *)(e), (num)) +my_bool my_charset_is_ascii_compatible(CHARSET_INFO *cs); #define use_mb(s) ((s)->cset->ismbchar != NULL) #define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b))) diff --git a/include/m_string.h b/include/m_string.h index e1cf7651519..c9c1d4e6800 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2011, Oracle and/or its affiliates. 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 @@ -60,6 +60,12 @@ # define bfill(A,B,C) memset((A),(C),(B)) #endif +# define bmove_align(A,B,C) memcpy((A),(B),(C)) + +#if !defined(HAVE_BCMP) +# define bcmp(A,B,C) memcmp((A),(B),(C)) +#endif + #if !defined(bzero) && (!defined(HAVE_BZERO) || !defined(HAVE_DECL_BZERO)) # define bzero(A,B) memset((A),0,(B)) #endif @@ -91,10 +97,7 @@ extern char NEAR _dig_vec_lower[]; /* Defined in strtod.c */ extern const double log_10[309]; -#ifndef strmov -#define strmov_overlapp(A,B) strmov(A,B) -#define strmake_overlapp(A,B,C) strmake(A,B,C) -#endif +extern char *strmov_overlapp(char *dest, const char *src); #ifdef BAD_MEMCPY /* Problem with gcc on Alpha */ #define memcpy_fixed(A,B,C) bmove((A),(B),(C)) @@ -102,7 +105,7 @@ extern const double log_10[309]; #define memcpy_fixed(A,B,C) memcpy((A),(B),(C)) #endif -#if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512) +#if (!defined(USE_BMOVE512) || defined(HAVE_valgrind)) && !defined(bmove512) #define bmove512(A,B,C) memcpy(A,B,C) #endif @@ -112,6 +115,25 @@ extern const double log_10[309]; extern void bfill(uchar *dst,size_t len,pchar fill); #endif +#if !defined(bzero) && !defined(HAVE_BZERO) +extern void bzero(void * dst,size_t len); +#endif + +#if !defined(bcmp) && !defined(HAVE_BCMP) +extern size_t bcmp(const uchar *s1,const uchar *s2,size_t len); +#endif +#ifdef HAVE_valgrind +extern size_t my_bcmp(const uchar *s1,const uchar *s2,size_t len); +#undef bcmp +#define bcmp(A,B,C) my_bcmp((A),(B),(C)) +#endif /* HAVE_valgrind */ + +#if defined(_lint) || defined(FORCE_INIT_OF_VARS) +#define LINT_INIT_STRUCT(var) bzero(&var, sizeof(var)) /* No uninitialize-warning */ +#else +#define LINT_INIT_STRUCT(var) +#endif + #ifndef bmove512 extern void bmove512(uchar *dst,const uchar *src,size_t len); #endif @@ -136,8 +158,6 @@ extern char *strmake(char *dst,const char *src,size_t length); #ifndef strmov extern char *strmov(char *dst,const char *src); -#else -extern char *strmov_overlapp(char *dst,const char *src); #endif extern char *strnmov(char *dst,const char *src,size_t n); extern char *strsuff(const char *src,const char *suffix); @@ -252,4 +272,12 @@ typedef struct st_mysql_lex_string LEX_STRING; #define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1)) #define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1)) +/* A variant with const and unsigned */ +struct st_mysql_const_unsigned_lex_string +{ + const uchar *str; + size_t length; +}; +typedef struct st_mysql_const_unsigned_lex_string LEX_CUSTRING; + #endif diff --git a/include/maria.h b/include/maria.h new file mode 100644 index 00000000000..192e5a565aa --- /dev/null +++ b/include/maria.h @@ -0,0 +1,481 @@ +/* Copyright (C) 2006-2008 MySQL AB, 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; either version 2 of the License, or + (at your option) any later version. + + 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 */ + +/* This file should be included when using maria functions */ + +#ifndef _maria_h +#define _maria_h +#ifdef __cplusplus +extern "C" { +#endif +#ifndef _my_base_h +#include <my_base.h> +#endif +#ifndef _m_ctype_h +#include <m_ctype.h> +#endif +#include "../storage/maria/ma_pagecache.h" +#include "my_handler.h" +#include "my_compare.h" +#include "ft_global.h" +#include <myisamchk.h> +#include <mysql/plugin.h> + +#define MARIA_CANNOT_ROLLBACK + +/* + Limit max keys according to HA_MAX_POSSIBLE_KEY; See myisamchk.h for details +*/ + +#if MAX_INDEXES > HA_MAX_POSSIBLE_KEY +#define MARIA_MAX_KEY HA_MAX_POSSIBLE_KEY /* Max allowed keys */ +#else +#define MARIA_MAX_KEY MAX_INDEXES /* Max allowed keys */ +#endif + +#define MARIA_NAME_IEXT ".MAI" +#define MARIA_NAME_DEXT ".MAD" +/* Max extra space to use when sorting keys */ +#define MARIA_MAX_TEMP_LENGTH 2*1024L*1024L*1024L +/* Possible values for maria_block_size (must be power of 2) */ +#define MARIA_KEY_BLOCK_LENGTH 8192 /* default key block length */ +#define MARIA_MIN_KEY_BLOCK_LENGTH 1024 /* Min key block length */ +#define MARIA_MAX_KEY_BLOCK_LENGTH 32768 +/* Minimal page cache when we only want to be able to scan a table */ +#define MARIA_MIN_PAGE_CACHE_SIZE (8192L*16L) + +/* + In the following macros '_keyno_' is 0 .. keys-1. + If there can be more keys than bits in the key_map, the highest bit + is for all upper keys. They cannot be switched individually. + This means that clearing of high keys is ignored, setting one high key + sets all high keys. +*/ +#define MARIA_KEYMAP_BITS (8 * SIZEOF_LONG_LONG) +#define MARIA_KEYMAP_HIGH_MASK (ULL(1) << (MARIA_KEYMAP_BITS - 1)) +#define maria_get_mask_all_keys_active(_keys_) \ + (((_keys_) < MARIA_KEYMAP_BITS) ? \ + ((ULL(1) << (_keys_)) - ULL(1)) : \ + (~ ULL(0))) +#if MARIA_MAX_KEY > MARIA_KEYMAP_BITS +#define maria_is_key_active(_keymap_,_keyno_) \ + (((_keyno_) < MARIA_KEYMAP_BITS) ? \ + test((_keymap_) & (ULL(1) << (_keyno_))) : \ + test((_keymap_) & MARIA_KEYMAP_HIGH_MASK)) +#define maria_set_key_active(_keymap_,_keyno_) \ + (_keymap_)|= (((_keyno_) < MARIA_KEYMAP_BITS) ? \ + (ULL(1) << (_keyno_)) : \ + MARIA_KEYMAP_HIGH_MASK) +#define maria_clear_key_active(_keymap_,_keyno_) \ + (_keymap_)&= (((_keyno_) < MARIA_KEYMAP_BITS) ? \ + (~ (ULL(1) << (_keyno_))) : \ + (~ (ULL(0))) /*ignore*/ ) +#else +#define maria_is_key_active(_keymap_,_keyno_) \ + test((_keymap_) & (ULL(1) << (_keyno_))) +#define maria_set_key_active(_keymap_,_keyno_) \ + (_keymap_)|= (ULL(1) << (_keyno_)) +#define maria_clear_key_active(_keymap_,_keyno_) \ + (_keymap_)&= (~ (ULL(1) << (_keyno_))) +#endif +#define maria_is_any_key_active(_keymap_) \ + test((_keymap_)) +#define maria_is_all_keys_active(_keymap_,_keys_) \ + ((_keymap_) == maria_get_mask_all_keys_active(_keys_)) +#define maria_set_all_keys_active(_keymap_,_keys_) \ + (_keymap_)= maria_get_mask_all_keys_active(_keys_) +#define maria_clear_all_keys_active(_keymap_) \ + (_keymap_)= 0 +#define maria_intersect_keys_active(_to_,_from_) \ + (_to_)&= (_from_) +#define maria_is_any_intersect_keys_active(_keymap1_,_keys_,_keymap2_) \ + ((_keymap1_) & (_keymap2_) & \ + maria_get_mask_all_keys_active(_keys_)) +#define maria_copy_keys_active(_to_,_maxkeys_,_from_) \ + (_to_)= (maria_get_mask_all_keys_active(_maxkeys_) & \ + (_from_)) + + /* Param to/from maria_info */ + +typedef ulonglong MARIA_RECORD_POS; + +typedef struct st_maria_info +{ + ha_rows records; /* Records in database */ + ha_rows deleted; /* Deleted records in database */ + MARIA_RECORD_POS recpos; /* Pos for last used record */ + MARIA_RECORD_POS newrecpos; /* Pos if we write new record */ + MARIA_RECORD_POS dup_key_pos; /* Position to record with dup key */ + my_off_t data_file_length; /* Length of data file */ + my_off_t max_data_file_length, index_file_length; + my_off_t max_index_file_length, delete_length; + ulonglong auto_increment; + ulonglong key_map; /* Which keys are used */ + time_t create_time; /* When table was created */ + time_t check_time; + time_t update_time; + ulong record_offset; + double *rec_per_key; /* for sql optimizing */ + ulong reclength; /* Recordlength */ + ulong mean_reclength; /* Mean recordlength (if packed) */ + char *data_file_name, *index_file_name; + enum data_file_type data_file_type; + uint keys; /* Number of keys in use */ + uint options; /* HA_OPTION_... used */ + uint reflength; + int errkey, /* With key was dupplicated on err */ + sortkey; /* clustered by this key */ + File filenr; /* (uniq) filenr for datafile */ +} MARIA_INFO; + + +typedef struct st_maria_create_info +{ + const char *index_file_name, *data_file_name; /* If using symlinks */ + ha_rows max_rows; + ha_rows reloc_rows; + ulonglong auto_increment; + ulonglong data_file_length; + ulonglong key_file_length; + /* Size of null bitmap at start of row */ + uint null_bytes; + uint old_options; + enum data_file_type org_data_file_type; + uint8 language; + my_bool with_auto_increment, transactional; +} MARIA_CREATE_INFO; + +struct st_maria_share; +struct st_maria_handler; /* For referense */ +typedef struct st_maria_handler MARIA_HA; +struct st_maria_s_param; +struct st_maria_keydef; +struct st_maria_page; + +typedef struct st_maria_key /* Internal info about a key */ +{ + uchar *data; /* Data for key */ + struct st_maria_keydef *keyinfo; /* Definition for key */ + uint data_length; /* Length of key data */ + uint ref_length; /* record ref + transid */ + uint32 flag; /* 0 or SEARCH_PART_KEY */ +} MARIA_KEY; + + +typedef struct st_maria_keydef /* Key definition with open & info */ +{ + struct st_maria_share *share; /* Pointer to base (set in open) */ +#ifdef THREAD + rw_lock_t root_lock; /* locking of tree */ +#endif + uint16 keysegs; /* Number of key-segment */ + uint16 flag; /* NOSAME, PACK_USED */ + + uint8 key_alg; /* BTREE, RTREE */ + uint8 key_nr; /* key number (auto) */ + uint16 block_length; /* Length of keyblock (auto) */ + uint16 underflow_block_length; /* When to execute underflow */ + uint16 keylength; /* Tot length of keyparts (auto) */ + uint16 minlength; /* min length of (packed) key (auto) */ + uint16 maxlength; /* max length of (packed) key (auto) */ + uint32 write_comp_flag; /* compare flag for write key (auto) */ + uint32 version; /* For concurrent read/write */ + uint32 ftkey_nr; /* full-text index number */ + + HA_KEYSEG *seg, *end; + struct st_mysql_ftparser *parser; /* Fulltext [pre]parser */ + int (*bin_search)(const MARIA_KEY *key, const struct st_maria_page *page, + uint32 comp_flag, uchar **ret_pos, uchar *buff, + my_bool *was_last_key); + uint (*get_key)(MARIA_KEY *key, uint page_flag, uint nod_flag, + uchar **page); + uchar *(*skip_key)(MARIA_KEY *key, uint page_flag, uint nod_flag, + uchar *page); + int (*pack_key)(const MARIA_KEY *key, uint nod_flag, + uchar *next_key, uchar *org_key, uchar *prev_key, + struct st_maria_s_param *s_temp); + void (*store_key)(struct st_maria_keydef *keyinfo, uchar *key_pos, + struct st_maria_s_param *s_temp); + my_bool (*ck_insert)(MARIA_HA *inf, MARIA_KEY *key); + my_bool (*ck_delete)(MARIA_HA *inf, MARIA_KEY *klen); + MARIA_KEY *(*make_key)(MARIA_HA *info, MARIA_KEY *int_key, uint keynr, + uchar *key, const uchar *record, + MARIA_RECORD_POS filepos, ulonglong trid); +} MARIA_KEYDEF; + + +#define MARIA_UNIQUE_HASH_LENGTH 4 + +typedef struct st_maria_unique_def /* Segment definition of unique */ +{ + uint16 keysegs; /* Number of key-segment */ + uint8 key; /* Mapped to which key */ + uint8 null_are_equal; + HA_KEYSEG *seg, *end; +} MARIA_UNIQUEDEF; + +typedef struct st_maria_decode_tree /* Decode huff-table */ +{ + uint16 *table; + uint quick_table_bits; + uchar *intervalls; +} MARIA_DECODE_TREE; + + +struct st_maria_bit_buff; + +/* + Note that null markers should always be first in a row ! + When creating a column, one should only specify: + type, length, null_bit and null_pos +*/ + +typedef struct st_maria_columndef /* column information */ +{ + enum en_fieldtype type; + uint32 offset; /* Offset to position in row */ + uint16 length; /* length of field */ + uint16 column_nr; + /* Intern variable (size of total storage area for the row) */ + uint16 fill_length; + uint16 null_pos; /* Position for null marker */ + uint16 empty_pos; /* Position for empty marker */ + uint8 null_bit; /* If column may be NULL */ + /* Intern. Set if column should be zero packed (part of empty_bits) */ + uint8 empty_bit; + +#ifndef NOT_PACKED_DATABASES + void(*unpack)(struct st_maria_columndef *rec, + struct st_maria_bit_buff *buff, + uchar *start, uchar *end); + enum en_fieldtype base_type; + uint space_length_bits, pack_type; + MARIA_DECODE_TREE *huff_tree; +#endif +} MARIA_COLUMNDEF; + + +extern ulong maria_block_size, maria_checkpoint_frequency; +extern ulong maria_concurrent_insert; +extern my_bool maria_flush, maria_single_user, maria_page_checksums; +extern my_bool maria_delay_key_write; +extern my_off_t maria_max_temp_length; +extern ulong maria_bulk_insert_tree_size, maria_data_pointer_size; +extern PAGECACHE maria_pagecache_var, *maria_pagecache; +extern MY_TMPDIR *maria_tmpdir; +/* + This is used to check if a symlink points into the mysql data home, + which is normally forbidden as it can be used to get access to + not privileged data +*/ +extern int (*maria_test_invalid_symlink)(const char *filename); + + /* Prototypes for maria-functions */ + +extern int maria_init(void); +extern void maria_end(void); +extern int maria_close(MARIA_HA *file); +extern int maria_delete(MARIA_HA *file, const uchar *buff); +extern MARIA_HA *maria_open(const char *name, int mode, + uint wait_if_locked); +extern MARIA_HA *maria_clone(struct st_maria_share *share, int mode); +extern int maria_panic(enum ha_panic_function function); +extern int maria_rfirst(MARIA_HA *file, uchar *buf, int inx); +extern int maria_rkey(MARIA_HA *file, uchar *buf, int inx, + const uchar *key, key_part_map keypart_map, + enum ha_rkey_function search_flag); +extern int maria_rlast(MARIA_HA *file, uchar *buf, int inx); +extern int maria_rnext(MARIA_HA *file, uchar *buf, int inx); +extern int maria_rnext_same(MARIA_HA *info, uchar *buf); +extern int maria_rprev(MARIA_HA *file, uchar *buf, int inx); +extern int maria_rrnd(MARIA_HA *file, uchar *buf, + MARIA_RECORD_POS pos); +extern int maria_scan_init(MARIA_HA *file); +extern int maria_scan(MARIA_HA *file, uchar *buf); +extern void maria_scan_end(MARIA_HA *file); +extern int maria_rsame(MARIA_HA *file, uchar *record, int inx); +extern int maria_rsame_with_pos(MARIA_HA *file, uchar *record, + int inx, MARIA_RECORD_POS pos); +extern int maria_update(MARIA_HA *file, const uchar *old, + uchar *new_record); +extern int maria_write(MARIA_HA *file, uchar *buff); +extern MARIA_RECORD_POS maria_position(MARIA_HA *file); +extern int maria_status(MARIA_HA *info, MARIA_INFO *x, uint flag); +extern int maria_lock_database(MARIA_HA *file, int lock_type); +extern int maria_create(const char *name, enum data_file_type record_type, + uint keys, MARIA_KEYDEF *keydef, + uint columns, MARIA_COLUMNDEF *columndef, + uint uniques, MARIA_UNIQUEDEF *uniquedef, + MARIA_CREATE_INFO *create_info, uint flags); +extern int maria_delete_table(const char *name); +extern int maria_rename(const char *from, const char *to); +extern int maria_extra(MARIA_HA *file, + enum ha_extra_function function, void *extra_arg); +extern int maria_reset(MARIA_HA *file); +extern ha_rows maria_records_in_range(MARIA_HA *info, int inx, + key_range *min_key, key_range *max_key); +extern int maria_is_changed(MARIA_HA *info); +extern int maria_delete_all_rows(MARIA_HA *info); +extern uint maria_get_pointer_length(ulonglong file_length, uint def); +extern int maria_commit(MARIA_HA *info); +extern int maria_begin(MARIA_HA *info); +extern void maria_disable_logging(MARIA_HA *info); +extern void maria_enable_logging(MARIA_HA *info); + +#define HA_RECOVER_ANY (HA_RECOVER_DEFAULT | HA_RECOVER_BACKUP | HA_RECOVER_FORCE | HA_RECOVER_QUICK) + +/* this is used to pass to mysql_mariachk_table */ + +#define MARIA_CHK_REPAIR 1 /* equivalent to mariachk -r */ +#define MARIA_CHK_VERIFY 2 /* Verify, run repair if failure */ + +typedef uint maria_bit_type; + +typedef struct st_maria_bit_buff +{ /* Used for packing of record */ + maria_bit_type current_byte; + uint bits; + uchar *pos, *end, *blob_pos, *blob_end; + uint error; +} MARIA_BIT_BUFF; + + +typedef struct st_maria_sort_info +{ +#ifdef THREAD + /* sync things */ + pthread_mutex_t mutex; + pthread_cond_t cond; +#endif + MARIA_HA *info, *new_info; + HA_CHECK *param; + char *buff; + SORT_KEY_BLOCKS *key_block, *key_block_end; + SORT_FT_BUF *ft_buf; + my_off_t filelength, dupp, buff_length; + pgcache_page_no_t page; + ha_rows max_records; + uint current_key, total_keys; + uint got_error, threads_running; + myf myf_rw; + enum data_file_type new_data_file_type, org_data_file_type; +} MARIA_SORT_INFO; + +typedef struct st_maria_sort_param +{ + pthread_t thr; + IO_CACHE read_cache, tempfile, tempfile_for_exceptions; + DYNAMIC_ARRAY buffpek; + MARIA_BIT_BUFF bit_buff; /* For parallel repair of packrec. */ + + MARIA_KEYDEF *keyinfo; + MARIA_SORT_INFO *sort_info; + HA_KEYSEG *seg; + uchar **sort_keys; + uchar *rec_buff; + void *wordlist, *wordptr; + MEM_ROOT wordroot; + uchar *record; + MY_TMPDIR *tmpdir; + + /* + The next two are used to collect statistics, see maria_update_key_parts for + description. + */ + ulonglong unique[HA_MAX_KEY_SEG+1]; + ulonglong notnull[HA_MAX_KEY_SEG+1]; + + MARIA_RECORD_POS pos,max_pos,filepos,start_recpos, current_filepos; + uint key, key_length,real_key_length,sortbuff_size; + uint maxbuffers, keys, find_length, sort_keys_length; + my_bool fix_datafile, master; + my_bool calc_checksum; /* calculate table checksum */ + size_t rec_buff_size; + + int (*key_cmp)(struct st_maria_sort_param *, const void *, const void *); + int (*key_read)(struct st_maria_sort_param *, uchar *); + int (*key_write)(struct st_maria_sort_param *, const uchar *); + void (*lock_in_memory)(HA_CHECK *); + int (*write_keys)(struct st_maria_sort_param *, register uchar **, + uint , struct st_buffpek *, IO_CACHE *); + uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint); + int (*write_key)(struct st_maria_sort_param *, IO_CACHE *,uchar *, + uint, uint); +} MARIA_SORT_PARAM; + + +/* functions in maria_check */ +void maria_chk_init(HA_CHECK *param); +void maria_chk_init_for_check(HA_CHECK *param, MARIA_HA *info); +int maria_chk_status(HA_CHECK *param, MARIA_HA *info); +int maria_chk_del(HA_CHECK *param, MARIA_HA *info, ulonglong test_flag); +int maria_chk_size(HA_CHECK *param, MARIA_HA *info); +int maria_chk_key(HA_CHECK *param, MARIA_HA *info); +int maria_chk_data_link(HA_CHECK *param, MARIA_HA *info, my_bool extend); +int maria_repair(HA_CHECK *param, MARIA_HA *info, char * name, my_bool); +int maria_sort_index(HA_CHECK *param, MARIA_HA *info, char * name); +int maria_zerofill(HA_CHECK *param, MARIA_HA *info, const char *name); +int maria_repair_by_sort(HA_CHECK *param, MARIA_HA *info, + const char *name, my_bool rep_quick); +int maria_repair_parallel(HA_CHECK *param, register MARIA_HA *info, + const char *name, my_bool rep_quick); +int maria_change_to_newfile(const char *filename, const char *old_ext, + const char *new_ext, time_t backup_time, + myf myflags); +void maria_lock_memory(HA_CHECK *param); +int maria_update_state_info(HA_CHECK *param, MARIA_HA *info, uint update); +void maria_update_key_parts(MARIA_KEYDEF *keyinfo, double *rec_per_key_part, + ulonglong *unique, ulonglong *notnull, + ulonglong records); +int maria_filecopy(HA_CHECK *param, File to, File from, my_off_t start, + my_off_t length, const char *type); +int maria_movepoint(MARIA_HA *info, uchar *record, my_off_t oldpos, + my_off_t newpos, uint prot_key); +int maria_write_data_suffix(MARIA_SORT_INFO *sort_info, my_bool fix_datafile); +int maria_test_if_almost_full(MARIA_HA *info); +int maria_recreate_table(HA_CHECK *param, MARIA_HA **org_info, char *filename); +int maria_disable_indexes(MARIA_HA *info); +int maria_enable_indexes(MARIA_HA *info); +int maria_indexes_are_disabled(MARIA_HA *info); +void maria_disable_non_unique_index(MARIA_HA *info, ha_rows rows); +my_bool maria_test_if_sort_rep(MARIA_HA *info, ha_rows rows, ulonglong key_map, + my_bool force); + +int maria_init_bulk_insert(MARIA_HA *info, ulong cache_size, ha_rows rows); +void maria_flush_bulk_insert(MARIA_HA *info, uint inx); +void maria_end_bulk_insert(MARIA_HA *info); +int maria_assign_to_pagecache(MARIA_HA *info, ulonglong key_map, + PAGECACHE *key_cache); +void maria_change_pagecache(PAGECACHE *old_key_cache, + PAGECACHE *new_key_cache); +int maria_preload(MARIA_HA *info, ulonglong key_map, my_bool ignore_leaves); +void maria_versioning(MARIA_HA *info, my_bool versioning); +void maria_ignore_trids(MARIA_HA *info); + +/* fulltext functions */ +FT_INFO *maria_ft_init_search(uint,void *, uint, uchar *, size_t, + CHARSET_INFO *, uchar *); + +/* 'Almost-internal' Maria functions */ + +void _ma_update_auto_increment_key(HA_CHECK *param, MARIA_HA *info, + my_bool repair); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/my_alarm.h b/include/my_alarm.h index b77683d8ffc..5ba6d9e1926 100644 --- a/include/my_alarm.h +++ b/include/my_alarm.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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 diff --git a/include/my_alloc.h b/include/my_alloc.h index 93b7438a1df..6ade4d08980 100644 --- a/include/my_alloc.h +++ b/include/my_alloc.h @@ -26,8 +26,8 @@ typedef struct st_used_mem { /* struct for once_alloc (block) */ struct st_used_mem *next; /* Next block in use */ - unsigned int left; /* memory left in block */ - unsigned int size; /* size of block */ + size_t left; /* memory left in block */ + size_t size; /* size of block */ } USED_MEM; diff --git a/include/my_atomic.h b/include/my_atomic.h new file mode 100644 index 00000000000..40d762f8ff0 --- /dev/null +++ b/include/my_atomic.h @@ -0,0 +1,260 @@ +/* Copyright (C) 2006 MySQL AB + + 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 */ + +/* + This header defines five atomic operations: + + my_atomic_add#(&var, what) + add 'what' to *var, and return the old value of *var + + my_atomic_fas#(&var, what) + 'Fetch And Store' + store 'what' in *var, and return the old value of *var + + my_atomic_cas#(&var, &old, new) + 'Compare And Swap' + if *var is equal to *old, then store 'new' in *var, and return TRUE + otherwise store *var in *old, and return FALSE + + my_atomic_load#(&var) + return *var + + my_atomic_store#(&var, what) + store 'what' in *var + + '#' is substituted by a size suffix - 8, 16, 32, or ptr + (e.g. my_atomic_add8, my_atomic_fas32, my_atomic_casptr). + + NOTE This operations are not always atomic, so they always must be + enclosed in my_atomic_rwlock_rdlock(lock)/my_atomic_rwlock_rdunlock(lock) + or my_atomic_rwlock_wrlock(lock)/my_atomic_rwlock_wrunlock(lock). + Hint: if a code block makes intensive use of atomic ops, it make sense + to take/release rwlock once for the whole block, not for every statement. + + On architectures where these operations are really atomic, rwlocks will + be optimized away. + 8- and 16-bit atomics aren't implemented for windows (see generic-msvc.h), + but can be added, if necessary. +*/ + +#ifndef my_atomic_rwlock_init + +#define intptr void * + +#ifndef MY_ATOMIC_MODE_RWLOCKS +#include "atomic/nolock.h" +#endif + +#ifndef make_atomic_cas_body +/* nolock.h was not able to generate even a CAS function, fall back */ +#include "atomic/rwlock.h" +#else +/* define missing functions by using the already generated ones */ +#ifndef make_atomic_add_body +#define make_atomic_add_body(S) \ + int ## S tmp=*a; \ + while (!my_atomic_cas ## S(a, &tmp, tmp+v)); \ + v=tmp; +#endif +#ifndef make_atomic_fas_body +#define make_atomic_fas_body(S) \ + int ## S tmp=*a; \ + while (!my_atomic_cas ## S(a, &tmp, v)); \ + v=tmp; +#endif +#ifndef make_atomic_load_body +#define make_atomic_load_body(S) \ + ret= 0; /* avoid compiler warning */ \ + (void)(my_atomic_cas ## S(a, &ret, ret)); +#endif +#ifndef make_atomic_store_body +#define make_atomic_store_body(S) \ + (void)(my_atomic_fas ## S (a, v)); +#endif +#endif + +/* + transparent_union doesn't work in g++ + Bug ? + + Darwin's gcc doesn't want to put pointers in a transparent_union + when built with -arch ppc64. Complains: + warning: 'transparent_union' attribute ignored +*/ +#if defined(__GNUC__) && !defined(__cplusplus) && \ + ! (defined(__APPLE__) && defined(_ARCH_PPC64)) +/* + we want to be able to use my_atomic_xxx functions with + both signed and unsigned integers. But gcc will issue a warning + "passing arg N of `my_atomic_XXX' as [un]signed due to prototype" + if the signedness of the argument doesn't match the prototype, or + "pointer targets in passing argument N of my_atomic_XXX differ in signedness" + if int* is used where uint* is expected (or vice versa). + Let's shut these warnings up +*/ +#define make_transparent_unions(S) \ + typedef union { \ + int ## S i; \ + uint ## S u; \ + } U_ ## S __attribute__ ((transparent_union)); \ + typedef union { \ + int ## S volatile *i; \ + uint ## S volatile *u; \ + } Uv_ ## S __attribute__ ((transparent_union)); +#define uintptr intptr +make_transparent_unions(8) +make_transparent_unions(16) +make_transparent_unions(32) +make_transparent_unions(ptr) +#undef uintptr +#undef make_transparent_unions +#define a U_a.i +#define cmp U_cmp.i +#define v U_v.i +#define set U_set.i +#else +#define U_8 int8 +#define U_16 int16 +#define U_32 int32 +#define U_ptr intptr +#define Uv_8 int8 +#define Uv_16 int16 +#define Uv_32 int32 +#define Uv_ptr intptr +#define U_a volatile *a +#define U_cmp *cmp +#define U_v v +#define U_set set +#endif /* __GCC__ transparent_union magic */ + +#ifdef HAVE_INLINE + +#define make_atomic_cas(S) \ +STATIC_INLINE int my_atomic_cas ## S(Uv_ ## S U_a, \ + Uv_ ## S U_cmp, U_ ## S U_set) \ +{ \ + int8 ret; \ + make_atomic_cas_body(S); \ + return ret; \ +} + +#define make_atomic_add(S) \ +STATIC_INLINE int ## S my_atomic_add ## S( \ + Uv_ ## S U_a, U_ ## S U_v) \ +{ \ + make_atomic_add_body(S); \ + return v; \ +} + +#define make_atomic_fas(S) \ +STATIC_INLINE int ## S my_atomic_fas ## S( \ + Uv_ ## S U_a, U_ ## S U_v) \ +{ \ + make_atomic_fas_body(S); \ + return v; \ +} + +#define make_atomic_load(S) \ +STATIC_INLINE int ## S my_atomic_load ## S(Uv_ ## S U_a) \ +{ \ + int ## S ret; \ + make_atomic_load_body(S); \ + return ret; \ +} + +#define make_atomic_store(S) \ +STATIC_INLINE void my_atomic_store ## S( \ + Uv_ ## S U_a, U_ ## S U_v) \ +{ \ + make_atomic_store_body(S); \ +} + +#else /* no inline functions */ + +#define make_atomic_add(S) \ +extern int ## S my_atomic_add ## S(Uv_ ## S U_a, U_ ## S U_v); + +#define make_atomic_fas(S) \ +extern int ## S my_atomic_fas ## S(Uv_ ## S U_a, U_ ## S U_v); + +#define make_atomic_cas(S) \ +extern int my_atomic_cas ## S(Uv_ ## S U_a, Uv_ ## S U_cmp, U_ ## S U_set); + +#define make_atomic_load(S) \ +extern int ## S my_atomic_load ## S(Uv_ ## S U_a); + +#define make_atomic_store(S) \ +extern void my_atomic_store ## S(Uv_ ## S U_a, U_ ## S U_v); + +#endif + +make_atomic_cas(32) +make_atomic_cas(ptr) + +make_atomic_add(32) + +make_atomic_load(32) +make_atomic_load(ptr) + +make_atomic_fas(32) +make_atomic_fas(ptr) + +make_atomic_store(32) +make_atomic_store(ptr) + +#ifdef _atomic_h_cleanup_ +#include _atomic_h_cleanup_ +#undef _atomic_h_cleanup_ +#endif + +#undef U_8 +#undef U_16 +#undef U_32 +#undef U_ptr +#undef a +#undef cmp +#undef v +#undef set +#undef U_a +#undef U_cmp +#undef U_v +#undef U_set +#undef make_atomic_add +#undef make_atomic_cas +#undef make_atomic_load +#undef make_atomic_store +#undef make_atomic_fas +#undef make_atomic_add_body +#undef make_atomic_cas_body +#undef make_atomic_load_body +#undef make_atomic_store_body +#undef make_atomic_fas_body +#undef intptr + +/* + the macro below defines (as an expression) the code that + will be run in spin-loops. Intel manuals recummend to have PAUSE there. + It is expected to be defined in include/atomic/ *.h files +*/ +#ifndef LF_BACKOFF +#define LF_BACKOFF (1) +#endif + +#define MY_ATOMIC_OK 0 +#define MY_ATOMIC_NOT_1CPU 1 +extern int my_atomic_initialize(); + +#endif + diff --git a/include/my_base.h b/include/my_base.h index 80ba4bcd004..8bc484eea0a 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -53,6 +53,7 @@ #define HA_OPEN_COPY 256 /* Open copy (for repair) */ /* Internal temp table, used for temporary results */ #define HA_OPEN_INTERNAL_TABLE 512 +#define HA_OPEN_MERGE_TABLE 1024 /* The following is parameter to ha_rkey() how to use key */ @@ -114,7 +115,7 @@ enum ha_storage_media { enum ha_extra_function { HA_EXTRA_NORMAL=0, /* Optimize for space (def) */ HA_EXTRA_QUICK=1, /* Optimize for speed */ - HA_EXTRA_NOT_USED=2, + HA_EXTRA_NOT_USED=2, /* Should be ignored by handler */ HA_EXTRA_CACHE=3, /* Cache record in HA_rrnd() */ HA_EXTRA_NO_CACHE=4, /* End caching of records (def) */ HA_EXTRA_NO_READCHECK=5, /* No readcheck on update */ @@ -198,7 +199,10 @@ enum ha_extra_function { begin and end of a statement. */ HA_EXTRA_ATTACH_CHILDREN, - HA_EXTRA_DETACH_CHILDREN + HA_EXTRA_DETACH_CHILDREN, + HA_EXTRA_DETACH_CHILD, + /* Inform handler we will force a close as part of flush */ + HA_EXTRA_PREPARE_FOR_FORCED_CLOSE }; /* Compatible option, to be deleted in 6.0 */ @@ -241,7 +245,10 @@ enum ha_base_keytype { #define HA_MAX_KEYTYPE 31 /* Must be log2-1 */ - /* These flags kan be OR:ed to key-flag */ +/* + These flags kan be OR:ed to key-flag + Note that these can only be up to 16 bits! +*/ #define HA_NOSAME 1 /* Set if not dupplicated records */ #define HA_PACK_KEY 2 /* Pack string key to previous key */ @@ -252,11 +259,13 @@ enum ha_base_keytype { #define HA_SPATIAL 1024 /* For spatial search */ #define HA_NULL_ARE_EQUAL 2048 /* NULL in key are cmp as equal */ #define HA_GENERATED_KEY 8192 /* Automaticly generated key */ +#define HA_RTREE_INDEX 16384 /* For RTREE search */ /* The combination of the above can be used for key type comparison. */ #define HA_KEYFLAG_MASK (HA_NOSAME | HA_PACK_KEY | HA_AUTO_KEY | \ HA_BINARY_PACK_KEY | HA_FULLTEXT | HA_UNIQUE_CHECK | \ - HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY) + HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY | \ + HA_RTREE_INDEX) #define HA_KEY_HAS_PART_KEY_SEG 65536 /* Key contains partial segments */ @@ -268,7 +277,7 @@ enum ha_base_keytype { #define HA_USES_PARSER 16384 /* Fulltext index uses [pre]parser */ #define HA_USES_BLOCK_SIZE ((uint) 32768) #define HA_SORT_ALLOWS_SAME 512 /* Intern bit when sorting records */ -#if MYSQL_VERSION_ID < 0x50200 +#if MYSQL_VERSION_ID < 50200 /* Key has a part that can have end space. If this is an unique key we have to handle it differently from other unique keys as we can find @@ -310,8 +319,10 @@ enum ha_base_keytype { #define HA_OPTION_RELIES_ON_SQL_LAYER 512 #define HA_OPTION_NULL_FIELDS 1024 #define HA_OPTION_PAGE_CHECKSUM 2048 -#define HA_OPTION_TEMP_COMPRESS_RECORD ((uint) 16384) /* set by isamchk */ -#define HA_OPTION_READ_ONLY_DATA ((uint) 32768) /* Set by isamchk */ +#define HA_OPTION_TEMP_COMPRESS_RECORD (1L << 15) /* set by isamchk */ +#define HA_OPTION_READ_ONLY_DATA (1L << 16) /* Set by isamchk */ +#define HA_OPTION_NO_CHECKSUM (1L << 17) +#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18) /* Bits in flag to create() */ @@ -434,18 +445,18 @@ enum ha_base_keytype { /* row not actually updated: new values same as the old values */ #define HA_ERR_RECORD_IS_THE_SAME 169 /* It is not possible to log this statement */ -#define HA_ERR_LOGGING_IMPOSSIBLE 170 /* It is not possible to log this - statement */ -#define HA_ERR_CORRUPT_EVENT 171 /* The event was corrupt, leading to - illegal data being read */ +#define HA_ERR_LOGGING_IMPOSSIBLE 170 +/* The event was corrupt, leading to illegal data being read */ +#define HA_ERR_CORRUPT_EVENT 171 #define HA_ERR_NEW_FILE 172 /* New file format */ -#define HA_ERR_ROWS_EVENT_APPLY 173 /* The event could not be processed - no other hanlder error happened */ +/* The event could not be processed no other handler error happened */ +#define HA_ERR_ROWS_EVENT_APPLY 173 #define HA_ERR_INITIALIZATION 174 /* Error during initialization */ #define HA_ERR_FILE_TOO_SHORT 175 /* File too short */ #define HA_ERR_WRONG_CRC 176 /* Wrong CRC on page */ -#define HA_ERR_TOO_MANY_CONCURRENT_TRXS 177 /*Too many active concurrent transactions */ -#define HA_ERR_LAST 177 /* Copy of last error nr */ +#define HA_ERR_ROW_NOT_VISIBLE 177 +#define HA_ERR_TOO_MANY_CONCURRENT_TRXS 178 /*Too many active concurrent transactions */ +#define HA_ERR_LAST 178 /* Copy of last error nr */ /* Number of different errors */ #define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1) @@ -478,6 +489,14 @@ typedef ulong key_part_map; #define MBR_DATA 16384 #define SEARCH_NULL_ARE_EQUAL 32768 /* NULL in keys are equal */ #define SEARCH_NULL_ARE_NOT_EQUAL 65536 /* NULL in keys are not equal */ +/* Use this when inserting a key in position order */ +#define SEARCH_INSERT SEARCH_NULL_ARE_NOT_EQUAL*2 +/* Only part of the key is specified while reading */ +#define SEARCH_PART_KEY SEARCH_INSERT*2 +/* Used when user key (key 2) contains transaction id's */ +#define SEARCH_USER_KEY_HAS_TRANSID SEARCH_PART_KEY*2 +/* Used when page key (key 1) contains transaction id's */ +#define SEARCH_PAGE_KEY_HAS_TRANSID SEARCH_USER_KEY_HAS_TRANSID*2 /* bits in opt_flag */ #define QUICK_USED 1 diff --git a/include/my_bit.h b/include/my_bit.h index 1e0a7488a81..266cfa8ff27 100644 --- a/include/my_bit.h +++ b/include/my_bit.h @@ -1,5 +1,5 @@ -/* - Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2007, 2011, Oracle and/or its affiliates. + Copyright (c) 2009-2011, Monty Program Ab 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 diff --git a/include/my_bitmap.h b/include/my_bitmap.h index 34c9ac9bb96..a98dd58bd72 100644 --- a/include/my_bitmap.h +++ b/include/my_bitmap.h @@ -1,5 +1,5 @@ -/* - Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. + Copyright (c) 2009-2011, Monty Program Ab 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 @@ -27,8 +27,6 @@ typedef uint32 my_bitmap_map; typedef struct st_bitmap { my_bitmap_map *bitmap; - uint n_bits; /* number of bits occupied by the above */ - my_bitmap_map last_word_mask; my_bitmap_map *last_word_ptr; /* mutex will be acquired for the duration of each bitmap operation if @@ -38,6 +36,8 @@ typedef struct st_bitmap #ifdef THREAD pthread_mutex_t *mutex; #endif + my_bitmap_map last_word_mask; + uint32 n_bits; /* number of bits occupied by the above */ } MY_BITMAP; #ifdef __cplusplus @@ -55,6 +55,8 @@ extern my_bool bitmap_is_overlapping(const MY_BITMAP *map1, extern my_bool bitmap_test_and_set(MY_BITMAP *map, uint bitmap_bit); extern my_bool bitmap_test_and_clear(MY_BITMAP *map, uint bitmap_bit); extern my_bool bitmap_fast_test_and_set(MY_BITMAP *map, uint bitmap_bit); +extern my_bool bitmap_union_is_set_all(const MY_BITMAP *map1, + const MY_BITMAP *map2); extern uint bitmap_set_next(MY_BITMAP *map); extern uint bitmap_get_first(const MY_BITMAP *map); extern uint bitmap_get_first_set(const MY_BITMAP *map); diff --git a/include/my_compare.h b/include/my_compare.h index dedae5c8052..fc607a5b6c6 100644 --- a/include/my_compare.h +++ b/include/my_compare.h @@ -1,4 +1,6 @@ -/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) Monty Program Ab; 1991-2011 + Copyright (C) 2002-2006 MySQL AB + Copyright (c) 2011, Oracle and/or its affiliates. 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 @@ -16,10 +18,12 @@ #ifndef _my_compare_h #define _my_compare_h -#include "my_base.h" -#include "m_ctype.h" #include "myisampack.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef struct st_HA_KEYSEG /* Key-portion */ { CHARSET_INFO *charset; @@ -36,33 +40,35 @@ typedef struct st_HA_KEYSEG /* Key-portion */ } HA_KEYSEG; #define get_key_length(length,key) \ -{ if ((uchar) *(key) != 255) \ - length= (uint) (uchar) *((key)++); \ +{ if (*(const uchar*) (key) != 255) \ + length= (uint) *(const uchar*) ((key)++); \ else \ - { length=mi_uint2korr((key)+1); (key)+=3; } \ + { length= mi_uint2korr((key)+1); (key)+=3; } \ } #define get_key_length_rdonly(length,key) \ -{ if ((uchar) *(key) != 255) \ - length= ((uint) (uchar) *((key))); \ +{ if (*(const uchar*) (key) != 255) \ + length= ((uint) *(const uchar*) ((key))); \ else \ - { length=mi_uint2korr((key)+1); } \ + { length= mi_uint2korr((key)+1); } \ } #define get_key_pack_length(length,length_pack,key) \ -{ if ((uchar) *(key) != 255) \ - { length= (uint) (uchar) *((key)++); length_pack=1; }\ +{ if (*(const uchar*) (key) != 255) \ + { length= (uint) *(const uchar*) ((key)++); length_pack= 1; }\ else \ - { length=mi_uint2korr((key)+1); (key)+=3; length_pack=3; } \ + { length=mi_uint2korr((key)+1); (key)+= 3; length_pack= 3; } \ } #define store_key_length_inc(key,length) \ { if ((length) < 255) \ - { *(key)++=(length); } \ + { *(key)++= (length); } \ else \ { *(key)=255; mi_int2store((key)+1,(length)); (key)+=3; } \ } +#define size_to_store_key_length(length) ((length) < 255 ? 1 : 3) + #define get_rec_bits(bit_ptr, bit_ofs, bit_len) \ (((((uint16) (bit_ptr)[1] << 8) | (uint16) (bit_ptr)[0]) >> (bit_ofs)) & \ ((1 << (bit_len)) - 1)) @@ -79,11 +85,14 @@ typedef struct st_HA_KEYSEG /* Key-portion */ #define clr_rec_bits(bit_ptr, bit_ofs, bit_len) \ set_rec_bits(0, bit_ptr, bit_ofs, bit_len) -extern int ha_compare_text(CHARSET_INFO *, uchar *, uint, uchar *, uint , - my_bool, my_bool); -extern int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, - register uchar *b, uint key_length, uint nextflag, - uint *diff_pos); - +extern int ha_compare_text(CHARSET_INFO *, const uchar *, uint, + const uchar *, uint , my_bool, my_bool); +extern int ha_key_cmp(register HA_KEYSEG *keyseg, register const uchar *a, + register const uchar *b, uint key_length, + uint32 nextflag, uint *diff_pos); +extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, const uchar *a); +#ifdef __cplusplus +} +#endif #endif /* _my_compare_h */ diff --git a/include/my_compiler.h b/include/my_compiler.h index 5f898621159..b5ccdb212d6 100644 --- a/include/my_compiler.h +++ b/include/my_compiler.h @@ -1,7 +1,7 @@ #ifndef MY_COMPILER_INCLUDED #define MY_COMPILER_INCLUDED -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, Oracle and/or its affiliates. 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 diff --git a/include/my_dbug.h b/include/my_dbug.h index f49466cc098..a91a745de33 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. + Copyright (C) 2000-2011 Monty Program Ab 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 @@ -14,16 +15,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MY_DBUG_INCLUDED -#define MY_DBUG_INCLUDED +#ifndef _my_dbug_h +#define _my_dbug_h #ifndef __WIN__ -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif #include <signal.h> #endif /* not __WIN__ */ @@ -54,25 +49,34 @@ private: extern "C" { #endif #if !defined(DBUG_OFF) && !defined(_lint) -struct _db_code_state_; -extern int _db_keyword_(struct _db_code_state_ *cs, const char *keyword); + +struct _db_stack_frame_ { + const char *func; /* function name of the previous stack frame */ + const char *file; /* filename of the function of previous frame */ + uint level; /* this nesting level, highest bit enables tracing */ + struct _db_stack_frame_ *prev; /* pointer to the previous frame */ +}; + +struct _db_code_state_; +extern my_bool _dbug_on_; +extern my_bool _db_keyword_(struct _db_code_state_ *cs, const char *keyword, + int strict_flag); extern int _db_strict_keyword_(const char *keyword); extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len); extern int _db_explain_init_(char *buf, size_t len); -extern void _db_setjmp_(void); -extern void _db_longjmp_(void); +extern int _db_is_pushed_(void); +extern void _db_setjmp_(void); +extern void _db_longjmp_(void); extern void _db_process_(const char *name); extern void _db_push_(const char *control); extern void _db_pop_(void); -extern void _db_set_(struct _db_code_state_ *cs, const char *control); +extern void _db_set_(const char *control); extern void _db_set_init_(const char *control); -extern void _db_enter_(const char *_func_,const char *_file_,uint _line_, - const char **_sfunc_,const char **_sfile_, - uint *_slevel_, char ***); -extern void _db_return_(uint _line_,const char **_sfunc_,const char **_sfile_, - uint *_slevel_); -extern void _db_pargs_(uint _line_,const char *keyword); -extern void _db_doprnt_ _VARARGS((const char *format,...)) +extern void _db_enter_(const char *_func_, const char *_file_, uint _line_, + struct _db_stack_frame_ *_stack_frame_); +extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_); +extern void _db_pargs_(uint _line_,const char *keyword); +extern void _db_doprnt_ _VARARGS((const char *format,...)) ATTRIBUTE_FORMAT(printf, 1, 2); extern void _db_dump_(uint _line_,const char *keyword, const unsigned char *memory, size_t length); @@ -84,45 +88,37 @@ extern void _db_flush_(); #ifdef __cplusplus -#define DBUG_ENTER(a) \ - const char *_db_func_, *_db_file_; \ - uint _db_level_; \ - char **_db_framep_; \ +#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ Dbug_violation_helper dbug_violation_helper; \ - _db_enter_ (a, __FILE__, __LINE__, &_db_func_, &_db_file_, \ - &_db_level_, &_db_framep_) + _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) #define DBUG_VIOLATION_HELPER_LEAVE dbug_violation_helper.leave() #else /* C */ -#define DBUG_ENTER(a) \ - const char *_db_func_, *_db_file_; \ - uint _db_level_; \ - char **_db_framep_; \ - _db_enter_ (a, __FILE__, __LINE__, &_db_func_, &_db_file_, \ - &_db_level_, &_db_framep_) +#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ + _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) #define DBUG_VIOLATION_HELPER_LEAVE do { } while(0) #endif /* C++ */ #define DBUG_LEAVE \ DBUG_VIOLATION_HELPER_LEAVE; \ - _db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_) + _db_return_ (__LINE__, &_db_stack_frame_) #define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0) #define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0) #define DBUG_EXECUTE(keyword,a1) \ - do {if (_db_keyword_(0, (keyword))) { a1 }} while(0) + do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0) #define DBUG_EXECUTE_IF(keyword,a1) \ - do {if (_db_strict_keyword_ (keyword)) { a1 } } while(0) + do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0) #define DBUG_EVALUATE(keyword,a1,a2) \ - (_db_keyword_(0,(keyword)) ? (a1) : (a2)) + (_db_keyword_(0,(keyword), 0) ? (a1) : (a2)) #define DBUG_EVALUATE_IF(keyword,a1,a2) \ - (_db_strict_keyword_((keyword)) ? (a1) : (a2)) + (_db_keyword_(0,(keyword), 1) ? (a1) : (a2)) #define DBUG_PRINT(keyword,arglist) \ do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0) #define DBUG_PUSH(a1) _db_push_ (a1) #define DBUG_POP() _db_pop_ () -#define DBUG_SET(a1) _db_set_ (0, (a1)) +#define DBUG_SET(a1) _db_set_ (a1) #define DBUG_SET_INITIAL(a1) _db_set_init_ (a1) #define DBUG_PROCESS(a1) _db_process_(a1) #define DBUG_FILE _db_fp_() @@ -132,9 +128,11 @@ extern void _db_flush_(); #define DBUG_END() _db_end_ () #define DBUG_LOCK_FILE _db_lock_file_() #define DBUG_UNLOCK_FILE _db_unlock_file_() -#define DBUG_ASSERT(A) assert(A) +#define DBUG_ASSERT(A) do { _db_flush_(); assert(A); } while(0) #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len)) #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len)) +#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0) +#define DEBUGGER_ON do { _dbug_on_= 1; } while(0) #define IF_DBUG(A) A #ifndef __WIN__ #define DBUG_ABORT() (_db_flush_(), abort()) @@ -168,37 +166,39 @@ extern void _db_suicide_(); #else /* No debugger */ #define DBUG_ENTER(a1) +#define DBUG_VIOLATION_HELPER_LEAVE do { } while(0) #define DBUG_LEAVE -#define DBUG_VIOLATION_HELPER_LEAVE #define DBUG_RETURN(a1) do { return(a1); } while(0) #define DBUG_VOID_RETURN do { return; } while(0) #define DBUG_EXECUTE(keyword,a1) do { } while(0) #define DBUG_EXECUTE_IF(keyword,a1) do { } while(0) #define DBUG_EVALUATE(keyword,a1,a2) (a2) #define DBUG_EVALUATE_IF(keyword,a1,a2) (a2) -#define DBUG_PRINT(keyword,arglist) do { } while(0) -#define DBUG_PUSH(a1) -#define DBUG_SET(a1) do { } while(0) -#define DBUG_SET_INITIAL(a1) do { } while(0) -#define DBUG_POP() -#define DBUG_PROCESS(a1) +#define DBUG_PRINT(keyword,arglist) do { } while(0) +#define DBUG_PUSH(a1) do { } while(0) +#define DBUG_SET(a1) do { } while(0) +#define DBUG_SET_INITIAL(a1) do { } while(0) +#define DBUG_POP() do { } while(0) +#define DBUG_PROCESS(a1) do { } while(0) #define DBUG_SETJMP(a1) setjmp(a1) #define DBUG_LONGJMP(a1) longjmp(a1) -#define DBUG_DUMP(keyword,a1,a2) do { } while(0) -#define DBUG_END() -#define DBUG_ASSERT(A) do { } while(0) -#define DBUG_LOCK_FILE +#define DBUG_DUMP(keyword,a1,a2) do { } while(0) +#define DBUG_END() do { } while(0) +#define DBUG_ASSERT(A) do { } while(0) +#define DBUG_LOCK_FILE do { } while(0) #define DBUG_FILE (stderr) -#define DBUG_UNLOCK_FILE +#define DBUG_UNLOCK_FILE do { } while(0) #define DBUG_EXPLAIN(buf,len) #define DBUG_EXPLAIN_INITIAL(buf,len) +#define DEBUGGER_OFF do { } while(0) +#define DEBUGGER_ON do { } while(0) #define IF_DBUG(A) #define DBUG_ABORT() do { } while(0) #define DBUG_SUICIDE() do { } while(0) #endif -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* MY_DBUG_INCLUDED */ +#endif /* _my_dbug_h */ diff --git a/include/my_getopt.h b/include/my_getopt.h index 8112303a6a5..aeed8fa1586 100644 --- a/include/my_getopt.h +++ b/include/my_getopt.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2002, 2011, Oracle and/or its affiliates. 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 diff --git a/include/my_global.h b/include/my_global.h index 8f4b67855db..5dca5710055 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2001, 2011, Oracle and/or its affiliates. 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 @@ -96,6 +96,9 @@ #define IF_WIN(A,B) (B) #endif +/* Make it easier to print null strings */ +#define val_or_null(A) ((A) ? (const char*) (A) : "(null)") + #ifndef EMBEDDED_LIBRARY #ifdef WITH_NDB_BINLOG #define HAVE_NDB_BINLOG 1 @@ -162,9 +165,14 @@ #define __builtin_expect(x, expected_value) (x) #endif -#define likely(x) __builtin_expect((x),1) -#define unlikely(x) __builtin_expect((x),0) - +/** + The semantics of builtin_expect() are that + 1) its two arguments are long + 2) it's likely that they are == + Those of our likely(x) are that x can be bool/int/longlong/pointer. +*/ +#define likely(x) __builtin_expect(((x) != 0),1) +#define unlikely(x) __builtin_expect(((x) != 0),0) /* The macros below are useful in optimising places where it has been @@ -361,7 +369,7 @@ C_MODE_END #define ulonglong2double(A) my_ulonglong2double(A) #define my_off_t2double(A) my_ulonglong2double(A) C_MODE_START -inline double my_ulonglong2double(unsigned long long A) { return (double) A; } +double my_ulonglong2double(unsigned long long A); C_MODE_END #endif /* _AIX */ @@ -416,6 +424,7 @@ C_MODE_END #ifndef stdin #include <stdio.h> #endif +#include <stdarg.h> #ifdef HAVE_STDLIB_H #include <stdlib.h> #endif @@ -440,6 +449,9 @@ C_MODE_END #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif #ifdef HAVE_SYS_TIMEB_H #include <sys/timeb.h> /* Avoid warnings on SCO */ #endif @@ -478,14 +490,13 @@ C_MODE_END #include <assert.h> /* an assert that works at compile-time. only for constant expression */ -#ifndef __GNUC__ +#ifdef _some_old_compiler_that_does_not_understand_the_construct_below_ #define compile_time_assert(X) do { } while(0) #else #define compile_time_assert(X) \ do \ { \ - char compile_time_assert[(X) ? 1 : -1] \ - __attribute__ ((unused)); \ + typedef char compile_time_assert[(X) ? 1 : -1]; \ } while(0) #endif @@ -585,6 +596,8 @@ int __void__; #define UNINIT_VAR(x) x= x #endif +#include <my_valgrind.h> + /* Define some useful general macros */ #if !defined(max) #define max(a, b) ((a) > (b) ? (a) : (b)) @@ -604,6 +617,7 @@ typedef unsigned short ushort; #define test(a) ((a) ? 1 : 0) #define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0) #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0) +#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1)) #define test_all_bits(a,b) (((a) & (b)) == (b)) #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0]))) @@ -661,6 +675,7 @@ C_MODE_END # endif #endif +typedef char my_bool; /* Small bool; Needed by my_dbug.h */ #include <my_dbug.h> #define MIN_ARRAY_SIZE 0 /* Zero or One. Gcc allows zero*/ @@ -789,10 +804,10 @@ typedef SOCKET_SIZE_TYPE size_socket; #endif /* get memory in huncs */ #define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD) - /* Typical record cash */ -#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD) - /* Typical key cash */ -#define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD) + /* Typical record cache */ +#define RECORD_CACHE_SIZE (uint) (128*1024-MALLOC_OVERHEAD) + /* Typical key cache */ +#define KEY_CACHE_SIZE (uint) (128L*1024L*1024L-MALLOC_OVERHEAD) /* Default size of a key cache block */ #define KEY_CACHE_BLOCK_SIZE (uint) 1024 @@ -937,9 +952,10 @@ typedef long long my_ptrdiff_t; #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1)) #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double)) +#define ALIGN_MAX_UNIT (sizeof(double)) /* Size to make adressable obj. */ -#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t))) - /* Offset of field f in structure t */ +#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A), sizeof(double))) +/* Offset of field f in structure t */ #define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f) #define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size) #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B)) @@ -1105,7 +1121,6 @@ typedef off_t os_off_t; typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */ typedef short int15; /* Most effective integer 0 <= x <= 32767 */ typedef int myf; /* Type of MyFlags in my_funcs */ -typedef char my_bool; /* Small bool */ #if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus)) typedef char bool; /* Ordinary boolean values 0 1 */ #endif @@ -1172,9 +1187,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */ #define SCALE_SEC 100 #define SCALE_USEC 10000 #define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */ -#define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */ - - +#define MY_HOW_OFTEN_TO_WRITE 10000 /* How often we want info on screen */ /* Define-funktions for reading and storing in machine independent format @@ -1183,7 +1196,7 @@ typedef char bool; /* Ordinary boolean values 0 1 */ /* Optimized store functions for Intel x86 */ #if defined(__i386__) || defined(_WIN32) -#define sint2korr(A) (*((int16 *) (A))) +#define sint2korr(A) (*((const int16 *) (A))) #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ (((uint32) 255L << 24) | \ (((uint32) (uchar) (A)[2]) << 16) |\ @@ -1192,9 +1205,9 @@ typedef char bool; /* Ordinary boolean values 0 1 */ (((uint32) (uchar) (A)[2]) << 16) |\ (((uint32) (uchar) (A)[1]) << 8) | \ ((uint32) (uchar) (A)[0]))) -#define sint4korr(A) (*((long *) (A))) -#define uint2korr(A) (*((uint16 *) (A))) -#if defined(HAVE_purify) && !defined(_WIN32) +#define sint4korr(A) (*((const long *) (A))) +#define uint2korr(A) (*((const uint16 *) (A))) +#if defined(HAVE_valgrind) && !defined(_WIN32) #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\ (((uint32) ((uchar) (A)[1])) << 8) +\ (((uint32) ((uchar) (A)[2])) << 16)) @@ -1205,9 +1218,9 @@ typedef char bool; /* Ordinary boolean values 0 1 */ Please, note, uint3korr reads 4 bytes (not 3) ! It means, that you have to provide enough allocated space ! */ -#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF) -#endif /* HAVE_purify && !_WIN32 */ -#define uint4korr(A) (*((uint32 *) (A))) +#define uint3korr(A) (long) (*((const unsigned int *) (A)) & 0xFFFFFF) +#endif /* HAVE_valgrind && !_WIN32 */ +#define uint4korr(A) (*((const uint32 *) (A))) #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ (((uint32) ((uchar) (A)[1])) << 8) +\ (((uint32) ((uchar) (A)[2])) << 16) +\ @@ -1219,8 +1232,8 @@ typedef char bool; /* Ordinary boolean values 0 1 */ (((uint32) ((uchar) (A)[3])) << 24)) + \ (((ulonglong) ((uchar) (A)[4])) << 32) + \ (((ulonglong) ((uchar) (A)[5])) << 40)) -#define uint8korr(A) (*((ulonglong *) (A))) -#define sint8korr(A) (*((longlong *) (A))) +#define uint8korr(A) (*((const ulonglong *) (A))) +#define sint8korr(A) (*((const longlong *) (A))) #define int2store(T,A) *((uint16*) (T))= (uint16) (A) #define int3store(T,A) do { *(T)= (uchar) ((A));\ *(T+1)=(uchar) (((uint) (A) >> 8));\ @@ -1245,13 +1258,13 @@ typedef union { } doubleget_union; #define doubleget(V,M) \ do { doubleget_union _tmp; \ - _tmp.m[0] = *((long*)(M)); \ - _tmp.m[1] = *(((long*) (M))+1); \ + _tmp.m[0] = *((const long*)(M)); \ + _tmp.m[1] = *(((const long*) (M))+1); \ (V) = _tmp.v; } while(0) -#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \ - *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \ +#define doublestore(T,V) do { *((long *) T) = ((const doubleget_union *)&V)->m[0]; \ + *(((long *) T)+1) = ((const doubleget_union *)&V)->m[1]; \ } while (0) -#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0) +#define float4get(V,M) do { *((float *) &(V)) = *((const float*) (M)); } while(0) #define float8get(V,M) doubleget((V),(M)) #define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float)) #define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V),sizeof(float)) @@ -1467,6 +1480,17 @@ do { doubleget_union _tmp; \ #endif /* WORDS_BIGENDIAN */ +/* sprintf does not always return the number of bytes :- */ +#ifdef SPRINTF_RETURNS_INT +#define my_sprintf(buff,args) sprintf args +#else +#ifdef SPRINTF_RETURNS_PTR +#define my_sprintf(buff,args) ((int)(sprintf args - buff)) +#else +#define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff)) +#endif +#endif + #ifndef THREAD #define thread_safe_increment(V,L) (V)++ #define thread_safe_decrement(V,L) (V)-- @@ -1538,13 +1562,22 @@ inline void operator delete[](void*, void*) { /* Do nothing */ } #if !defined(max) #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) -#endif +#endif /* Only Linux is known to need an explicit sync of the directory to make sure a file creation/deletion/renaming in(from,to) this directory durable. */ #ifdef TARGET_OS_LINUX #define NEED_EXPLICIT_SYNC_DIR 1 +#else +/* + On linux default rwlock scheduling policy is good enough for + waiting_threads.c, on other systems use our special implementation + (which is slower). + + QQ perhaps this should be tested in configure ? how ? +*/ +#define WT_RWLOCKS_USE_MUTEXES 1 #endif #if !defined(__cplusplus) && !defined(bool) @@ -1599,4 +1632,23 @@ static inline double rint(double x) #endif #endif +/* Provide __func__ macro definition for platforms that miss it. */ +#if __STDC_VERSION__ < 199901L +# if __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ "<unknown>" +# endif +#elif defined(_MSC_VER) +# if _MSC_VER < 1300 +# define __func__ "<unknown>" +# else +# define __func__ __FUNCTION__ +# endif +#elif defined(__BORLANDC__) +# define __func__ __FUNC__ +#else +# define __func__ "<unknown>" +#endif + #endif /* my_global_h */ diff --git a/include/my_handler.h b/include/my_handler.h new file mode 100644 index 00000000000..ca324c5b881 --- /dev/null +++ b/include/my_handler.h @@ -0,0 +1,56 @@ +/* Copyright (c) Monty Program Ab; 1991-2011 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; version 2 + of the License. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#ifndef _my_handler_h +#define _my_handler_h + +/* + There is a hard limit for the maximum number of keys as there are only + 8 bits in the index file header for the number of keys in a table. + This means that 0..255 keys can exist for a table. The idea of + HA_MAX_POSSIBLE_KEY is to ensure that one can use myisamchk & tools on + a MyISAM table for which one has more keys than MyISAM is normally + compiled for. If you don't have this, you will get a core dump when + running myisamchk compiled for 128 keys on a table with 255 keys. +*/ + +#define HA_MAX_POSSIBLE_KEY 255 /* For myisamchk */ +/* + The following defines can be increased if necessary. + But beware the dependency of HA_MAX_POSSIBLE_KEY_BUFF and HA_MAX_KEY_LENGTH. +*/ + +#define HA_MAX_KEY_LENGTH 1000 /* Max length in bytes */ +#define HA_MAX_KEY_SEG 32 /* Max segments for key */ + +#define HA_MAX_POSSIBLE_KEY_BUFF (HA_MAX_KEY_LENGTH + 24+ 6+6) +#define HA_MAX_KEY_BUFF (HA_MAX_KEY_LENGTH+HA_MAX_KEY_SEG*6+8+8) +#define HA_MAX_MSG_BUF 1024 /* used in CHECK TABLE, REPAIR TABLE */ + +/* + Inside an in-memory data record, memory pointers to pieces of the + record (like BLOBs) are stored in their native byte order and in + this amount of bytes. +*/ +#define portable_sizeof_char_ptr 8 + +/* Register / unregister errors for my_error() */ + +extern void my_handler_error_register(void); +extern void my_handler_error_unregister(void); + +#endif /* _my_handler_h */ diff --git a/include/my_pthread.h b/include/my_pthread.h index 87cdaaad0dd..1f5be847da6 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc, + 2010-2011 Oracle and/or its affiliates, 2009-2010 Monty Program Ab. 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 @@ -84,25 +85,27 @@ typedef volatile LONG my_pthread_once_t; so it can be used directly as a 64 bit value. The value stored is in 100ns units. */ - union ft64 { +union ft64 { FILETIME ft; __int64 i64; - }; +}; + struct timespec { union ft64 tv; /* The max timeout value in millisecond for pthread_cond_timedwait */ long max_timeout_msec; }; -#define set_timespec(ABSTIME,SEC) { \ - GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \ - (ABSTIME).tv.i64+= (__int64)(SEC)*10000000; \ - (ABSTIME).max_timeout_msec= (long)((SEC)*1000); \ -} -#define set_timespec_nsec(ABSTIME,NSEC) { \ - GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \ - (ABSTIME).tv.i64+= (__int64)(NSEC)/100; \ - (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \ -} + +#define set_timespec_time_nsec(ABSTIME,TIME,NSEC) do { \ + (ABSTIME).tv.i64= (TIME)+(__int64)(NSEC)/100; \ + (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \ +} while(0) + +#define set_timespec_nsec(ABSTIME,NSEC) do { \ + union ft64 tv; \ + GetSystemTimeAsFileTime(&tv.ft); \ + set_timespec_time_nsec((ABSTIME), tv.i64, (NSEC)); \ +} while(0) void win_pthread_init(void); int win_pthread_setspecific(void *A,void *B,uint length); @@ -123,9 +126,7 @@ int my_pthread_once(my_pthread_once_t *once_control,void (*init_routine)(void)); struct tm *localtime_r(const time_t *timep,struct tm *tmp); struct tm *gmtime_r(const time_t *timep,struct tm *tmp); - void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ - #ifndef ETIMEDOUT #define ETIMEDOUT 145 /* Win32 might not have this */ #endif @@ -133,6 +134,8 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ #define HAVE_LOCALTIME_R 1 #define _REENTRANT 1 #define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 +#define PTHREAD_STACK_MIN 65536 + /* Windows has two ways to use thread local storage. The most efficient @@ -166,7 +169,7 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ #define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0) #define pthread_mutex_lock(A) (EnterCriticalSection(A),0) #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 my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B)) #define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) @@ -180,6 +183,7 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ #define pthread_detach_this_thread() #define pthread_condattr_init(A) #define pthread_condattr_destroy(A) +#define pthread_yield() Sleep(0) /* according to MSDN */ #define my_pthread_getprio(thread_id) pthread_dummy(0) @@ -219,7 +223,11 @@ extern int my_pthread_getprio(pthread_t thread_id); typedef void *(* pthread_handler)(void *); #define my_pthread_once_t pthread_once_t +#if defined(PTHREAD_ONCE_INITIALIZER) +#define MY_PTHREAD_ONCE_INIT PTHREAD_ONCE_INITIALIZER +#else #define MY_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT +#endif #define my_pthread_once(C,F) pthread_once(C,F) /* Test first for RTS or FSU threads */ @@ -246,13 +254,13 @@ int my_sigwait(const sigset_t *set,int *sig); #ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT #ifndef SAFE_MUTEX -#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b)) -extern int my_pthread_mutex_init(pthread_mutex_t *mp, - const pthread_mutexattr_t *attr); +#define pthread_mutex_init(a,b) my_pthread_mutex_noposix_init((a),(b)) +extern int my_pthread_mutex_noposix_init(pthread_mutex_t *mp, + const pthread_mutexattr_t *attr); #endif /* SAFE_MUTEX */ -#define pthread_cond_init(a,b) my_pthread_cond_init((a),(b)) -extern int my_pthread_cond_init(pthread_cond_t *mp, - const pthread_condattr_t *attr); +#define pthread_cond_init(a,b) my_pthread_cond_noposix_init((a),(b)) +extern int my_pthread_cond_noposix_init(pthread_cond_t *mp, + const pthread_condattr_t *attr); #endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */ #if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK) @@ -412,64 +420,80 @@ void my_pthread_attr_getstacksize(pthread_attr_t *attrib, size_t *size); int my_pthread_mutex_trylock(pthread_mutex_t *mutex); #endif +#if !defined(HAVE_PTHREAD_YIELD_ONE_ARG) && !defined(HAVE_PTHREAD_YIELD_ZERO_ARG) +/* no pthread_yield() available */ +#ifdef HAVE_SCHED_YIELD +#define pthread_yield() sched_yield() +#elif defined(HAVE_PTHREAD_YIELD_NP) /* can be Mac OS X */ +#define pthread_yield() pthread_yield_np() +#elif defined(HAVE_THR_YIELD) +#define pthread_yield() thr_yield() +#endif +#endif + /* The defines set_timespec and set_timespec_nsec should be used for calculating an absolute time at which pthread_cond_timedwait should timeout */ -#ifdef HAVE_TIMESPEC_TS_SEC -#ifndef set_timespec -#define set_timespec(ABSTIME,SEC) \ -{ \ - (ABSTIME).ts_sec=time(0) + (time_t) (SEC); \ - (ABSTIME).ts_nsec=0; \ -} -#endif /* !set_timespec */ + +#define set_timespec(ABSTIME,SEC) set_timespec_nsec((ABSTIME),(SEC)*1000000000ULL) + #ifndef set_timespec_nsec -#define set_timespec_nsec(ABSTIME,NSEC) \ -{ \ - ulonglong now= my_getsystime() + (NSEC/100); \ - (ABSTIME).ts_sec= (now / ULL(10000000)); \ - (ABSTIME).ts_nsec= (now % ULL(10000000) * 100 + ((NSEC) % 100)); \ -} +#define set_timespec_nsec(ABSTIME,NSEC) \ + set_timespec_time_nsec((ABSTIME),my_getsystime(),(NSEC)) #endif /* !set_timespec_nsec */ + +/* adapt for two different flavors of struct timespec */ +#ifdef HAVE_TIMESPEC_TS_SEC +#define MY_tv_sec ts_sec +#define MY_tv_nsec ts_nsec #else -#ifndef set_timespec -#define set_timespec(ABSTIME,SEC) \ -{\ - struct timeval tv;\ - gettimeofday(&tv,0);\ - (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\ - (ABSTIME).tv_nsec=tv.tv_usec*1000;\ -} -#endif /* !set_timespec */ -#ifndef set_timespec_nsec -#define set_timespec_nsec(ABSTIME,NSEC) \ -{\ - ulonglong now= my_getsystime() + (NSEC/100); \ - (ABSTIME).tv_sec= (time_t) (now / ULL(10000000)); \ - (ABSTIME).tv_nsec= (long) (now % ULL(10000000) * 100 + ((NSEC) % 100)); \ -} -#endif /* !set_timespec_nsec */ +#define MY_tv_sec tv_sec +#define MY_tv_nsec tv_nsec #endif /* HAVE_TIMESPEC_TS_SEC */ - /* safe_mutex adds checking to mutex for easier debugging */ +#ifndef set_timespec_time_nsec +#define set_timespec_time_nsec(ABSTIME,TIME,NSEC) do { \ + ulonglong nsec= (NSEC); \ + ulonglong now= (TIME) + (nsec/100); \ + (ABSTIME).MY_tv_sec= (now / ULL(10000000)); \ + (ABSTIME).MY_tv_nsec= (now % ULL(10000000) * 100 + (nsec % 100)); \ +} while(0) +#endif /* !set_timespec_time_nsec */ + +/* safe_mutex adds checking to mutex for easier debugging */ #if defined(__NETWARE__) && !defined(SAFE_MUTEX_DETECT_DESTROY) #define SAFE_MUTEX_DETECT_DESTROY #endif +struct st_hash; typedef struct st_safe_mutex_t { pthread_mutex_t global,mutex; - const char *file; + const char *file, *name; uint line,count; + myf create_flags, active_flags; + ulong id; pthread_t thread; + struct st_hash *locked_mutex, *used_mutex; + struct st_safe_mutex_t *prev, *next; #ifdef SAFE_MUTEX_DETECT_DESTROY struct st_safe_mutex_info_t *info; /* to track destroying of mutexes */ #endif } safe_mutex_t; +typedef struct st_safe_mutex_deadlock_t +{ + const char *file, *name; + safe_mutex_t *mutex; + uint line; + ulong count; + ulong id; + my_bool warning_only; +} safe_mutex_deadlock_t; + #ifdef SAFE_MUTEX_DETECT_DESTROY /* Used to track the destroying of mutexes. This needs to be a seperate @@ -487,8 +511,10 @@ typedef struct st_safe_mutex_info_t #endif /* SAFE_MUTEX_DETECT_DESTROY */ int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr, + const char *name, myf my_flags, const char *file, uint line); -int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line); +int safe_mutex_lock(safe_mutex_t *mp, myf my_flags, const char *file, + uint line); int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line); int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line); int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file, @@ -498,8 +524,12 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file, uint line); void safe_mutex_global_init(void); void safe_mutex_end(FILE *file); +void safe_mutex_free_deadlock_data(safe_mutex_t *mp); /* Wrappers if safe mutex is actually used */ +#define MYF_TRY_LOCK 1 +#define MYF_NO_DEADLOCK_DETECTION 2 + #ifdef SAFE_MUTEX #undef pthread_mutex_init #undef pthread_mutex_lock @@ -511,13 +541,15 @@ void safe_mutex_end(FILE *file); #undef pthread_cond_wait #undef pthread_cond_timedwait #undef pthread_mutex_trylock -#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),__FILE__,__LINE__) -#define pthread_mutex_lock(A) safe_mutex_lock((A), FALSE, __FILE__, __LINE__) +#define my_pthread_mutex_init(A,B,C,D) safe_mutex_init((A),(B),(C),(D),__FILE__,__LINE__) +#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),#A,0,__FILE__,__LINE__) +#define pthread_mutex_lock(A) safe_mutex_lock((A), 0, __FILE__, __LINE__) +#define my_pthread_mutex_lock(A,B) safe_mutex_lock((A), (B), __FILE__, __LINE__) #define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__) #define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__) #define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__) #define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__) -#define pthread_mutex_trylock(A) safe_mutex_lock((A), TRUE, __FILE__, __LINE__) +#define pthread_mutex_trylock(A) safe_mutex_lock((A), MYF_TRY_LOCK, __FILE__, __LINE__) #define pthread_mutex_t safe_mutex_t #define safe_mutex_assert_owner(mp) \ DBUG_ASSERT((mp)->count > 0 && \ @@ -526,8 +558,11 @@ void safe_mutex_end(FILE *file); DBUG_ASSERT(! (mp)->count || \ ! pthread_equal(pthread_self(), (mp)->thread)) #else -#define safe_mutex_assert_owner(mp) -#define safe_mutex_assert_not_owner(mp) +#define my_pthread_mutex_init(A,B,C,D) pthread_mutex_init((A),(B)) +#define my_pthread_mutex_lock(A,B) pthread_mutex_lock(A) +#define safe_mutex_assert_owner(mp) do {} while(0) +#define safe_mutex_assert_not_owner(mp) do {} while(0) +#define safe_mutex_free_deadlock_data(mp) do {} while(0) #endif /* SAFE_MUTEX */ #if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) @@ -653,6 +688,7 @@ extern pthread_mutexattr_t my_errorcheck_mutexattr; typedef ulong my_thread_id; +extern void my_threadattr_global_init(void); extern my_bool my_thread_global_init(void); extern void my_thread_global_end(void); extern my_bool my_thread_init(void); @@ -661,22 +697,23 @@ extern const char *my_thread_name(void); extern my_thread_id my_thread_dbug_id(void); extern int pthread_no_free(void *); extern int pthread_dummy(int); +extern void my_mutex_init(); +extern void my_mutex_end(); /* All thread specific variables are in the following struct */ #define THREAD_NAME_SIZE 10 #ifndef DEFAULT_THREAD_STACK -#if SIZEOF_CHARP > 4 /* - MySQL can survive with 32K, but some glibc libraries require > 128K stack - To resolve hostnames. Also recursive stored procedures needs stack. + We need to have at least 256K stack to handle calls to myisamchk_init() + with the current number of keys and key parts. */ -#define DEFAULT_THREAD_STACK (256*1024L) -#else -#define DEFAULT_THREAD_STACK (192*1024) -#endif +#define DEFAULT_THREAD_STACK (288*1024L) #endif +#define MY_PTHREAD_LOCK_READ 0 +#define MY_PTHREAD_LOCK_WRITE 1 + struct st_my_thread_var { int thr_errno; @@ -691,6 +728,9 @@ struct st_my_thread_var my_bool init; struct st_my_thread_var *next,**prev; void *opt_info; + uint lock_type; /* used by conditional release the queue */ + void *stack_ends_here; + safe_mutex_t *mutex_in_use; #ifndef DBUG_OFF void *dbug; char name[THREAD_NAME_SIZE+1]; @@ -698,7 +738,10 @@ struct st_my_thread_var }; extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); +extern void **my_thread_var_dbug(); +extern safe_mutex_t **my_thread_var_mutex_in_use(); extern uint my_thread_end_wait_time; +extern my_bool safe_mutex_deadlock_detector; #define my_thread_var (_my_thread_var()) #define my_errno my_thread_var->thr_errno /* diff --git a/include/my_stacktrace.h b/include/my_stacktrace.h index 30cac3871c5..a2fd89852fc 100644 --- a/include/my_stacktrace.h +++ b/include/my_stacktrace.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2001, 2011, Oracle and/or its affiliates. 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 diff --git a/include/my_sys.h b/include/my_sys.h index f6cd9dada99..93f413092e0 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (C) 2000-2003 MySQL AB 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 @@ -25,19 +25,6 @@ typedef struct my_aio_result { } my_aio_result; #endif -#ifdef HAVE_VALGRIND -# include <valgrind/memcheck.h> -# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len) -# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len) -# define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len) -# define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len) -#else /* HAVE_VALGRIND */ -# define MEM_UNDEFINED(a,len) ((void) 0) -# define MEM_NOACCESS(a,len) ((void) 0) -# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0) -# define MEM_CHECK_DEFINED(a,len) ((void) 0) -#endif /* HAVE_VALGRIND */ - #ifndef THREAD extern int NEAR my_errno; /* Last error in mysys */ #else @@ -73,12 +60,14 @@ extern int NEAR my_errno; /* Last error in mysys */ #define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */ #define MY_REDEL_MAKE_BACKUP 256 #define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */ -#define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */ +#define MY_SHORT_WAIT 64 /* my_lock() don't wait if can't lock */ +#define MY_FORCE_LOCK 128 /* use my_lock() even if disable_locking */ +#define MY_NO_WAIT 256 /* my_lock() don't wait at all */ #define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */ #define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */ #define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */ #define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */ -#define MY_DONT_OVERWRITE_FILE 1024 /* my_copy: Don't overwrite file */ +#define MY_DONT_OVERWRITE_FILE 2048 /* my_copy: Don't overwrite file */ #define MY_THREADSAFE 2048 /* my_seek(): lock fd mutex */ #define MY_SYNC 4096 /* my_copy(): sync dst file */ @@ -102,9 +91,11 @@ extern int NEAR my_errno; /* Last error in mysys */ #define ME_COLOUR1 ((1 << ME_HIGHBYTE)) /* Possibly error-colours */ #define ME_COLOUR2 ((2 << ME_HIGHBYTE)) #define ME_COLOUR3 ((3 << ME_HIGHBYTE)) -#define ME_FATALERROR 1024 /* Fatal statement error */ -#define ME_NO_WARNING_FOR_ERROR 2048 /* Don't push a warning for error */ -#define ME_NO_SP_HANDLER 4096 /* Don't call stored routine error handlers */ +#define ME_JUST_INFO 1024 /**< not error but just info */ +#define ME_JUST_WARNING 2048 /**< not error but just warning */ +#define ME_FATALERROR 4096 /* Fatal statement error */ +#define ME_NO_WARNING_FOR_ERROR 8192 /* Don't push a warning for error */ +#define ME_NO_SP_HANDLER 16384 /* Don't call stored routine error handlers */ /* Bits in last argument to fn_format */ #define MY_REPLACE_DIR 1 /* replace dir in name with 'dir' */ @@ -144,6 +135,9 @@ extern int NEAR my_errno; /* Last error in mysys */ #define GETDATE_GMT 8 #define GETDATE_FIXEDLENGTH 16 +/* Extra length needed for filename if one calls my_create_backup_name */ +#define MY_BACKUP_NAME_EXTRA_LENGTH 17 + /* defines when allocating data */ #ifdef SAFEMALLOC #define my_malloc(SZ,FLAG) _mymalloc((SZ), __FILE__, __LINE__, FLAG ) @@ -154,7 +148,6 @@ extern int NEAR my_errno; /* Last error in mysys */ #define my_memdup(A,B,C) _my_memdup((A),(B), __FILE__,__LINE__,C) #define my_strdup(A,C) _my_strdup((A), __FILE__,__LINE__,C) #define my_strndup(A,B,C) _my_strndup((A),(B),__FILE__,__LINE__,C) -#define TRASH(A,B) do { bfill(A, B, 0x8F); MEM_UNDEFINED(A, B); } while (0) #define QUICK_SAFEMALLOC sf_malloc_quick=1 #define NORMAL_SAFEMALLOC sf_malloc_quick=0 extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick; @@ -182,7 +175,6 @@ extern char *my_strndup(const char *from, size_t length, #define CALLER_INFO_PROTO /* nothing */ #define CALLER_INFO /* nothing */ #define ORIG_CALLER_INFO /* nothing */ -#define TRASH(A,B) do{MEM_CHECK_ADDRESSABLE(A,B);MEM_UNDEFINED(A,B);} while (0) #endif #if defined(ENABLED_DEBUG_SYNC) @@ -232,6 +224,7 @@ extern int errno; /* declare errno */ #endif /* #ifndef errno */ extern char *home_dir; /* Home directory for user */ extern const char *my_progname; /* program-name (printed in errors) */ +extern const char *my_progname_short; /* like above but without directory */ extern char NEAR curr_dir[]; /* Current directory for user */ extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags); extern int (*fatal_error_handler_hook)(uint my_err, const char *str, @@ -239,6 +232,9 @@ extern int (*fatal_error_handler_hook)(uint my_err, const char *str, extern uint my_file_limit; extern ulong my_thread_stack_size; +extern const char *(*proc_info_hook)(void *, const char *, const char *, + const char *, const unsigned int); + #ifdef HAVE_LARGE_PAGES extern my_bool my_use_large_pages; extern uint my_large_page_size; @@ -252,6 +248,7 @@ extern CHARSET_INFO compiled_charsets[]; /* statistics */ extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; extern ulong my_file_total_opened; +extern ulong my_sync_count; extern uint mysys_usage_id; extern my_bool my_init_done; @@ -272,6 +269,7 @@ extern size_t sf_malloc_cur_memory, sf_malloc_max_memory; extern ulong my_default_record_cache_size; extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io, NEAR my_disable_flush_key_blocks, NEAR my_disable_symlinks; +extern my_bool my_disable_sync; extern char wild_many,wild_one,wild_prefix; extern const char *charsets_dir; /* from default.c */ @@ -309,7 +307,13 @@ enum flush_type As my_disable_flush_pagecache_blocks is always 0, the following option is strictly equivalent to FLUSH_KEEP */ - FLUSH_FORCE_WRITE + FLUSH_FORCE_WRITE, + /** + @brief like FLUSH_KEEP but return immediately if file is already being + flushed (even partially) by another thread; only for page cache, + forbidden for key cache. + */ + FLUSH_KEEP_LAZY }; typedef struct st_record_cache /* Used when cacheing records */ @@ -568,6 +572,7 @@ my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */ *(info)->current_pos) typedef uint32 ha_checksum; +extern ha_checksum my_crc_dbug_check; /* Define the type of function to be passed to process_default_option_files */ typedef int (*Process_option_func)(void *ctx, const char *group_name, @@ -667,6 +672,7 @@ extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags); extern FILE *my_freopen(const char *path, const char *mode, FILE *stream); extern int my_fclose(FILE *fd,myf MyFlags); extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags); +extern int my_chmod(const char *name, mode_t mode, myf my_flags); extern int my_sync(File fd, myf my_flags); extern int my_sync_dir(const char *dir_name, myf my_flags); extern int my_sync_dir_by_file(const char *file_name, myf my_flags); @@ -674,6 +680,8 @@ extern int my_error _VARARGS((int nr,myf MyFlags, ...)); extern int my_printf_error _VARARGS((uint my_err, const char *format, myf MyFlags, ...)) ATTRIBUTE_FORMAT(printf, 2, 4); +extern int my_printv_error(uint error, const char *format, myf MyFlags, + va_list ap); extern int my_error_register(const char **errmsgs, int first, int last); extern const char **my_error_unregister(int first, int last); extern int my_message(uint my_err, const char *str,myf MyFlags); @@ -681,7 +689,10 @@ extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags); extern int my_message_curses(uint my_err, const char *str,myf MyFlags); extern my_bool my_init(void); extern void my_end(int infoflag); -extern int my_redel(const char *from, const char *to, int MyFlags); +extern int my_redel(const char *from, const char *to, time_t backup_time_stamp, + myf MyFlags); +void my_create_backup_name(char *to, const char *from, + time_t backup_time_stamp); extern int my_copystat(const char *from, const char *to, int MyFlags); extern char * my_filename(File fd); @@ -797,6 +808,9 @@ extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length); extern my_off_t my_b_filelength(IO_CACHE *info); extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...); extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap); +extern int init_strvar_from_file(char *var, int max_size, IO_CACHE *f, + const char *default_val); +extern int init_intvar_from_file(int* var, IO_CACHE* f, int default_val); extern my_bool open_cached_file(IO_CACHE *cache,const char *dir, const char *prefix, size_t cache_size, myf cache_myflags); @@ -816,7 +830,7 @@ extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array,uint element_size, extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size, uint init_alloc,uint alloc_increment CALLER_INFO_PROTO); -extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element); +extern my_bool insert_dynamic(DYNAMIC_ARRAY *array, const uchar * element); extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array); extern uchar *pop_dynamic(DYNAMIC_ARRAY*); extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index); @@ -885,11 +899,21 @@ extern my_bool my_compress(uchar *, size_t *, size_t *); extern my_bool my_uncompress(uchar *, size_t , size_t *); extern uchar *my_compress_alloc(const uchar *packet, size_t *len, size_t *complen); +extern void *my_az_allocator(void *dummy, unsigned int items, unsigned int size); +extern void my_az_free(void *dummy, void *address); +extern int my_compress_buffer(uchar *dest, size_t *destLen, + const uchar *source, size_t sourceLen); extern int packfrm(uchar *, size_t, uchar **, size_t *); extern int unpackfrm(uchar **, size_t *, const uchar *); extern ha_checksum my_checksum(ha_checksum crc, const uchar *mem, size_t count); +#ifndef DBUG_OFF +extern void my_debug_put_break_here(void); +#else +#define my_debug_put_break_here() do {} while(0) +#endif + extern void my_sleep(ulong m_seconds); extern ulong crc32(ulong crc, const uchar *buf, uint len); extern uint my_set_max_open_files(uint files); @@ -948,6 +972,22 @@ int my_getpagesize(void); int my_msync(int, void *, size_t, int); +#define MY_UUID_SIZE 16 +#define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12) + +void my_uuid_init(ulong seed1, ulong seed2); +void my_uuid(uchar *guid); +void my_uuid2str(const uchar *guid, char *s); +void my_uuid_end(); + +struct my_rnd_struct { + unsigned long seed1,seed2,max_value; + double max_value_dbl; +}; + +void my_rnd_init(struct my_rnd_struct *rand_st, ulong seed1, ulong seed2); +double my_rnd(struct my_rnd_struct *rand_st); + /* character sets */ extern uint get_charset_number(const char *cs_name, uint cs_flags); extern uint get_collation_number(const char *name); diff --git a/include/my_time.h b/include/my_time.h index ab6fe2f1503..3e198d9c8e1 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2004, 2011, Oracle and/or its affiliates. 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 diff --git a/include/my_tree.h b/include/my_tree.h index 24bbdd54019..ceeb849ad0c 100644 --- a/include/my_tree.h +++ b/include/my_tree.h @@ -51,7 +51,7 @@ typedef struct st_tree { TREE_ELEMENT *root,null_element; TREE_ELEMENT **parents[MAX_TREE_HEIGHT]; uint offset_to_key,elements_in_tree,size_of_element; - ulong memory_limit, allocated; + size_t memory_limit, allocated; qsort_cmp2 compare; void *custom_arg; MEM_ROOT mem_root; @@ -61,13 +61,13 @@ typedef struct st_tree { } TREE; /* Functions on whole tree */ -void init_tree(TREE *tree, ulong default_alloc_size, ulong memory_limit, +void init_tree(TREE *tree, size_t default_alloc_size, size_t memory_limit, int size, qsort_cmp2 compare, my_bool with_delete, tree_element_free free_element, void *custom_arg); void delete_tree(TREE*); void reset_tree(TREE*); - /* similar to delete tree, except we do not my_free() blocks in mem_root - */ + + /* similar to delete tree, except we do not my_free() blocks in mem_root */ #define is_tree_inited(tree) ((tree)->root != 0) /* Functions on leafs */ @@ -86,6 +86,7 @@ void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, int r_offs); ha_rows tree_record_pos(TREE *tree, const void *key, enum ha_rkey_function search_flag, void *custom_arg); +#define reset_free_element(tree) (tree)->free= 0 #define TREE_ELEMENT_EXTRA_SIZE (sizeof(TREE_ELEMENT) + sizeof(void*)) diff --git a/include/my_valgrind.h b/include/my_valgrind.h new file mode 100644 index 00000000000..da434454565 --- /dev/null +++ b/include/my_valgrind.h @@ -0,0 +1,42 @@ +/* Copyright (C) 2010 Monty Program Ab + + 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 */ + + +/* Some defines to make it easier to use valgrind */ + +#ifdef HAVE_valgrind +#define IF_VALGRIND(A,B) (A) +#else +#define IF_VALGRIND(A,B) (B) +#endif + +#if defined(HAVE_valgrind)&& defined(HAVE_VALGRIND_MEMCHECK_H) +#include <valgrind/memcheck.h> +#define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len) +#define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len) +#define MEM_CHECK_ADDRESSABLE(a,len) VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,len) +#define MEM_CHECK_DEFINED(a,len) VALGRIND_CHECK_MEM_IS_DEFINED(a,len) +#else /* HAVE_VALGRIND */ +# define MEM_UNDEFINED(a,len) ((void) 0) +# define MEM_NOACCESS(a,len) ((void) 0) +# define MEM_CHECK_ADDRESSABLE(a,len) ((void) 0) +# define MEM_CHECK_DEFINED(a,len) ((void) 0) +#endif /* HAVE_VALGRIND */ + +#ifdef SAFEMALLOC +#define TRASH(A,B) do { bfill(A, B, 0x8F); MEM_UNDEFINED(A, B); } while (0) +#else +#define TRASH(A,B) do{MEM_CHECK_ADDRESSABLE(A,B);MEM_UNDEFINED(A,B);} while (0) +#endif diff --git a/include/myisam.h b/include/myisam.h index 92e6699896a..34ed58d354c 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2011, Oracle and/or its affiliates. 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 @@ -32,33 +32,13 @@ extern "C" { #ifndef _keycache_h #include "keycache.h" #endif -#include <mysql/plugin.h> +#include "my_handler.h" #include "my_compare.h" +#include <myisamchk.h> +#include <mysql/plugin.h> /* - There is a hard limit for the maximum number of keys as there are only - 8 bits in the index file header for the number of keys in a table. - This means that 0..255 keys can exist for a table. The idea of - HA_MAX_POSSIBLE_KEY is to ensure that one can use myisamchk & tools on - a MyISAM table for which one has more keys than MyISAM is normally - compiled for. If you don't have this, you will get a core dump when - running myisamchk compiled for 128 keys on a table with 255 keys. -*/ - -#define HA_MAX_POSSIBLE_KEY 255 /* For myisamchk */ -/* - The following defines can be increased if necessary. - But beware the dependency of MI_MAX_POSSIBLE_KEY_BUFF and HA_MAX_KEY_LENGTH. -*/ - -#define HA_MAX_KEY_LENGTH 1000 /* Max length in bytes */ -#define HA_MAX_KEY_SEG 16 /* Max segments for key */ - -#define HA_MAX_POSSIBLE_KEY_BUFF (HA_MAX_KEY_LENGTH + 24+ 6+6) -#define HA_MAX_KEY_BUFF (HA_MAX_KEY_LENGTH+HA_MAX_KEY_SEG*6+8+8) - -/* - Limit max keys according to HA_MAX_POSSIBLE_KEY + Limit max keys according to HA_MAX_POSSIBLE_KEY; See myisamchk.h for details */ #if MAX_INDEXES > HA_MAX_POSSIBLE_KEY @@ -68,15 +48,7 @@ extern "C" { #endif #define MI_MAX_POSSIBLE_KEY_BUFF HA_MAX_POSSIBLE_KEY_BUFF -/* - The following defines can be increased if necessary. - But beware the dependency of MI_MAX_POSSIBLE_KEY_BUFF and MI_MAX_KEY_LENGTH. -*/ -#define MI_MAX_KEY_LENGTH 1000 /* Max length in bytes */ -#define MI_MAX_KEY_SEG 16 /* Max segments for key */ -#define MI_MAX_KEY_BUFF (MI_MAX_KEY_LENGTH+MI_MAX_KEY_SEG*6+8+8) -#define MI_MAX_MSG_BUF 1024 /* used in CHECK TABLE, REPAIR TABLE */ #define MI_NAME_IEXT ".MYI" #define MI_NAME_DEXT ".MYD" @@ -255,7 +227,7 @@ struct st_mi_bit_buff; typedef struct st_columndef /* column information */ { - int16 type; /* en_fieldtype */ + enum en_fieldtype type; uint16 length; /* length of field */ uint32 offset; /* Offset to position in row */ uint8 null_bit; /* If column may be 0 */ @@ -270,7 +242,6 @@ typedef struct st_columndef /* column information */ #endif } MI_COLUMNDEF; - extern char * myisam_log_filename; /* Name of logfile */ extern ulong myisam_block_size; extern ulong myisam_concurrent_insert; @@ -320,13 +291,15 @@ extern int mi_extra(struct st_myisam_info *file, enum ha_extra_function function, void *extra_arg); extern int mi_reset(struct st_myisam_info *file); -extern ha_rows mi_records_in_range(MI_INFO *info, int inx, +extern ha_rows mi_records_in_range(MI_INFO *info,int inx, key_range *min_key, key_range *max_key); extern int mi_log(int activate_log); extern int mi_is_changed(struct st_myisam_info *info); extern int mi_delete_all_rows(struct st_myisam_info *info); extern ulong _mi_calc_blob_length(uint length , const uchar *pos); extern uint mi_get_pointer_length(ulonglong file_length, uint def); +extern int mi_make_backup_of_index(struct st_myisam_info *info, + time_t backup_time, myf flags); #define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for mmap file */ /* this is used to pass to mysql_myisamchk_table */ @@ -334,195 +307,113 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def); #define MYISAMCHK_REPAIR 1 /* equivalent to myisamchk -r */ #define MYISAMCHK_VERIFY 2 /* Verify, run repair if failure */ -/* - Definitions needed for myisamchk.c - - Entries marked as "QQ to be removed" are NOT used to - pass check/repair options to mi_check.c. They are used - internally by myisamchk.c or/and ha_myisam.cc and should NOT - be stored together with other flags. They should be removed - from the following list to make addition of new flags possible. -*/ - -#define T_AUTO_INC 1 -#define T_AUTO_REPAIR 2 /* QQ to be removed */ -#define T_BACKUP_DATA 4 -#define T_CALC_CHECKSUM 8 -#define T_CHECK 16 /* QQ to be removed */ -#define T_CHECK_ONLY_CHANGED 32 /* QQ to be removed */ -#define T_CREATE_MISSING_KEYS 64 -#define T_DESCRIPT 128 -#define T_DONT_CHECK_CHECKSUM 256 -#define T_EXTEND 512 -#define T_FAST (1L << 10) /* QQ to be removed */ -#define T_FORCE_CREATE (1L << 11) /* QQ to be removed */ -#define T_FORCE_UNIQUENESS (1L << 12) -#define T_INFO (1L << 13) -#define T_MEDIUM (1L << 14) -#define T_QUICK (1L << 15) /* QQ to be removed */ -#define T_READONLY (1L << 16) /* QQ to be removed */ -#define T_REP (1L << 17) -#define T_REP_BY_SORT (1L << 18) /* QQ to be removed */ -#define T_REP_PARALLEL (1L << 19) /* QQ to be removed */ -#define T_RETRY_WITHOUT_QUICK (1L << 20) -#define T_SAFE_REPAIR (1L << 21) -#define T_SILENT (1L << 22) -#define T_SORT_INDEX (1L << 23) /* QQ to be removed */ -#define T_SORT_RECORDS (1L << 24) /* QQ to be removed */ -#define T_STATISTICS (1L << 25) -#define T_UNPACK (1L << 26) -#define T_UPDATE_STATE (1L << 27) -#define T_VERBOSE (1L << 28) -#define T_VERY_SILENT (1L << 29) -#define T_WAIT_FOREVER (1L << 30) -#define T_WRITE_LOOP ((ulong) 1L << 31) - -#define T_REP_ANY (T_REP | T_REP_BY_SORT | T_REP_PARALLEL) - -/* - Flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed - to mi_check.c follows: -*/ - -#define TT_USEFRM 1 -#define TT_FOR_UPGRADE 2 +typedef uint mi_bit_type; -#define O_NEW_INDEX 1 /* Bits set in out_flag */ -#define O_NEW_DATA 2 -#define O_DATA_LOST 4 +typedef struct st_mi_bit_buff +{ /* Used for packing of record */ + mi_bit_type current_byte; + uint bits; + uchar *pos, *end, *blob_pos, *blob_end; + uint error; +} MI_BIT_BUFF; -/* these struct is used by my_check to tell it what to do */ -typedef struct st_sort_key_blocks /* Used when sorting */ +typedef struct st_sort_info { - uchar *buff,*end_pos; - uchar lastkey[MI_MAX_POSSIBLE_KEY_BUFF]; - uint last_length; - int inited; -} SORT_KEY_BLOCKS; - - -/* - MyISAM supports several statistics collection methods. Currently statistics - collection method is not stored in MyISAM file and has to be specified for - each table analyze/repair operation in MI_CHECK::stats_method. -*/ +#ifdef THREAD + /* sync things */ + pthread_mutex_t mutex; + pthread_cond_t cond; +#endif + MI_INFO *info; + HA_CHECK *param; + uchar *buff; + SORT_KEY_BLOCKS *key_block, *key_block_end; + SORT_FT_BUF *ft_buf; + my_off_t filelength, dupp, buff_length; + ha_rows max_records; + uint current_key, total_keys; + uint got_error, threads_running; + myf myf_rw; + enum data_file_type new_data_file_type; +} MI_SORT_INFO; -typedef enum -{ - /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */ - MI_STATS_METHOD_NULLS_NOT_EQUAL, - /* Treat NULLs as equal when collecting statistics (like 4.0 did) */ - MI_STATS_METHOD_NULLS_EQUAL, - /* Ignore NULLs - count only tuples without NULLs in the index components */ - MI_STATS_METHOD_IGNORE_NULLS -} enum_mi_stats_method; - -typedef struct st_mi_check_param +typedef struct st_mi_sort_param { - ulonglong auto_increment_value; - ulonglong max_data_file_length; - ulonglong keys_in_use; - ulonglong max_record_length; - my_off_t search_after_block; - my_off_t new_file_pos,key_file_blocks; - my_off_t keydata,totaldata,key_blocks,start_check_pos; - ha_rows total_records,total_deleted; - ha_checksum record_checksum,glob_crc; - ulonglong use_buffers; - ulong read_buffer_length,write_buffer_length, - sort_buffer_length,sort_key_blocks; - uint out_flag,warning_printed,error_printed,verbose; - uint opt_sort_key,total_files,max_level; - uint testflag, key_cache_block_size; - uint8 language; - my_bool using_global_keycache, opt_lock_memory, opt_follow_links; - my_bool retry_repair, force_sort; - char temp_filename[FN_REFLEN],*isam_file_name; - MY_TMPDIR *tmpdir; - int tmpfile_createflag; - myf myf_rw; - IO_CACHE read_cache; + pthread_t thr; + IO_CACHE read_cache, tempfile, tempfile_for_exceptions; + DYNAMIC_ARRAY buffpek; + MI_BIT_BUFF bit_buff; /* For parallel repair of packrec. */ + MI_KEYDEF *keyinfo; + MI_SORT_INFO *sort_info; + HA_KEYSEG *seg; + uchar **sort_keys; + uchar *rec_buff; + void *wordlist, *wordptr; + MEM_ROOT wordroot; + uchar *record; + MY_TMPDIR *tmpdir; + /* The next two are used to collect statistics, see update_key_parts for description. */ - ulonglong unique_count[MI_MAX_KEY_SEG+1]; - ulonglong notnull_count[MI_MAX_KEY_SEG+1]; - - ha_checksum key_crc[HA_MAX_POSSIBLE_KEY]; - ulong rec_per_key_part[MI_MAX_KEY_SEG*HA_MAX_POSSIBLE_KEY]; - void *thd; - const char *db_name, *table_name; - const char *op_name; - enum_mi_stats_method stats_method; -#ifdef THREAD - pthread_mutex_t print_msg_mutex; - my_bool need_print_msg_lock; -#endif -} MI_CHECK; + ulonglong unique[HA_MAX_KEY_SEG+1]; + ulonglong notnull[HA_MAX_KEY_SEG+1]; + + my_off_t pos,max_pos,filepos,start_recpos; + uint key, key_length,real_key_length,sortbuff_size; + uint maxbuffers, keys, find_length, sort_keys_length; + my_bool fix_datafile, master; + my_bool calc_checksum; /* calculate table checksum */ + + int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *); + int (*key_read)(struct st_mi_sort_param *,void *); + int (*key_write)(struct st_mi_sort_param *, const void *); + void (*lock_in_memory)(HA_CHECK *); + NEAR int (*write_keys)(struct st_mi_sort_param *, register uchar **, + uint , struct st_buffpek *, IO_CACHE *); + NEAR uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint); + NEAR int (*write_key)(struct st_mi_sort_param *, IO_CACHE *,uchar *, + uint, uint); +} MI_SORT_PARAM; -typedef struct st_sort_ft_buf -{ - uchar *buf, *end; - int count; - uchar lastkey[MI_MAX_KEY_BUFF]; -} SORT_FT_BUF; - -typedef struct st_sort_info -{ - my_off_t filelength,dupp,buff_length; - ha_rows max_records; - uint current_key, total_keys; - myf myf_rw; - enum data_file_type new_data_file_type; - MI_INFO *info; - MI_CHECK *param; - uchar *buff; - SORT_KEY_BLOCKS *key_block,*key_block_end; - SORT_FT_BUF *ft_buf; - /* sync things */ - uint got_error, threads_running; -#ifdef THREAD - pthread_mutex_t mutex; - pthread_cond_t cond; -#endif -} SORT_INFO; /* functions in mi_check */ -void myisamchk_init(MI_CHECK *param); -int chk_status(MI_CHECK *param, MI_INFO *info); -int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag); -int chk_size(MI_CHECK *param, MI_INFO *info); -int chk_key(MI_CHECK *param, MI_INFO *info); -int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend); -int mi_repair(MI_CHECK *param, register MI_INFO *info, +void myisamchk_init(HA_CHECK *param); +int chk_status(HA_CHECK *param, MI_INFO *info); +int chk_del(HA_CHECK *param, register MI_INFO *info, ulonglong test_flag); +int chk_size(HA_CHECK *param, MI_INFO *info); +int chk_key(HA_CHECK *param, MI_INFO *info); +int chk_data_link(HA_CHECK *param, MI_INFO *info, my_bool extend); +int mi_repair(HA_CHECK *param, register MI_INFO *info, char * name, int rep_quick); -int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name); -int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, +int mi_sort_index(HA_CHECK *param, register MI_INFO *info, char * name); +int mi_repair_by_sort(HA_CHECK *param, register MI_INFO *info, const char * name, int rep_quick); -int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, +int mi_repair_parallel(HA_CHECK *param, register MI_INFO *info, const char * name, int rep_quick); int change_to_newfile(const char * filename, const char * old_ext, - const char * new_ext, uint raid_chunks, + const char * new_ext, time_t backup_time, + uint raid_chunks, myf myflags); -int lock_file(MI_CHECK *param, File file, my_off_t start, int lock_type, +int lock_file(HA_CHECK *param, File file, my_off_t start, int lock_type, const char *filetype, const char *filename); -void lock_memory(MI_CHECK *param); -void update_auto_increment_key(MI_CHECK *param, MI_INFO *info, +void lock_memory(HA_CHECK *param); +void update_auto_increment_key(HA_CHECK *param, MI_INFO *info, my_bool repair); -int update_state_info(MI_CHECK *param, MI_INFO *info,uint update); +int update_state_info(HA_CHECK *param, MI_INFO *info,uint update); void update_key_parts(MI_KEYDEF *keyinfo, ulong *rec_per_key_part, ulonglong *unique, ulonglong *notnull, ulonglong records); -int filecopy(MI_CHECK *param, File to,File from,my_off_t start, +int filecopy(HA_CHECK *param, File to,File from,my_off_t start, my_off_t length, const char *type); int movepoint(MI_INFO *info,uchar *record,my_off_t oldpos, my_off_t newpos, uint prot_key); -int write_data_suffix(SORT_INFO *sort_info, my_bool fix_datafile); +int write_data_suffix(MI_SORT_INFO *sort_info, my_bool fix_datafile); int test_if_almost_full(MI_INFO *info); -int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename); +int recreate_table(HA_CHECK *param, MI_INFO **org_info, char *filename); void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows); my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map, my_bool force); @@ -536,6 +427,13 @@ void mi_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache); int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves); +int write_data_suffix(MI_SORT_INFO *sort_info, my_bool fix_datafile); +int flush_pending_blocks(MI_SORT_PARAM *param); +int sort_ft_buf_flush(MI_SORT_PARAM *sort_param); +int thr_write_keys(MI_SORT_PARAM *sort_param); +int sort_write_record(MI_SORT_PARAM *sort_param); +int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong); + #ifdef __cplusplus } #endif diff --git a/include/myisamchk.h b/include/myisamchk.h new file mode 100644 index 00000000000..7d7100bdd71 --- /dev/null +++ b/include/myisamchk.h @@ -0,0 +1,181 @@ +/* Copyright (C) 2006 MySQL AB + + 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; either version 2 of the License, or + (at your option) any later version. + + 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 */ + +/* Definitions needed for myisamchk/mariachk.c */ + +/* + Entries marked as "QQ to be removed" are NOT used to + pass check/repair options to xxx_check.c. They are used + internally by xxxchk.c or/and ha_xxxx.cc and should NOT + be stored together with other flags. They should be removed + from the following list to make addition of new flags possible. +*/ + +#ifndef _myisamchk_h +#define _myisamchk_h + +#define T_AUTO_INC 1 +#define T_AUTO_REPAIR 2 /* QQ to be removed */ +#define T_BACKUP_DATA 4 +#define T_CALC_CHECKSUM 8 +#define T_CHECK 16 /* QQ to be removed */ +#define T_CHECK_ONLY_CHANGED 32 /* QQ to be removed */ +#define T_CREATE_MISSING_KEYS 64 +#define T_DESCRIPT 128 +#define T_DONT_CHECK_CHECKSUM 256 +#define T_EXTEND 512 +#define T_FAST (1L << 10) /* QQ to be removed */ +#define T_FORCE_CREATE (1L << 11) /* QQ to be removed */ +#define T_FORCE_UNIQUENESS (1L << 12) +#define T_INFO (1L << 13) +#define T_MEDIUM (1L << 14) +#define T_QUICK (1L << 15) /* QQ to be removed */ +#define T_READONLY (1L << 16) /* QQ to be removed */ +#define T_REP (1L << 17) +#define T_REP_BY_SORT (1L << 18) /* QQ to be removed */ +#define T_REP_PARALLEL (1L << 19) /* QQ to be removed */ +#define T_RETRY_WITHOUT_QUICK (1L << 20) +#define T_SAFE_REPAIR (1L << 21) +#define T_SILENT (1L << 22) +#define T_SORT_INDEX (1L << 23) /* QQ to be removed */ +#define T_SORT_RECORDS (1L << 24) /* QQ to be removed */ +#define T_STATISTICS (1L << 25) +#define T_UNPACK (1L << 26) +#define T_UPDATE_STATE (1L << 27) +#define T_VERBOSE (1L << 28) +#define T_VERY_SILENT (1L << 29) +#define T_WAIT_FOREVER (1L << 30) +#define T_WRITE_LOOP ((ulong) 1L << 31) +#define T_ZEROFILL ((ulonglong) 1L << 32) +#define T_ZEROFILL_KEEP_LSN ((ulonglong) 1L << 33) +/** If repair should not bump create_rename_lsn */ +#define T_NO_CREATE_RENAME_LSN ((ulonglong) 1L << 33) + +#define T_REP_ANY (T_REP | T_REP_BY_SORT | T_REP_PARALLEL) + +/* + Flags used by xxxxchk.c or/and ha_xxxx.cc that are NOT passed + to xxxcheck.c follows: +*/ + +#define TT_USEFRM 1 +#define TT_FOR_UPGRADE 2 + +/* Bits set in out_flag */ +#define O_NEW_DATA 2 +#define O_DATA_LOST 4 + +typedef struct st_sort_key_blocks /* Used when sorting */ +{ + uchar *buff, *end_pos; + uchar lastkey[HA_MAX_POSSIBLE_KEY_BUFF]; + uint last_length; + int inited; +} SORT_KEY_BLOCKS; + + +/* + MARIA/MYISAM supports several statistics collection + methods. Currently statistics collection method is not stored in + MARIA file and has to be specified for each table analyze/repair + operation in MI_CHECK::stats_method. +*/ + +typedef enum +{ + /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */ + MI_STATS_METHOD_NULLS_NOT_EQUAL, + /* Treat NULLs as equal when collecting statistics (like 4.0 did) */ + MI_STATS_METHOD_NULLS_EQUAL, + /* Ignore NULLs - count only tuples without NULLs in the index components */ + MI_STATS_METHOD_IGNORE_NULLS +} enum_handler_stats_method; + + +typedef struct st_handler_check_param +{ + char *isam_file_name; + MY_TMPDIR *tmpdir; + void *thd; + const char *db_name, *table_name, *op_name; + ulonglong auto_increment_value; + ulonglong max_data_file_length; + ulonglong keys_in_use; + ulonglong max_record_length; + /* + The next two are used to collect statistics, see update_key_parts for + description. + */ + ulonglong unique_count[HA_MAX_KEY_SEG + 1]; + ulonglong notnull_count[HA_MAX_KEY_SEG + 1]; + + my_off_t search_after_block; + my_off_t new_file_pos, key_file_blocks; + my_off_t keydata, totaldata, key_blocks, start_check_pos; + my_off_t used, empty, splits, del_length, link_used, lost; + ha_rows total_records, total_deleted, records,del_blocks; + ha_rows full_page_count, tail_count; + ha_checksum record_checksum, glob_crc; + ha_checksum key_crc[HA_MAX_POSSIBLE_KEY]; + ha_checksum tmp_key_crc[HA_MAX_POSSIBLE_KEY]; + ha_checksum tmp_record_checksum; + ulonglong org_key_map; + ulonglong testflag; + + /* Following is used to check if rows are visible */ + ulonglong max_trid, max_found_trid; + ulonglong not_visible_rows_found; + ulonglong use_buffers; /* Used as param to getopt() */ + size_t read_buffer_length, write_buffer_length; + size_t sort_buffer_length, sort_key_blocks; + time_t backup_time; /* To sign backup files */ + ulong rec_per_key_part[HA_MAX_KEY_SEG * HA_MAX_POSSIBLE_KEY]; + double new_rec_per_key_part[HA_MAX_KEY_SEG * HA_MAX_POSSIBLE_KEY]; + uint out_flag, warning_printed, error_printed, verbose; + uint opt_sort_key, total_files, max_level; + uint key_cache_block_size, pagecache_block_size; + int tmpfile_createflag, err_count; + myf myf_rw; + uint8 language; + my_bool using_global_keycache, opt_lock_memory, opt_follow_links; + my_bool retry_repair, force_sort, calc_checksum, static_row_size; + char temp_filename[FN_REFLEN]; + IO_CACHE read_cache; + enum_handler_stats_method stats_method; +#ifdef THREAD + pthread_mutex_t print_msg_mutex; + my_bool need_print_msg_lock; +#endif +} HA_CHECK; + + +typedef struct st_sort_ftbuf +{ + uchar *buf, *end; + int count; + uchar lastkey[HA_MAX_KEY_BUFF]; +} SORT_FT_BUF; + + +typedef struct st_buffpek { + my_off_t file_pos; /* Where we are in the sort file */ + uchar *base, *key; /* Key pointers */ + ha_rows count; /* Number of rows in table */ + ulong mem_count; /* numbers of keys in memory */ + ulong max_keys; /* Max keys in buffert */ +} BUFFPEK; + +#endif /* _myisamchk_h */ diff --git a/include/myisampack.h b/include/myisampack.h index 7d4871bd1cb..34a085e4e5a 100644 --- a/include/myisampack.h +++ b/include/myisampack.h @@ -24,58 +24,58 @@ #define mi_sint1korr(A) ((int8)(*A)) #define mi_uint1korr(A) ((uint8)(*A)) -#define mi_sint2korr(A) ((int16) (((int16) (((uchar*) (A))[1])) +\ - ((int16) ((int16) ((char*) (A))[0]) << 8))) -#define mi_sint3korr(A) ((int32) (((((uchar*) (A))[0]) & 128) ? \ +#define mi_sint2korr(A) ((int16) (((int16) (((const uchar*) (A))[1])) +\ + ((int16) ((int16) ((const char*) (A))[0]) << 8))) +#define mi_sint3korr(A) ((int32) (((((const uchar*) (A))[0]) & 128) ? \ (((uint32) 255L << 24) | \ - (((uint32) ((uchar*) (A))[0]) << 16) |\ - (((uint32) ((uchar*) (A))[1]) << 8) | \ - ((uint32) ((uchar*) (A))[2])) : \ - (((uint32) ((uchar*) (A))[0]) << 16) |\ - (((uint32) ((uchar*) (A))[1]) << 8) | \ - ((uint32) ((uchar*) (A))[2]))) -#define mi_sint4korr(A) ((int32) (((int32) (((uchar*) (A))[3])) +\ - ((int32) (((uchar*) (A))[2]) << 8) +\ - ((int32) (((uchar*) (A))[1]) << 16) +\ - ((int32) ((int16) ((char*) (A))[0]) << 24))) + (((uint32) ((const uchar*) (A))[0]) << 16) |\ + (((uint32) ((const uchar*) (A))[1]) << 8) | \ + ((uint32) ((const uchar*) (A))[2])) : \ + (((uint32) ((const uchar*) (A))[0]) << 16) |\ + (((uint32) ((const uchar*) (A))[1]) << 8) | \ + ((uint32) ((const uchar*) (A))[2]))) +#define mi_sint4korr(A) ((int32) (((int32) (((const uchar*) (A))[3])) +\ + ((int32) (((const uchar*) (A))[2]) << 8) +\ + ((int32) (((const uchar*) (A))[1]) << 16) +\ + ((int32) ((int16) ((const char*) (A))[0]) << 24))) #define mi_sint8korr(A) ((longlong) mi_uint8korr(A)) -#define mi_uint2korr(A) ((uint16) (((uint16) (((uchar*) (A))[1])) +\ - ((uint16) (((uchar*) (A))[0]) << 8))) -#define mi_uint3korr(A) ((uint32) (((uint32) (((uchar*) (A))[2])) +\ - (((uint32) (((uchar*) (A))[1])) << 8) +\ - (((uint32) (((uchar*) (A))[0])) << 16))) -#define mi_uint4korr(A) ((uint32) (((uint32) (((uchar*) (A))[3])) +\ - (((uint32) (((uchar*) (A))[2])) << 8) +\ - (((uint32) (((uchar*) (A))[1])) << 16) +\ - (((uint32) (((uchar*) (A))[0])) << 24))) -#define mi_uint5korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[4])) +\ - (((uint32) (((uchar*) (A))[3])) << 8) +\ - (((uint32) (((uchar*) (A))[2])) << 16) +\ - (((uint32) (((uchar*) (A))[1])) << 24)) +\ - (((ulonglong) (((uchar*) (A))[0])) << 32)) -#define mi_uint6korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[5])) +\ - (((uint32) (((uchar*) (A))[4])) << 8) +\ - (((uint32) (((uchar*) (A))[3])) << 16) +\ - (((uint32) (((uchar*) (A))[2])) << 24)) +\ - (((ulonglong) (((uint32) (((uchar*) (A))[1])) +\ - (((uint32) (((uchar*) (A))[0]) << 8)))) <<\ +#define mi_uint2korr(A) ((uint16) (((uint16) (((const uchar*) (A))[1])) +\ + ((uint16) (((const uchar*) (A))[0]) << 8))) +#define mi_uint3korr(A) ((uint32) (((uint32) (((const uchar*) (A))[2])) +\ + (((uint32) (((const uchar*) (A))[1])) << 8) +\ + (((uint32) (((const uchar*) (A))[0])) << 16))) +#define mi_uint4korr(A) ((uint32) (((uint32) (((const uchar*) (A))[3])) +\ + (((uint32) (((const uchar*) (A))[2])) << 8) +\ + (((uint32) (((const uchar*) (A))[1])) << 16) +\ + (((uint32) (((const uchar*) (A))[0])) << 24))) +#define mi_uint5korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[4])) +\ + (((uint32) (((const uchar*) (A))[3])) << 8) +\ + (((uint32) (((const uchar*) (A))[2])) << 16) +\ + (((uint32) (((const uchar*) (A))[1])) << 24)) +\ + (((ulonglong) (((const uchar*) (A))[0])) << 32)) +#define mi_uint6korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[5])) +\ + (((uint32) (((const uchar*) (A))[4])) << 8) +\ + (((uint32) (((const uchar*) (A))[3])) << 16) +\ + (((uint32) (((const uchar*) (A))[2])) << 24)) +\ + (((ulonglong) (((uint32) (((const uchar*) (A))[1])) +\ + (((uint32) (((const uchar*) (A))[0]) << 8)))) <<\ 32)) -#define mi_uint7korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[6])) +\ - (((uint32) (((uchar*) (A))[5])) << 8) +\ - (((uint32) (((uchar*) (A))[4])) << 16) +\ - (((uint32) (((uchar*) (A))[3])) << 24)) +\ - (((ulonglong) (((uint32) (((uchar*) (A))[2])) +\ - (((uint32) (((uchar*) (A))[1])) << 8) +\ - (((uint32) (((uchar*) (A))[0])) << 16))) <<\ +#define mi_uint7korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[6])) +\ + (((uint32) (((const uchar*) (A))[5])) << 8) +\ + (((uint32) (((const uchar*) (A))[4])) << 16) +\ + (((uint32) (((const uchar*) (A))[3])) << 24)) +\ + (((ulonglong) (((uint32) (((const uchar*) (A))[2])) +\ + (((uint32) (((const uchar*) (A))[1])) << 8) +\ + (((uint32) (((const uchar*) (A))[0])) << 16))) <<\ 32)) -#define mi_uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\ - (((uint32) (((uchar*) (A))[6])) << 8) +\ - (((uint32) (((uchar*) (A))[5])) << 16) +\ - (((uint32) (((uchar*) (A))[4])) << 24)) +\ - (((ulonglong) (((uint32) (((uchar*) (A))[3])) +\ - (((uint32) (((uchar*) (A))[2])) << 8) +\ - (((uint32) (((uchar*) (A))[1])) << 16) +\ - (((uint32) (((uchar*) (A))[0])) << 24))) <<\ +#define mi_uint8korr(A) ((ulonglong)(((uint32) (((const uchar*) (A))[7])) +\ + (((uint32) (((const uchar*) (A))[6])) << 8) +\ + (((uint32) (((const uchar*) (A))[5])) << 16) +\ + (((uint32) (((const uchar*) (A))[4])) << 24)) +\ + (((ulonglong) (((uint32) (((const uchar*) (A))[3])) +\ + (((uint32) (((const uchar*) (A))[2])) << 8) +\ + (((uint32) (((const uchar*) (A))[1])) << 16) +\ + (((uint32) (((const uchar*) (A))[0])) << 24))) <<\ 32)) /* This one is for uniformity */ @@ -132,85 +132,85 @@ ((uchar*) (T))[3]= ((uchar*) &A)[3]; } #define mi_float4get(V,M) { float def_temp;\ - ((uchar*) &def_temp)[0]= ((uchar*) (M))[0];\ - ((uchar*) &def_temp)[1]= ((uchar*) (M))[1];\ - ((uchar*) &def_temp)[2]= ((uchar*) (M))[2];\ - ((uchar*) &def_temp)[3]= ((uchar*) (M))[3];\ + ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\ + ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1]; \ + ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\ + ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\ (V)= def_temp; } -#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[0];\ - ((uchar*) (T))[1]= ((uchar*) &V)[1];\ - ((uchar*) (T))[2]= ((uchar*) &V)[2];\ - ((uchar*) (T))[3]= ((uchar*) &V)[3];\ - ((uchar*) (T))[4]= ((uchar*) &V)[4];\ - ((uchar*) (T))[5]= ((uchar*) &V)[5];\ - ((uchar*) (T))[6]= ((uchar*) &V)[6];\ - ((uchar*) (T))[7]= ((uchar*) &V)[7]; } +#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[0];\ + ((uchar*) (T))[1]= ((const uchar*) &V)[1];\ + ((uchar*) (T))[2]= ((const uchar*) &V)[2];\ + ((uchar*) (T))[3]= ((const uchar*) &V)[3];\ + ((uchar*) (T))[4]= ((const uchar*) &V)[4];\ + ((uchar*) (T))[5]= ((const uchar*) &V)[5];\ + ((uchar*) (T))[6]= ((const uchar*) &V)[6];\ + ((uchar*) (T))[7]= ((const uchar*) &V)[7]; } #define mi_float8get(V,M) { double def_temp;\ - ((uchar*) &def_temp)[0]= ((uchar*) (M))[0];\ - ((uchar*) &def_temp)[1]= ((uchar*) (M))[1];\ - ((uchar*) &def_temp)[2]= ((uchar*) (M))[2];\ - ((uchar*) &def_temp)[3]= ((uchar*) (M))[3];\ - ((uchar*) &def_temp)[4]= ((uchar*) (M))[4];\ - ((uchar*) &def_temp)[5]= ((uchar*) (M))[5];\ - ((uchar*) &def_temp)[6]= ((uchar*) (M))[6];\ - ((uchar*) &def_temp)[7]= ((uchar*) (M))[7]; \ + ((uchar*) &def_temp)[0]= ((const uchar*) (M))[0];\ + ((uchar*) &def_temp)[1]= ((const uchar*) (M))[1];\ + ((uchar*) &def_temp)[2]= ((const uchar*) (M))[2];\ + ((uchar*) &def_temp)[3]= ((const uchar*) (M))[3];\ + ((uchar*) &def_temp)[4]= ((const uchar*) (M))[4];\ + ((uchar*) &def_temp)[5]= ((const uchar*) (M))[5];\ + ((uchar*) &def_temp)[6]= ((const uchar*) (M))[6];\ + ((uchar*) &def_temp)[7]= ((const uchar*) (M))[7]; \ (V)= def_temp; } #else -#define mi_float4store(T,A) { ((uchar*) (T))[0]= ((uchar*) &A)[3];\ - ((uchar*) (T))[1]= ((uchar*) &A)[2];\ - ((uchar*) (T))[2]= ((uchar*) &A)[1];\ - ((uchar*) (T))[3]= ((uchar*) &A)[0]; } +#define mi_float4store(T,A) { ((uchar*) (T))[0]= ((const uchar*) &A)[3];\ + ((uchar*) (T))[1]= ((const uchar*) &A)[2];\ + ((uchar*) (T))[2]= ((const uchar*) &A)[1];\ + ((uchar*) (T))[3]= ((const uchar*) &A)[0]; } #define mi_float4get(V,M) { float def_temp;\ - ((uchar*) &def_temp)[0]= ((uchar*) (M))[3];\ - ((uchar*) &def_temp)[1]= ((uchar*) (M))[2];\ - ((uchar*) &def_temp)[2]= ((uchar*) (M))[1];\ - ((uchar*) &def_temp)[3]= ((uchar*) (M))[0];\ + ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\ + ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\ + ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\ + ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\ (V)= def_temp; } #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) -#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[3];\ - ((uchar*) (T))[1]= ((uchar*) &V)[2];\ - ((uchar*) (T))[2]= ((uchar*) &V)[1];\ - ((uchar*) (T))[3]= ((uchar*) &V)[0];\ - ((uchar*) (T))[4]= ((uchar*) &V)[7];\ - ((uchar*) (T))[5]= ((uchar*) &V)[6];\ - ((uchar*) (T))[6]= ((uchar*) &V)[5];\ - ((uchar*) (T))[7]= ((uchar*) &V)[4];} +#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[3];\ + ((uchar*) (T))[1]= ((const uchar*) &V)[2];\ + ((uchar*) (T))[2]= ((const uchar*) &V)[1];\ + ((uchar*) (T))[3]= ((const uchar*) &V)[0];\ + ((uchar*) (T))[4]= ((const uchar*) &V)[7];\ + ((uchar*) (T))[5]= ((const uchar*) &V)[6];\ + ((uchar*) (T))[6]= ((const uchar*) &V)[5];\ + ((uchar*) (T))[7]= ((const uchar*) &V)[4];} #define mi_float8get(V,M) { double def_temp;\ - ((uchar*) &def_temp)[0]= ((uchar*) (M))[3];\ - ((uchar*) &def_temp)[1]= ((uchar*) (M))[2];\ - ((uchar*) &def_temp)[2]= ((uchar*) (M))[1];\ - ((uchar*) &def_temp)[3]= ((uchar*) (M))[0];\ - ((uchar*) &def_temp)[4]= ((uchar*) (M))[7];\ - ((uchar*) &def_temp)[5]= ((uchar*) (M))[6];\ - ((uchar*) &def_temp)[6]= ((uchar*) (M))[5];\ - ((uchar*) &def_temp)[7]= ((uchar*) (M))[4];\ + ((uchar*) &def_temp)[0]= ((const uchar*) (M))[3];\ + ((uchar*) &def_temp)[1]= ((const uchar*) (M))[2];\ + ((uchar*) &def_temp)[2]= ((const uchar*) (M))[1];\ + ((uchar*) &def_temp)[3]= ((const uchar*) (M))[0];\ + ((uchar*) &def_temp)[4]= ((const uchar*) (M))[7];\ + ((uchar*) &def_temp)[5]= ((const uchar*) (M))[6];\ + ((uchar*) &def_temp)[6]= ((const uchar*) (M))[5];\ + ((uchar*) &def_temp)[7]= ((const uchar*) (M))[4];\ (V)= def_temp; } #else -#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((uchar*) &V)[7];\ - ((uchar*) (T))[1]= ((uchar*) &V)[6];\ - ((uchar*) (T))[2]= ((uchar*) &V)[5];\ - ((uchar*) (T))[3]= ((uchar*) &V)[4];\ - ((uchar*) (T))[4]= ((uchar*) &V)[3];\ - ((uchar*) (T))[5]= ((uchar*) &V)[2];\ - ((uchar*) (T))[6]= ((uchar*) &V)[1];\ - ((uchar*) (T))[7]= ((uchar*) &V)[0];} +#define mi_float8store(T,V) { ((uchar*) (T))[0]= ((const uchar*) &V)[7];\ + ((uchar*) (T))[1]= ((const uchar*) &V)[6];\ + ((uchar*) (T))[2]= ((const uchar*) &V)[5];\ + ((uchar*) (T))[3]= ((const uchar*) &V)[4];\ + ((uchar*) (T))[4]= ((const uchar*) &V)[3];\ + ((uchar*) (T))[5]= ((const uchar*) &V)[2];\ + ((uchar*) (T))[6]= ((const uchar*) &V)[1];\ + ((uchar*) (T))[7]= ((const uchar*) &V)[0];} #define mi_float8get(V,M) { double def_temp;\ - ((uchar*) &def_temp)[0]= ((uchar*) (M))[7];\ - ((uchar*) &def_temp)[1]= ((uchar*) (M))[6];\ - ((uchar*) &def_temp)[2]= ((uchar*) (M))[5];\ - ((uchar*) &def_temp)[3]= ((uchar*) (M))[4];\ - ((uchar*) &def_temp)[4]= ((uchar*) (M))[3];\ - ((uchar*) &def_temp)[5]= ((uchar*) (M))[2];\ - ((uchar*) &def_temp)[6]= ((uchar*) (M))[1];\ - ((uchar*) &def_temp)[7]= ((uchar*) (M))[0];\ + ((uchar*) &def_temp)[0]= ((const uchar*) (M))[7];\ + ((uchar*) &def_temp)[1]= ((const uchar*) (M))[6];\ + ((uchar*) &def_temp)[2]= ((const uchar*) (M))[5];\ + ((uchar*) &def_temp)[3]= ((const uchar*) (M))[4];\ + ((uchar*) &def_temp)[4]= ((const uchar*) (M))[3];\ + ((uchar*) &def_temp)[5]= ((const uchar*) (M))[2];\ + ((uchar*) &def_temp)[6]= ((const uchar*) (M))[1];\ + ((uchar*) &def_temp)[7]= ((const uchar*) (M))[0];\ (V)= def_temp; } #endif /* __FLOAT_WORD_ORDER */ #endif /* WORDS_BIGENDIAN */ @@ -223,7 +223,7 @@ #else #define mi_rowstore(T,A) { mi_int4store(T, 0);\ mi_int4store(((uchar*) (T) + 4), A); } -#define mi_rowkorr(T) mi_uint4korr((uchar*) (T) + 4) +#define mi_rowkorr(T) mi_uint4korr((const uchar*) (T) + 4) #endif #if SIZEOF_OFF_T > 4 @@ -234,5 +234,5 @@ bfill((char*) (T), 8, 255);\ else { mi_int4store((T), 0);\ mi_int4store(((T) + 4), A); }} -#define mi_sizekorr(T) mi_uint4korr((uchar*) (T) + 4) +#define mi_sizekorr(T) mi_uint4korr((const uchar*) (T) + 4) #endif diff --git a/include/mysql.h b/include/mysql.h index da477278e70..48b4b019485 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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 @@ -532,6 +532,7 @@ int STDCALL mysql_set_server_option(MYSQL *mysql, int STDCALL mysql_ping(MYSQL *mysql); const char * STDCALL mysql_stat(MYSQL *mysql); const char * STDCALL mysql_get_server_info(MYSQL *mysql); +const char * STDCALL mysql_get_server_name(MYSQL *mysql); const char * STDCALL mysql_get_client_info(void); unsigned long STDCALL mysql_get_client_version(void); const char * STDCALL mysql_get_host_info(MYSQL *mysql); @@ -565,6 +566,7 @@ void STDCALL mysql_debug(const char *debug); void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name); unsigned int STDCALL mysql_thread_safe(void); my_bool STDCALL mysql_embedded(void); +my_bool STDCALL mariadb_connection(MYSQL *mysql); MYSQL_MANAGER* STDCALL mysql_manager_init(MYSQL_MANAGER* con); MYSQL_MANAGER* STDCALL mysql_manager_connect(MYSQL_MANAGER* con, const char* host, diff --git a/include/mysql.h.pp b/include/mysql.h.pp index ceb4b2d591c..a3bce0e5506 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -27,7 +27,7 @@ typedef struct st_net { unsigned int *return_status; unsigned char reading_or_writing; char save_char; - my_bool unused0; + char net_skip_rest_factor; my_bool unused; my_bool compress; my_bool unused1; @@ -97,12 +97,11 @@ unsigned long my_net_read(NET *net); struct sockaddr; int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen, unsigned int timeout); -struct rand_struct { - unsigned long seed1,seed2,max_value; - double max_value_dbl; +struct my_rnd_struct; +enum Item_result +{ + STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT }; -enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, - DECIMAL_RESULT}; typedef struct st_udf_args { unsigned int arg_count; @@ -123,10 +122,8 @@ typedef struct st_udf_init my_bool const_item; void *extension; } UDF_INIT; -void randominit(struct rand_struct *, unsigned long seed1, - unsigned long seed2); -double my_rnd(struct rand_struct *); -void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st); +void create_random_string(char *to, unsigned int length, + struct my_rnd_struct *rand_st); void hash_password(unsigned long *to, const char *password, unsigned int password_len); void make_scrambled_password_323(char *to, const char *password); void scramble_323(char *to, const char *message, const char *password); @@ -204,8 +201,8 @@ typedef unsigned long long my_ulonglong; typedef struct st_used_mem { struct st_used_mem *next; - unsigned int left; - unsigned int size; + size_t left; + size_t size; } USED_MEM; typedef struct st_mem_root { @@ -225,8 +222,10 @@ typedef struct st_typelib { unsigned int *type_lengths; } TYPELIB; extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); -extern int find_type_or_exit(const char *x, TYPELIB *typelib, - const char *option); +extern int find_type_with_warning(const char *x, TYPELIB *typelib, + const char *option); +extern unsigned int find_type_or_exit(const char *x, TYPELIB *typelib, + const char *option); extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name); extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); extern const char *get_type(TYPELIB *typelib,unsigned int nr); @@ -488,6 +487,7 @@ int mysql_set_server_option(MYSQL *mysql, int mysql_ping(MYSQL *mysql); const char * mysql_stat(MYSQL *mysql); const char * mysql_get_server_info(MYSQL *mysql); +const char * mysql_get_server_name(MYSQL *mysql); const char * mysql_get_client_info(void); unsigned long mysql_get_client_version(void); const char * mysql_get_host_info(MYSQL *mysql); @@ -521,6 +521,7 @@ void mysql_debug(const char *debug); void myodbc_remove_escape(MYSQL *mysql,char *name); unsigned int mysql_thread_safe(void); my_bool mysql_embedded(void); +my_bool mariadb_connection(MYSQL *mysql); MYSQL_MANAGER* mysql_manager_init(MYSQL_MANAGER* con); MYSQL_MANAGER* mysql_manager_connect(MYSQL_MANAGER* con, const char* host, diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index b49a5c22186..7a684614bf4 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 2010, Oracle and/or its affiliates 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 @@ -18,13 +18,27 @@ #ifndef _my_plugin_h #define _my_plugin_h - /* On Windows, exports from DLL need to be declared -*/ -#if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN)) -#define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport) -#else + Also, plugin needs to be declared as extern "C" because MSVC + unlike other compilers, uses C++ mangling for variables not only + for functions. +*/ +#if defined(_MSC_VER) +#if defined(MYSQL_DYNAMIC_PLUGIN) + #ifdef __cplusplus + #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport) + #else + #define MYSQL_PLUGIN_EXPORT __declspec(dllexport) + #endif +#else /* MYSQL_DYNAMIC_PLUGIN */ + #ifdef __cplusplus + #define MYSQL_PLUGIN_EXPORT extern "C" + #else + #define MYSQL_PLUGIN_EXPORT + #endif +#endif /*MYSQL_DYNAMIC_PLUGIN */ +#else /*_MSC_VER */ #define MYSQL_PLUGIN_EXPORT #endif @@ -566,19 +580,22 @@ typedef struct st_mysql_ftparser_boolean_info nothing. See enum_ftparser_mode above. */ +/* TODO: Change the following int to size_t at next ABI update */ +typedef int mysql_ft_size_t; + typedef struct st_mysql_ftparser_param { int (*mysql_parse)(struct st_mysql_ftparser_param *, - char *doc, int doc_len); + const unsigned char *doc, mysql_ft_size_t doc_len); int (*mysql_add_word)(struct st_mysql_ftparser_param *, - char *word, int word_len, + const unsigned char *word, mysql_ft_size_t word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; struct charset_info_st *cs; - char *doc; - int length; - int flags; + const unsigned char *doc; + mysql_ft_size_t length; + unsigned int flags; enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; @@ -688,7 +705,6 @@ int thd_in_lock_tables(const MYSQL_THD thd); int thd_tablespace_op(const MYSQL_THD thd); long long thd_test_options(const MYSQL_THD thd, long long test_options); int thd_sql_command(const MYSQL_THD thd); -const char *thd_proc_info(MYSQL_THD thd, const char *info); void **thd_ha_data(const MYSQL_THD thd, const struct handlerton *hton); int thd_tx_isolation(const MYSQL_THD thd); char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length, @@ -696,6 +712,10 @@ char *thd_security_context(MYSQL_THD thd, char *buffer, unsigned int length, /* Increments the row counter, see THD::row_count */ void thd_inc_row_count(MYSQL_THD thd); +#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, __func__, __FILE__, __LINE__) +const char *set_thd_proc_info(MYSQL_THD, const char * info, const char *func, + const char *file, const unsigned int line); + /** Create a temporary file. diff --git a/include/mysql/plugin.h.pp b/include/mysql/plugin.h.pp index e4906ea6547..ac86f687723 100644 --- a/include/mysql/plugin.h.pp +++ b/include/mysql/plugin.h.pp @@ -70,19 +70,20 @@ typedef struct st_mysql_ftparser_boolean_info char prev; char *quot; } MYSQL_FTPARSER_BOOLEAN_INFO; +typedef int mysql_ft_size_t; typedef struct st_mysql_ftparser_param { int (*mysql_parse)(struct st_mysql_ftparser_param *, - char *doc, int doc_len); + const unsigned char *doc, mysql_ft_size_t doc_len); int (*mysql_add_word)(struct st_mysql_ftparser_param *, - char *word, int word_len, + const unsigned char *word, mysql_ft_size_t word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; struct charset_info_st *cs; - char *doc; - int length; - int flags; + const unsigned char *doc; + mysql_ft_size_t length; + unsigned int flags; enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; struct st_mysql_ftparser @@ -116,12 +117,13 @@ int thd_in_lock_tables(const void* thd); int thd_tablespace_op(const void* thd); long long thd_test_options(const void* thd, long long test_options); int thd_sql_command(const void* thd); -const char *thd_proc_info(void* thd, const char *info); void **thd_ha_data(const void* thd, const struct handlerton *hton); int thd_tx_isolation(const void* thd); char *thd_security_context(void* thd, char *buffer, unsigned int length, unsigned int max_query_len); void thd_inc_row_count(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, const unsigned int line); int mysql_tmpfile(const char *prefix); int thd_killed(const void* thd); unsigned long thd_get_thread_id(const void* thd); diff --git a/include/mysql_com.h b/include/mysql_com.h index 357519d549a..96eb8f21d3f 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (C) 2000 MySQL AB 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 @@ -254,7 +254,7 @@ typedef struct st_net { unsigned int *return_status; unsigned char reading_or_writing; char save_char; - my_bool unused0; /* Please remove with the next incompatible ABI change. */ + char net_skip_rest_factor; my_bool unused; /* Please remove with the next incompatible ABI change */ my_bool compress; my_bool unused1; /* Please remove with the next incompatible ABI change. */ @@ -277,16 +277,6 @@ typedef struct st_net { /** Client library sqlstate buffer. Set along with the error message. */ char sqlstate[SQLSTATE_LENGTH+1]; void *extension; -#if defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY) - /* - Controls whether a big packet should be skipped. - - Initially set to FALSE by default. Unauthenticated sessions must have - this set to FALSE so that the server can't be tricked to read packets - indefinitely. - */ - my_bool skip_big_packet; -#endif } NET; @@ -426,11 +416,7 @@ void my_net_set_read_timeout(NET *net, uint timeout); struct sockaddr; int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen, unsigned int timeout); - -struct rand_struct { - unsigned long seed1,seed2,max_value; - double max_value_dbl; -}; +struct my_rnd_struct; #ifdef __cplusplus } @@ -438,8 +424,13 @@ struct rand_struct { /* The following is for user defined functions */ -enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, - DECIMAL_RESULT}; +enum Item_result +{ + STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT, DECIMAL_RESULT +#ifdef MYSQL_SERVER + ,IMPOSSIBLE_RESULT /* Yes, we know this is ugly, don't tell us */ +#endif +}; typedef struct st_udf_args { @@ -484,10 +475,8 @@ extern "C" { implemented in sql/password.c */ -void randominit(struct rand_struct *, unsigned long seed1, - unsigned long seed2); -double my_rnd(struct rand_struct *); -void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st); +void create_random_string(char *to, unsigned int length, + struct my_rnd_struct *rand_st); void hash_password(unsigned long *to, const char *password, unsigned int password_len); void make_scrambled_password_323(char *to, const char *password); diff --git a/include/mysql_embed.h b/include/mysql_embed.h index e3318864f17..1747e602b7f 100644 --- a/include/mysql_embed.h +++ b/include/mysql_embed.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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 diff --git a/include/mysql_version.h.in b/include/mysql_version.h.in index 04a43f2c968..c37e99d7a8c 100644 --- a/include/mysql_version.h.in +++ b/include/mysql_version.h.in @@ -11,6 +11,7 @@ #define PROTOCOL_VERSION @PROTOCOL_VERSION@ #define MYSQL_SERVER_VERSION "@VERSION@" #define MYSQL_BASE_VERSION "mysqld-@MYSQL_BASE_VERSION@" +#define MARIADB_BASE_VERSION "mariadb-@MYSQL_BASE_VERSION@" #define MYSQL_SERVER_SUFFIX_DEF "@MYSQL_SERVER_SUFFIX@" #define FRM_VER @DOT_FRM_VERSION@ #define MYSQL_VERSION_ID @MYSQL_VERSION_ID@ diff --git a/include/mysys_err.h b/include/mysys_err.h index e51ccf0163c..52946cff53c 100644 --- a/include/mysys_err.h +++ b/include/mysys_err.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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 @@ -67,7 +67,10 @@ extern const char * NEAR globerrs[]; /* my_error_messages is here */ #define EE_CHANGE_OWNERSHIP 31 #define EE_CHANGE_PERMISSIONS 32 #define EE_CANT_SEEK 33 -#define EE_ERROR_LAST 33 /* Copy last error nr */ +#define EE_CANT_CHMOD 34 +#define EE_CANT_COPY_OWNERSHIP 35 +#define EE_ERROR_LAST 35 /* Copy last error nr */ + /* Add error numbers before EE_ERROR_LAST and change it accordingly. */ /* exit codes for all MySQL programs */ @@ -86,9 +89,7 @@ extern const char * NEAR globerrs[]; /* my_error_messages is here */ #define EXIT_OPTION_DISABLED 12 #define EXIT_ARGUMENT_INVALID 13 - #ifdef __cplusplus } #endif #endif - diff --git a/include/sslopt-longopts.h b/include/sslopt-longopts.h index 16037e4d6cd..3a5e282597c 100644 --- a/include/sslopt-longopts.h +++ b/include/sslopt-longopts.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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 diff --git a/include/thr_lock.h b/include/thr_lock.h index 90e34fc15f6..e13960d1558 100644 --- a/include/thr_lock.h +++ b/include/thr_lock.h @@ -85,6 +85,12 @@ enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1, THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 }; +/* Priority for locks */ +#define THR_LOCK_LATE_PRIV 1 /* For locks to be merged with org lock */ +#define THR_LOCK_MERGE_PRIV 2 /* For merge tables */ + +#define THR_UNLOCK_UPDATE_STATUS 1 + extern ulong max_write_lock_count; extern ulong table_lock_wait_timeout; extern my_bool thr_lock_inited; @@ -119,9 +125,10 @@ typedef struct st_thr_lock_data { struct st_thr_lock_data *next,**prev; struct st_thr_lock *lock; pthread_cond_t *cond; - enum thr_lock_type type; void *status_param; /* Param to status functions */ - void *debug_print_param; + void *debug_print_param; /* Used by MariaDB for TABLE ref */ + enum thr_lock_type type; + uint priority; } THR_LOCK_DATA; struct st_lock_list { @@ -138,11 +145,15 @@ typedef struct st_thr_lock { /* write_lock_count is incremented for write locks and reset on read locks */ ulong write_lock_count; uint read_no_write_count; - void (*get_status)(void*, int); /* When one gets a lock */ + void (*get_status)(void*, my_bool); /* When one gets a lock */ void (*copy_status)(void*,void*); void (*update_status)(void*); /* Before release of write */ - void (*restore_status)(void*); /* Before release of read */ + void (*restore_status)(void*); /* Before release of read */ + my_bool (*start_trans)(void*); /* When all locks are taken */ my_bool (*check_status)(void *); + void (*fix_status)(void *, void *);/* For thr_merge_locks() */ + const char *name; /* Used for error reporting */ + my_bool allow_multiple_concurrent_insert; } THR_LOCK; @@ -156,13 +167,11 @@ void thr_lock_init(THR_LOCK *lock); void thr_lock_delete(THR_LOCK *lock); void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data, void *status_param); -enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, - THR_LOCK_OWNER *owner, - enum thr_lock_type lock_type); -void thr_unlock(THR_LOCK_DATA *data); +void thr_unlock(THR_LOCK_DATA *data, uint unlock_flags); enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data, uint count, THR_LOCK_OWNER *owner); -void thr_multi_unlock(THR_LOCK_DATA **data,uint count); +void thr_multi_unlock(THR_LOCK_DATA **data,uint count, uint unlock_flags); +void thr_merge_locks(THR_LOCK_DATA **data, uint org_count, uint new_count); void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock); my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread); void thr_print_locks(void); /* For debugging */ diff --git a/include/typelib.h b/include/typelib.h index 46106d1bdab..16c719e3419 100644 --- a/include/typelib.h +++ b/include/typelib.h @@ -27,8 +27,10 @@ typedef struct st_typelib { /* Different types saved here */ } TYPELIB; extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position); -extern int find_type_or_exit(const char *x, TYPELIB *typelib, - const char *option); +extern int find_type_with_warning(const char *x, TYPELIB *typelib, + const char *option); +extern unsigned int find_type_or_exit(const char *x, TYPELIB *typelib, + const char *option); extern int find_type(char *x, const TYPELIB *typelib, unsigned int full_name); extern void make_type(char *to,unsigned int nr,TYPELIB *typelib); extern const char *get_type(TYPELIB *typelib,unsigned int nr); diff --git a/include/violite.h b/include/violite.h index 32354938e13..c5c9ee89110 100644 --- a/include/violite.h +++ b/include/violite.h @@ -91,6 +91,7 @@ my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port); /* Remotes in_addr */ void vio_in_addr(Vio *vio, struct in_addr *in); my_bool vio_poll_read(Vio *vio,uint timeout); +ssize_t vio_pending(Vio *vio); #ifdef HAVE_OPENSSL #include <openssl/opensslv.h> @@ -125,8 +126,8 @@ struct st_VioSSLFd SSL_CTX *ssl_context; }; -int sslaccept(struct st_VioSSLFd*, Vio *, long timeout); -int sslconnect(struct st_VioSSLFd*, Vio *, long timeout); +int sslaccept(struct st_VioSSLFd*, Vio *, long timeout, char *error_string); +int sslconnect(struct st_VioSSLFd*, Vio *, long timeout, char *error_string); struct st_VioSSLFd *new_VioSSLConnectorFd(const char *key_file, const char *cert_file, diff --git a/include/waiting_threads.h b/include/waiting_threads.h new file mode 100644 index 00000000000..1e580529938 --- /dev/null +++ b/include/waiting_threads.h @@ -0,0 +1,130 @@ +/* Copyright (C) 2008 MySQL AB, 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 _waiting_threads_h +#define _waiting_threads_h + +#include <my_global.h> +#include <my_sys.h> + +#include <lf.h> + +C_MODE_START + +typedef struct st_wt_resource_id WT_RESOURCE_ID; +typedef struct st_wt_resource WT_RESOURCE; + +typedef struct st_wt_resource_type { + my_bool (*compare)(const void *a, const void *b); + const void *(*make_key)(const WT_RESOURCE_ID *id, uint *len); /* not used */ +} WT_RESOURCE_TYPE; + +struct st_wt_resource_id { + ulonglong value; + const WT_RESOURCE_TYPE *type; +}; +/* the below differs from sizeof(WT_RESOURCE_ID) by the amount of padding */ +#define sizeof_WT_RESOURCE_ID (sizeof(ulonglong)+sizeof(void*)) + +#define WT_WAIT_STATS 24 +#define WT_CYCLE_STATS 32 +extern ulonglong wt_wait_table[WT_WAIT_STATS]; +extern uint32 wt_wait_stats[WT_WAIT_STATS+1]; +extern uint32 wt_cycle_stats[2][WT_CYCLE_STATS+1]; +extern uint32 wt_success_stats; + +typedef struct st_wt_thd { + /* + XXX + there's no protection (mutex) against concurrent access of the + dynarray below. it is assumed that a caller will have it anyway + (not to protect this array but to protect its own - caller's - + data structures), and we'll get it for free. A caller needs to + ensure that a blocker won't release a resource before a blocked + thread starts waiting, which is usually done with a mutex. + + If the above assumption is wrong, we'll need to add a mutex here. + */ + DYNAMIC_ARRAY my_resources; + /* + 'waiting_for' is modified under waiting_for->lock, and only by thd itself + 'waiting_for' is read lock-free (using pinning protocol), but a thd object + can read its own 'waiting_for' without any locks or tricks. + */ + WT_RESOURCE *waiting_for; + LF_PINS *pins; + + /* pointers to values */ + const ulong *timeout_short; + const ulong *deadlock_search_depth_short; + const ulong *timeout_long; + const ulong *deadlock_search_depth_long; + + /* + weight relates to the desirability of a transaction being killed if it's + part of a deadlock. In a deadlock situation transactions with lower weights + are killed first. + + Examples of using the weight to implement different selection strategies: + + 1. Latest + Keep all weights equal. + 2. Random + Assight weights at random. + (variant: modify a weight randomly before every lock request) + 3. Youngest + Set weight to -NOW() + 4. Minimum locks + count locks granted in your lock manager, store the value as a weight + 5. Minimum work + depends on the definition of "work". For example, store the number + of rows modifies in this transaction (or a length of REDO log for a + transaction) as a weight. + + It is only statistically relevant and is not protected by any locks. + */ + ulong volatile weight; + /* + 'killed' is indirectly protected by waiting_for->lock because + a killed thread needs to clear its 'waiting_for' and thus needs a lock. + That is a thread needs an exclusive lock to read 'killed' reliably. + But other threads may change 'killed' from 0 to 1, a shared + lock is enough for that. + */ + my_bool killed; +#ifndef DBUG_OFF + const char *name; +#endif +} WT_THD; + +#define WT_TIMEOUT ETIMEDOUT +#define WT_OK 0 +#define WT_DEADLOCK -1 +#define WT_DEPTH_EXCEEDED -2 +#define WT_FREE_TO_GO -3 + +void wt_init(void); +void wt_end(void); +void wt_thd_lazy_init(WT_THD *, const ulong *, const ulong *, const ulong *, const ulong *); +void wt_thd_destroy(WT_THD *); +int wt_thd_will_wait_for(WT_THD *, WT_THD *, const WT_RESOURCE_ID *); +int wt_thd_cond_timedwait(WT_THD *, pthread_mutex_t *); +void wt_thd_release(WT_THD *, const WT_RESOURCE_ID *); +#define wt_thd_release_all(THD) wt_thd_release((THD), 0) +my_bool wt_resource_id_memcmp(const void *, const void *); + +C_MODE_END + +#endif diff --git a/include/welcome_copyright_notice.h b/include/welcome_copyright_notice.h index 5a96da4ceb4..6898cc8630c 100644 --- a/include/welcome_copyright_notice.h +++ b/include/welcome_copyright_notice.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2011, Oracle and/or its affiliates. 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 @@ -22,10 +22,6 @@ */ #define ORACLE_WELCOME_COPYRIGHT_NOTICE(years) \ - "Copyright (c) " years ", Oracle and/or its affiliates. All rights reserved.\n" \ - "\n" \ - "Oracle is a registered trademark of Oracle Corporation and/or its\n" \ - "affiliates. Other names may be trademarks of their respective\n" \ - "owners.\n" + "Copyright (c) " years ", Oracle, Monty Program Ab and others.\n" #endif /* _welcome_copyright_notice_h_ */ diff --git a/include/wqueue.h b/include/wqueue.h new file mode 100644 index 00000000000..658f3d66f12 --- /dev/null +++ b/include/wqueue.h @@ -0,0 +1,27 @@ + +#ifndef _wqueue_h +#define _wqueue_h + +#include <my_global.h> +#include <my_pthread.h> + +/* info about requests in a waiting queue */ +typedef struct st_pagecache_wqueue +{ + struct st_my_thread_var *last_thread; /* circular list of waiting + threads */ +} WQUEUE; + +#ifdef THREAD +void wqueue_link_into_queue(WQUEUE *wqueue, struct st_my_thread_var *thread); +void wqueue_unlink_from_queue(WQUEUE *wqueue, struct st_my_thread_var *thread); +void wqueue_add_to_queue(WQUEUE *wqueue, struct st_my_thread_var *thread); +void wqueue_add_and_wait(WQUEUE *wqueue, + struct st_my_thread_var *thread, + pthread_mutex_t *lock); +void wqueue_release_queue(WQUEUE *wqueue); +void wqueue_release_one_locktype_from_queue(WQUEUE *wqueue); + +#endif + +#endif |