diff options
Diffstat (limited to 'include')
88 files changed, 4408 insertions, 1600 deletions
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index b2b64a08676..219a2917917 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -14,31 +14,27 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA SET(HEADERS_GEN_CONFIGURE -${CMAKE_CURRENT_BINARY_DIR}/mysql_version.h -${CMAKE_CURRENT_BINARY_DIR}/my_config.h -${CMAKE_CURRENT_BINARY_DIR}/mysqld_ername.h -${CMAKE_CURRENT_BINARY_DIR}/mysqld_error.h -${CMAKE_CURRENT_BINARY_DIR}/sql_state.h + mysql_version.h + my_config.h + mysqld_ername.h + mysqld_error.h + sql_state.h ) -SET(HEADERS_ABI + +SET(HEADERS mysql.h mysql_com.h mysql_time.h + ma_dyncol.h my_list.h my_alloc.h typelib.h - mysql/plugin.h - mysql/plugin_audit.h - mysql/plugin_ftparser.h -) - -SET(HEADERS - ${HEADERS_ABI} my_dbug.h m_string.h my_sys.h my_xml.h mysql_embed.h + my_decimal_limits.h my_pthread.h decimal.h errmsg.h @@ -49,13 +45,33 @@ SET(HEADERS my_dir.h sslopt-vars.h sslopt-case.h + my_valgrind.h sql_common.h keycache.h m_ctype.h my_attribute.h my_compiler.h - ${HEADERS_GEN_CONFIGURE} + handler_state.h + handler_ername.h ) INSTALL(FILES ${HEADERS} DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT Development) -INSTALL(DIRECTORY mysql/ DESTINATION ${INSTALL_INCLUDEDIR}/mysql COMPONENT Development FILES_MATCHING PATTERN "*.h") +FOREACH(f ${HEADERS_GEN_CONFIGURE}) + INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT Development PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) +ENDFOREACH(f) +INSTALL(DIRECTORY mysql/ DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT Development FILES_MATCHING PATTERN "*.h") + +STRING(REPLACE "." "\\." EXCL_RE "${HEADERS};${HEADERS_GEN_CONFIGURE}") +STRING(REPLACE ";" "|" EXCL_RE "${EXCL_RE}") + +INSTALL(DIRECTORY . DESTINATION ${INSTALL_INCLUDEDIR}/private COMPONENT Development + FILES_MATCHING PATTERN "*.h" + PATTERN CMakeFiles EXCLUDE + PATTERN mysql EXCLUDE + REGEX "\\./(${EXCL_RE}$)" EXCLUDE) + +INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/. DESTINATION ${INSTALL_INCLUDEDIR}/private COMPONENT Development + FILES_MATCHING PATTERN "*.h" + PATTERN CMakeFiles EXCLUDE + PATTERN mysql EXCLUDE + REGEX "\\./(${EXCL_RE}$)" EXCLUDE) diff --git a/include/atomic/nolock.h b/include/atomic/nolock.h index 1da184158ab..56f37644f96 100644 --- a/include/atomic/nolock.h +++ b/include/atomic/nolock.h @@ -36,7 +36,7 @@ choose the Solaris implementation on Solaris (mainly for SunStudio compilers). */ -# if defined(_MSV_VER) +# if defined(_MSC_VER) # include "generic-msvc.h" # elif __GNUC__ # if defined(HAVE_SOLARIS_ATOMIC) diff --git a/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h index 2238347d419..173e32e790c 100644 --- a/include/atomic/x86-gcc.h +++ b/include/atomic/x86-gcc.h @@ -124,10 +124,10 @@ asm volatile ("push %%ebx;" \ "movl (%%ecx), %%ebx;" \ "movl 4(%%ecx), %%ecx;" \ - LOCK_prefix "; cmpxchg8b %0;" \ + LOCK_prefix "; cmpxchg8b (%%esi);" \ "setz %2; pop %%ebx" \ - : "=m" (*a), "+A" (*cmp), "=c" (ret) \ - : "c" (&set), "m" (*a) \ + : "+S" (a), "+A" (*cmp), "=c" (ret) \ + : "c" (&set) \ : "memory", "esp") #endif diff --git a/include/decimal.h b/include/decimal.h index 0257242d865..935d341437d 100644 --- a/include/decimal.h +++ b/include/decimal.h @@ -41,14 +41,14 @@ int internal_str2dec(const char *from, decimal_t *to, char **end, int decimal2string(const decimal_t *from, char *to, int *to_len, int fixed_precision, int fixed_decimals, char filler); -int decimal2ulonglong(decimal_t *from, ulonglong *to); +int decimal2ulonglong(const decimal_t *from, ulonglong *to); int ulonglong2decimal(ulonglong from, decimal_t *to); -int decimal2longlong(decimal_t *from, longlong *to); +int decimal2longlong(const decimal_t *from, longlong *to); int longlong2decimal(longlong from, decimal_t *to); int decimal2double(const decimal_t *from, double *to); int double2decimal(double from, decimal_t *to); int decimal_actual_fraction(decimal_t *from); -int decimal2bin(decimal_t *from, uchar *to, int precision, int scale); +int decimal2bin(const decimal_t *from, uchar *to, int precision, int scale); int bin2decimal(const uchar *from, decimal_t *to, int precision, int scale); int decimal_size(int precision, int scale); diff --git a/include/ft_global.h b/include/ft_global.h index ca779735cb3..73726018d0a 100644 --- a/include/ft_global.h +++ b/include/ft_global.h @@ -26,6 +26,8 @@ extern "C" { #endif +#include <my_compare.h> + #define HA_FT_MAXBYTELEN 254 #define HA_FT_MAXCHARLEN (HA_FT_MAXBYTELEN/3) @@ -65,9 +67,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/handler_ername.h b/include/handler_ername.h new file mode 100644 index 00000000000..50f7f535806 --- /dev/null +++ b/include/handler_ername.h @@ -0,0 +1,81 @@ +/* Copyright (c) 2013 SkySQL 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ + +/* Names of all handler error numbers. Used by mysqltest */ + +{ "HA_ERR_KEY_NOT_FOUND", HA_ERR_KEY_NOT_FOUND, "" }, +{ "HA_ERR_FOUND_DUPP_KEY", HA_ERR_FOUND_DUPP_KEY, "" }, +{ "HA_ERR_INTERNAL_ERROR", HA_ERR_INTERNAL_ERROR, "" }, +{ "HA_ERR_RECORD_CHANGED", HA_ERR_RECORD_CHANGED, "" }, +{ "HA_ERR_WRONG_INDEX", HA_ERR_WRONG_INDEX, "" }, +{ "HA_ERR_CRASHED", HA_ERR_CRASHED, "" }, +{ "HA_ERR_WRONG_IN_RECORD", HA_ERR_WRONG_IN_RECORD, "" }, +{ "HA_ERR_OUT_OF_MEM", HA_ERR_OUT_OF_MEM, "" }, +{ "HA_ERR_NOT_A_TABLE", HA_ERR_NOT_A_TABLE, "" }, +{ "HA_ERR_WRONG_COMMAND", HA_ERR_WRONG_COMMAND, "" }, +{ "HA_ERR_OLD_FILE", HA_ERR_OLD_FILE, "" }, +{ "HA_ERR_NO_ACTIVE_RECORD", HA_ERR_NO_ACTIVE_RECORD, "" }, +{ "HA_ERR_RECORD_DELETED", HA_ERR_RECORD_DELETED, "" }, +{ "HA_ERR_RECORD_FILE_FULL", HA_ERR_RECORD_FILE_FULL, "" }, +{ "HA_ERR_INDEX_FILE_FULL", HA_ERR_INDEX_FILE_FULL, "" }, +{ "HA_ERR_END_OF_FILE", HA_ERR_END_OF_FILE, "" }, +{ "HA_ERR_UNSUPPORTED", HA_ERR_UNSUPPORTED, "" }, +{ "HA_ERR_TO_BIG_ROW", HA_ERR_TO_BIG_ROW, "" }, +{ "HA_WRONG_CREATE_OPTION", HA_WRONG_CREATE_OPTION, "" }, +{ "HA_ERR_FOUND_DUPP_UNIQUE", HA_ERR_FOUND_DUPP_UNIQUE, "" }, +{ "HA_ERR_UNKNOWN_CHARSET", HA_ERR_UNKNOWN_CHARSET, "" }, +{ "HA_ERR_WRONG_MRG_TABLE_DEF", HA_ERR_WRONG_MRG_TABLE_DEF, "" }, +{ "HA_ERR_CRASHED_ON_REPAIR", HA_ERR_CRASHED_ON_REPAIR, "" }, +{ "HA_ERR_CRASHED_ON_USAGE", HA_ERR_CRASHED_ON_USAGE, "" }, +{ "HA_ERR_LOCK_WAIT_TIMEOUT", HA_ERR_LOCK_WAIT_TIMEOUT, "" }, +{ "HA_ERR_LOCK_TABLE_FULL", HA_ERR_LOCK_TABLE_FULL, "" }, +{ "HA_ERR_READ_ONLY_TRANSACTION", HA_ERR_READ_ONLY_TRANSACTION, "" }, +{ "HA_ERR_LOCK_DEADLOCK", HA_ERR_LOCK_DEADLOCK, "" }, +{ "HA_ERR_CANNOT_ADD_FOREIGN", HA_ERR_CANNOT_ADD_FOREIGN, "" }, +{ "HA_ERR_NO_REFERENCED_ROW", HA_ERR_NO_REFERENCED_ROW, "" }, +{ "HA_ERR_ROW_IS_REFERENCED", HA_ERR_ROW_IS_REFERENCED, "" }, +{ "HA_ERR_NO_SAVEPOINT", HA_ERR_NO_SAVEPOINT, "" }, +{ "HA_ERR_NON_UNIQUE_BLOCK_SIZE", HA_ERR_NON_UNIQUE_BLOCK_SIZE, "" }, +{ "HA_ERR_NO_SUCH_TABLE", HA_ERR_NO_SUCH_TABLE, "" }, +{ "HA_ERR_TABLE_EXIST", HA_ERR_TABLE_EXIST, "" }, +{ "HA_ERR_NO_CONNECTION", HA_ERR_NO_CONNECTION, "" }, +{ "HA_ERR_NULL_IN_SPATIAL", HA_ERR_NULL_IN_SPATIAL, "" }, +{ "HA_ERR_TABLE_DEF_CHANGED", HA_ERR_TABLE_DEF_CHANGED, "" }, +{ "HA_ERR_NO_PARTITION_FOUND", HA_ERR_NO_PARTITION_FOUND, "" }, +{ "HA_ERR_RBR_LOGGING_FAILED", HA_ERR_RBR_LOGGING_FAILED, "" }, +{ "HA_ERR_DROP_INDEX_FK", HA_ERR_DROP_INDEX_FK, "" }, +{ "HA_ERR_FOREIGN_DUPLICATE_KEY", HA_ERR_FOREIGN_DUPLICATE_KEY, "" }, +{ "HA_ERR_TABLE_NEEDS_UPGRADE", HA_ERR_TABLE_NEEDS_UPGRADE, "" }, +{ "HA_ERR_TABLE_READONLY", HA_ERR_TABLE_READONLY, "" }, +{ "HA_ERR_AUTOINC_READ_FAILED", HA_ERR_AUTOINC_READ_FAILED, "" }, +{ "HA_ERR_AUTOINC_ERANGE", HA_ERR_AUTOINC_ERANGE, "" }, +{ "HA_ERR_GENERIC", HA_ERR_GENERIC, "" }, +{ "HA_ERR_RECORD_IS_THE_SAME", HA_ERR_RECORD_IS_THE_SAME, "" }, +{ "HA_ERR_LOGGING_IMPOSSIBLE", HA_ERR_LOGGING_IMPOSSIBLE, "" }, +{ "HA_ERR_CORRUPT_EVENT", HA_ERR_CORRUPT_EVENT, "" }, +{ "HA_ERR_NEW_FILE", HA_ERR_NEW_FILE, "" }, +{ "HA_ERR_ROWS_EVENT_APPLY", HA_ERR_ROWS_EVENT_APPLY, "" }, +{ "HA_ERR_INITIALIZATION", HA_ERR_INITIALIZATION, "" }, +{ "HA_ERR_FILE_TOO_SHORT", HA_ERR_FILE_TOO_SHORT, "" }, +{ "HA_ERR_WRONG_CRC", HA_ERR_WRONG_CRC, "" }, +{ "HA_ERR_TOO_MANY_CONCURRENT_TRXS", HA_ERR_TOO_MANY_CONCURRENT_TRXS, "" }, +{ "HA_ERR_INDEX_COL_TOO_LONG", HA_ERR_INDEX_COL_TOO_LONG, "" }, +{ "HA_ERR_INDEX_CORRUPT", HA_ERR_INDEX_CORRUPT, "" }, +{ "HA_ERR_UNDO_REC_TOO_BIG", HA_ERR_UNDO_REC_TOO_BIG, "" }, +{ "HA_ERR_TABLE_IN_FK_CHECK", HA_ERR_TABLE_IN_FK_CHECK, "" }, +{ "HA_ERR_ROW_NOT_VISIBLE", HA_ERR_ROW_NOT_VISIBLE, "" }, +{ "HA_ERR_ABORTED_BY_USER", HA_ERR_ABORTED_BY_USER, "" }, +{ "HA_ERR_DISK_FULL", HA_ERR_DISK_FULL, "" }, +{ "HA_ERR_INCOMPATIBLE_DEFINITION", HA_ERR_INCOMPATIBLE_DEFINITION, "" }, diff --git a/include/handler_state.h b/include/handler_state.h new file mode 100644 index 00000000000..65604a672fb --- /dev/null +++ b/include/handler_state.h @@ -0,0 +1,21 @@ +/* + Map handler error message to sql states. Note that this list MUST be in + increasing order! + See sql_state.c for usage +*/ + +{ HA_ERR_KEY_NOT_FOUND, "02000", "" }, +{ HA_ERR_FOUND_DUPP_KEY, "23000", "" }, +{ HA_ERR_WRONG_COMMAND, "0A000", "" }, +{ HA_ERR_UNSUPPORTED, "0A000", "" }, +{ HA_WRONG_CREATE_OPTION, "0A000", "" }, +{ HA_ERR_FOUND_DUPP_UNIQUE, "23000", "" }, +{ HA_ERR_UNKNOWN_CHARSET, "0A000", "" }, +{ HA_ERR_READ_ONLY_TRANSACTION, "25000", "" }, +{ HA_ERR_LOCK_DEADLOCK, "40001", "" }, +{ HA_ERR_NO_REFERENCED_ROW, "23000", "" }, +{ HA_ERR_ROW_IS_REFERENCED, "23000", "" }, +{ HA_ERR_TABLE_EXIST, "42S01", "" }, +{ HA_ERR_FOREIGN_DUPLICATE_KEY, "23000", "" }, +{ HA_ERR_TABLE_READONLY, "25000", "" }, +{ HA_ERR_AUTOINC_ERANGE, "22003", "" }, diff --git a/include/hash.h b/include/hash.h index c0efa28fed8..98bcf911db2 100644 --- a/include/hash.h +++ b/include/hash.h @@ -27,11 +27,6 @@ typedef declarations, even when identical, the definition may not be repeated. */ -#ifndef CHARSET_INFO_DEFINED -#define CHARSET_INFO_DEFINED -typedef struct charset_info_st CHARSET_INFO; -#endif /* CHARSET_INFO_DEFINED */ - #ifdef __cplusplus extern "C" { #endif @@ -48,6 +43,7 @@ extern "C" { typedef uint my_hash_value_type; 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 */ @@ -96,6 +92,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 02cb5400686..2b7fd28699d 100644 --- a/include/heap.h +++ b/include/heap.h @@ -1,5 +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 @@ -103,8 +102,8 @@ typedef struct st_heap_block HP_PTRS *root; /* Top-level block */ struct st_level_info level_info[HP_MAX_LEVELS+1]; uint levels; /* number of used levels */ - uint records_in_block; /* Records in one heap-block */ uint recbuffer; /* Length of one saved record */ + ulong records_in_block; /* Records in one heap-block */ ulong last_allocated; /* number of records there is allocated space for */ } HP_BLOCK; @@ -135,12 +134,15 @@ typedef struct st_heap_share { HP_BLOCK block; HP_KEYDEF *keydef; - ulong min_records,max_records; /* Params to open */ ulonglong data_length,index_length,max_table_size; + ulonglong auto_increment; + ulong min_records,max_records; /* Params to open */ + ulong records; /* records */ + ulong blength; /* records rounded up to 2^n */ + ulong deleted; /* Deleted records in database */ uint key_stat_version; /* version to indicate insert/delete */ - uint records; /* records */ - uint blength; /* records rounded up to 2^n */ - uint deleted; /* Deleted records in database */ + uint key_version; /* Updated on key change */ + uint file_version; /* Update on clear */ uint reclength; /* Length of one record */ uint changed; uint keys,max_key_length; @@ -155,7 +157,6 @@ typedef struct st_heap_share LIST open_list; uint auto_key; uint auto_key_type; /* real type of the auto key segment */ - ulonglong auto_increment; } HP_SHARE; struct st_hp_hash_info; @@ -174,6 +175,8 @@ typedef struct st_heap_info enum ha_rkey_function last_find_flag; TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1]; TREE_ELEMENT **last_pos; + uint key_version; /* Version at last read */ + uint file_version; /* Version at scan */ uint lastkey_len; my_bool implicit_emptied; THR_LOCK_DATA lock; @@ -184,12 +187,12 @@ typedef struct st_heap_info typedef struct st_heap_create_info { HP_KEYDEF *keydef; - ulong max_records; - ulong min_records; uint auto_key; /* keynr [1 - maxkey] for auto key */ uint auto_key_type; uint keys; uint reclength; + ulong max_records; + ulong min_records; ulonglong max_table_size; ulonglong auto_increment; my_bool with_auto_increment; diff --git a/include/keycache.h b/include/keycache.h index 3184f980298..8fa9bf1cd18 100644 --- a/include/keycache.h +++ b/include/keycache.h @@ -22,96 +22,145 @@ C_MODE_START -/* declare structures that is used by st_key_cache */ +/* + Currently the default key cache is created as non-partitioned at + the start of the server unless the server is started with the parameter + --key-cache-partitions that is greater than 0 +*/ -struct st_block_link; -typedef struct st_block_link BLOCK_LINK; -struct st_keycache_page; -typedef struct st_keycache_page KEYCACHE_PAGE; -struct st_hash_link; -typedef struct st_hash_link HASH_LINK; +#define DEFAULT_KEY_CACHE_PARTITIONS 0 -/* info about requests in a waiting queue */ -typedef struct st_keycache_wqueue -{ - struct st_my_thread_var *last_thread; /* circular list of waiting threads */ -} KEYCACHE_WQUEUE; +/* + MAX_KEY_CACHE_PARTITIONS cannot be greater than + sizeof(MYISAM_SHARE::dirty_part_map) + Currently sizeof(MYISAM_SHARE::dirty_part_map)=sizeof(ulonglong) +*/ + +#define MAX_KEY_CACHE_PARTITIONS 64 + +/* The structure to get statistical data about a key cache */ -#define CHANGED_BLOCKS_HASH 128 /* must be power of 2 */ +typedef struct st_key_cache_statistics +{ + ulonglong mem_size; /* memory for cache buffers/auxiliary structures */ + ulonglong block_size; /* size of the each buffers in the key cache */ + ulonglong blocks_used; /* maximum number of used blocks/buffers */ + ulonglong blocks_unused; /* number of currently unused blocks */ + ulonglong blocks_changed; /* number of currently dirty blocks */ + ulonglong blocks_warm; /* number of blocks in warm sub-chain */ + ulonglong read_requests; /* number of read requests (read hits) */ + ulonglong reads; /* number of actual reads from files into buffers */ + ulonglong write_requests; /* number of write requests (write hits) */ + ulonglong writes; /* number of actual writes from buffers into files */ +} KEY_CACHE_STATISTICS; + +#define NUM_LONG_KEY_CACHE_STAT_VARIABLES 3 + +/* The type of a key cache object */ +typedef enum key_cache_type +{ + SIMPLE_KEY_CACHE, + PARTITIONED_KEY_CACHE +} KEY_CACHE_TYPE; + + +typedef + int (*INIT_KEY_CACHE) + (void *, uint key_cache_block_size, + size_t use_mem, uint division_limit, uint age_threshold); +typedef + int (*RESIZE_KEY_CACHE) + (void *, uint key_cache_block_size, + size_t use_mem, uint division_limit, uint age_threshold); +typedef + void (*CHANGE_KEY_CACHE_PARAM) + (void *keycache_cb, + uint division_limit, uint age_threshold); +typedef + uchar* (*KEY_CACHE_READ) + (void *keycache_cb, + File file, my_off_t filepos, int level, + uchar *buff, uint length, + uint block_length, int return_buffer); +typedef + int (*KEY_CACHE_INSERT) + (void *keycache_cb, + File file, my_off_t filepos, int level, + uchar *buff, uint length); +typedef + int (*KEY_CACHE_WRITE) + (void *keycache_cb, + File file, void *file_extra, + my_off_t filepos, int level, + uchar *buff, uint length, + uint block_length, int force_write); +typedef + int (*FLUSH_KEY_BLOCKS) + (void *keycache_cb, + int file, void *file_extra, + enum flush_type type); +typedef + int (*RESET_KEY_CACHE_COUNTERS) + (const char *name, void *keycache_cb); +typedef + void (*END_KEY_CACHE) + (void *keycache_cb, my_bool cleanup); +typedef + void (*GET_KEY_CACHE_STATISTICS) + (void *keycache_cb, uint partition_no, + KEY_CACHE_STATISTICS *key_cache_stats); /* - The key cache structure - It also contains read-only statistics parameters. + An object of the type KEY_CACHE_FUNCS contains pointers to all functions + from the key cache interface. + Currently a key cache can be of two types: simple and partitioned. + For each of them its own static structure of the type KEY_CACHE_FUNCS is + defined . The structures contain the pointers to the implementations of + the interface functions used by simple key caches and partitioned key + caches respectively. Pointers to these structures are assigned to key cache + objects at the time of their creation. */ +typedef struct st_key_cache_funcs +{ + INIT_KEY_CACHE init; + RESIZE_KEY_CACHE resize; + CHANGE_KEY_CACHE_PARAM change_param; + KEY_CACHE_READ read; + KEY_CACHE_INSERT insert; + KEY_CACHE_WRITE write; + FLUSH_KEY_BLOCKS flush; + RESET_KEY_CACHE_COUNTERS reset_counters; + END_KEY_CACHE end; + GET_KEY_CACHE_STATISTICS get_stats; +} KEY_CACHE_FUNCS; + + typedef struct st_key_cache { - my_bool key_cache_inited; - my_bool in_resize; /* true during resize operation */ - my_bool resize_in_flush; /* true during flush of resize operation */ + KEY_CACHE_TYPE key_cache_type; /* type of the key cache used for debugging */ + void *keycache_cb; /* control block of the used key cache */ + KEY_CACHE_FUNCS *interface_funcs; /* interface functions of the key cache */ + ulonglong param_buff_size; /* size the memory allocated for the cache */ + ulonglong param_block_size; /* size of the blocks in the key cache */ + ulonglong param_division_limit;/* min. percentage of warm blocks */ + ulonglong param_age_threshold; /* determines when hot block is downgraded */ + ulonglong param_partitions; /* number of the key cache partitions */ + my_bool key_cache_inited; /* <=> key cache has been created */ my_bool can_be_used; /* usage of cache for read/write is allowed */ - size_t key_cache_mem_size; /* specified size of the cache memory */ - uint key_cache_block_size; /* size of the page buffer of a cache block */ - ulong min_warm_blocks; /* min number of warm blocks; */ - ulong age_threshold; /* age threshold for hot blocks */ - ulonglong keycache_time; /* total number of block link operations */ - uint hash_entries; /* max number of entries in the hash table */ - int hash_links; /* max number of hash links */ - int hash_links_used; /* number of hash links currently used */ - int disk_blocks; /* max number of blocks in the cache */ - ulong blocks_used; /* maximum number of concurrently used blocks */ - ulong blocks_unused; /* number of currently unused blocks */ - ulong blocks_changed; /* number of currently dirty blocks */ - ulong warm_blocks; /* number of blocks in warm sub-chain */ - ulong cnt_for_resize_op; /* counter to block resize operation */ - long blocks_available; /* number of blocks available in the LRU chain */ - HASH_LINK **hash_root; /* arr. of entries into hash table buckets */ - HASH_LINK *hash_link_root; /* memory for hash table links */ - HASH_LINK *free_hash_list; /* list of free hash links */ - BLOCK_LINK *free_block_list; /* list of free blocks */ - BLOCK_LINK *block_root; /* memory for block links */ - uchar *block_mem; /* memory for block buffers */ - BLOCK_LINK *used_last; /* ptr to the last block of the LRU chain */ - BLOCK_LINK *used_ins; /* ptr to the insertion block in LRU chain */ - mysql_mutex_t cache_lock; /* to lock access to the cache structure */ - KEYCACHE_WQUEUE resize_queue; /* threads waiting during resize operation */ - /* - Waiting for a zero resize count. Using a queue for symmetry though - only one thread can wait here. - */ - KEYCACHE_WQUEUE waiting_for_resize_cnt; - KEYCACHE_WQUEUE waiting_for_hash_link; /* waiting for a free hash link */ - KEYCACHE_WQUEUE waiting_for_block; /* requests waiting for a free block */ - BLOCK_LINK *changed_blocks[CHANGED_BLOCKS_HASH]; /* hash for dirty file bl.*/ - BLOCK_LINK *file_blocks[CHANGED_BLOCKS_HASH]; /* hash for other file bl.*/ - - /* - The following variables are and variables used to hold parameters for - initializing the key cache. - */ - - ulonglong param_buff_size; /* size the memory allocated for the cache */ - ulonglong param_block_size; /* size of the blocks in the key cache */ - ulonglong param_division_limit; /* min. percentage of warm blocks */ - ulonglong param_age_threshold; /* determines when hot block is downgraded */ - - /* Statistics variables. These are reset in reset_key_cache_counters(). */ - ulong global_blocks_changed; /* number of currently dirty blocks */ - ulonglong global_cache_w_requests;/* number of write requests (write hits) */ - ulonglong global_cache_write; /* number of writes from cache to files */ - ulonglong global_cache_r_requests;/* number of read requests (read hits) */ - ulonglong global_cache_read; /* number of reads from files to cache */ - - int blocks; /* max number of blocks in the cache */ - my_bool in_init; /* Set to 1 in MySQL during init/resize */ + my_bool in_init; /* set to 1 in MySQL during init/resize */ + uint partitions; /* actual number of partitions */ + size_t key_cache_mem_size; /* specified size of the cache memory */ + pthread_mutex_t op_lock; /* to serialize operations like 'resize' */ } KEY_CACHE; + /* The default key cache */ extern KEY_CACHE dflt_key_cache_var, *dflt_key_cache; extern int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, size_t use_mem, uint division_limit, - uint age_threshold); + uint age_threshold, uint partitions); extern int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, size_t use_mem, uint division_limit, uint age_threshold); @@ -125,22 +174,34 @@ extern int key_cache_insert(KEY_CACHE *keycache, File file, my_off_t filepos, int level, uchar *buff, uint length); extern int key_cache_write(KEY_CACHE *keycache, - File file, my_off_t filepos, int level, + File file, void *file_extra, + my_off_t filepos, int level, uchar *buff, uint length, - uint block_length,int force_write); + uint block_length, int force_write); extern int flush_key_blocks(KEY_CACHE *keycache, - int file, enum flush_type type); + int file, void *file_extra, + enum flush_type type); extern void end_key_cache(KEY_CACHE *keycache, my_bool cleanup); +extern void get_key_cache_statistics(KEY_CACHE *keycache, + uint partition_no, + KEY_CACHE_STATISTICS *key_cache_stats); /* 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, KEY_CACHE *new_data); extern int reset_key_cache_counters(const char *name, - KEY_CACHE *key_cache); + KEY_CACHE *key_cache, void *); +extern int repartition_key_cache(KEY_CACHE *keycache, + uint key_cache_block_size, + size_t use_mem, + uint division_limit, + uint age_threshold, + uint partitions); C_MODE_END #endif /* _keycache_h */ diff --git a/include/lf.h b/include/lf.h index 01f10234f05..07769d10943 100644 --- a/include/lf.h +++ b/include/lf.h @@ -95,7 +95,7 @@ nolock_wrap(lf_dynarray_iterate, int, */ #define LF_PINBOX_PINS 4 -#define LF_PURGATORY_SIZE 10 +#define LF_PURGATORY_SIZE 100 typedef void lf_pinbox_free_func(void *, void *, void*); @@ -115,10 +115,11 @@ typedef struct { void *purgatory; uint32 purgatory_count; uint32 volatile link; -/* we want sizeof(LF_PINS) to be 64 to avoid false sharing */ -#if SIZEOF_INT*2+SIZEOF_CHARP*(LF_PINBOX_PINS+3) != 64 - char pad[64-sizeof(uint32)*2-sizeof(void*)*(LF_PINBOX_PINS+3)]; -#endif +/* 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; /* @@ -187,6 +188,8 @@ typedef struct st_lf_allocator { 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); @@ -220,7 +223,8 @@ C_MODE_START #define LF_HASH_UNIQUE 1 -/* lf_hash overhead per element is sizeof(LF_SLIST). */ +/* lf_hash overhead per element (that is, sizeof(LF_SLIST) */ +extern const int LF_HASH_OVERHEAD; typedef struct { LF_DYNARRAY array; /* hash itself */ diff --git a/include/m_ctype.h b/include/m_ctype.h index 87b1e529f65..001884afe81 100644 --- a/include/m_ctype.h +++ b/include/m_ctype.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2013, 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 @@ -33,11 +33,11 @@ extern "C" { #define MY_CS_TO_UPPER_TABLE_SIZE 256 #define MY_CS_SORT_ORDER_TABLE_SIZE 256 #define MY_CS_TO_UNI_TABLE_SIZE 256 + #define CHARSET_DIR "charsets/" #define my_wc_t ulong -#define MY_CS_MAX_CHAR 0xFFFF #define MY_CS_REPLACEMENT_CHARACTER 0xFFFD /* @@ -54,26 +54,47 @@ extern "C" { #define MY_PUT_MB2(s, code) { (s)[0]= code >> 8; (s)[1]= code & 0xFF; } #endif +typedef const struct my_charset_handler_st MY_CHARSET_HANDLER; +typedef const struct my_collation_handler_st MY_COLLATION_HANDLER; +typedef const struct unicase_info_st MY_UNICASE_INFO; +typedef const struct uni_ctype_st MY_UNI_CTYPE; +typedef const struct my_uni_idx_st MY_UNI_IDX; -typedef struct unicase_info_st +struct unicase_info_st { uint32 toupper; uint32 tolower; uint32 sort; -} MY_UNICASE_INFO; +}; + +extern MY_UNICASE_INFO *const my_unicase_default[256]; +extern MY_UNICASE_INFO *const my_unicase_turkish[256]; +extern MY_UNICASE_INFO *const my_unicase_mysql500[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; -extern MY_UNICASE_INFO *my_unicase_default[256]; -extern MY_UNICASE_INFO *my_unicase_turkish[256]; -extern MY_UNICASE_INFO *my_unicase_mysql500[256]; +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 +struct uni_ctype_st { uchar pctype; - uchar *ctype; -} MY_UNI_CTYPE; + const uchar *ctype; +}; extern MY_UNI_CTYPE my_uni_ctype[256]; @@ -101,7 +122,7 @@ extern MY_UNI_CTYPE my_uni_ctype[256]; #define MY_CS_BINSORT 16 /* if binary sort order */ #define MY_CS_PRIMARY 32 /* if primary collation */ #define MY_CS_STRNXFRM 64 /* if strnxfrm is used for sort */ -#define MY_CS_UNICODE 128 /* is a charset is BMP Unicode */ +#define MY_CS_UNICODE 128 /* is a charset is full unicode */ #define MY_CS_READY 256 /* if a charset is initialized */ #define MY_CS_AVAILABLE 512 /* If either compiled-in or loaded*/ #define MY_CS_CSSORT 1024 /* if case sensitive sort order */ @@ -116,12 +137,12 @@ extern MY_UNI_CTYPE my_uni_ctype[256]; #define MY_REPERTOIRE_EXTENDED 2 /* Extended characters: U+0080..U+FFFF */ #define MY_REPERTOIRE_UNICODE30 3 /* ASCII | EXTENDED: U+0000..U+FFFF */ -typedef struct my_uni_idx_st +struct my_uni_idx_st { uint16 from; uint16 to; - uchar *tab; -} MY_UNI_IDX; + const uchar *tab; +}; typedef struct { @@ -143,7 +164,8 @@ enum my_lex_states MY_LEX_USER_VARIABLE_DELIMITER, MY_LEX_SYSTEM_VAR, MY_LEX_IDENT_OR_KEYWORD, MY_LEX_IDENT_OR_HEX, MY_LEX_IDENT_OR_BIN, MY_LEX_IDENT_OR_NCHAR, - MY_LEX_STRING_OR_DELIMITER + MY_LEX_STRING_OR_DELIMITER, MY_LEX_MINUS_OR_COMMENT, MY_LEX_PLACEHOLDER, + MY_LEX_COMMA }; struct charset_info_st; @@ -152,41 +174,41 @@ struct charset_info_st; extern int (*my_string_stack_guard)(int); /* See strings/CHARSET_INFO.txt for information about this structure */ -typedef struct my_collation_handler_st +struct my_collation_handler_st { my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t)); /* Collation routines */ - int (*strnncoll)(struct charset_info_st *, + int (*strnncoll)(CHARSET_INFO *, const uchar *, size_t, const uchar *, size_t, my_bool); - int (*strnncollsp)(struct charset_info_st *, + int (*strnncollsp)(CHARSET_INFO *, const uchar *, size_t, const uchar *, size_t, my_bool diff_if_only_endspace_difference); - size_t (*strnxfrm)(struct charset_info_st *, + size_t (*strnxfrm)(CHARSET_INFO *, uchar *, size_t, const uchar *, size_t); - size_t (*strnxfrmlen)(struct charset_info_st *, size_t); - my_bool (*like_range)(struct charset_info_st *, + size_t (*strnxfrmlen)(CHARSET_INFO *, size_t); + my_bool (*like_range)(CHARSET_INFO *, const char *s, size_t s_length, pchar w_prefix, pchar w_one, pchar w_many, size_t res_length, char *min_str, char *max_str, size_t *min_len, size_t *max_len); - int (*wildcmp)(struct charset_info_st *, + int (*wildcmp)(CHARSET_INFO *, const char *str,const char *str_end, const char *wildstr,const char *wildend, int escape,int w_one, int w_many); - int (*strcasecmp)(struct charset_info_st *, const char *, const char *); + int (*strcasecmp)(CHARSET_INFO *, const char *, const char *); - uint (*instr)(struct charset_info_st *, + uint (*instr)(CHARSET_INFO *, const char *b, size_t b_length, const char *s, size_t s_length, my_match_t *match, uint nmatch); /* Hash calculation */ - void (*hash_sort)(struct charset_info_st *cs, const uchar *key, size_t len, + void (*hash_sort)(CHARSET_INFO *cs, const uchar *key, size_t len, ulong *nr1, ulong *nr2); - my_bool (*propagate)(struct charset_info_st *cs, const uchar *str, size_t len); -} MY_COLLATION_HANDLER; + my_bool (*propagate)(CHARSET_INFO *cs, const uchar *str, size_t len); +}; extern MY_COLLATION_HANDLER my_collation_mb_bin_handler; extern MY_COLLATION_HANDLER my_collation_8bit_bin_handler; @@ -194,89 +216,82 @@ extern MY_COLLATION_HANDLER my_collation_8bit_simple_ci_handler; extern MY_COLLATION_HANDLER my_collation_ucs2_uca_handler; /* Some typedef to make it easy for C++ to make function pointers */ -typedef int (*my_charset_conv_mb_wc)(struct charset_info_st *, my_wc_t *, +typedef int (*my_charset_conv_mb_wc)(CHARSET_INFO *, my_wc_t *, const uchar *, const uchar *); -typedef int (*my_charset_conv_wc_mb)(struct charset_info_st *, my_wc_t, +typedef int (*my_charset_conv_wc_mb)(CHARSET_INFO *, my_wc_t, uchar *, uchar *); -typedef size_t (*my_charset_conv_case)(struct charset_info_st *, +typedef size_t (*my_charset_conv_case)(CHARSET_INFO *, char *, size_t, char *, size_t); /* See strings/CHARSET_INFO.txt about information on this structure */ -typedef struct my_charset_handler_st +struct my_charset_handler_st { my_bool (*init)(struct charset_info_st *, void *(*alloc)(size_t)); /* Multibyte routines */ - uint (*ismbchar)(struct charset_info_st *, const char *, const char *); - uint (*mbcharlen)(struct charset_info_st *, uint c); - size_t (*numchars)(struct charset_info_st *, const char *b, const char *e); - size_t (*charpos)(struct charset_info_st *, const char *b, const char *e, + uint (*ismbchar)(CHARSET_INFO *, const char *, const char *); + uint (*mbcharlen)(CHARSET_INFO *, uint c); + size_t (*numchars)(CHARSET_INFO *, const char *b, const char *e); + size_t (*charpos)(CHARSET_INFO *, const char *b, const char *e, size_t pos); - size_t (*well_formed_len)(struct charset_info_st *, + size_t (*well_formed_len)(CHARSET_INFO *, const char *b,const char *e, size_t nchars, int *error); - size_t (*lengthsp)(struct charset_info_st *, const char *ptr, size_t length); - size_t (*numcells)(struct charset_info_st *, const char *b, const char *e); + size_t (*lengthsp)(CHARSET_INFO *, const char *ptr, size_t length); + size_t (*numcells)(CHARSET_INFO *, const char *b, const char *e); /* Unicode conversion */ my_charset_conv_mb_wc mb_wc; my_charset_conv_wc_mb wc_mb; /* CTYPE scanner */ - int (*ctype)(struct charset_info_st *cs, int *ctype, + int (*ctype)(CHARSET_INFO *cs, int *ctype, const uchar *s, const uchar *e); /* Functions for case and sort conversion */ - size_t (*caseup_str)(struct charset_info_st *, char *); - size_t (*casedn_str)(struct charset_info_st *, char *); + size_t (*caseup_str)(CHARSET_INFO *, char *); + size_t (*casedn_str)(CHARSET_INFO *, char *); my_charset_conv_case caseup; my_charset_conv_case casedn; /* Charset dependant snprintf() */ - size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, + size_t (*snprintf)(CHARSET_INFO *, char *to, size_t n, const char *fmt, ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5); - size_t (*long10_to_str)(struct charset_info_st *, char *to, size_t n, + size_t (*long10_to_str)(CHARSET_INFO *, char *to, size_t n, int radix, long int val); - size_t (*longlong10_to_str)(struct charset_info_st *, char *to, size_t n, + size_t (*longlong10_to_str)(CHARSET_INFO *, char *to, size_t n, int radix, longlong val); - void (*fill)(struct charset_info_st *, char *to, size_t len, int fill); + void (*fill)(CHARSET_INFO *, char *to, size_t len, int fill); /* String-to-number conversion routines */ - long (*strntol)(struct charset_info_st *, const char *s, size_t l, + long (*strntol)(CHARSET_INFO *, const char *s, size_t l, int base, char **e, int *err); - ulong (*strntoul)(struct charset_info_st *, const char *s, size_t l, + ulong (*strntoul)(CHARSET_INFO *, const char *s, size_t l, int base, char **e, int *err); - longlong (*strntoll)(struct charset_info_st *, const char *s, size_t l, + longlong (*strntoll)(CHARSET_INFO *, const char *s, size_t l, int base, char **e, int *err); - ulonglong (*strntoull)(struct charset_info_st *, const char *s, size_t l, + ulonglong (*strntoull)(CHARSET_INFO *, const char *s, size_t l, int base, char **e, int *err); - double (*strntod)(struct charset_info_st *, char *s, size_t l, char **e, + double (*strntod)(CHARSET_INFO *, char *s, size_t l, char **e, int *err); - longlong (*strtoll10)(struct charset_info_st *cs, + longlong (*strtoll10)(CHARSET_INFO *cs, const char *nptr, char **endptr, int *error); - ulonglong (*strntoull10rnd)(struct charset_info_st *cs, + ulonglong (*strntoull10rnd)(CHARSET_INFO *cs, const char *str, size_t length, int unsigned_fl, char **endptr, int *error); - size_t (*scan)(struct charset_info_st *, const char *b, const char *e, + size_t (*scan)(CHARSET_INFO *, const char *b, const char *e, int sq); -} MY_CHARSET_HANDLER; +}; extern MY_CHARSET_HANDLER my_charset_8bit_handler; extern MY_CHARSET_HANDLER my_charset_ucs2_handler; - -/* - We define this CHARSET_INFO_DEFINED here to prevent a repeat of the - typedef in hash.c, which will cause a compiler error. -*/ -#define CHARSET_INFO_DEFINED - /* See strings/CHARSET_INFO.txt about information on this structure */ -typedef struct charset_info_st +struct charset_info_st { uint number; uint primary_number; @@ -286,17 +301,17 @@ typedef struct charset_info_st const char *name; const char *comment; const char *tailoring; - uchar *ctype; - uchar *to_lower; - uchar *to_upper; - uchar *sort_order; - uint16 *contractions; - uint16 **sort_order_big; - uint16 *tab_to_uni; - MY_UNI_IDX *tab_from_uni; - MY_UNICASE_INFO **caseinfo; - uchar *state_map; - uchar *ident_map; + const uchar *ctype; + const uchar *to_lower; + const uchar *to_upper; + const uchar *sort_order; + const MY_CONTRACTIONS *contractions; + const uint16 *const *sort_order_big; + const uint16 *tab_to_uni; + MY_UNI_IDX *tab_from_uni; + MY_UNICASE_INFO *const *caseinfo; + const uchar *state_map; + const uchar *ident_map; uint strxfrm_multiply; uchar caseup_multiply; uchar casedn_multiply; @@ -310,83 +325,62 @@ typedef struct charset_info_st MY_CHARSET_HANDLER *cset; MY_COLLATION_HANDLER *coll; -} CHARSET_INFO; +}; #define ILLEGAL_CHARSET_INFO_NUMBER (~0U) +extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_bin; +extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_latin1; +extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_filename; +extern MYSQL_PLUGIN_IMPORT struct charset_info_st my_charset_utf8_general_ci; + +extern struct charset_info_st my_charset_big5_bin; +extern struct charset_info_st my_charset_big5_chinese_ci; +extern struct charset_info_st my_charset_cp1250_czech_ci; +extern struct charset_info_st my_charset_cp932_bin; +extern struct charset_info_st my_charset_cp932_japanese_ci; +extern struct charset_info_st my_charset_eucjpms_bin; +extern struct charset_info_st my_charset_eucjpms_japanese_ci; +extern struct charset_info_st my_charset_euckr_bin; +extern struct charset_info_st my_charset_euckr_korean_ci; +extern struct charset_info_st my_charset_gb2312_bin; +extern struct charset_info_st my_charset_gb2312_chinese_ci; +extern struct charset_info_st my_charset_gbk_bin; +extern struct charset_info_st my_charset_gbk_chinese_ci; +extern struct charset_info_st my_charset_latin1_bin; +extern struct charset_info_st my_charset_latin1_german2_ci; +extern struct charset_info_st my_charset_latin2_czech_ci; +extern struct charset_info_st my_charset_sjis_bin; +extern struct charset_info_st my_charset_sjis_japanese_ci; +extern struct charset_info_st my_charset_tis620_bin; +extern struct charset_info_st my_charset_tis620_thai_ci; +extern struct charset_info_st my_charset_ucs2_bin; +extern struct charset_info_st my_charset_ucs2_general_ci; +extern struct charset_info_st my_charset_ucs2_general_mysql500_ci; +extern struct charset_info_st my_charset_ucs2_unicode_ci; +extern struct charset_info_st my_charset_ucs2_general_mysql500_ci; +extern struct charset_info_st my_charset_ujis_bin; +extern struct charset_info_st my_charset_ujis_japanese_ci; +extern struct charset_info_st my_charset_utf16_bin; +extern struct charset_info_st my_charset_utf16_general_ci; +extern struct charset_info_st my_charset_utf16_unicode_ci; +extern struct charset_info_st my_charset_utf32_bin; +extern struct charset_info_st my_charset_utf32_general_ci; +extern struct charset_info_st my_charset_utf32_unicode_ci; +extern struct charset_info_st my_charset_utf8_bin; +extern struct charset_info_st my_charset_utf8_general_mysql500_ci; +extern struct charset_info_st my_charset_utf8_unicode_ci; +extern struct charset_info_st my_charset_utf8mb4_bin; +extern struct charset_info_st my_charset_utf8mb4_general_ci; +extern struct charset_info_st my_charset_utf8mb4_unicode_ci; -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin; -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1; -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename; - -extern CHARSET_INFO my_charset_big5_chinese_ci; -extern CHARSET_INFO my_charset_big5_bin; -extern CHARSET_INFO my_charset_cp932_japanese_ci; -extern CHARSET_INFO my_charset_cp932_bin; -extern CHARSET_INFO my_charset_cp1250_czech_ci; -extern CHARSET_INFO my_charset_eucjpms_japanese_ci; -extern CHARSET_INFO my_charset_eucjpms_bin; -extern CHARSET_INFO my_charset_euckr_korean_ci; -extern CHARSET_INFO my_charset_euckr_bin; -extern CHARSET_INFO my_charset_gb2312_chinese_ci; -extern CHARSET_INFO my_charset_gb2312_bin; -extern CHARSET_INFO my_charset_gbk_chinese_ci; -extern CHARSET_INFO my_charset_gbk_bin; -extern CHARSET_INFO my_charset_latin1_german2_ci; -extern CHARSET_INFO my_charset_latin1_bin; -extern CHARSET_INFO my_charset_latin2_czech_ci; -extern CHARSET_INFO my_charset_sjis_japanese_ci; -extern CHARSET_INFO my_charset_sjis_bin; -extern CHARSET_INFO my_charset_tis620_thai_ci; -extern CHARSET_INFO my_charset_tis620_bin; -extern CHARSET_INFO my_charset_ucs2_general_ci; -extern CHARSET_INFO my_charset_ucs2_bin; -extern CHARSET_INFO my_charset_ucs2_unicode_ci; -extern CHARSET_INFO my_charset_ucs2_general_mysql500_ci; -extern CHARSET_INFO my_charset_ujis_japanese_ci; -extern CHARSET_INFO my_charset_ujis_bin; -extern CHARSET_INFO my_charset_utf16_bin; -extern CHARSET_INFO my_charset_utf16_general_ci; -extern CHARSET_INFO my_charset_utf16_unicode_ci; -extern CHARSET_INFO my_charset_utf32_bin; -extern CHARSET_INFO my_charset_utf32_general_ci; -extern CHARSET_INFO my_charset_utf32_unicode_ci; - -extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_utf8_general_ci; -extern CHARSET_INFO my_charset_utf8_unicode_ci; -extern CHARSET_INFO my_charset_utf8_bin; -extern CHARSET_INFO my_charset_utf8_general_mysql500_ci; -extern CHARSET_INFO my_charset_utf8mb4_bin; -extern CHARSET_INFO my_charset_utf8mb4_general_ci; -extern CHARSET_INFO my_charset_utf8mb4_unicode_ci; #define MY_UTF8MB3 "utf8" #define MY_UTF8MB4 "utf8mb4" - -/* Helper functions to handle contraction */ -static inline my_bool -my_cs_have_contractions(CHARSET_INFO *cs) -{ - return cs->contractions != NULL; -} - -static inline my_bool -my_cs_can_be_contraction_head(CHARSET_INFO *cs, my_wc_t wc) -{ - return ((const char *) cs->contractions)[0x40 * 0x40 * 2 + (wc & 0xFF)]; -} - -static inline my_bool -my_cs_can_be_contraction_tail(CHARSET_INFO *cs, my_wc_t wc) -{ - return ((const char *) cs->contractions)[0x40 * 0x40 * 2 + (wc & 0xFF)]; -} - -static inline uint16* -my_cs_contraction2_weight(CHARSET_INFO *cs, my_wc_t wc1, my_wc_t wc2) -{ - return &cs->contractions[(wc1 - 0x40) * 0x40 + wc2 - 0x40]; -} - +my_bool my_cs_have_contractions(CHARSET_INFO *cs); +my_bool my_cs_can_be_contraction_head(CHARSET_INFO *cs, my_wc_t wc); +my_bool my_cs_can_be_contraction_tail(CHARSET_INFO *cs, my_wc_t wc); +const uint16 *my_cs_contraction2_weight(CHARSET_INFO *cs, my_wc_t wc1, + my_wc_t wc2); /* declarations for simple charsets */ extern size_t my_strnxfrm_simple(CHARSET_INFO *, uchar *, size_t, @@ -402,10 +396,13 @@ extern int my_strnncollsp_simple(CHARSET_INFO *, const uchar *, size_t, extern void my_hash_sort_simple(CHARSET_INFO *cs, const uchar *key, size_t len, ulong *nr1, ulong *nr2); +extern void my_hash_sort_bin(CHARSET_INFO *cs, + const uchar *key, size_t len, ulong *nr1, + ulong *nr2); extern size_t my_lengthsp_8bit(CHARSET_INFO *cs, const char *ptr, size_t length); -extern uint my_instr_simple(struct charset_info_st *, +extern uint my_instr_simple(CHARSET_INFO *, const char *b, size_t b_length, const char *s, size_t s_length, my_match_t *match, uint nmatch); @@ -429,7 +426,7 @@ int my_mb_ctype_mb(CHARSET_INFO *,int *, const uchar *,const uchar *); size_t my_scan_8bit(CHARSET_INFO *cs, const char *b, const char *e, int sq); -size_t my_snprintf_8bit(struct charset_info_st *, char *to, size_t n, +size_t my_snprintf_8bit(CHARSET_INFO *, char *to, size_t n, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 4, 5); @@ -530,7 +527,7 @@ size_t my_numcells_mb(CHARSET_INFO *, const char *b, const char *e); size_t my_charpos_mb(CHARSET_INFO *, const char *b, const char *e, size_t pos); size_t my_well_formed_len_mb(CHARSET_INFO *, const char *b, const char *e, size_t pos, int *error); -uint my_instr_mb(struct charset_info_st *, +uint my_instr_mb(CHARSET_INFO *, const char *b, size_t b_length, const char *s, size_t s_length, my_match_t *match, uint nmatch); @@ -569,10 +566,10 @@ int my_wildcmp_unicode(CHARSET_INFO *cs, const char *str, const char *str_end, const char *wildstr, const char *wildend, int escape, int w_one, int w_many, - MY_UNICASE_INFO **weights); + MY_UNICASE_INFO *const *weights); extern my_bool my_parse_charset_xml(const char *bug, size_t len, - int (*add)(CHARSET_INFO *cs)); + int (*add)(struct charset_info_st *cs)); extern char *my_strchr(CHARSET_INFO *cs, const char *str, const char *end, pchar c); extern size_t my_strcspn(CHARSET_INFO *cs, const char *str, const char *end, @@ -634,7 +631,6 @@ extern size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n, #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)) - #define use_mb(s) ((s)->cset->ismbchar != NULL) #define my_ismbchar(s, a, b) ((s)->cset->ismbchar((s), (a), (b))) #ifdef USE_MB diff --git a/include/m_string.h b/include/m_string.h index bb76d9273a5..1f59fd06084 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2012, 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,9 +60,11 @@ # define bfill(A,B,C) memset((A),(C),(B)) #endif -#if !defined(bzero) && (!defined(HAVE_BZERO) || !HAVE_DECL_BZERO || defined(_AIX)) -/* See autoconf doku: "HAVE_DECL_symbol" will be defined after configure, to 0 or 1 */ -/* AIX has bzero() as a function, but the declaration prototype is strangely hidden */ +# define bmove_align(A,B,C) memcpy((A),(B),(C)) + +# define bcmp(A,B,C) memcmp((A),(B),(C)) + +#if !defined(bzero) # define bzero(A,B) memset((A),0,(B)) #endif @@ -81,21 +83,21 @@ extern void (*my_str_free)(void *); #define strmov(A,B) __builtin_stpcpy((A),(B)) #elif defined(HAVE_STPCPY) #define strmov(A,B) stpcpy((A),(B)) -#ifndef stpcpy -extern char *stpcpy(char *, const char *); /* For AIX with gcc 2.95.3 */ -#endif #endif /* Declared in int2str() */ -extern char _dig_vec_upper[]; -extern char _dig_vec_lower[]; +extern const char _dig_vec_upper[]; +extern const char _dig_vec_lower[]; -#ifndef strmov -#define strmov_overlapp(A,B) strmov(A,B) -#define strmake_overlapp(A,B,C) strmake(A,B,C) +extern char *strmov_overlapp(char *dest, const char *src); + +#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 - /* Prototypes for string functions */ +/* Prototypes for string functions */ extern void bmove_upp(uchar *dst,const uchar *src,size_t len); extern void bchange(uchar *dst,size_t old_len,const uchar *src, @@ -106,10 +108,17 @@ extern char *strcend(const char *, pchar); extern char *strfill(char * s,size_t len,pchar fill); extern char *strmake(char *dst,const char *src,size_t length); +#if !defined(__GNUC__) || (__GNUC__ < 4) +#define strmake_buf(D,S) strmake(D, S, sizeof(D) - 1) +#else +#define strmake_buf(D,S) ({ \ + compile_time_assert(sizeof(D) != sizeof(char*)); \ + strmake(D, S, sizeof(D) - 1); \ + }) +#endif + #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 *strcont(const char *src, const char *set); @@ -201,13 +210,7 @@ extern ulonglong strtoull(const char *str, char **ptr, int base); } #endif -/* - LEX_STRING -- a pair of a C-string and its length. - (it's part of the plugin API as a MYSQL_LEX_STRING) -*/ - #include <mysql/plugin.h> -typedef struct st_mysql_lex_string LEX_STRING; #define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1)) #define USTRING_WITH_LEN(X) ((uchar*) X), ((size_t) (sizeof(X) - 1)) @@ -220,74 +223,13 @@ struct st_mysql_const_lex_string }; typedef struct st_mysql_const_lex_string LEX_CSTRING; -/* SPACE_INT is a word that contains only spaces */ -#if SIZEOF_INT == 4 -#define SPACE_INT 0x20202020 -#elif SIZEOF_INT == 8 -#define SPACE_INT 0x2020202020202020 -#else -#error define the appropriate constant for a word full of spaces -#endif - -/** - Skip trailing space. - - On most systems reading memory in larger chunks (ideally equal to the size of - the chinks that the machine physically reads from memory) causes fewer memory - access loops and hence increased performance. - This is why the 'int' type is used : it's closest to that (according to how - it's defined in C). - So when we determine the amount of whitespace at the end of a string we do - the following : - 1. We divide the string into 3 zones : - a) from the start of the string (__start) to the first multiple - of sizeof(int) (__start_words) - b) from the end of the string (__end) to the last multiple of sizeof(int) - (__end_words) - c) a zone that is aligned to sizeof(int) and can be safely accessed - through an int * - 2. We start comparing backwards from (c) char-by-char. If all we find is - space then we continue - 3. If there are elements in zone (b) we compare them as unsigned ints to a - int mask (SPACE_INT) consisting of all spaces - 4. Finally we compare the remaining part (a) of the string char by char. - This covers for the last non-space unsigned int from 3. (if any) - - This algorithm works well for relatively larger strings, but it will slow - the things down for smaller strings (because of the additional calculations - and checks compared to the naive method). Thus the barrier of length 20 - is added. - - @param ptr pointer to the input string - @param len the length of the string - @return the last non-space character -*/ - -static inline const uchar *skip_trailing_space(const uchar *ptr,size_t len) +/* A variant with const and unsigned */ +struct st_mysql_const_unsigned_lex_string { - const uchar *end= ptr + len; - - if (len > 20) - { - const uchar *end_words= (const uchar *)(intptr) - (((ulonglong)(intptr)end) / SIZEOF_INT * SIZEOF_INT); - const uchar *start_words= (const uchar *)(intptr) - ((((ulonglong)(intptr)ptr) + SIZEOF_INT - 1) / SIZEOF_INT * SIZEOF_INT); - - DBUG_ASSERT(((ulonglong)(intptr)ptr) >= SIZEOF_INT); - if (end_words > ptr) - { - while (end > end_words && end[-1] == 0x20) - end--; - if (end[-1] == 0x20 && start_words < end_words) - while (end > start_words && ((unsigned *)end)[-1] == SPACE_INT) - end -= SIZEOF_INT; - } - } - while (end > ptr && end[-1] == 0x20) - end--; - return (end); -} + const uchar *str; + size_t length; +}; +typedef struct st_mysql_const_unsigned_lex_string LEX_CUSTRING; static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str) { diff --git a/include/ma_dyncol.h b/include/ma_dyncol.h new file mode 100644 index 00000000000..6174328d62a --- /dev/null +++ b/include/ma_dyncol.h @@ -0,0 +1,147 @@ +/* Copyright (c) 2011, Monty Program Ab + Copyright (c) 2011, Oleksandr Byelkin + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ + +#ifndef ma_dyncol_h +#define ma_dyncol_h + +#include <decimal.h> +#include <my_decimal_limits.h> +#include <mysql_time.h> + +/* + Max length for data in a dynamic colums. This comes from how the + how the offset are stored. +*/ +#define MAX_DYNAMIC_COLUMN_LENGTH 0X1FFFFFFFL + +/* NO and OK is the same used just to show semantics */ +#define ER_DYNCOL_NO ER_DYNCOL_OK + +enum enum_dyncol_func_result +{ + ER_DYNCOL_OK= 0, + ER_DYNCOL_YES= 1, /* For functions returning 0/1 */ + ER_DYNCOL_FORMAT= -1, /* Wrong format of the encoded string */ + ER_DYNCOL_LIMIT= -2, /* Some limit reached */ + ER_DYNCOL_RESOURCE= -3, /* Out of resourses */ + ER_DYNCOL_DATA= -4, /* Incorrect input data */ + ER_DYNCOL_UNKNOWN_CHARSET= -5 /* Unknown character set */ +}; + +typedef DYNAMIC_STRING DYNAMIC_COLUMN; + +enum enum_dynamic_column_type +{ + DYN_COL_NULL= 0, + DYN_COL_INT, + DYN_COL_UINT, + DYN_COL_DOUBLE, + DYN_COL_STRING, + DYN_COL_DECIMAL, + DYN_COL_DATETIME, + DYN_COL_DATE, + DYN_COL_TIME +}; + +typedef enum enum_dynamic_column_type DYNAMIC_COLUMN_TYPE; + +struct st_dynamic_column_value +{ + DYNAMIC_COLUMN_TYPE type; + union + { + long long long_value; + unsigned long long ulong_value; + double double_value; + struct { + LEX_STRING value; + CHARSET_INFO *charset; + } string; + struct { + decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]; + decimal_t value; + } decimal; + MYSQL_TIME time_value; + } x; +}; + +typedef struct st_dynamic_column_value DYNAMIC_COLUMN_VALUE; + +enum enum_dyncol_func_result +dynamic_column_create(DYNAMIC_COLUMN *str, + uint column_nr, DYNAMIC_COLUMN_VALUE *value); + +enum enum_dyncol_func_result +dynamic_column_create_many(DYNAMIC_COLUMN *str, + uint column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values); + +enum enum_dyncol_func_result +dynamic_column_update(DYNAMIC_COLUMN *org, uint column_nr, + DYNAMIC_COLUMN_VALUE *value); +enum enum_dyncol_func_result +dynamic_column_update_many(DYNAMIC_COLUMN *str, + uint add_column_count, + uint *column_numbers, + DYNAMIC_COLUMN_VALUE *values); + +enum enum_dyncol_func_result +dynamic_column_delete(DYNAMIC_COLUMN *org, uint column_nr); + +enum enum_dyncol_func_result +dynamic_column_exists(DYNAMIC_COLUMN *org, uint column_nr); + +/* List of not NULL columns */ +enum enum_dyncol_func_result +dynamic_column_list(DYNAMIC_COLUMN *org, DYNAMIC_ARRAY *array_of_uint); + +/* + if the column do not exists it is NULL +*/ +enum enum_dyncol_func_result +dynamic_column_get(DYNAMIC_COLUMN *org, uint column_nr, + DYNAMIC_COLUMN_VALUE *store_it_here); + +#define dynamic_column_initialize(A) memset((A), 0, sizeof(*(A))) +#define dynamic_column_column_free(V) dynstr_free(V) + +/*************************************************************************** + Internal functions, don't use if you don't know what you are doing... +***************************************************************************/ + +#define dynamic_column_reassociate(V,P,L, A) dynstr_reassociate((V),(P),(L),(A)) + +#define dynamic_column_value_init(V) (V)->type= DYN_COL_NULL + +/* + Prepare value for using as decimal +*/ +void dynamic_column_prepare_decimal(DYNAMIC_COLUMN_VALUE *value); + +#endif diff --git a/include/maria.h b/include/maria.h new file mode 100644 index 00000000000..aba5d508070 --- /dev/null +++ b/include/maria.h @@ -0,0 +1,412 @@ +/* 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 +#include <my_base.h> +#include <my_sys.h> +#include <m_ctype.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) */ + mysql_rwlock_t root_lock; /* locking of tree */ + 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 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 my_bool maria_upgrade(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_NONE 0 /* No automatic recover */ +#define HA_RECOVER_DEFAULT 1 /* Automatic recover active */ +#define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */ +#define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */ +#define HA_RECOVER_QUICK 8 /* Don't check rows in data file */ + +#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; + +/* 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_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, size_t 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_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); +uint maria_max_key_length(void); +#define maria_max_key_segments() HA_MAX_KEY_SEG + +/* 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 57d86f56755..c3707cba395 100644 --- a/include/my_alarm.h +++ b/include/my_alarm.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. 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 9e2ef541b3c..85ac75fc666 100644 --- a/include/my_alloc.h +++ b/include/my_alloc.h @@ -30,8 +30,8 @@ extern "C" { 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 index cd12f527dea..7c589cd776a 100644 --- a/include/my_atomic.h +++ b/include/my_atomic.h @@ -28,10 +28,9 @@ store 'what' in *var, and return the old value of *var my_atomic_cas#(&var, &old, new) - An odd variation of 'Compare And Set/Swap' + '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 - Usually, &old should not be accessed if the operation is successful. my_atomic_load#(&var) return *var diff --git a/include/my_attribute.h b/include/my_attribute.h index 78999f25675..14ed35cfe24 100644 --- a/include/my_attribute.h +++ b/include/my_attribute.h @@ -36,10 +36,15 @@ #ifndef __attribute__ # if !defined(__GNUC__) # define __attribute__(A) -# elif GCC_VERSION < 2008 -# define __attribute__(A) -# elif defined(__cplusplus) && GCC_VERSION < 3004 -# define __attribute__(A) +# else +# ifndef GCC_VERSION +# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) +# endif +# if GCC_VERSION < 2008 +# define __attribute__(A) +# elif defined(__cplusplus) && GCC_VERSION < 3004 +# define __attribute__(A) +# endif # endif #endif diff --git a/include/my_base.h b/include/my_base.h index c10a325763e..36c97d61cb9 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -19,8 +19,6 @@ #ifndef _my_base_h #define _my_base_h -#ifndef stdin /* Included first in handler */ -#define CHSIZE_USED #include <my_global.h> #include <my_dir.h> /* This includes types */ #include <my_sys.h> @@ -31,7 +29,6 @@ #define EOVERFLOW 84 #endif -#endif /* stdin */ #include <my_list.h> /* The following is bits in the flag parameter to ha_open() */ @@ -48,6 +45,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 */ @@ -109,7 +107,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 */ @@ -194,7 +192,10 @@ enum ha_extra_function { HA_EXTRA_ADD_CHILDREN_LIST, HA_EXTRA_ATTACH_CHILDREN, HA_EXTRA_IS_ATTACHED_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 */ @@ -237,7 +238,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 */ @@ -248,11 +252,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) /* Key contains partial segments. @@ -276,6 +282,9 @@ enum ha_base_keytype { #define HA_USES_BLOCK_SIZE ((uint) 32768) #define HA_SORT_ALLOWS_SAME 512 /* Intern bit when sorting records */ +/* This flag can be used only in KEY::ext_key_flags */ +#define HA_EXT_NOSAME 131072 + /* These flags can be added to key-seg-flag */ #define HA_SPACE_PACK 1 /* Pack space in key-seg */ @@ -292,6 +301,7 @@ enum ha_base_keytype { */ #define HA_END_SPACE_ARE_EQUAL 512 #define HA_BIT_PART 1024 +#define HA_CAN_MEMCMP 2048 /* internal, never stored in frm */ /* optionbits for database */ #define HA_OPTION_PACK_RECORD 1 @@ -306,8 +316,12 @@ 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 */ +/* .frm has extra create options in linked-list format */ +#define HA_OPTION_TEXT_CREATE_OPTIONS (1L << 14) +#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() */ @@ -435,22 +449,25 @@ 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_INDEX_COL_TOO_LONG 178 /* Index column length exceeds limit */ -#define HA_ERR_INDEX_CORRUPT 179 /* Index corrupted */ +#define HA_ERR_INDEX_COL_TOO_LONG 178 /* Index column length exceeds limit */ +#define HA_ERR_INDEX_CORRUPT 179 /* Index corrupted */ #define HA_ERR_UNDO_REC_TOO_BIG 180 /* Undo log record too big */ #define HA_ERR_TABLE_IN_FK_CHECK 181 /* Table being used in foreign key check */ -#define HA_ERR_LAST 181 /* Copy of last error nr */ +#define HA_ERR_ROW_NOT_VISIBLE 182 +#define HA_ERR_ABORTED_BY_USER 183 +#define HA_ERR_DISK_FULL 184 +#define HA_ERR_INCOMPATIBLE_DEFINITION 185 +#define HA_ERR_LAST 185 /* Copy of last error nr */ /* Number of different errors */ #define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1) @@ -483,6 +500,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 @@ -516,7 +541,7 @@ enum en_fieldtype { }; enum data_file_type { - STATIC_RECORD, DYNAMIC_RECORD, COMPRESSED_RECORD, BLOCK_RECORD + STATIC_RECORD, DYNAMIC_RECORD, COMPRESSED_RECORD, BLOCK_RECORD, NO_RECORD }; /* For key ranges */ @@ -539,11 +564,13 @@ typedef struct st_key_range enum ha_rkey_function flag; } key_range; +typedef void *range_id_t; + typedef struct st_key_multi_range { key_range start_key; key_range end_key; - char *ptr; /* Free to use by caller (ptr to row etc) */ + range_id_t ptr; /* Free to use by caller (ptr to row etc) */ uint range_flag; /* key range flags see above */ } KEY_MULTI_RANGE; diff --git a/include/my_bit.h b/include/my_bit.h index 8d9f485a0d0..174e0f70083 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 @@ -17,6 +17,8 @@ #ifndef MY_BIT_INCLUDED #define MY_BIT_INCLUDED +#include <my_global.h> + /* Some useful bit functions */ diff --git a/include/my_bitmap.h b/include/my_bitmap.h index 29e55345352..7bed045bd86 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 @@ -20,14 +20,13 @@ #define MY_BIT_NONE (~(uint) 0) #include <m_string.h> +#include <my_pthread.h> 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 @@ -35,12 +34,15 @@ typedef struct st_bitmap acquiring the mutex */ mysql_mutex_t *mutex; + my_bitmap_map last_word_mask; + uint32 n_bits; /* number of bits occupied by the above */ } MY_BITMAP; #ifdef __cplusplus extern "C" { #endif extern void create_last_word_mask(MY_BITMAP *map); +#define bitmap_init(A,B,C,D) my_bitmap_init(A,B,C,D) extern my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits, my_bool thread_safe); extern my_bool bitmap_is_clear_all(const MY_BITMAP *map); @@ -52,6 +54,12 @@ 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 my_bool bitmap_exists_intersection(const MY_BITMAP **bitmap_array, + uint bitmap_count, + uint start_bit, uint end_bit); + 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_check_opt.h b/include/my_check_opt.h index 7b064f69ef1..f952792d2c8 100644 --- a/include/my_check_opt.h +++ b/include/my_check_opt.h @@ -60,6 +60,12 @@ extern "C" { #define T_VERY_SILENT (1UL << 29) #define T_WAIT_FOREVER (1UL << 30) #define T_WRITE_LOOP (1UL << 31) +#define T_ZEROFILL (1ULL << 32) +#define T_ZEROFILL_KEEP_LSN (1ULL << 33) +/** If repair should not bump create_rename_lsn */ +#define T_NO_CREATE_RENAME_LSN (1ULL << 34) +/** If repair shouldn't do any locks */ +#define T_NO_LOCKS (1ULL << 35) #define T_REP_ANY (T_REP | T_REP_BY_SORT | T_REP_PARALLEL) diff --git a/include/my_compare.h b/include/my_compare.h index 3821780492d..0db22b593f4 100644 --- a/include/my_compare.h +++ b/include/my_compare.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2011, Oracle and/or its affiliates. + Copyright (c) Monty Program Ab; 1991-2011 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 @@ -40,7 +41,7 @@ extern "C" { */ #define HA_MAX_KEY_LENGTH 1000 /* Max length in bytes */ -#define HA_MAX_KEY_SEG 16 /* Max segments for key */ +#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) @@ -61,22 +62,22 @@ 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; } \ } #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); } \ } #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; } \ } @@ -106,11 +107,12 @@ 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, +extern int ha_compare_text(CHARSET_INFO *, const uchar *, uint, + const uchar *, uint , my_bool, my_bool); +extern int ha_key_cmp(HA_KEYSEG *keyseg, const uchar *a, + const uchar *b, uint key_length, uint nextflag, uint *diff_pos); +extern HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, const uchar *a); /* Inside an in-memory data record, memory pointers to pieces of the @@ -122,4 +124,31 @@ extern int ha_key_cmp(register HA_KEYSEG *keyseg, register uchar *a, } #endif +/** + Return values of index_cond_func_xxx functions. + + 0=ICP_NO_MATCH - index tuple doesn't satisfy the pushed index condition (the + engine should discard the tuple and go to the next one) + 1=ICP_MATCH - index tuple satisfies the pushed index condition (the + engine should fetch and return the record) + 2=ICP_OUT_OF_RANGE - index tuple is out range that we're scanning, e.g. this + if we're scanning "t.key BETWEEN 10 AND 20" and got a + "t.key=21" tuple (the engine should stop scanning and + return HA_ERR_END_OF_FILE right away). + 3=ICP_ABORTED_BY_USER - engine must stop scanning and should return + HA_ERR_ABORTED_BY_USER right away + -1= ICP_ERROR - Reserved for internal errors in engines. Should not be + returned by index_cond_func_xxx +*/ + +typedef enum icp_result { + ICP_ERROR=-1, + ICP_NO_MATCH=0, + ICP_MATCH=1, + ICP_OUT_OF_RANGE=2, + ICP_ABORTED_BY_USER=3 +} ICP_RESULT; + +typedef ICP_RESULT (*index_cond_func_t)(void *param); + #endif /* _my_compare_h */ diff --git a/include/my_context.h b/include/my_context.h new file mode 100644 index 00000000000..dd44103d3b2 --- /dev/null +++ b/include/my_context.h @@ -0,0 +1,232 @@ +/* + Copyright 2011 Kristian Nielsen and Monty Program Ab + + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* + Simple API for spawning a co-routine, to be used for async libmysqlclient. + + Idea is that by implementing this interface using whatever facilities are + available for given platform, we can use the same code for the generic + libmysqlclient-async code. + + (This particular implementation uses Posix ucontext swapcontext().) +*/ + +#ifdef __WIN__ +#define MY_CONTEXT_USE_WIN32_FIBERS 1 +#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__x86_64__) && !defined(__ILP32__) +#define MY_CONTEXT_USE_X86_64_GCC_ASM +#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__i386__) +#define MY_CONTEXT_USE_I386_GCC_ASM +#elif defined(HAVE_UCONTEXT_H) +#define MY_CONTEXT_USE_UCONTEXT +#else +#define MY_CONTEXT_DISABLE +#endif + +#ifdef MY_CONTEXT_USE_WIN32_FIBERS +struct my_context { + void (*user_func)(void *); + void *user_arg; + void *app_fiber; + void *lib_fiber; + int return_value; +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_UCONTEXT +#include <ucontext.h> + +struct my_context { + void (*user_func)(void *); + void *user_data; + void *stack; + size_t stack_size; + ucontext_t base_context; + ucontext_t spawned_context; + int active; +#ifdef HAVE_VALGRIND + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_X86_64_GCC_ASM +#include <stdint.h> + +struct my_context { + uint64_t save[9]; + void *stack_top; + void *stack_bot; +#ifdef HAVE_VALGRIND + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_I386_GCC_ASM +#include <stdint.h> + +struct my_context { + uint64_t save[7]; + void *stack_top; + void *stack_bot; +#ifdef HAVE_VALGRIND + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_DISABLE +struct my_context { + int dummy; +}; +#endif + + +/* + Initialize an asynchroneous context object. + Returns 0 on success, non-zero on failure. +*/ +extern int my_context_init(struct my_context *c, size_t stack_size); + +/* Free an asynchroneous context object, deallocating any resources used. */ +extern void my_context_destroy(struct my_context *c); + +/* + Spawn an asynchroneous context. The context will run the supplied user + function, passing the supplied user data pointer. + + The context must have been initialised with my_context_init() prior to + this call. + + The user function may call my_context_yield(), which will cause this + function to return 1. Then later my_context_continue() may be called, which + will resume the asynchroneous context by returning from the previous + my_context_yield() call. + + When the user function returns, this function returns 0. + + In case of error, -1 is returned. +*/ +extern int my_context_spawn(struct my_context *c, void (*f)(void *), void *d); + +/* + Suspend an asynchroneous context started with my_context_spawn. + + When my_context_yield() is called, execution immediately returns from the + last my_context_spawn() or my_context_continue() call. Then when later + my_context_continue() is called, execution resumes by returning from this + my_context_yield() call. + + Returns 0 if ok, -1 in case of error. +*/ +extern int my_context_yield(struct my_context *c); + +/* + Resume an asynchroneous context. The context was spawned by + my_context_spawn(), and later suspended inside my_context_yield(). + + The asynchroneous context may be repeatedly suspended with + my_context_yield() and resumed with my_context_continue(). + + Each time it is suspended, this function returns 1. When the originally + spawned user function returns, this function returns 0. + + In case of error, -1 is returned. +*/ +extern int my_context_continue(struct my_context *c); + + +struct mysql_async_context { + /* + This is set to the value that should be returned from foo_start() or + foo_cont() when a call is suspended. + */ + unsigned int events_to_wait_for; + /* + It is also set to the event(s) that triggered when a suspended call is + resumed, eg. whether we woke up due to connection completed or timeout + in mysql_real_connect_cont(). + */ + unsigned int events_occured; + /* + This is set to the result of the whole asynchronous operation when it + completes. It uses a union, as different calls have different return + types. + */ + union { + void *r_ptr; + const void *r_const_ptr; + int r_int; + my_bool r_my_bool; + } ret_result; + /* + The timeout value, for suspended calls that need to wake up on a timeout + (eg. mysql_real_connect_start(). + */ + unsigned int timeout_value; + /* + This flag is set when we are executing inside some asynchronous call + foo_start() or foo_cont(). It is used to decide whether to use the + synchronous or asynchronous version of calls that may block such as + recv(). + + Note that this flag is not set when a call is suspended, eg. after + returning from foo_start() and before re-entering foo_cont(). + */ + my_bool active; + /* + This flag is set when an asynchronous operation is in progress, but + suspended. Ie. it is set when foo_start() or foo_cont() returns because + the operation needs to block, suspending the operation. + + It is used to give an error (rather than crash) if the application + attempts to call some foo_cont() method when no suspended operation foo is + in progress. + */ + my_bool suspended; + /* + If non-NULL, this is a pointer to a callback hook that will be invoked with + the user data argument just before the context is suspended, and just after + it is resumed. + */ + void (*suspend_resume_hook)(my_bool suspend, void *user_data); + void *suspend_resume_hook_user_data; + /* + This is used to save the execution contexts so that we can suspend an + operation and switch back to the application context, to resume the + suspended context later when the application re-invokes us with + foo_cont(). + */ + struct my_context async_context; +}; diff --git a/include/my_cpu.h b/include/my_cpu.h new file mode 100644 index 00000000000..026b92c1b74 --- /dev/null +++ b/include/my_cpu.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2013, MariaDB foundation Ab and SkySQL + + 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., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA +*/ + +/* instructions for specific cpu's */ + +/* + Macros for adjusting thread priority (hardware multi-threading) + The defines are the same ones used by the linux kernel +*/ + +#if defined(__powerpc__) +/* Very low priority */ +#define HMT_very_low() asm volatile("or 31,31,31") +/* Low priority */ +#define HMT_low() asm volatile("or 1,1,1") +/* Medium low priority */ +#define HMT_medium_low() asm volatile("or 6,6,6") +/* Medium priority */ +#define HMT_medium() asm volatile("or 2,2,2") +/* Medium high priority */ +#define HMT_medium_high() asm volatile("or 5,5,5") +/* High priority */ +#define HMT_high() asm volatile("or 3,3,3") +#else +#define HMT_very_low() +#define HMT_low() +#define HMT_medium_low() +#define HMT_medium() +#define HMT_medium_high() +#define HMT_high() +#endif diff --git a/include/my_dbug.h b/include/my_dbug.h index 19356718966..a7ada40f8bc 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 @@ -13,16 +14,10 @@ along with this program; if not, write to the Free Software 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__ */ @@ -64,11 +59,14 @@ extern void _db_lock_file_(void); extern void _db_unlock_file_(void); extern FILE *_db_fp_(void); extern void _db_flush_(); +extern void dbug_swap_code_state(void **code_state_store); +extern void dbug_free_code_state(void **code_state_store); extern const char* _db_get_func_(void); #define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) #define DBUG_LEAVE _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) \ @@ -87,17 +85,19 @@ extern const char* _db_get_func_(void); #define DBUG_SET_INITIAL(a1) _db_set_init_ (a1) #define DBUG_PROCESS(a1) _db_process_(a1) #define DBUG_FILE _db_fp_() -#define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1)) -#define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2)) #define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2) #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,B) A +#define DBUG_SWAP_CODE_STATE(arg) dbug_swap_code_state(arg) +#define DBUG_FREE_CODE_STATE(arg) dbug_free_code_state(arg) + #ifndef __WIN__ #define DBUG_ABORT() (_db_flush_(), abort()) #else @@ -111,15 +111,6 @@ extern const char* _db_get_func_(void); (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\ _exit(3)) #endif -#define DBUG_CHECK_CRASH(func, op) \ - do { char _dbuf_[255]; strxnmov(_dbuf_, sizeof(_dbuf_)-1, (func), (op)); \ - DBUG_EXECUTE_IF(_dbuf_, DBUG_ABORT()); } while(0) -#define DBUG_CRASH_ENTER(func) \ - DBUG_ENTER(func); DBUG_CHECK_CRASH(func, "_crash_enter") -#define DBUG_CRASH_RETURN(val) \ - DBUG_CHECK_CRASH(_db_get_func_(), "_crash_return") -#define DBUG_CRASH_VOID_RETURN \ - DBUG_CHECK_CRASH (_db_get_func_(), "_crash_return") /* Make the program fail, without creating a core file. @@ -139,6 +130,7 @@ extern void _db_suicide_(); #else /* No debugger */ #define DBUG_ENTER(a1) +#define DBUG_VIOLATION_HELPER_LEAVE do { } while(0) #define DBUG_LEAVE #define DBUG_RETURN(a1) do { return(a1); } while(0) #define DBUG_VOID_RETURN do { return; } while(0) @@ -152,8 +144,6 @@ extern void _db_suicide_(); #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() do { } while(0) #define DBUG_ASSERT(A) do { } while(0) @@ -164,6 +154,9 @@ extern void _db_suicide_(); #define DBUG_EXPLAIN_INITIAL(buf,len) #define DEBUGGER_OFF do { } while(0) #define DEBUGGER_ON do { } while(0) +#define IF_DBUG(A,B) B +#define DBUG_SWAP_CODE_STATE(arg) do { } while(0) +#define DBUG_FREE_CODE_STATE(arg) do { } while(0) #define DBUG_ABORT() do { } while(0) #define DBUG_CRASH_ENTER(func) #define DBUG_CRASH_RETURN(val) do { return(val); } while(0) @@ -191,4 +184,4 @@ void debug_sync_point(const char* lock_name, uint lock_timeout); } #endif -#endif /* MY_DBUG_INCLUDED */ +#endif /* _my_dbug_h */ diff --git a/include/my_decimal_limits.h b/include/my_decimal_limits.h new file mode 100644 index 00000000000..50d70357c42 --- /dev/null +++ b/include/my_decimal_limits.h @@ -0,0 +1,45 @@ +#ifndef MY_DECIMAL_LIMITS_INCLUDED +#define MY_DECIMAL_LIMITS_INCLUDED +/* Copyright (c) 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 + 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 DECIMAL_LONGLONG_DIGITS 22 +#define DECIMAL_LONG_DIGITS 10 +#define DECIMAL_LONG3_DIGITS 8 + +/** maximum length of buffer in our big digits (uint32). */ +#define DECIMAL_BUFF_LENGTH 9 + +/* the number of digits that my_decimal can possibly contain */ +#define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9) + + +/** + maximum guaranteed precision of number in decimal digits (number of our + digits * number of decimal digits in one our big digit - number of decimal + digits in one our big digit decreased by 1 (because we always put decimal + point on the border of our big digits)) +*/ +#define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2) +#define DECIMAL_MAX_SCALE 30 +#define DECIMAL_NOT_SPECIFIED 31 + +/** + maximum length of string representation (number of maximum decimal + digits + 1 position for sign + 1 position for decimal point, no terminator) +*/ +#define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2) + +#endif /* MY_DECIMAL_LIMITS_INCLUDED */ diff --git a/include/my_getopt.h b/include/my_getopt.h index 1c4264e2aa2..e3318661c83 100644 --- a/include/my_getopt.h +++ b/include/my_getopt.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2002, 2013, 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 695884cb6c6..cf140cf54ce 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1,5 +1,6 @@ /* - Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2001, 2013, Oracle and/or its affiliates. + Copyright (c) 2009, 2017, MariaDB Corporation 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 @@ -45,6 +46,8 @@ #undef __WIN__ #undef __WIN32__ #define HAVE_ERRNO_AS_DEFINE +#define _POSIX_MONOTONIC_CLOCK +#define _POSIX_THREAD_CPUTIME #endif /* __CYGWIN__ */ /* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */ @@ -87,10 +90,10 @@ #define IF_WIN(A,B) B #endif -#ifdef HAVE_purify -#define IF_PURIFY(A,B) A +#ifdef WITH_PARTITION_STORAGE_ENGINE +#define IF_PARTITIONING(A,B) A #else -#define IF_PURIFY(A,B) B +#define IF_PARTITIONING(A,B) B #endif #ifndef EMBEDDED_LIBRARY @@ -196,8 +199,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) /* Fix problem with S_ISLNK() on Linux */ #if defined(TARGET_OS_LINUX) || defined(__GLIBC__) @@ -213,11 +222,6 @@ #include <sys/types.h> #endif -#ifdef HAVE_THREADS_WITHOUT_SOCKETS -/* MIT pthreads does not work with unix sockets */ -#undef HAVE_SYS_UN_H -#endif - #define __EXTENSIONS__ 1 /* We want some extension */ #ifndef __STDC_EXT__ #define __STDC_EXT__ 1 /* To get large file support on hpux */ @@ -286,22 +290,10 @@ 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); } +inline double my_ulonglong2double(unsigned long long A) { return (double)A; } C_MODE_END #endif /* _AIX */ -#ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don't have this defined */ -#undef HAVE_SNPRINTF -#endif -#ifdef HAVE_BROKEN_PREAD -/* - pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without - installing the kernel patch PHKL_20349 or greater -*/ -#undef HAVE_PREAD -#undef HAVE_PWRITE -#endif - #ifdef UNDEF_HAVE_INITGROUPS /* For AIX 4.3 */ #undef HAVE_INITGROUPS #endif @@ -347,8 +339,8 @@ C_MODE_END #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif -#ifdef HAVE_SYS_TIMEB_H -#include <sys/timeb.h> /* Avoid warnings on SCO */ +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> #endif #if TIME_WITH_SYS_TIME # include <sys/time.h> @@ -385,7 +377,7 @@ 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) \ @@ -430,6 +422,9 @@ extern "C" int madvise(void *addr, size_t len, int behav); #define SIGNAL_HANDLER_RESET_ON_DELIVERY #endif +/* don't assume that STDERR_FILENO is 2, mysqld can freopen */ +#undef STDERR_FILENO + /* Deprecated workaround for false-positive uninitialized variables warnings. Those should be silenced using tool-specific heuristics. @@ -446,8 +441,6 @@ extern "C" int madvise(void *addr, size_t len, int behav); #ifndef SO_EXT #ifdef _WIN32 #define SO_EXT ".dll" -#elif defined(__APPLE__) -#define SO_EXT ".dylib" #else #define SO_EXT ".so" #endif @@ -476,8 +469,10 @@ typedef unsigned short ushort; #define swap_variables(t, a, b) { t dummy; dummy= a; a= b; b= dummy; } #define test(a) ((a) ? 1 : 0) +#define MY_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]))) @@ -513,6 +508,10 @@ C_MODE_END # endif #endif +#ifdef DBUG_OFF +#undef EXTRA_DEBUG +#endif + /* Some types that is different between systems */ typedef int File; /* File descriptor */ @@ -669,15 +668,14 @@ typedef SOCKET_SIZE_TYPE size_socket; #define MALLOC_OVERHEAD 8 /* 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) +#define ONCE_ALLOC_INIT (uint) 4096 + /* Typical record cache */ +#define RECORD_CACHE_SIZE (uint) (128*1024) + /* Typical key cache */ +#define KEY_CACHE_SIZE (uint) (128L*1024L*1024L) /* Default size of a key cache block */ #define KEY_CACHE_BLOCK_SIZE (uint) 1024 - /* Some things that this system doesn't have */ #ifdef _WIN32 @@ -735,10 +733,10 @@ inline unsigned long long my_double2ulonglong(double d) #define strtok_r(A,B,C) strtok((A),(B)) #endif -/* This is from the old m-machine.h file */ - -#if SIZEOF_LONG_LONG > 4 +#if SIZEOF_LONG_LONG >= 8 #define HAVE_LONG_LONG 1 +#else +#error WHAT? sizeof(long long) < 8 ??? #endif /* @@ -801,18 +799,7 @@ inline unsigned long long my_double2ulonglong(double d) #endif #ifdef HAVE_ISINF -/* Check if C compiler is affected by GCC bug #39228 */ -#if !defined(__cplusplus) && defined(HAVE_BROKEN_ISINF) -/* Force store/reload of the argument to/from a 64-bit double */ -static inline double my_isinf(double x) -{ - volatile double t= x; - return isinf(t); -} -#else -/* System-provided isinf() is available and safe to use */ #define my_isinf(X) isinf(X) -#endif #else /* !HAVE_ISINF */ #define my_isinf(X) (!finite(X) && !isnan(X)) #endif @@ -828,6 +815,17 @@ static inline double my_isinf(double x) #define M_LN2 0.69314718055994530942 #endif +#ifndef HAVE_LOG2 +/* + This will be slightly slower and perhaps a tiny bit less accurate than + doing it the IEEE754 way but log2() should be available on C99 systems. +*/ +static inline double log2(double x) +{ + return (log(x) / M_LN2); +} +#endif + /* Max size that must be added to a so that we know Size to make adressable obj. @@ -840,9 +838,12 @@ 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(double))) #define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size) #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B)) +#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1)) /* Custom version of standard offsetof() macro which can be used to get @@ -856,8 +857,7 @@ typedef long long my_ptrdiff_t; and related routines are refactored. */ -#define my_offsetof(TYPE, MEMBER) \ - ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10)) +#define my_offsetof(TYPE, MEMBER) PTR_BYTE_DIFF(&((TYPE *)0x10)->MEMBER, 0x10) #define NullS (char *) 0 @@ -940,11 +940,11 @@ typedef unsigned long long my_ulonglong; #endif #if SIZEOF_CHARP == SIZEOF_INT -typedef int intptr; +typedef unsigned int intptr; #elif SIZEOF_CHARP == SIZEOF_LONG -typedef long intptr; +typedef unsigned long intptr; #elif SIZEOF_CHARP == SIZEOF_LONG_LONG -typedef long long intptr; +typedef unsigned long long intptr; #else #error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long) #endif @@ -970,6 +970,10 @@ typedef unsigned long my_off_t; typedef ulonglong table_map; /* Used for table bits in join */ typedef ulong nesting_map; /* Used for flags of nesting constructs */ +/* often used type names - opaque declarations */ +typedef const struct charset_info_st CHARSET_INFO; +typedef struct st_mysql_lex_string LEX_STRING; + #if defined(__WIN__) #define socket_errno WSAGetLastError() #define SOCKET_EINTR WSAEINTR @@ -1042,9 +1046,7 @@ typedef char my_bool; /* Small bool */ #define YESNO(X) ((X) ? "yes" : "no") #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 @@ -1053,7 +1055,7 @@ typedef char my_bool; /* Small bool */ /* 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) |\ @@ -1062,12 +1064,22 @@ typedef char my_bool; /* Small bool */ (((uint32) (uchar) (A)[2]) << 16) |\ (((uint32) (uchar) (A)[1]) << 8) | \ ((uint32) (uchar) (A)[0]))) -#define sint4korr(A) (*((long *) (A))) -#define uint2korr(A) (*((uint16 *) (A))) +#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)) -#define uint4korr(A) (*((uint32 *) (A))) +#else +/* + ATTENTION ! + + Please, note, uint3korr reads 4 bytes (not 3) ! + It means, that you have to provide enough allocated space ! +*/ +#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) +\ @@ -1079,8 +1091,8 @@ typedef char my_bool; /* Small bool */ (((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));\ @@ -1105,13 +1117,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)) @@ -1337,49 +1349,36 @@ do { doubleget_union _tmp; \ #define NO_EMBEDDED_ACCESS_CHECKS #endif -#if defined(_WIN32) +#ifdef _WIN32 #define dlsym(lib, name) (void*)GetProcAddress((HMODULE)lib, name) #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0) #define dlclose(lib) FreeLibrary((HMODULE)lib) -#ifndef HAVE_DLOPEN -#define HAVE_DLOPEN -#endif +static inline char *dlerror(void) +{ + static char win_errormsg[2048]; + if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, + 0, GetLastError(), 0, win_errormsg, 2048, NULL)) + return win_errormsg; + return ""; +} +#define HAVE_DLOPEN 1 +#define HAVE_DLERROR 1 #endif -#ifdef HAVE_DLOPEN -#if defined(HAVE_DLFCN_H) +#ifdef HAVE_DLFCN_H #include <dlfcn.h> #endif -#endif +#ifdef HAVE_DLOPEN #ifndef HAVE_DLERROR -#ifdef _WIN32 -#define DLERROR_GENERATE(errmsg, error_number) \ - char win_errormsg[2048]; \ - if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, \ - 0, error_number, 0, win_errormsg, 2048, NULL)) \ - { \ - char *ptr; \ - for (ptr= &win_errormsg[0] + strlen(win_errormsg) - 1; \ - ptr >= &win_errormsg[0] && strchr("\r\n\t\0x20", *ptr); \ - ptr--) \ - *ptr= 0; \ - errmsg= win_errormsg; \ - } \ - else \ - errmsg= "" #define dlerror() "" -#define dlopen_errno GetLastError() -#else /* _WIN32 */ +#endif +#else #define dlerror() "No support for dynamic loading (static build?)" -#define DLERROR_GENERATE(errmsg, error_number) errmsg= dlerror() -#define dlopen_errno errno -#endif /* _WIN32 */ -#else /* HAVE_DLERROR */ -#define DLERROR_GENERATE(errmsg, error_number) errmsg= dlerror() -#define dlopen_errno errno -#endif /* HAVE_DLERROR */ - +#define dlopen(A,B) 0 +#define dlsym(A,B) 0 +#define dlclose(A) 0 +#endif /* * Include standard definitions of operator new and delete. @@ -1394,18 +1393,33 @@ do { doubleget_union _tmp; \ /* Length of decimal number represented by INT64. */ #define MY_INT64_NUM_DECIMAL_DIGITS 21 +#ifdef __cplusplus +#include <limits> /* should be included before min/max macros */ +#endif + /* Define some useful general macros (should be done after all headers). */ #if !defined(max) #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) #endif +#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1) + /* 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) @@ -1413,6 +1427,7 @@ do { doubleget_union _tmp; \ #endif /* Provide __func__ macro definition for platforms that miss it. */ +#if !defined (__func__) #if __STDC_VERSION__ < 199901L # if __GNUC__ >= 2 # define __func__ __FUNCTION__ @@ -1430,6 +1445,7 @@ do { doubleget_union _tmp; \ #else # define __func__ "<unknown>" #endif +#endif /* !defined(__func__) */ #ifndef HAVE_RINT /** @@ -1486,7 +1502,6 @@ static inline double rint(double x) /* Things we don't need in the embedded version of MySQL */ /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */ -#undef HAVE_OPENSSL #undef HAVE_SMEM /* No shared memory */ #endif /* EMBEDDED_LIBRARY */ diff --git a/include/my_net.h b/include/my_net.h index d2b8c9a4414..f8c4f99bae7 100644 --- a/include/my_net.h +++ b/include/my_net.h @@ -43,7 +43,7 @@ C_MODE_START #include <sys/ioctl.h> #endif -#if !defined(__WIN__) && !defined(HAVE_BROKEN_NETINET_INCLUDES) +#if !defined(__WIN__) #include <netinet/in_systm.h> #include <netinet/in.h> #include <netinet/ip.h> diff --git a/include/my_nosys.h b/include/my_nosys.h index d4690d32b54..97f36d00c57 100644 --- a/include/my_nosys.h +++ b/include/my_nosys.h @@ -39,11 +39,6 @@ extern size_t my_quick_read(File Filedes,uchar *Buffer,size_t Count, myf myFlags); extern size_t my_quick_write(File Filedes,const uchar *Buffer,size_t Count); -#if defined(USE_HALLOC) -#define my_malloc(a,b) halloc(a,1) -#define my_no_flags_free(a) hfree(a) -#endif - #endif /* __MY_NOSYS__ */ #ifdef __cplusplus diff --git a/include/my_pthread.h b/include/my_pthread.h index 6ff198ac6f3..9b5703dedb7 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. + Copyright (c) 2009, 2014, MariaDB 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 @@ -85,50 +86,11 @@ typedef volatile LONG my_pthread_once_t; #define MY_PTHREAD_ONCE_INPROGRESS 1 #define MY_PTHREAD_ONCE_DONE 2 -/* - Struct and macros to be used in combination with the - windows implementation of pthread_cond_timedwait -*/ - -#ifndef HAVE_STRUCT_TIMESPEC -/* - Declare a union to make sure FILETIME is properly aligned - so it can be used directly as a 64 bit value. The value - stored is in 100ns units. - */ - union ft64 { - FILETIME ft; - __int64 i64; - }; +#if !STRUCT_TIMESPEC_HAS_TV_SEC || !STRUCT_TIMESPEC_HAS_TV_NSEC struct timespec { - union ft64 tv; - /* The max timeout value in millisecond for pthread_cond_timedwait */ - long max_timeout_msec; + time_t tv_sec; + long tv_nsec; }; -#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); \ -} - -/** - Compare two timespec structs. - - @retval 1 If TS1 ends after TS2. - - @retval 0 If TS1 is equal to TS2. - - @retval -1 If TS1 ends before TS2. -*/ -#define cmp_timespec(TS1, TS2) \ - ((TS1.tv.i64 > TS2.tv.i64) ? 1 : \ - ((TS1.tv.i64 < TS2.tv.i64) ? -1 : 0)) - #endif int win_pthread_mutex_trylock(pthread_mutex_t *mutex); @@ -164,11 +126,12 @@ int pthread_cancel(pthread_t thread); #ifndef ETIMEDOUT #define ETIMEDOUT 145 /* Win32 doesn't have this */ #endif + +#define getpid() GetCurrentThreadId() #define HAVE_LOCALTIME_R 1 #define _REENTRANT 1 #define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 - #undef SAFE_MUTEX /* This will cause conflicts */ #define pthread_key(T,V) DWORD V #define pthread_key_create(A,B) ((*A=TlsAlloc())==0xFFFFFFFF) @@ -187,7 +150,6 @@ int pthread_cancel(pthread_t thread); #define pthread_mutex_destroy(A) (DeleteCriticalSection(A), 0) #define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) - /* Dummy defines for easier code */ #define pthread_attr_setdetachstate(A,B) pthread_dummy(0) #define pthread_attr_setscope(A,B) @@ -249,28 +211,13 @@ extern int my_pthread_create_detached; int sigwait(sigset_t *set, int *sig); #endif -#ifndef HAVE_NONPOSIX_SIGWAIT #define my_sigwait(A,B) sigwait((A),(B)) -#else -int my_sigwait(const sigset_t *set,int *sig); -#endif - -#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); -#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); -#endif /* HAVE_NONPOSIX_PTHREAD_MUTEX_INIT */ #if defined(HAVE_SIGTHREADMASK) && !defined(HAVE_PTHREAD_SIGMASK) #define pthread_sigmask(A,B,C) sigthreadmask((A),(B),(C)) #endif -#if !defined(HAVE_SIGWAIT) && !defined(HAVE_rts_threads) && !defined(sigwait) && !defined(alpha_linux_port) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(_AIX) +#if !defined(HAVE_SIGWAIT) && !defined(HAVE_rts_threads) && !defined(sigwait) && !defined(alpha_linux_port) && !defined(_AIX) int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */ #endif @@ -296,24 +243,12 @@ int sigwait(sigset_t *setp, int *sigp); /* Use our implemention */ #define my_sigset(A,B) signal((A),(B)) #endif -#if !defined(HAVE_PTHREAD_ATTR_SETSCOPE) || defined(HAVE_DEC_3_2_THREADS) +#if !defined(HAVE_PTHREAD_ATTR_SETSCOPE) #define pthread_attr_setscope(A,B) #undef HAVE_GETHOSTBYADDR_R /* No definition */ #endif -#if defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) && !defined(SAFE_MUTEX) -extern int my_pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, - struct timespec *abstime); -#define pthread_cond_timedwait(A,B,C) my_pthread_cond_timedwait((A),(B),(C)) -#endif - -#if !defined( HAVE_NONPOSIX_PTHREAD_GETSPECIFIC) #define my_pthread_getspecific(A,B) ((A) pthread_getspecific(B)) -#else -#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B)) -void *my_pthread_getspecific_imp(pthread_key_t key); -#endif #ifndef HAVE_LOCALTIME_R struct tm *localtime_r(const time_t *clock, struct tm *res); @@ -334,34 +269,7 @@ struct tm *gmtime_r(const time_t *clock, struct tm *res); #define pthread_key_delete(A) pthread_dummy(0) #endif -#ifdef HAVE_CTHREADS_WRAPPER /* For MacOSX */ -#define pthread_cond_destroy(A) pthread_dummy(0) -#define pthread_mutex_destroy(A) pthread_dummy(0) -#define pthread_attr_delete(A) pthread_dummy(0) -#define pthread_condattr_delete(A) pthread_dummy(0) -#define pthread_attr_setstacksize(A,B) pthread_dummy(0) -#define pthread_equal(A,B) ((A) == (B)) -#define pthread_cond_timedwait(a,b,c) pthread_cond_wait((a),(b)) -#define pthread_attr_init(A) pthread_attr_create(A) -#define pthread_attr_destroy(A) pthread_attr_delete(A) -#define pthread_attr_setdetachstate(A,B) pthread_dummy(0) -#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D)) -#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) -#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) -#undef pthread_detach_this_thread -#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); } -#endif - -#ifdef HAVE_DARWIN5_THREADS -#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C)) -#define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) -#define pthread_condattr_init(A) pthread_dummy(0) -#define pthread_condattr_destroy(A) pthread_dummy(0) -#undef pthread_detach_this_thread -#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); } -#endif - -#if ((defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT)) || defined(HAVE_DEC_3_2_THREADS)) && !defined(HAVE_CTHREADS_WRAPPER) +#if defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT) /* This is set on AIX_3_2 and Siemens unix (and DEC OSF/1 3.2 too) */ #define pthread_key_create(A,B) \ pthread_keycreate(A,(B) ?\ @@ -401,7 +309,7 @@ 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) +#if !defined(HAVE_PTHREAD_YIELD_ZERO_ARG) /* no pthread_yield() available */ #ifdef HAVE_SCHED_YIELD #define pthread_yield() sched_yield() @@ -417,34 +325,21 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex); 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 */ -#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)); \ -} -#endif /* !set_timespec_nsec */ -#else -#ifndef set_timespec + #define set_timespec(ABSTIME,SEC) set_timespec_nsec((ABSTIME),(SEC)*1000000000ULL) -#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)); \ -} +#define set_timespec_nsec(ABSTIME,NSEC) \ + set_timespec_time_nsec((ABSTIME), my_hrtime().val*1000 + (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 +#define MY_tv_sec tv_sec +#define MY_tv_nsec tv_nsec #endif /* HAVE_TIMESPEC_TS_SEC */ /** @@ -456,37 +351,49 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex); @retval -1 If TS1 ends before TS2. */ -#ifdef HAVE_TIMESPEC_TS_SEC #ifndef cmp_timespec #define cmp_timespec(TS1, TS2) \ - ((TS1.ts_sec > TS2.ts_sec || \ - (TS1.ts_sec == TS2.ts_sec && TS1.ts_nsec > TS2.ts_nsec)) ? 1 : \ - ((TS1.ts_sec < TS2.ts_sec || \ - (TS1.ts_sec == TS2.ts_sec && TS1.ts_nsec < TS2.ts_nsec)) ? -1 : 0)) + ((TS1.MY_tv_sec > TS2.MY_tv_sec || \ + (TS1.MY_tv_sec == TS2.MY_tv_sec && TS1.MY_tv_nsec > TS2.MY_tv_nsec)) ? 1 : \ + ((TS1.MY_tv_sec < TS2.MY_tv_sec || \ + (TS1.MY_tv_sec == TS2.MY_tv_sec && TS1.MY_tv_nsec < TS2.MY_tv_nsec)) ? -1 : 0)) #endif /* !cmp_timespec */ -#else -#ifndef cmp_timespec -#define cmp_timespec(TS1, TS2) \ - ((TS1.tv_sec > TS2.tv_sec || \ - (TS1.tv_sec == TS2.tv_sec && TS1.tv_nsec > TS2.tv_nsec)) ? 1 : \ - ((TS1.tv_sec < TS2.tv_sec || \ - (TS1.tv_sec == TS2.tv_sec && TS1.tv_nsec < TS2.tv_nsec)) ? -1 : 0)) -#endif /* !cmp_timespec */ -#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,NSEC) do { \ + ulonglong _now_= (NSEC); \ + (ABSTIME).MY_tv_sec= (_now_ / 1000000000ULL); \ + (ABSTIME).MY_tv_nsec= (_now_ % 1000000000ULL); \ +} while(0) +#endif /* !set_timespec_time_nsec */ +/* safe_mutex adds checking to mutex for easier debugging */ +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 @@ -504,8 +411,9 @@ 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 *file, uint line); -int safe_mutex_lock(safe_mutex_t *mp, my_bool try_lock, const char *file, uint line); + const char *name, 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, @@ -515,8 +423,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 @@ -528,13 +440,13 @@ 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 pthread_mutex_init(A,B) safe_mutex_init((A),(B),#A,__FILE__,__LINE__) +#define pthread_mutex_lock(A) safe_mutex_lock((A),0,__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 && \ @@ -542,9 +454,13 @@ void safe_mutex_end(FILE *file); #define safe_mutex_assert_not_owner(mp) \ DBUG_ASSERT(! (mp)->count || \ ! pthread_equal(pthread_self(), (mp)->thread)) +#define safe_mutex_setflags(mp, F) do { (mp)->create_flags|= (F); } while (0) #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 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) +#define safe_mutex_setflags(mp, F) do {} while (0) #endif /* SAFE_MUTEX */ #if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) @@ -582,12 +498,6 @@ int my_pthread_fastmutex_lock(my_pthread_fastmutex_t *mp); /* READ-WRITE thread locking */ -#ifdef HAVE_BROKEN_RWLOCK /* For OpenUnix */ -#undef HAVE_PTHREAD_RWLOCK_RDLOCK -#undef HAVE_RWLOCK_INIT -#undef HAVE_RWLOCK_T -#endif - #if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS) /* use these defs for simple mutex locking */ #define rw_lock_t pthread_mutex_t @@ -811,6 +721,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_reinit(void); extern void my_thread_global_end(void); @@ -819,22 +730,23 @@ extern void my_thread_end(void); extern const char *my_thread_name(void); extern my_thread_id my_thread_dbug_id(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 + #include <mysql/psi/mysql_thread.h> #define INSTRUMENT_ME 0 @@ -853,7 +765,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]; @@ -862,7 +776,9 @@ 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 /* @@ -942,6 +858,21 @@ extern uint thd_lib_detected; #define status_var_add(V,C) (V)+=(C) #define status_var_sub(V,C) (V)-=(C) +#ifdef SAFE_MUTEX +#define mysql_mutex_record_order(A,B) \ + do { \ + mysql_mutex_lock(A); mysql_mutex_lock(B); \ + mysql_mutex_unlock(B); mysql_mutex_unlock(A); \ + } while(0) +#else +#define mysql_mutex_record_order(A,B) do { } while(0) +#endif + +/* At least Windows and NetBSD do not have this definition */ +#ifndef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN 65536 +#endif + #ifdef __cplusplus } #endif diff --git a/include/my_stacktrace.h b/include/my_stacktrace.h index ee038678947..ad05a7df9ab 100644 --- a/include/my_stacktrace.h +++ b/include/my_stacktrace.h @@ -1,4 +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 @@ -49,60 +50,40 @@ void my_safe_print_str(const char* val, int max_len); void my_write_core(int sig); #if BACKTRACE_DEMANGLE char *my_demangle(const char *mangled_name, int *status); -#endif +#endif /* BACKTRACE_DEMANGLE */ #ifdef __WIN__ void my_set_exception_pointers(EXCEPTION_POINTERS *ep); +#endif /* __WIN__ */ +#else +#define my_init_stacktrace() do { } while(0) +#endif /* ! (defined(HAVE_STACKTRACE) || defined(HAVE_BACKTRACE)) */ + +#ifndef _WIN32 +#define MY_ADDR_RESOLVE_FORK +#endif + +#if defined(HAVE_BFD_H) || defined(MY_ADDR_RESOLVE_FORK) +#define HAVE_MY_ADDR_RESOLVE 1 #endif + +typedef struct { + const char *file; + const char *func; + uint line; +} my_addr_loc; + +#ifdef HAVE_MY_ADDR_RESOLVE +int my_addr_resolve(void *ptr, my_addr_loc *loc); +const char *my_addr_resolve_init(); +#else +#define my_addr_resolve_init() (0) +#define my_addr_resolve(A,B) (1) #endif #ifdef HAVE_WRITE_CORE void my_write_core(int sig); #endif - - -/** - Async-signal-safe utility functions used by signal handler routines. - Declared here in order to unit-test them. - These are not general-purpose, but tailored to the signal handling routines. -*/ -/** - Converts a longlong value to string. - @param base 10 for decimal, 16 for hex values (0..9a..f) - @param val The value to convert - @param buf Assumed to point to the *end* of the buffer. - @returns Pointer to the first character of the converted string. - Negative values: - for base-10 the return string will be prepended with '-' - for base-16 the return string will contain 16 characters - Implemented with simplicity, and async-signal-safety in mind. -*/ -char *my_safe_itoa(int base, longlong val, char *buf); - -/** - Converts a ulonglong value to string. - @param base 10 for decimal, 16 for hex values (0..9a..f) - @param val The value to convert - @param buf Assumed to point to the *end* of the buffer. - @returns Pointer to the first character of the converted string. - Implemented with simplicity, and async-signal-safety in mind. -*/ -char *my_safe_utoa(int base, ulonglong val, char *buf); - -/** - A (very) limited version of snprintf. - @param to Destination buffer. - @param n Size of destination buffer. - @param fmt printf() style format string. - @returns Number of bytes written, including terminating '\0' - Supports 'd' 'i' 'u' 'x' 'p' 's' conversion. - Supports 'l' and 'll' modifiers for integral types. - Does not support any width/precision. - Implemented with simplicity, and async-signal-safety in mind. -*/ -size_t my_safe_snprintf(char* to, size_t n, const char* fmt, ...) - ATTRIBUTE_FORMAT(printf, 3, 4); - /** A (very) limited version of snprintf, which writes the result to STDERR. @sa my_safe_snprintf diff --git a/include/my_sys.h b/include/my_sys.h index 9983ee3319f..cd74fdf427b 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. + Copyright (c) 2010, 2017, MariaDB Corporation 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 @@ -28,18 +29,7 @@ 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 */ +#include <my_valgrind.h> #include <my_pthread.h> @@ -49,7 +39,7 @@ typedef struct my_aio_result { #ifdef _WIN32 #include <malloc.h> /*for alloca*/ #endif -#include <sys/stat.h> +#include <mysql/plugin.h> #define MY_INIT(name) { my_progname= name; my_init(); } @@ -73,10 +63,9 @@ typedef struct my_aio_result { #define MY_FAE 8 /* Fatal if any error */ #define MY_WME 16 /* Write message on error */ #define MY_WAIT_IF_FULL 32 /* Wait and try again if disk full error */ -#define MY_IGNORE_BADFD 32 /* my_sync: ignore 'bad descriptor' errors */ -#define MY_SYNC_DIR 8192 /* my_create/delete/rename: sync directory */ -#define MY_UNUSED 64 /* Unused (was support for RAID) */ -#define MY_FULL_IO 512 /* For my_read - loop intil I/O is complete */ +#define MY_IGNORE_BADFD 32 /* my_sync(): ignore 'bad descriptor' errors */ +#define MY_NOSYMLINKS 512 /* my_open(): don't follow symlinks */ +#define MY_FULL_IO 512 /* my_read(): loop intil I/O is complete */ #define MY_DONT_CHECK_FILESIZE 128 /* Option to init_io_cache() */ #define MY_LINK_WARNING 32 /* my_redel() gives warning if links */ #define MY_COPYTIME 64 /* my_redel() copys time */ @@ -84,16 +73,19 @@ typedef struct my_aio_result { #define MY_RESOLVE_LINK 128 /* my_realpath(); Only resolve links */ #define MY_HOLD_ORIGINAL_MODES 128 /* my_copy() holds to file modes */ #define MY_REDEL_MAKE_BACKUP 256 -#define MY_REDEL_NO_COPY_STAT 512 /* my_redel() doesn't call my_copystat() */ #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 */ +#define MY_SYNC_DIR 32768 /* my_create/delete/rename: sync directory */ +#define MY_SYNC_FILESIZE 65536 /* my_sync(): safe sync when file is extended */ #define MY_CHECK_ERROR 1 /* Params to my_end; Check open-close */ #define MY_GIVE_INFO 2 /* Give time info about process*/ @@ -111,7 +103,9 @@ typedef struct my_aio_result { #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_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 */ /* Bits in last argument to fn_format */ #define MY_REPLACE_DIR 1 /* replace dir in name with 'dir' */ @@ -151,6 +145,9 @@ typedef struct my_aio_result { #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 */ extern void *my_malloc(size_t Size,myf MyFlags); extern void *my_multi_malloc(myf MyFlags, ...); @@ -158,18 +155,9 @@ extern void *my_realloc(void *oldpoint, size_t Size, myf MyFlags); extern void my_free(void *ptr); extern void *my_memdup(const void *from,size_t length,myf MyFlags); extern char *my_strdup(const char *from,myf MyFlags); -extern char *my_strndup(const char *from, size_t length, - myf MyFlags); -#define TRASH(A,B) do{MEM_CHECK_ADDRESSABLE(A,B);MEM_UNDEFINED(A,B);} while (0) -#if defined(ENABLED_DEBUG_SYNC) -extern void (*debug_sync_C_callback_ptr)(const char *, size_t); -#define DEBUG_SYNC_C(_sync_point_name_) do { \ - if (debug_sync_C_callback_ptr != NULL) \ - (*debug_sync_C_callback_ptr)(STRING_WITH_LEN(_sync_point_name_)); } \ - while(0) -#else -#define DEBUG_SYNC_C(_sync_point_name_) -#endif /* defined(ENABLED_DEBUG_SYNC) */ +extern char *my_strndup(const char *from, size_t length, myf MyFlags); + +extern int sf_leaking_memory; /* set to 1 to disable memleak detection */ #ifdef HAVE_LARGE_PAGES extern uint my_get_large_page_size(void); @@ -181,7 +169,7 @@ extern void my_large_free(uchar *ptr); #define my_large_free(A) my_free_lock((A)) #endif /* HAVE_LARGE_PAGES */ -#ifdef HAVE_ALLOCA +#if defined(HAVE_ALLOCA) && !defined(HAVE_valgrind) #if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43) #pragma alloca #endif /* _AIX */ @@ -193,12 +181,15 @@ extern void my_large_free(uchar *ptr); #define alloca __builtin_alloca #endif /* GNUC */ #define my_alloca(SZ) alloca((size_t) (SZ)) -#define my_afree(PTR) {} +#define my_afree(PTR) ((void)0) #else #define my_alloca(SZ) my_malloc(SZ,MYF(MY_FAE)) #define my_afree(PTR) my_free(PTR) #endif /* HAVE_ALLOCA */ +#define my_safe_alloca(size, min_length) ((size <= min_length) ? my_alloca(size) : my_malloc(size,MYF(MY_FAE))) +#define my_safe_afree(ptr, size, min_length) ((size <= min_length) ? my_afree(ptr) : my_free(ptr)) + #ifndef errno /* did we already get it? */ #ifdef HAVE_ERRNO_AS_DEFINE #include <errno.h> /* errno is a define */ @@ -207,16 +198,17 @@ extern int errno; /* declare errno */ #endif #endif /* #ifndef errno */ extern char *home_dir; /* Home directory for user */ +extern MYSQL_PLUGIN_IMPORT char *mysql_data_home; extern const char *my_progname; /* program-name (printed in errors) */ +extern const char *my_progname_short; /* like above but without directory */ extern char curr_dir[]; /* Current directory for user */ extern void (*error_handler_hook)(uint my_err, const char *str,myf MyFlags); extern void (*fatal_error_handler_hook)(uint my_err, const char *str, myf MyFlags); -extern void(*sql_print_warning_hook)(const char *format,...); extern uint my_file_limit; -extern ulong my_thread_stack_size; +extern ulonglong my_thread_stack_size; -extern const char *(*proc_info_hook)(void *, const char *, const char *, +extern const char *(*proc_info_hook)(MYSQL_THD, const char *, const char *, const char *, const unsigned int); #ifdef HAVE_LARGE_PAGES @@ -228,14 +220,16 @@ extern uint my_large_page_size; #define MY_ALL_CHARSETS_SIZE 2048 extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info; extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE]; -extern CHARSET_INFO compiled_charsets[]; +extern struct charset_info_st 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; - +extern my_bool my_init_done, my_thr_key_mysys_exists; +extern my_bool my_assert_on_error; +extern myf my_global_flags; /* Set to MY_WME for more error messages */ /* Point to current my_message() */ extern void (*my_sigtstp_cleanup)(void), /* Executed before jump to shell */ @@ -252,6 +246,7 @@ extern my_bool my_use_symdir; extern ulong my_default_record_cache_size; extern my_bool my_disable_locking, my_disable_async_io, my_disable_flush_key_blocks, my_disable_symlinks; +extern my_bool my_disable_sync, my_disable_copystat_in_redel; extern char wild_many,wild_one,wild_prefix; extern const char *charsets_dir; /* from default.c */ @@ -282,7 +277,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 */ @@ -313,9 +314,6 @@ struct st_my_file_info int oflag; /* open flags, e.g O_APPEND */ #endif enum file_type type; -#if !defined(HAVE_PREAD) && !defined(_WIN32) - mysql_mutex_t mutex; -#endif }; extern struct st_my_file_info *my_file_info; @@ -492,16 +490,6 @@ typedef struct st_io_cache /* Used when cacheing files */ typedef int (*qsort2_cmp)(const void *, const void *, const void *); -/* - Subset of struct stat fields filled by stat/lstat/fstat that uniquely - identify a file -*/ -typedef struct st_file_id -{ - dev_t st_dev; - ino_t st_ino; -} ST_FILE_ID; - /* defines for mf_iocache */ /* Test if buffer is inited */ @@ -537,6 +525,8 @@ typedef struct st_file_id #define my_b_tell(info) ((info)->pos_in_file + \ (size_t) (*(info)->current_pos - (info)->request_pos)) +#define my_b_write_tell(info) ((info)->pos_in_file + \ + ((info)->write_pos - (info)->write_buffer)) #define my_b_get_buffer_start(info) (info)->request_pos #define my_b_get_bytes_in_buffer(info) (char*) (info)->read_end - \ @@ -552,11 +542,14 @@ my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */ *(info)->current_pos) typedef uint32 ha_checksum; +extern ulong 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, const char *option); +extern int (*mysys_test_invalid_symlink)(const char *filename); + #include <my_alloc.h> @@ -580,15 +573,15 @@ extern File my_create(const char *FileName,int CreateFlags, extern int my_close(File Filedes,myf MyFlags); extern int my_mkdir(const char *dir, int Flags, myf MyFlags); extern int my_readlink(char *to, const char *filename, myf MyFlags); -extern int my_is_symlink(const char *filename, ST_FILE_ID *file_id); +extern int my_is_symlink(const char *filename); extern int my_realpath(char *to, const char *filename, myf MyFlags); -extern int my_is_same_file(File file, const ST_FILE_ID *file_id); extern File my_create_with_symlink(const char *linkname, const char *filename, int createflags, int access_flags, myf MyFlags); -extern int my_delete_with_symlink(const char *name, myf MyFlags); extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); extern int my_symlink(const char *content, const char *linkname, myf MyFlags); +extern int my_handler_delete_with_symlink(const char *filename, myf sync_dir); + extern size_t my_read(File Filedes,uchar *Buffer,size_t Count,myf MyFlags); extern size_t my_pread(File Filedes,uchar *Buffer,size_t Count,my_off_t offset, myf MyFlags); @@ -612,20 +605,16 @@ extern void *my_memmem(const void *haystack, size_t haystacklen, #ifdef _WIN32 extern int my_access(const char *path, int amode); +#define my_check_user(A,B) (NULL) +#define my_set_user(A,B,C) (0) #else #define my_access access +struct passwd *my_check_user(const char *user, myf MyFlags); +int my_set_user(const char *user, struct passwd *user_info, myf MyFlags); #endif extern int check_if_legal_filename(const char *path); extern int check_if_legal_tablename(const char *path); -extern my_bool is_filename_allowed(const char *name, size_t length); - -#ifdef _WIN32 -extern int nt_share_delete(const char *name,myf MyFlags); -#define my_delete_allow_opened(fname,flags) nt_share_delete((fname),(flags)) -#else -#define my_delete_allow_opened(fname,flags) my_delete((fname),(flags)) -#endif #ifdef _WIN32 /* Windows-only functions (CRT equivalents)*/ @@ -640,8 +629,12 @@ extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags); 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_vfprintf(FILE *stream, const char* format, va_list args); +extern int my_fprintf(FILE *stream, const char* format, ...); extern File my_fileno(FILE *fd); 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 const char *my_basename(const char *filename); extern void thr_set_sync_wait_callback(void (*before_sync)(void), void (*after_sync)(void)); extern int my_sync(File fd, myf my_flags); @@ -655,13 +648,15 @@ extern void my_printv_error(uint error, const char *format, myf MyFlags, va_list ap); extern int my_error_register(const char** (*get_errmsgs) (), int first, int last); -extern void my_printf_warning (const char * format, ...); extern const char **my_error_unregister(int first, int last); extern void my_message(uint my_err, const char *str,myf MyFlags); extern void my_message_stderr(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); @@ -684,6 +679,7 @@ extern my_bool has_path(const char *name); extern char *convert_dirname(char *to, const char *from, const char *from_end); extern void to_unix_path(char * name); extern char * fn_ext(const char *name); +extern char * fn_ext2(const char *name); extern char * fn_same(char * toname,const char *name,int flag); extern char * fn_format(char * to,const char *name,const char *dir, const char *form, uint flag); @@ -760,6 +756,8 @@ extern size_t my_b_fill(IO_CACHE *info); extern void my_b_seek(IO_CACHE *info,my_off_t pos); 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_write_backtick_quote(IO_CACHE *info, const char *str, + size_t len); 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 my_bool open_cached_file(IO_CACHE *cache,const char *dir, @@ -779,7 +777,7 @@ extern my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size, /* init_dynamic_array() function is deprecated */ extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, uint init_alloc, uint alloc_increment); -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); @@ -806,6 +804,8 @@ extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str); extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size); extern my_bool dynstr_trunc(DYNAMIC_STRING *str, size_t n); extern void dynstr_free(DYNAMIC_STRING *str); +extern void dynstr_reassociate(DYNAMIC_STRING *str, char **res, size_t *length, + size_t *alloc_length); #ifdef HAVE_MLOCK extern void *my_malloc_lock(size_t length,myf flags); extern void my_free_lock(void *ptr); @@ -851,24 +851,43 @@ 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); void my_free_open_file_info(void); -extern time_t my_time(myf flags); -extern ulonglong my_getsystime(void); -extern ulonglong my_micro_time(); -extern ulonglong my_micro_time_and_time(time_t *time_arg); -time_t my_time_possible_from_micro(ulonglong microtime); extern my_bool my_gethwaddr(uchar *to); extern int my_getncpus(); +#define HRTIME_RESOLUTION 1000000ULL /* microseconds */ +typedef struct {ulonglong val;} my_hrtime_t; +void my_time_init(); +extern my_hrtime_t my_hrtime(); +extern ulonglong my_interval_timer(void); +extern ulonglong my_getcputime(void); + +#define microsecond_interval_timer() (my_interval_timer()/1000) +#define hrtime_to_time(X) ((X).val/HRTIME_RESOLUTION) +#define hrtime_from_time(X) ((ulonglong)((X)*HRTIME_RESOLUTION)) +#define hrtime_to_double(X) ((X).val/(double)HRTIME_RESOLUTION) +#define hrtime_sec_part(X) ((ulong)((X).val % HRTIME_RESOLUTION)) +#define my_time(X) hrtime_to_time(my_hrtime()) + #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> @@ -911,6 +930,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); @@ -931,7 +966,7 @@ extern void free_charsets(void); extern char *get_charsets_dir(char *buf); extern my_bool my_charset_same(CHARSET_INFO *cs1, CHARSET_INFO *cs2); extern my_bool init_compiled_charsets(myf flags); -extern void add_compiled_collation(CHARSET_INFO *cs); +extern void add_compiled_collation(struct charset_info_st *cs); extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info, char *to, size_t to_length, const char *from, size_t length); diff --git a/include/my_time.h b/include/my_time.h index ea63fb479b3..bcf1a8cb215 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -1,4 +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 @@ -45,7 +46,7 @@ typedef long my_time_t; #define TIMESTAMP_MAX_YEAR 2038 #define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1) #define TIMESTAMP_MAX_VALUE INT_MAX32 -#define TIMESTAMP_MIN_VALUE 1 +#define TIMESTAMP_MIN_VALUE 0 /* two-digit years < this are 20..; >= this are 19.. */ #define YY_PART_YEAR 70 @@ -64,43 +65,72 @@ typedef long my_time_t; #endif /* Flags to str_to_datetime */ -#define TIME_FUZZY_DATE 1 + +/* + TIME_FUZZY_DATES is used for the result will only be used for comparison + purposes. Conversion is as relaxed as possible. +*/ +#define TIME_FUZZY_DATES 1 #define TIME_DATETIME_ONLY 2 -/* Must be same as MODE_NO_ZERO_IN_DATE */ -#define TIME_NO_ZERO_IN_DATE (65536L*2*2*2*2*2*2*2) -/* Must be same as MODE_NO_ZERO_DATE */ -#define TIME_NO_ZERO_DATE (TIME_NO_ZERO_IN_DATE*2) -#define TIME_INVALID_DATES (TIME_NO_ZERO_DATE*2) +#define TIME_TIME_ONLY 4 +#define TIME_NO_ZERO_IN_DATE (1UL << 23) /* == MODE_NO_ZERO_IN_DATE */ +#define TIME_NO_ZERO_DATE (1UL << 24) /* == MODE_NO_ZERO_DATE */ +#define TIME_INVALID_DATES (1UL << 25) /* == MODE_INVALID_DATES */ #define MYSQL_TIME_WARN_TRUNCATED 1 #define MYSQL_TIME_WARN_OUT_OF_RANGE 2 +#define MYSQL_TIME_NOTE_TRUNCATED 16 + +#define MYSQL_TIME_WARN_WARNINGS (MYSQL_TIME_WARN_TRUNCATED|MYSQL_TIME_WARN_OUT_OF_RANGE) +#define MYSQL_TIME_WARN_NOTES (MYSQL_TIME_NOTE_TRUNCATED) + +#define MYSQL_TIME_WARN_HAVE_WARNINGS(x) MY_TEST((x) & MYSQL_TIME_WARN_WARNINGS) +#define MYSQL_TIME_WARN_HAVE_NOTES(x) MY_TEST((x) & MYSQL_TIME_WARN_NOTES) /* Limits for the TIME data type */ #define TIME_MAX_HOUR 838 #define TIME_MAX_MINUTE 59 #define TIME_MAX_SECOND 59 -#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \ - TIME_MAX_SECOND) +#define TIME_MAX_SECOND_PART 999999 +#define TIME_SECOND_PART_FACTOR (TIME_MAX_SECOND_PART+1) +#define TIME_SECOND_PART_DIGITS 6 +#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + TIME_MAX_SECOND) #define TIME_MAX_VALUE_SECONDS (TIME_MAX_HOUR * 3600L + \ TIME_MAX_MINUTE * 60L + TIME_MAX_SECOND) my_bool check_date(const MYSQL_TIME *ltime, my_bool not_zero_date, ulonglong flags, int *was_cut); enum enum_mysql_timestamp_type +str_to_time(const char *str, uint length, MYSQL_TIME *l_time, + ulonglong flag, int *warning); +enum enum_mysql_timestamp_type str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, ulonglong flags, int *was_cut); -longlong number_to_datetime(longlong nr, MYSQL_TIME *time_res, +longlong number_to_datetime(longlong nr, ulong sec_part, MYSQL_TIME *time_res, ulonglong flags, int *was_cut); + +static inline +longlong double_to_datetime(double nr, MYSQL_TIME *ltime, uint flags, int *cut) +{ + if (nr < 0 || nr > LONGLONG_MAX) + nr= (double)LONGLONG_MAX; + return number_to_datetime((longlong) floor(nr), + (ulong)((nr-floor(nr))*TIME_SECOND_PART_FACTOR), + ltime, flags, cut); +} + +int number_to_time(my_bool neg, ulonglong nr, ulong sec_part, + MYSQL_TIME *ltime, int *was_cut); ulonglong TIME_to_ulonglong_datetime(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_date(const MYSQL_TIME *); ulonglong TIME_to_ulonglong_time(const MYSQL_TIME *); ulonglong TIME_to_ulonglong(const MYSQL_TIME *); +double TIME_to_double(const MYSQL_TIME *my_time); +longlong pack_time(MYSQL_TIME *my_time); +MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time); -my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time, - int *warning); - -int check_time_range(struct st_mysql_time *, int *warning); +int check_time_range(struct st_mysql_time *my_time, uint dec, int *warning); long calc_daynr(uint year,uint month,uint day); uint calc_days_in_year(uint year); @@ -133,8 +163,7 @@ static inline my_bool validate_timestamp_range(const MYSQL_TIME *t) } my_time_t -my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, - my_bool *in_dst_time_gap); +my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone, uint *error_code); void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); @@ -147,11 +176,28 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type); sent using binary protocol fit in this buffer. */ #define MAX_DATE_STRING_REP_LENGTH 30 +#define AUTO_SEC_PART_DIGITS 31 /* same as NOT_FIXED_DEC */ -int my_time_to_str(const MYSQL_TIME *l_time, char *to); +int my_time_to_str(const MYSQL_TIME *l_time, char *to, uint digits); int my_date_to_str(const MYSQL_TIME *l_time, char *to); -int my_datetime_to_str(const MYSQL_TIME *l_time, char *to); -int my_TIME_to_str(const MYSQL_TIME *l_time, char *to); +int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, uint digits); +int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, uint digits); + +static inline longlong sec_part_shift(longlong second_part, uint digits) +{ + return second_part / (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; +} +static inline longlong sec_part_unshift(longlong second_part, uint digits) +{ + return second_part * (longlong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; +} +static inline ulong sec_part_truncate(ulong second_part, uint digits) +{ + /* the cast here should be unnecessary! */ + return second_part - second_part % (ulong)log_10_int[TIME_SECOND_PART_DIGITS - digits]; +} + +#define hrtime_to_my_time(X) ((my_time_t)hrtime_to_time(X)) /* Available interval types used in any statement. diff --git a/include/my_tree.h b/include/my_tree.h index 4457bb1bc85..1069b232360 100644 --- a/include/my_tree.h +++ b/include/my_tree.h @@ -31,7 +31,17 @@ extern "C" { #define tree_set_pointer(element,ptr) *((uchar **) (element+1))=((uchar*) (ptr)) +/* + A tree with its flag set to TREE_ONLY_DUPS behaves differently on inserting + an element that is not in the tree: + the element is not added at all, but instead tree_insert() returns a special + address TREE_ELEMENT_UNIQUE as an indication that the function has not failed + due to lack of memory. +*/ + +#define TREE_ELEMENT_UNIQUE ((TREE_ELEMENT *) 1) #define TREE_NO_DUPS 1 +#define TREE_ONLY_DUPS 2 typedef enum { left_root_right, right_root_left } TREE_WALK; typedef uint32 element_count; @@ -52,7 +62,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; @@ -62,13 +72,13 @@ typedef struct st_tree { } TREE; /* Functions on whole tree */ -void init_tree(TREE *tree, size_t 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 */ @@ -87,6 +97,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..4bd4cf99ada --- /dev/null +++ b/include/my_valgrind.h @@ -0,0 +1,43 @@ +/* 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 */ + +#ifdef HAVE_valgrind +#define IF_VALGRIND(A,B) A +#else +#define IF_VALGRIND(A,B) B +#endif + +#if defined(HAVE_VALGRIND) && defined(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 DBUG_OFF +#define TRASH_FILL(A,B,C) do { memset(A, C, B); MEM_UNDEFINED(A, B); } while (0) +#else +#define TRASH_FILL(A,B,C) do{ MEM_CHECK_ADDRESSABLE(A,B);MEM_UNDEFINED(A,B);} while (0) +#endif +#define TRASH_ALLOC(A,B) TRASH_FILL(A,B,0xA5) +#define TRASH_FREE(A,B) TRASH_FILL(A,B,0x8F) +#define TRASH(A,B) TRASH_FREE(A,B) + diff --git a/include/myisam.h b/include/myisam.h index a9fcd7e4369..186b049b32e 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 2013, 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,20 +22,15 @@ extern "C" { #endif -#ifndef _my_base_h #include <my_base.h> -#endif -#ifndef _m_ctype_h #include <m_ctype.h> -#endif -#ifndef _keycache_h #include "keycache.h" -#endif #include "my_compare.h" +#include <myisamchk.h> #include <mysql/plugin.h> #include <my_check_opt.h> /* - 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 @@ -52,8 +47,6 @@ extern "C" { #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" @@ -232,7 +225,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 */ @@ -247,7 +240,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; @@ -297,13 +289,17 @@ 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 myisam_max_key_length() HA_MAX_KEY_LENGTH +#define myisam_max_key_segments() HA_MAX_KEY_SEG #define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for mmap file */ /* this is used to pass to mysql_myisamchk_table */ @@ -311,159 +307,128 @@ 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 */ -/* - Flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed - to mi_check.c follows: -*/ +typedef uint mi_bit_type; -#define TT_USEFRM 1 -#define TT_FOR_UPGRADE 2 +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; -#define O_NEW_INDEX 1 /* Bits set in out_flag */ -#define O_NEW_DATA 2 -#define O_DATA_LOST 4 - -/* 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. -*/ + /* sync things */ + mysql_mutex_t mutex; + mysql_cond_t cond; + 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; + volatile uint got_error; + uint 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; - ulonglong sort_buffer_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_key_blocks; - uint out_flag,warning_printed,error_printed,verbose; - uint opt_sort_key,total_files,max_level; - uint testflag, key_cache_block_size; - uint16 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; + 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; - int tmpfile_createflag; - myf myf_rw; - IO_CACHE read_cache; - - /* + + /* 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; - mysql_mutex_t print_msg_mutex; - my_bool need_print_msg_lock; -} MI_CHECK; - -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; - mysql_mutex_t mutex; - mysql_cond_t cond; -} SORT_INFO; + 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 *); + int (*write_keys)(struct st_mi_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_mi_sort_param *, IO_CACHE *,uchar *, + uint, uint); +} MI_SORT_PARAM; /* 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, - char * name, int rep_quick, my_bool no_copy_stat); -int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name, - my_bool no_copy_stat); -int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, - const char * name, int rep_quick, my_bool no_copy_stat); -int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info, - const char * name, int rep_quick, my_bool no_copy_stat); +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(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(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, myf myflags); -int lock_file(MI_CHECK *param, File file, my_off_t start, int lock_type, + const char * new_ext, time_t backup_time, myf myflags); +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 *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); -int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows); +int mi_init_bulk_insert(MI_INFO *info, size_t cache_size, ha_rows rows); void mi_flush_bulk_insert(MI_INFO *info, uint inx); void mi_end_bulk_insert(MI_INFO *info); -int mi_assign_to_key_cache(MI_INFO *info, ulonglong key_map, +int mi_assign_to_key_cache(MI_INFO *info, ulonglong key_map, KEY_CACHE *key_cache); 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, ulonglong); + #ifdef __cplusplus } #endif diff --git a/include/myisamchk.h b/include/myisamchk.h new file mode 100644 index 00000000000..ded463f10ca --- /dev/null +++ b/include/myisamchk.h @@ -0,0 +1,146 @@ +/* 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 + +/* + 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 +#define TT_FROM_MYSQL 4 + +/* 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 sort_buffer_length; + ulonglong use_buffers; /* Used as param to getopt() */ + size_t read_buffer_length, write_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, note_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; + uint16 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; + /* For reporting progress */ + uint stage, max_stage; + uint progress_counter; /* How often to call _report_progress() */ + ulonglong progress, max_progress; + + mysql_mutex_t print_msg_mutex; + my_bool need_print_msg_lock; +} 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 4f9b9d01efb..0795455dc3e 100644 --- a/include/myisampack.h +++ b/include/myisampack.h @@ -28,58 +28,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 */ @@ -136,85 +136,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 */ @@ -227,7 +227,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 @@ -238,6 +238,6 @@ 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 #endif /* MYISAMPACK_INCLUDED */ diff --git a/include/mysql.h b/include/mysql.h index 3a27ab4128c..2f205ec6463 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -1,4 +1,6 @@ -/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. +/* + Copyright (c) 2000, 2012, Oracle and/or its affiliates. + Copyright (c) 2012, 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 @@ -46,9 +48,6 @@ extern "C" { #ifndef MYSQL_ABI_CHECK #include <sys/types.h> #endif -#ifdef __LCC__ -#include <winsock2.h> /* For windows */ -#endif typedef char my_bool; #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__) #define __WIN__ @@ -60,11 +59,13 @@ typedef char my_bool; #endif #ifndef my_socket_defined -#ifdef __WIN__ -#define my_socket SOCKET +#if defined (_WIN64) +#define my_socket unsigned long long +#elif defined (_WIN32) +#define my_socket unsigned int #else typedef int my_socket; -#endif /* __WIN__ */ +#endif /* _WIN64 */ #endif /* my_socket_defined */ #endif /* _global_h */ @@ -74,6 +75,7 @@ typedef int my_socket; #include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */ +extern unsigned int mariadb_deinitialize_ssl; extern unsigned int mysql_port; extern char *mysql_unix_port; @@ -134,6 +136,7 @@ typedef unsigned long long my_ulonglong; /* backward compatibility define - to be removed eventually */ #define ER_WARN_DATA_TRUNCATED WARN_DATA_TRUNCATED +#define WARN_PLUGIN_DELETE_BUILTIN ER_PLUGIN_DELETE_BUILTIN typedef struct st_mysql_rows { struct st_mysql_rows *next; /* list of rows */ @@ -168,8 +171,10 @@ enum mysql_option MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, MYSQL_ENABLE_CLEARTEXT_PLUGIN, - /* Set MYSQL_OPT_SSL_MODE to be the same as in 5.6 (ABI compatibility). */ - MYSQL_OPT_SSL_MODE= 38 + + /* MariaDB options */ + MYSQL_PROGRESS_CALLBACK=5999, + MYSQL_OPT_NONBLOCK=6000 }; /** @@ -226,11 +231,6 @@ enum mysql_protocol_type MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY }; -enum mysql_ssl_mode -{ - SSL_MODE_REQUIRED= 3 -}; - typedef struct character_set { unsigned int number; /* character set number */ @@ -252,7 +252,7 @@ typedef struct st_mysql unsigned char *connector_fd; /* ConnectorFd for SSL */ char *host,*user,*passwd,*unix_socket,*server_version,*host_info; char *info, *db; - struct charset_info_st *charset; + const struct charset_info_st *charset; MYSQL_FIELD *fields; MEM_ROOT field_alloc; my_ulonglong affected_rows; @@ -322,6 +322,26 @@ typedef struct st_mysql_parameters void *extension; } MYSQL_PARAMETERS; +/* + Flag bits, the asynchronous methods return a combination of these ORed + together to let the application know when to resume the suspended operation. +*/ + +/* + Wait for data to be available on socket to read. + mysql_get_socket_fd() will return socket descriptor. +*/ +#define MYSQL_WAIT_READ 1 +/* Wait for socket to be ready to write data. */ +#define MYSQL_WAIT_WRITE 2 +/* Wait for select() to mark exception on socket. */ +#define MYSQL_WAIT_EXCEPT 4 +/* + Wait until timeout occurs. Value of timeout can be obtained from + mysql_get_timeout_value(). +*/ +#define MYSQL_WAIT_TIMEOUT 8 + #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY) #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet) #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length) @@ -383,6 +403,10 @@ const char * STDCALL mysql_info(MYSQL *mysql); unsigned long STDCALL mysql_thread_id(MYSQL *mysql); const char * STDCALL mysql_character_set_name(MYSQL *mysql); int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname); +int STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql, + const char *csname); +int STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql, + int status); MYSQL * STDCALL mysql_init(MYSQL *mysql); my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, @@ -391,6 +415,12 @@ my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql); my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db); +int STDCALL mysql_change_user_start(my_bool *ret, MYSQL *mysql, + const char *user, + const char *passwd, + const char *db); +int STDCALL mysql_change_user_cont(my_bool *ret, MYSQL *mysql, + int status); MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, @@ -398,13 +428,44 @@ MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, unsigned int port, const char *unix_socket, unsigned long clientflag); +int STDCALL mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag); +int STDCALL mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, + int status); int STDCALL mysql_select_db(MYSQL *mysql, const char *db); +int STDCALL mysql_select_db_start(int *ret, MYSQL *mysql, + const char *db); +int STDCALL mysql_select_db_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_query(MYSQL *mysql, const char *q); +int STDCALL mysql_query_start(int *ret, MYSQL *mysql, + const char *q); +int STDCALL mysql_query_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_send_query(MYSQL *mysql, const char *q, unsigned long length); +int STDCALL mysql_send_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int STDCALL mysql_send_query_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_real_query(MYSQL *mysql, const char *q, unsigned long length); +int STDCALL mysql_real_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int STDCALL mysql_real_query_cont(int *ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); +int STDCALL mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql); +int STDCALL mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); void STDCALL mysql_get_character_set_info(MYSQL *mysql, @@ -431,27 +492,66 @@ mysql_set_local_infile_default(MYSQL *mysql); int STDCALL mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level); +int STDCALL mysql_shutdown_start(int *ret, MYSQL *mysql, + enum mysql_enum_shutdown_level + shutdown_level); +int STDCALL mysql_shutdown_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_dump_debug_info(MYSQL *mysql); +int STDCALL mysql_dump_debug_info_start(int *ret, MYSQL *mysql); +int STDCALL mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_refresh(MYSQL *mysql, unsigned int refresh_options); +int STDCALL mysql_refresh_start(int *ret, MYSQL *mysql, + unsigned int refresh_options); +int STDCALL mysql_refresh_cont(int *ret, MYSQL *mysql, int status); int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid); +int STDCALL mysql_kill_start(int *ret, MYSQL *mysql, + unsigned long pid); +int STDCALL mysql_kill_cont(int *ret, MYSQL *mysql, int status); int STDCALL mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option); +int STDCALL mysql_set_server_option_start(int *ret, MYSQL *mysql, + enum enum_mysql_set_option + option); +int STDCALL mysql_set_server_option_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_ping(MYSQL *mysql); +int STDCALL mysql_ping_start(int *ret, MYSQL *mysql); +int STDCALL mysql_ping_cont(int *ret, MYSQL *mysql, int status); const char * STDCALL mysql_stat(MYSQL *mysql); +int STDCALL mysql_stat_start(const char **ret, MYSQL *mysql); +int STDCALL mysql_stat_cont(const char **ret, MYSQL *mysql, + int status); 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); unsigned long STDCALL mysql_get_server_version(MYSQL *mysql); unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); +int STDCALL mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int STDCALL mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild); +int STDCALL mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int STDCALL mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); +int STDCALL mysql_list_processes_start(MYSQL_RES **ret, + MYSQL *mysql); +int STDCALL mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg); void STDCALL mysql_free_result(MYSQL_RES *result); +int STDCALL mysql_free_result_start(MYSQL_RES *result); +int STDCALL mysql_free_result_cont(MYSQL_RES *result, int status); void STDCALL mysql_data_seek(MYSQL_RES *result, my_ulonglong offset); MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, @@ -459,10 +559,19 @@ MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset); MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); +int STDCALL mysql_fetch_row_start(MYSQL_ROW *ret, + MYSQL_RES *result); +int STDCALL mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, + int status); unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, const char *wild); +int STDCALL mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, + const char *table, + const char *wild); +int STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); unsigned long STDCALL mysql_escape_string(char *to,const char *from, unsigned long from_length); unsigned long STDCALL mysql_hex_string(char *to,const char *from, @@ -474,7 +583,12 @@ 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); my_bool STDCALL mysql_read_query_result(MYSQL *mysql); +int STDCALL mysql_read_query_result_start(my_bool *ret, + MYSQL *mysql); +int STDCALL mysql_read_query_result_cont(my_bool *ret, + MYSQL *mysql, int status); /* @@ -653,16 +767,25 @@ enum enum_stmt_attr_type STMT_ATTR_PREFETCH_ROWS }; - MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql); int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length); +int STDCALL mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt, + const char *query, unsigned long length); +int STDCALL mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status); int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status); int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status); int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset); int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt, + int status); unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt); my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, @@ -673,12 +796,25 @@ my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); +int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt); +int STDCALL mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt); +int STDCALL mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status); my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length); +int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, + unsigned long len); +int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt); MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt); unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); @@ -694,13 +830,35 @@ my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt); my_bool STDCALL mysql_commit(MYSQL * mysql); +int STDCALL mysql_commit_start(my_bool *ret, MYSQL * mysql); +int STDCALL mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool STDCALL mysql_rollback(MYSQL * mysql); +int STDCALL mysql_rollback_start(my_bool *ret, MYSQL * mysql); +int STDCALL mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status); my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode); +int STDCALL mysql_autocommit_start(my_bool *ret, MYSQL * mysql, + my_bool auto_mode); +int STDCALL mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool STDCALL mysql_more_results(MYSQL *mysql); int STDCALL mysql_next_result(MYSQL *mysql); +int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql); +int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status); int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status); +void STDCALL mysql_close_slow_part(MYSQL *mysql); void STDCALL mysql_close(MYSQL *sock); - +int STDCALL mysql_close_start(MYSQL *sock); +int STDCALL mysql_close_cont(MYSQL *sock, int status); +my_socket STDCALL mysql_get_socket(const MYSQL *mysql); +unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql); +unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql); + +/******************************************************************** + mysql_net_ functions - low-level API to MySQL protocol +*********************************************************************/ +unsigned long STDCALL mysql_net_read_packet(MYSQL *mysql); +unsigned long STDCALL mysql_net_field_length(unsigned char **packet); /* status return codes */ #define MYSQL_NO_DATA 100 diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 774bf2d0301..4f7407095c9 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -1,7 +1,5 @@ typedef char my_bool; typedef int my_socket; -#include "mysql_version.h" -#include "mysql_com.h" enum enum_server_command { COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST, @@ -27,8 +25,8 @@ typedef struct st_net { unsigned int *return_status; unsigned char reading_or_writing; char save_char; + char net_skip_rest_factor; my_bool unused1; - my_bool unused2; my_bool compress; my_bool unused3; unsigned char *unused; @@ -66,9 +64,7 @@ enum mysql_enum_shutdown_level { SHUTDOWN_WAIT_TRANSACTIONS= (unsigned char)(1 << 1), SHUTDOWN_WAIT_UPDATES= (unsigned char)(1 << 3), SHUTDOWN_WAIT_ALL_BUFFERS= ((unsigned char)(1 << 3) << 1), - SHUTDOWN_WAIT_CRITICAL_BUFFERS= ((unsigned char)(1 << 3) << 1) + 1, - KILL_QUERY= 254, - KILL_CONNECTION= 255 + SHUTDOWN_WAIT_CRITICAL_BUFFERS= ((unsigned char)(1 << 3) << 1) + 1 }; enum enum_cursor_type { @@ -97,12 +93,12 @@ 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, + TIME_RESULT,IMPOSSIBLE_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 +119,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); @@ -142,10 +136,10 @@ void get_salt_from_password(unsigned char *res, const char *password); void make_password_from_salt(char *to, const unsigned char *hash_stage2); char *octet2hex(char *to, const char *str, unsigned int len); char *get_tty_password(const char *opt_message); +void get_tty_password_buff(const char *opt_message, char *to, size_t length); const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); my_bool my_thread_init(void); void my_thread_end(void); -#include "mysql_time.h" enum enum_mysql_timestamp_type { MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, @@ -158,7 +152,6 @@ typedef struct st_mysql_time my_bool neg; enum enum_mysql_timestamp_type time_type; } MYSQL_TIME; -#include "my_list.h" typedef struct st_list { struct st_list *prev,*next; void *data; @@ -171,6 +164,7 @@ extern LIST *list_reverse(LIST *root); extern void list_free(LIST *root,unsigned int free_data); extern unsigned int list_length(LIST *); extern int list_walk(LIST *,list_walk_action action,unsigned char * argument); +extern unsigned int mariadb_deinitialize_ssl; extern unsigned int mysql_port; extern char *mysql_unix_port; typedef struct st_mysql_field { @@ -199,13 +193,11 @@ typedef struct st_mysql_field { typedef char **MYSQL_ROW; typedef unsigned int MYSQL_FIELD_OFFSET; typedef unsigned long long my_ulonglong; -#include "typelib.h" -#include "my_alloc.h" 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,6 +217,8 @@ 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_with_warning(const char *x, TYPELIB *typelib, + const char *option); extern int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option); extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); @@ -242,7 +236,6 @@ typedef struct st_mysql_rows { unsigned long length; } MYSQL_ROWS; typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; -#include "my_alloc.h" typedef struct embedded_query_result EMBEDDED_QUERY_RESULT; typedef struct st_mysql_data { MYSQL_ROWS *data; @@ -264,7 +257,8 @@ enum mysql_option MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, MYSQL_ENABLE_CLEARTEXT_PLUGIN, - MYSQL_OPT_SSL_MODE= 38 + MYSQL_PROGRESS_CALLBACK=5999, + MYSQL_OPT_NONBLOCK=6000 }; struct st_mysql_options_extention; struct st_mysql_options { @@ -308,10 +302,6 @@ enum mysql_protocol_type MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP, MYSQL_PROTOCOL_SOCKET, MYSQL_PROTOCOL_PIPE, MYSQL_PROTOCOL_MEMORY }; -enum mysql_ssl_mode -{ - SSL_MODE_REQUIRED= 3 -}; typedef struct character_set { unsigned int number; @@ -331,7 +321,7 @@ typedef struct st_mysql unsigned char *connector_fd; char *host,*user,*passwd,*unix_socket,*server_version,*host_info; char *info, *db; - struct charset_info_st *charset; + const struct charset_info_st *charset; MYSQL_FIELD *fields; MEM_ROOT field_alloc; my_ulonglong affected_rows; @@ -406,6 +396,10 @@ const char * mysql_info(MYSQL *mysql); unsigned long mysql_thread_id(MYSQL *mysql); const char * mysql_character_set_name(MYSQL *mysql); int mysql_set_character_set(MYSQL *mysql, const char *csname); +int mysql_set_character_set_start(int *ret, MYSQL *mysql, + const char *csname); +int mysql_set_character_set_cont(int *ret, MYSQL *mysql, + int status); MYSQL * mysql_init(MYSQL *mysql); my_bool mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert, const char *ca, @@ -413,6 +407,12 @@ my_bool mysql_ssl_set(MYSQL *mysql, const char *key, const char * mysql_get_ssl_cipher(MYSQL *mysql); my_bool mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db); +int mysql_change_user_start(my_bool *ret, MYSQL *mysql, + const char *user, + const char *passwd, + const char *db); +int mysql_change_user_cont(my_bool *ret, MYSQL *mysql, + int status); MYSQL * mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, @@ -420,13 +420,44 @@ MYSQL * mysql_real_connect(MYSQL *mysql, const char *host, unsigned int port, const char *unix_socket, unsigned long clientflag); +int mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag); +int mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, + int status); int mysql_select_db(MYSQL *mysql, const char *db); +int mysql_select_db_start(int *ret, MYSQL *mysql, + const char *db); +int mysql_select_db_cont(int *ret, MYSQL *mysql, + int status); int mysql_query(MYSQL *mysql, const char *q); +int mysql_query_start(int *ret, MYSQL *mysql, + const char *q); +int mysql_query_cont(int *ret, MYSQL *mysql, + int status); int mysql_send_query(MYSQL *mysql, const char *q, unsigned long length); +int mysql_send_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int mysql_send_query_cont(int *ret, MYSQL *mysql, + int status); int mysql_real_query(MYSQL *mysql, const char *q, unsigned long length); +int mysql_real_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int mysql_real_query_cont(int *ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_store_result(MYSQL *mysql); +int mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql); +int mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_use_result(MYSQL *mysql); void mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *charset); @@ -445,27 +476,66 @@ mysql_set_local_infile_default(MYSQL *mysql); int mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level); +int mysql_shutdown_start(int *ret, MYSQL *mysql, + enum mysql_enum_shutdown_level + shutdown_level); +int mysql_shutdown_cont(int *ret, MYSQL *mysql, + int status); int mysql_dump_debug_info(MYSQL *mysql); +int mysql_dump_debug_info_start(int *ret, MYSQL *mysql); +int mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, + int status); int mysql_refresh(MYSQL *mysql, unsigned int refresh_options); +int mysql_refresh_start(int *ret, MYSQL *mysql, + unsigned int refresh_options); +int mysql_refresh_cont(int *ret, MYSQL *mysql, int status); int mysql_kill(MYSQL *mysql,unsigned long pid); +int mysql_kill_start(int *ret, MYSQL *mysql, + unsigned long pid); +int mysql_kill_cont(int *ret, MYSQL *mysql, int status); int mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option); +int mysql_set_server_option_start(int *ret, MYSQL *mysql, + enum enum_mysql_set_option + option); +int mysql_set_server_option_cont(int *ret, MYSQL *mysql, + int status); int mysql_ping(MYSQL *mysql); +int mysql_ping_start(int *ret, MYSQL *mysql); +int mysql_ping_cont(int *ret, MYSQL *mysql, int status); const char * mysql_stat(MYSQL *mysql); +int mysql_stat_start(const char **ret, MYSQL *mysql); +int mysql_stat_cont(const char **ret, MYSQL *mysql, + int status); 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); unsigned long mysql_get_server_version(MYSQL *mysql); unsigned int mysql_get_proto_info(MYSQL *mysql); MYSQL_RES * mysql_list_dbs(MYSQL *mysql,const char *wild); +int mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_list_tables(MYSQL *mysql,const char *wild); +int mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_list_processes(MYSQL *mysql); +int mysql_list_processes_start(MYSQL_RES **ret, + MYSQL *mysql); +int mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); int mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg); void mysql_free_result(MYSQL_RES *result); +int mysql_free_result_start(MYSQL_RES *result); +int mysql_free_result_cont(MYSQL_RES *result, int status); void mysql_data_seek(MYSQL_RES *result, my_ulonglong offset); MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, @@ -473,10 +543,19 @@ MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset); MYSQL_ROW mysql_fetch_row(MYSQL_RES *result); +int mysql_fetch_row_start(MYSQL_ROW *ret, + MYSQL_RES *result); +int mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, + int status); unsigned long * mysql_fetch_lengths(MYSQL_RES *result); MYSQL_FIELD * mysql_fetch_field(MYSQL_RES *result); MYSQL_RES * mysql_list_fields(MYSQL *mysql, const char *table, const char *wild); +int mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, + const char *table, + const char *wild); +int mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); unsigned long mysql_escape_string(char *to,const char *from, unsigned long from_length); unsigned long mysql_hex_string(char *to,const char *from, @@ -488,7 +567,12 @@ 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); my_bool mysql_read_query_result(MYSQL *mysql); +int mysql_read_query_result_start(my_bool *ret, + MYSQL *mysql); +int mysql_read_query_result_cont(my_bool *ret, + MYSQL *mysql, int status); enum enum_mysql_stmt_state { MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE, @@ -559,12 +643,22 @@ enum enum_stmt_attr_type MYSQL_STMT * mysql_stmt_init(MYSQL *mysql); int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length); +int mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt, + const char *query, unsigned long length); +int mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status); int mysql_stmt_execute(MYSQL_STMT *stmt); +int mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt); +int mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status); int mysql_stmt_fetch(MYSQL_STMT *stmt); +int mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt); +int mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status); int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset); int mysql_stmt_store_result(MYSQL_STMT *stmt); +int mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt); +int mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt, + int status); unsigned long mysql_stmt_param_count(MYSQL_STMT * stmt); my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, @@ -575,12 +669,25 @@ my_bool mysql_stmt_attr_get(MYSQL_STMT *stmt, my_bool mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool mysql_stmt_close(MYSQL_STMT * stmt); +int mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); +int mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); my_bool mysql_stmt_reset(MYSQL_STMT * stmt); +int mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt); +int mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status); my_bool mysql_stmt_free_result(MYSQL_STMT *stmt); +int mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt); +int mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); my_bool mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length); +int mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, + unsigned long len); +int mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); MYSQL_RES * mysql_stmt_result_metadata(MYSQL_STMT *stmt); MYSQL_RES * mysql_stmt_param_metadata(MYSQL_STMT *stmt); unsigned int mysql_stmt_errno(MYSQL_STMT * stmt); @@ -595,9 +702,28 @@ my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT *stmt); my_ulonglong mysql_stmt_insert_id(MYSQL_STMT *stmt); unsigned int mysql_stmt_field_count(MYSQL_STMT *stmt); my_bool mysql_commit(MYSQL * mysql); +int mysql_commit_start(my_bool *ret, MYSQL * mysql); +int mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool mysql_rollback(MYSQL * mysql); +int mysql_rollback_start(my_bool *ret, MYSQL * mysql); +int mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status); my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode); +int mysql_autocommit_start(my_bool *ret, MYSQL * mysql, + my_bool auto_mode); +int mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool mysql_more_results(MYSQL *mysql); int mysql_next_result(MYSQL *mysql); +int mysql_next_result_start(int *ret, MYSQL *mysql); +int mysql_next_result_cont(int *ret, MYSQL *mysql, int status); int mysql_stmt_next_result(MYSQL_STMT *stmt); +int mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt); +int mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status); +void mysql_close_slow_part(MYSQL *mysql); void mysql_close(MYSQL *sock); +int mysql_close_start(MYSQL *sock); +int mysql_close_cont(MYSQL *sock, int status); +my_socket mysql_get_socket(const MYSQL *mysql); +unsigned int mysql_get_timeout_value(const MYSQL *mysql); +unsigned int mysql_get_timeout_value_ms(const MYSQL *mysql); +unsigned long mysql_net_read_packet(MYSQL *mysql); +unsigned long mysql_net_field_length(unsigned char **packet); diff --git a/include/mysql/auth_dialog_client.h b/include/mysql/auth_dialog_client.h new file mode 100644 index 00000000000..2c58aac9444 --- /dev/null +++ b/include/mysql/auth_dialog_client.h @@ -0,0 +1,56 @@ +#ifndef MYSQL_AUTH_DIALOG_CLIENT_INCLUDED +/* Copyright (C) 2010 Sergei Golubchik and 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 */ + +/** + @file + + Definitions needed to use Dialog client authentication plugin +*/ + +struct st_mysql; + +#define MYSQL_AUTH_DIALOG_CLIENT_INCLUDED + +/** + type of the mysql_authentication_dialog_ask function + + @param mysql mysql + @param type type of the input + 1 - ordinary string input + 2 - password string + @param prompt prompt + @param buf a buffer to store the use input + @param buf_len the length of the buffer + + @retval a pointer to the user input string. + It may be equal to 'buf' or to 'mysql->password'. + In all other cases it is assumed to be an allocated + string, and the "dialog" plugin will free() it. +*/ +typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql, + int type, const char *prompt, char *buf, int buf_len); + +/** + first byte of the question string is the question "type". + It can be an "ordinary" or a "password" question. + The last bit set marks a last question in the authentication exchange. +*/ +#define ORDINARY_QUESTION "\2" +#define LAST_QUESTION "\3" +#define PASSWORD_QUESTION "\4" +#define LAST_PASSWORD "\5" + +#endif diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h index 9be9914a49b..b2df0019dfe 100644 --- a/include/mysql/client_plugin.h +++ b/include/mysql/client_plugin.h @@ -1,5 +1,6 @@ #ifndef MYSQL_CLIENT_PLUGIN_INCLUDED -/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + Copyright (c) 2010, 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 @@ -23,6 +24,27 @@ */ #define MYSQL_CLIENT_PLUGIN_INCLUDED +/* + On Windows, exports from DLL need to be declared + Also, plugin needs to be declared as extern "C" because MSVC + unlike other compilers, uses C++ mangling for variables not only + for functions. +*/ +#undef MYSQL_PLUGIN_EXPORT +#if defined(_MSC_VER) + #ifdef __cplusplus + #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport) + #else + #define MYSQL_PLUGIN_EXPORT __declspec(dllexport) + #endif +#else /*_MSC_VER */ + #ifdef __cplusplus + #define MYSQL_PLUGIN_EXPORT extern "C" + #else + #define MYSQL_PLUGIN_EXPORT + #endif +#endif + #ifndef MYSQL_ABI_CHECK #include <stdarg.h> #include <stdlib.h> @@ -74,6 +96,8 @@ struct st_mysql_client_plugin_AUTHENTICATION int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql); }; +#include <mysql/auth_dialog_client.h> + /******** using plugins ************/ /** diff --git a/include/mysql/client_plugin.h.pp b/include/mysql/client_plugin.h.pp index 93eaff7501e..b6ba9cf08ad 100644 --- a/include/mysql/client_plugin.h.pp +++ b/include/mysql/client_plugin.h.pp @@ -3,7 +3,6 @@ struct st_mysql_client_plugin int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *); }; struct st_mysql; -#include <mysql/plugin_auth_common.h> typedef struct st_plugin_vio_info { enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET, @@ -24,6 +23,9 @@ struct st_mysql_client_plugin_AUTHENTICATION int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *); int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql); }; +struct st_mysql; +typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql, + int type, const char *prompt, char *buf, int buf_len); struct st_mysql_client_plugin * mysql_load_plugin(struct st_mysql *mysql, const char *name, int type, int argc, ...); diff --git a/include/mysql/innodb_priv.h b/include/mysql/innodb_priv.h deleted file mode 100644 index aa9cc717ea4..00000000000 --- a/include/mysql/innodb_priv.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - - 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - -#ifndef INNODB_PRIV_INCLUDED -#define INNODB_PRIV_INCLUDED - -/** @file Declaring server-internal functions that are used by InnoDB. */ - -#include <sql_priv.h> - -class THD; - -int get_quote_char_for_identifier(THD *thd, const char *name, uint length); -bool schema_table_store_record(THD *thd, TABLE *table); -void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); -bool check_global_access(THD *thd, ulong want_access); -uint strconvert(CHARSET_INFO *from_cs, const char *from, - CHARSET_INFO *to_cs, char *to, uint to_length, - uint *errors); -void sql_print_error(const char *format, ...); - - - -#endif /* INNODB_PRIV_INCLUDED */ diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index 5cbfa61f4cc..6b2dba46193 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2005, 2013, Oracle and/or its affiliates + Copyright (C) 2009, 2013, 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 @@ -23,21 +24,17 @@ 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 */ +#else /*_MSC_VER */ #ifdef __cplusplus - #define MYSQL_PLUGIN_EXPORT extern "C" + #define MYSQL_PLUGIN_EXPORT extern "C" #else - #define MYSQL_PLUGIN_EXPORT + #define MYSQL_PLUGIN_EXPORT #endif -#endif /*MYSQL_DYNAMIC_PLUGIN */ -#else /*_MSC_VER */ -#define MYSQL_PLUGIN_EXPORT #endif #ifdef __cplusplus @@ -71,8 +68,12 @@ typedef struct st_mysql_xid MYSQL_XID; Plugin API. Common for all plugin types. */ +/* MySQL plugin interface version */ #define MYSQL_PLUGIN_INTERFACE_VERSION 0x0103 +/* MariaDB plugin interface version */ +#define MARIA_PLUGIN_INTERFACE_VERSION 0x0104 + /* The allowable types of plugins */ @@ -95,6 +96,14 @@ typedef struct st_mysql_xid MYSQL_XID; #define PLUGIN_LICENSE_GPL_STRING "GPL" #define PLUGIN_LICENSE_BSD_STRING "BSD" +/* definitions of code maturity for plugins */ +#define MariaDB_PLUGIN_MATURITY_UNKNOWN 0 +#define MariaDB_PLUGIN_MATURITY_EXPERIMENTAL 1 +#define MariaDB_PLUGIN_MATURITY_ALPHA 2 +#define MariaDB_PLUGIN_MATURITY_BETA 3 +#define MariaDB_PLUGIN_MATURITY_GAMMA 4 +#define MariaDB_PLUGIN_MATURITY_STABLE 5 + /* Macros for beginning and ending plugin declarations. Between mysql_declare_plugin and mysql_declare_plugin_end there should @@ -104,14 +113,35 @@ typedef struct st_mysql_xid MYSQL_XID; #ifndef MYSQL_DYNAMIC_PLUGIN #define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \ -MYSQL_PLUGIN_EXPORT int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \ -MYSQL_PLUGIN_EXPORT int PSIZE= sizeof(struct st_mysql_plugin); \ -MYSQL_PLUGIN_EXPORT struct st_mysql_plugin DECLS[]= { +int VERSION= MYSQL_PLUGIN_INTERFACE_VERSION; \ +int PSIZE= sizeof(struct st_mysql_plugin); \ +struct st_mysql_plugin DECLS[]= { + +#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \ +MYSQL_PLUGIN_EXPORT int VERSION; \ +int VERSION= MARIA_PLUGIN_INTERFACE_VERSION; \ +MYSQL_PLUGIN_EXPORT int PSIZE; \ +int PSIZE= sizeof(struct st_maria_plugin); \ +MYSQL_PLUGIN_EXPORT struct st_maria_plugin DECLS[]; \ +struct st_maria_plugin DECLS[]= { #else + #define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \ -MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \ -MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \ -MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]= { +MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_; \ +int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \ +MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_; \ +int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \ +MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]; \ +struct st_mysql_plugin _mysql_plugin_declarations_[]= { + +#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \ +MYSQL_PLUGIN_EXPORT int _maria_plugin_interface_version_; \ +int _maria_plugin_interface_version_= MARIA_PLUGIN_INTERFACE_VERSION; \ +MYSQL_PLUGIN_EXPORT int _maria_sizeof_struct_st_plugin_; \ +int _maria_sizeof_struct_st_plugin_= sizeof(struct st_maria_plugin); \ +MYSQL_PLUGIN_EXPORT struct st_maria_plugin _maria_plugin_declarations_[]; \ +struct st_maria_plugin _maria_plugin_declarations_[]= { + #endif #define mysql_declare_plugin(NAME) \ @@ -120,19 +150,32 @@ __MYSQL_DECLARE_PLUGIN(NAME, \ builtin_ ## NAME ## _sizeof_struct_st_plugin, \ builtin_ ## NAME ## _plugin) +#define maria_declare_plugin(NAME) \ +MARIA_DECLARE_PLUGIN__(NAME, \ + builtin_maria_ ## NAME ## _plugin_interface_version, \ + builtin_maria_ ## NAME ## _sizeof_struct_st_plugin, \ + builtin_maria_ ## NAME ## _plugin) + #define mysql_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0,0}} +#define maria_declare_plugin_end ,{0,0,0,0,0,0,0,0,0,0,0,0,0}} /* declarations for SHOW STATUS support in plugins */ enum enum_mysql_show_type { - SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG, - SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, + SHOW_UNDEF, SHOW_BOOL, SHOW_UINT, SHOW_ULONG, + SHOW_ULONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, + SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_always_last }; +/* backward compatibility mapping. */ +#define SHOW_INT SHOW_UINT +#define SHOW_LONG SHOW_ULONG +#define SHOW_LONGLONG SHOW_ULONGLONG + struct st_mysql_show_var { const char *name; char *value; @@ -249,7 +292,7 @@ typedef void (*mysql_var_update_func)(MYSQL_THD thd, #define DECLARE_MYSQL_SYSVAR_BASIC(name, type) struct { \ MYSQL_PLUGIN_VAR_HEADER; \ type *value; \ - const type def_val; \ + const type def_val; \ } MYSQL_SYSVAR_NAME(name) #define DECLARE_MYSQL_SYSVAR_SIMPLE(name, type) struct { \ @@ -286,7 +329,7 @@ typedef void (*mysql_var_update_func)(MYSQL_THD thd, #define DECLARE_MYSQL_THDVAR_TYPELIB(name, type) struct { \ MYSQL_PLUGIN_VAR_HEADER; \ int offset; \ - type def_val; \ + const type def_val; \ DECLARE_THDVAR_FUNC(type); \ TYPELIB *typelib; \ } MYSQL_SYSVAR_NAME(name) @@ -437,6 +480,30 @@ struct st_mysql_plugin unsigned long flags; /* flags for plugin */ }; +/* + MariaDB extension for plugins declaration structure. + + It also copy current MySQL plugin fields to have more independency + in plugins extension +*/ + +struct st_maria_plugin +{ + int type; /* the plugin type (a MYSQL_XXX_PLUGIN value) */ + void *info; /* pointer to type-specific plugin descriptor */ + const char *name; /* plugin name */ + const char *author; /* plugin author (for SHOW PLUGINS) */ + const char *descr; /* general descriptive text (for SHOW PLUGINS ) */ + int license; /* the plugin license (PLUGIN_LICENSE_XXX) */ + int (*init)(void *); /* the function to invoke when plugin is loaded */ + int (*deinit)(void *);/* the function to invoke when plugin is unloaded */ + unsigned int version; /* plugin version (for SHOW PLUGINS) */ + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + const char *version_info; /* plugin version string */ + unsigned int maturity; /* MariaDB_PLUGIN_MATURITY_XXX */ +}; + /************************************************************************* API for Full-text parser plugin. (MYSQL_FTPARSER_PLUGIN) */ @@ -547,7 +614,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); void thd_storage_lock_wait(MYSQL_THD thd, long long value); int thd_tx_isolation(const MYSQL_THD thd); @@ -571,23 +637,6 @@ void thd_inc_row_count(MYSQL_THD thd); int mysql_tmpfile(const char *prefix); /** - Check the killed state of a connection - - @details - In MySQL support for the KILL statement is cooperative. The KILL - statement only sets a "killed" flag. This function returns the value - of that flag. A thread should check it often, especially inside - time-consuming loops, and gracefully abort the operation if it is - non-zero. - - @param thd user thread connection handle - @retval 0 the connection is active - @retval 1 the connection has been killed -*/ -int thd_killed(const MYSQL_THD thd); - - -/** Return the thread id of a user thread @param thd user thread connection handle diff --git a/include/mysql/plugin_audit.h b/include/mysql/plugin_audit.h index 40a4b5dead2..31589f071f0 100644 --- a/include/mysql/plugin_audit.h +++ b/include/mysql/plugin_audit.h @@ -25,7 +25,7 @@ #define MYSQL_AUDIT_CLASS_MASK_SIZE 1 -#define MYSQL_AUDIT_INTERFACE_VERSION 0x0301 +#define MYSQL_AUDIT_INTERFACE_VERSION 0x0302 /************************************************************************* @@ -59,10 +59,10 @@ struct mysql_event_general struct charset_info_st *general_charset; unsigned long long general_time; unsigned long long general_rows; - MYSQL_LEX_STRING general_host; - MYSQL_LEX_STRING general_sql_command; - MYSQL_LEX_STRING general_external_user; - MYSQL_LEX_STRING general_ip; + /* Added in version 0x302 */ + unsigned long long query_id; + const char *database; + unsigned int database_length; }; @@ -101,6 +101,52 @@ struct mysql_event_connection unsigned int database_length; }; +/* + AUDIT CLASS : TABLE + + LOCK occurs when a connection "locks" (this does not necessarily mean a table + lock and also happens for row-locking engines) the table at the beginning of + a statement. This event is generated at the beginning of every statement for + every affected table, unless there's a LOCK TABLES statement in effect (in + which case it is generated once for LOCK TABLES and then is suppressed until + the tables are unlocked). + + CREATE/DROP/RENAME occur when a table is created, dropped, or renamed. +*/ + +#define MYSQL_AUDIT_TABLE_CLASS 15 +#define MYSQL_AUDIT_TABLE_CLASSMASK (1 << MYSQL_AUDIT_TABLE_CLASS) +#define MYSQL_AUDIT_TABLE_LOCK 0 +#define MYSQL_AUDIT_TABLE_CREATE 1 +#define MYSQL_AUDIT_TABLE_DROP 2 +#define MYSQL_AUDIT_TABLE_RENAME 3 +#define MYSQL_AUDIT_TABLE_ALTER 4 + +struct mysql_event_table +{ + unsigned int event_subclass; + unsigned long thread_id; + const char *user; + const char *priv_user; + const char *priv_host; + const char *external_user; + const char *proxy_user; + const char *host; + const char *ip; + const char *database; + unsigned int database_length; + const char *table; + unsigned int table_length; + /* for MYSQL_AUDIT_TABLE_LOCK, true if read-only, false if read/write */ + int read_only; + /* for MYSQL_AUDIT_TABLE_RENAME */ + const char *new_database; + unsigned int new_database_length; + const char *new_table; + unsigned int new_table_length; + /* Added in version 0x302 */ + unsigned long long query_id; +}; /************************************************************************* Here we define the descriptor structure, that is referred from diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 794e2679356..74903fd74e3 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -1,13 +1,9 @@ -#include "plugin.h" -#include <mysql/services.h> -#include <mysql/service_my_snprintf.h> extern struct my_snprintf_service_st { size_t (*my_snprintf_type)(char*, size_t, const char*, ...); size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); } *my_snprintf_service; size_t my_snprintf(char* to, size_t n, const char* fmt, ...); size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); -#include <mysql/service_thd_alloc.h> struct st_mysql_lex_string { char *str; @@ -31,7 +27,6 @@ void *thd_memdup(void* thd, const void* str, unsigned int size); MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, const char *str, unsigned int size, int allocate_lex_string); -#include <mysql/service_thd_wait.h> typedef enum _thd_wait_type_e { THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, @@ -51,7 +46,6 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); -#include <mysql/service_thread_scheduler.h> struct scheduler_functions; extern struct my_thread_scheduler_service { int (*set)(struct scheduler_functions *scheduler); @@ -59,6 +53,57 @@ extern struct my_thread_scheduler_service { } *my_thread_scheduler_service; int my_thread_scheduler_set(struct scheduler_functions *scheduler); int my_thread_scheduler_reset(); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +enum thd_kill_levels { + THD_IS_NOT_KILLED=0, + THD_ABORT_SOFTLY=50, + THD_ABORT_ASAP=100, +}; +extern struct kill_statement_service_st { + enum thd_kill_levels (*thd_kill_level_func)(const void*); +} *thd_kill_statement_service; +enum thd_kill_levels thd_kill_level(const void*); +typedef struct logger_handle_st LOGGER_HANDLE; +extern struct logger_service_st { + void (*logger_init_mutexes)(); + LOGGER_HANDLE* (*open)(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int (*close)(LOGGER_HANDLE *log); + int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...); + int (*write)(LOGGER_HANDLE *log, const char *buffer, size_t size); + int (*rotate)(LOGGER_HANDLE *log); +} *logger_service; + void logger_init_mutexes(); + LOGGER_HANDLE *logger_open(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int logger_close(LOGGER_HANDLE *log); + int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); + int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); + int logger_rotate(LOGGER_HANDLE *log); struct st_mysql_xid { long formatID; long gtrid_length; @@ -68,9 +113,10 @@ struct st_mysql_xid { typedef struct st_mysql_xid MYSQL_XID; enum enum_mysql_show_type { - SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG, - SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, + SHOW_UNDEF, SHOW_BOOL, SHOW_UINT, SHOW_ULONG, + SHOW_ULONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, + SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_always_last }; struct st_mysql_show_var { @@ -103,8 +149,22 @@ struct st_mysql_plugin void * __reserved1; unsigned long flags; }; -#include "plugin_ftparser.h" -#include "plugin.h" +struct st_maria_plugin +{ + int type; + void *info; + const char *name; + const char *author; + const char *descr; + int license; + int (*init)(void *); + int (*deinit)(void *); + unsigned int version; + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + const char *version_info; + unsigned int maturity; +}; enum enum_ftparser_mode { MYSQL_FTPARSER_SIMPLE_MODE= 0, @@ -132,16 +192,16 @@ typedef struct st_mysql_ftparser_boolean_info typedef struct st_mysql_ftparser_param { int (*mysql_parse)(struct st_mysql_ftparser_param *, - char *doc, int doc_len); + const char *doc, int doc_len); int (*mysql_add_word)(struct st_mysql_ftparser_param *, - char *word, int word_len, + const char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; - struct charset_info_st *cs; - char *doc; + const struct charset_info_st *cs; + const char *doc; int length; - int flags; + unsigned int flags; enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; struct st_mysql_ftparser @@ -179,7 +239,6 @@ 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); void thd_storage_lock_wait(void* thd, long long value); int thd_tx_isolation(const void* thd); @@ -187,7 +246,6 @@ char *thd_security_context(void* thd, char *buffer, unsigned int length, unsigned int max_query_len); void thd_inc_row_count(void* thd); int mysql_tmpfile(const char *prefix); -int thd_killed(const void* thd); unsigned long thd_get_thread_id(const void* thd); void thd_get_xid(const void* thd, MYSQL_XID *xid); void mysql_query_cache_invalidate4(void* thd, @@ -210,10 +268,9 @@ struct mysql_event_general struct charset_info_st *general_charset; unsigned long long general_time; unsigned long long general_rows; - MYSQL_LEX_STRING general_host; - MYSQL_LEX_STRING general_sql_command; - MYSQL_LEX_STRING general_external_user; - MYSQL_LEX_STRING general_ip; + unsigned long long query_id; + const char *database; + unsigned int database_length; }; struct mysql_event_connection { @@ -235,6 +292,28 @@ struct mysql_event_connection const char *database; unsigned int database_length; }; +struct mysql_event_table +{ + unsigned int event_subclass; + unsigned long thread_id; + const char *user; + const char *priv_user; + const char *priv_host; + const char *external_user; + const char *proxy_user; + const char *host; + const char *ip; + const char *database; + unsigned int database_length; + const char *table; + unsigned int table_length; + int read_only; + const char *new_database; + unsigned int new_database_length; + const char *new_table; + unsigned int new_table_length; + unsigned long long query_id; +}; struct st_mysql_audit { int interface_version; diff --git a/include/mysql/plugin_auth.h b/include/mysql/plugin_auth.h index fc661de17c4..156fb386aae 100644 --- a/include/mysql/plugin_auth.h +++ b/include/mysql/plugin_auth.h @@ -1,5 +1,6 @@ #ifndef MYSQL_PLUGIN_AUTH_INCLUDED -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + 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 @@ -26,7 +27,7 @@ #include <mysql/plugin.h> -#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0100 +#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0200 #include <mysql/plugin_auth_common.h> @@ -74,10 +75,10 @@ typedef struct st_mysql_server_auth_info /** The unique user name that was used by the plugin to authenticate. - Plugins should put null-terminated UTF-8 here. + Not used by the server. Available through the @@EXTERNAL_USER variable. */ - char external_user[512]; + char external_user[MYSQL_USERNAME_LENGTH+1]; /** This only affects the "Authentication failed. Password used: %s" @@ -107,7 +108,7 @@ typedef struct st_mysql_server_auth_info */ struct st_mysql_auth { - int interface_version; /** version plugin uses */ + int interface_version; /**< version plugin uses */ /** A plugin that a client must use for authentication with this server plugin. Can be NULL to mean "any plugin". diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index 3807556fd1b..84b2434a125 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -1,13 +1,9 @@ -#include <mysql/plugin.h> -#include <mysql/services.h> -#include <mysql/service_my_snprintf.h> extern struct my_snprintf_service_st { size_t (*my_snprintf_type)(char*, size_t, const char*, ...); size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); } *my_snprintf_service; size_t my_snprintf(char* to, size_t n, const char* fmt, ...); size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); -#include <mysql/service_thd_alloc.h> struct st_mysql_lex_string { char *str; @@ -31,7 +27,6 @@ void *thd_memdup(void* thd, const void* str, unsigned int size); MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, const char *str, unsigned int size, int allocate_lex_string); -#include <mysql/service_thd_wait.h> typedef enum _thd_wait_type_e { THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, @@ -51,7 +46,6 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); -#include <mysql/service_thread_scheduler.h> struct scheduler_functions; extern struct my_thread_scheduler_service { int (*set)(struct scheduler_functions *scheduler); @@ -59,6 +53,57 @@ extern struct my_thread_scheduler_service { } *my_thread_scheduler_service; int my_thread_scheduler_set(struct scheduler_functions *scheduler); int my_thread_scheduler_reset(); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +enum thd_kill_levels { + THD_IS_NOT_KILLED=0, + THD_ABORT_SOFTLY=50, + THD_ABORT_ASAP=100, +}; +extern struct kill_statement_service_st { + enum thd_kill_levels (*thd_kill_level_func)(const void*); +} *thd_kill_statement_service; +enum thd_kill_levels thd_kill_level(const void*); +typedef struct logger_handle_st LOGGER_HANDLE; +extern struct logger_service_st { + void (*logger_init_mutexes)(); + LOGGER_HANDLE* (*open)(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int (*close)(LOGGER_HANDLE *log); + int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...); + int (*write)(LOGGER_HANDLE *log, const char *buffer, size_t size); + int (*rotate)(LOGGER_HANDLE *log); +} *logger_service; + void logger_init_mutexes(); + LOGGER_HANDLE *logger_open(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int logger_close(LOGGER_HANDLE *log); + int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); + int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); + int logger_rotate(LOGGER_HANDLE *log); struct st_mysql_xid { long formatID; long gtrid_length; @@ -68,9 +113,10 @@ struct st_mysql_xid { typedef struct st_mysql_xid MYSQL_XID; enum enum_mysql_show_type { - SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG, - SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, + SHOW_UNDEF, SHOW_BOOL, SHOW_UINT, SHOW_ULONG, + SHOW_ULONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, + SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_always_last }; struct st_mysql_show_var { @@ -103,8 +149,22 @@ struct st_mysql_plugin void * __reserved1; unsigned long flags; }; -#include "plugin_ftparser.h" -#include "plugin.h" +struct st_maria_plugin +{ + int type; + void *info; + const char *name; + const char *author; + const char *descr; + int license; + int (*init)(void *); + int (*deinit)(void *); + unsigned int version; + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + const char *version_info; + unsigned int maturity; +}; enum enum_ftparser_mode { MYSQL_FTPARSER_SIMPLE_MODE= 0, @@ -132,16 +192,16 @@ typedef struct st_mysql_ftparser_boolean_info typedef struct st_mysql_ftparser_param { int (*mysql_parse)(struct st_mysql_ftparser_param *, - char *doc, int doc_len); + const char *doc, int doc_len); int (*mysql_add_word)(struct st_mysql_ftparser_param *, - char *word, int word_len, + const char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; - struct charset_info_st *cs; - char *doc; + const struct charset_info_st *cs; + const char *doc; int length; - int flags; + unsigned int flags; enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; struct st_mysql_ftparser @@ -179,7 +239,6 @@ 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); void thd_storage_lock_wait(void* thd, long long value); int thd_tx_isolation(const void* thd); @@ -187,7 +246,6 @@ char *thd_security_context(void* thd, char *buffer, unsigned int length, unsigned int max_query_len); void thd_inc_row_count(void* thd); int mysql_tmpfile(const char *prefix); -int thd_killed(const void* thd); unsigned long thd_get_thread_id(const void* thd); void thd_get_xid(const void* thd, MYSQL_XID *xid); void mysql_query_cache_invalidate4(void* thd, @@ -196,7 +254,6 @@ void mysql_query_cache_invalidate4(void* thd, void *thd_get_ha_data(const void* thd, const struct handlerton *hton); void thd_set_ha_data(void* thd, const struct handlerton *hton, const void *ha_data); -#include <mysql/plugin_auth_common.h> typedef struct st_plugin_vio_info { enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET, @@ -218,8 +275,8 @@ typedef struct st_mysql_server_auth_info unsigned int user_name_length; const char *auth_string; unsigned long auth_string_length; - char authenticated_as[48 +1]; - char external_user[512]; + char authenticated_as[512 +1]; + char external_user[512 +1]; int password_used; const char *host_or_ip; unsigned int host_or_ip_length; diff --git a/include/mysql/plugin_auth_common.h b/include/mysql/plugin_auth_common.h index 23b2e5cbc2f..c0b61730d0d 100644 --- a/include/mysql/plugin_auth_common.h +++ b/include/mysql/plugin_auth_common.h @@ -1,5 +1,6 @@ #ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab + 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 @@ -14,6 +15,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef _WIN32 +#include <windows.h> +#endif + /** @file @@ -23,7 +28,7 @@ #define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED /** the max allowed length for a user name */ -#define MYSQL_USERNAME_LENGTH 48 +#define MYSQL_USERNAME_LENGTH 512 /** return values of the plugin authenticate_user() method. diff --git a/include/mysql/plugin_ftparser.h b/include/mysql/plugin_ftparser.h index 2d4d56378df..324fce7ae86 100644 --- a/include/mysql/plugin_ftparser.h +++ b/include/mysql/plugin_ftparser.h @@ -178,16 +178,16 @@ typedef struct st_mysql_ftparser_boolean_info typedef struct st_mysql_ftparser_param { int (*mysql_parse)(struct st_mysql_ftparser_param *, - char *doc, int doc_len); + const char *doc, int doc_len); int (*mysql_add_word)(struct st_mysql_ftparser_param *, - char *word, int word_len, + const char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; - struct charset_info_st *cs; - char *doc; + const struct charset_info_st *cs; + const char *doc; int length; - int flags; + unsigned int flags; enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index 1a9fa0c759c..8cb6348b24d 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -1,13 +1,9 @@ -#include "plugin.h" -#include <mysql/services.h> -#include <mysql/service_my_snprintf.h> extern struct my_snprintf_service_st { size_t (*my_snprintf_type)(char*, size_t, const char*, ...); size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); } *my_snprintf_service; size_t my_snprintf(char* to, size_t n, const char* fmt, ...); size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); -#include <mysql/service_thd_alloc.h> struct st_mysql_lex_string { char *str; @@ -31,7 +27,6 @@ void *thd_memdup(void* thd, const void* str, unsigned int size); MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, const char *str, unsigned int size, int allocate_lex_string); -#include <mysql/service_thd_wait.h> typedef enum _thd_wait_type_e { THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, @@ -51,7 +46,6 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); -#include <mysql/service_thread_scheduler.h> struct scheduler_functions; extern struct my_thread_scheduler_service { int (*set)(struct scheduler_functions *scheduler); @@ -59,6 +53,57 @@ extern struct my_thread_scheduler_service { } *my_thread_scheduler_service; int my_thread_scheduler_set(struct scheduler_functions *scheduler); int my_thread_scheduler_reset(); +extern struct progress_report_service_st { + void (*thd_progress_init_func)(void* thd, unsigned int max_stage); + void (*thd_progress_report_func)(void* thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(void* thd); + void (*thd_progress_end_func)(void* thd); + const char *(*set_thd_proc_info_func)(void*, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; +void thd_progress_init(void* thd, unsigned int max_stage); +void thd_progress_report(void* thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(void* thd); +void thd_progress_end(void* thd); +const char *set_thd_proc_info(void*, const char * info, const char *func, + const char *file, unsigned int line); +extern void (*debug_sync_C_callback_ptr)(void*, const char *, size_t); +enum thd_kill_levels { + THD_IS_NOT_KILLED=0, + THD_ABORT_SOFTLY=50, + THD_ABORT_ASAP=100, +}; +extern struct kill_statement_service_st { + enum thd_kill_levels (*thd_kill_level_func)(const void*); +} *thd_kill_statement_service; +enum thd_kill_levels thd_kill_level(const void*); +typedef struct logger_handle_st LOGGER_HANDLE; +extern struct logger_service_st { + void (*logger_init_mutexes)(); + LOGGER_HANDLE* (*open)(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int (*close)(LOGGER_HANDLE *log); + int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...); + int (*write)(LOGGER_HANDLE *log, const char *buffer, size_t size); + int (*rotate)(LOGGER_HANDLE *log); +} *logger_service; + void logger_init_mutexes(); + LOGGER_HANDLE *logger_open(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int logger_close(LOGGER_HANDLE *log); + int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); + int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); + int logger_rotate(LOGGER_HANDLE *log); struct st_mysql_xid { long formatID; long gtrid_length; @@ -68,9 +113,10 @@ struct st_mysql_xid { typedef struct st_mysql_xid MYSQL_XID; enum enum_mysql_show_type { - SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG, - SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, + SHOW_UNDEF, SHOW_BOOL, SHOW_UINT, SHOW_ULONG, + SHOW_ULONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, + SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_always_last }; struct st_mysql_show_var { @@ -103,7 +149,22 @@ struct st_mysql_plugin void * __reserved1; unsigned long flags; }; -#include "plugin_ftparser.h" +struct st_maria_plugin +{ + int type; + void *info; + const char *name; + const char *author; + const char *descr; + int license; + int (*init)(void *); + int (*deinit)(void *); + unsigned int version; + struct st_mysql_show_var *status_vars; + struct st_mysql_sys_var **system_vars; + const char *version_info; + unsigned int maturity; +}; struct st_mysql_daemon { int interface_version; @@ -132,7 +193,6 @@ 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); void thd_storage_lock_wait(void* thd, long long value); int thd_tx_isolation(const void* thd); @@ -140,7 +200,6 @@ char *thd_security_context(void* thd, char *buffer, unsigned int length, unsigned int max_query_len); void thd_inc_row_count(void* thd); int mysql_tmpfile(const char *prefix); -int thd_killed(const void* thd); unsigned long thd_get_thread_id(const void* thd); void thd_get_xid(const void* thd, MYSQL_XID *xid); void mysql_query_cache_invalidate4(void* thd, @@ -176,16 +235,16 @@ typedef struct st_mysql_ftparser_boolean_info typedef struct st_mysql_ftparser_param { int (*mysql_parse)(struct st_mysql_ftparser_param *, - char *doc, int doc_len); + const char *doc, int doc_len); int (*mysql_add_word)(struct st_mysql_ftparser_param *, - char *word, int word_len, + const char *word, int word_len, MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); void *ftparser_state; void *mysql_ftparam; - struct charset_info_st *cs; - char *doc; + const struct charset_info_st *cs; + const char *doc; int length; - int flags; + unsigned int flags; enum enum_ftparser_mode mode; } MYSQL_FTPARSER_PARAM; struct st_mysql_ftparser diff --git a/include/mysql/psi/mysql_file.h b/include/mysql/psi/mysql_file.h index 6fc6689c47d..aa3ed7e901d 100644 --- a/include/mysql/psi/mysql_file.h +++ b/include/mysql/psi/mysql_file.h @@ -435,17 +435,17 @@ #endif /** - @def mysql_file_delete_with_symlink(K, P1, P2) + @def mysql_file_delete_with_symlink(K, P1, P2, P3) Instrumented delete with symbolic link. @c mysql_file_delete_with_symlink is a replacement - for @c my_delete_with_symlink. + for @c my_handler_delete_with_symlink. */ #ifdef HAVE_PSI_INTERFACE - #define mysql_file_delete_with_symlink(K, P1, P2) \ - inline_mysql_file_delete_with_symlink(K, __FILE__, __LINE__, P1, P2) + #define mysql_file_delete_with_symlink(K, P1, P2, P3) \ + inline_mysql_file_delete_with_symlink(K, __FILE__, __LINE__, P1, P2, P3) #else - #define mysql_file_delete_with_symlink(K, P1, P2) \ - inline_mysql_file_delete_with_symlink(P1, P2) + #define mysql_file_delete_with_symlink(K, P1, P2, P3) \ + inline_mysql_file_delete_with_symlink(P1, P2, P3) #endif /** @@ -1319,6 +1319,7 @@ inline_mysql_file_rename( return result; } + static inline File inline_mysql_file_create_with_symlink( #ifdef HAVE_PSI_INTERFACE @@ -1353,21 +1354,25 @@ inline_mysql_file_delete_with_symlink( #ifdef HAVE_PSI_INTERFACE PSI_file_key key, const char *src_file, uint src_line, #endif - const char *name, myf flags) + const char *name, const char *ext, myf flags) { int result; + char fullname[FN_REFLEN]; #ifdef HAVE_PSI_INTERFACE struct PSI_file_locker *locker= NULL; PSI_file_locker_state state; +#endif + fn_format(fullname, name, "", ext, MY_UNPACK_FILENAME | MY_APPEND_EXT); +#ifdef HAVE_PSI_INTERFACE if (likely(PSI_server != NULL)) { locker= PSI_server->get_thread_file_name_locker(&state, key, PSI_FILE_DELETE, - name, &locker); + fullname, &locker); if (likely(locker != NULL)) PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line); } #endif - result= my_delete_with_symlink(name, flags); + result= my_handler_delete_with_symlink(fullname, flags); #ifdef HAVE_PSI_INTERFACE if (likely(locker != NULL)) PSI_server->end_file_wait(locker, (size_t) 0); @@ -1375,6 +1380,7 @@ inline_mysql_file_delete_with_symlink( return result; } + static inline int inline_mysql_file_rename_with_symlink( #ifdef HAVE_PSI_INTERFACE diff --git a/include/mysql/psi/mysql_thread.h b/include/mysql/psi/mysql_thread.h index 6292cbc2700..f421f95cfd5 100644 --- a/include/mysql/psi/mysql_thread.h +++ b/include/mysql/psi/mysql_thread.h @@ -213,6 +213,9 @@ typedef struct st_mysql_cond mysql_cond_t; #define mysql_mutex_assert_not_owner(M) \ safe_mutex_assert_not_owner(&(M)->m_mutex) +#define mysql_mutex_setflags(M, F) \ + safe_mutex_setflags(&(M)->m_mutex, (F)) + /** Wrappers for instrumented prlock objects. */ #define mysql_prlock_assert_write_owner(M) \ @@ -233,7 +236,7 @@ typedef struct st_mysql_cond mysql_cond_t; #ifdef HAVE_PSI_INTERFACE #ifdef SAFE_MUTEX #define mysql_mutex_init(K, M, A) \ - inline_mysql_mutex_init(K, M, A, __FILE__, __LINE__) + inline_mysql_mutex_init(K, M, A, #M, __FILE__, __LINE__) #else #define mysql_mutex_init(K, M, A) \ inline_mysql_mutex_init(K, M, A) @@ -241,7 +244,7 @@ typedef struct st_mysql_cond mysql_cond_t; #else #ifdef SAFE_MUTEX #define mysql_mutex_init(K, M, A) \ - inline_mysql_mutex_init(M, A, __FILE__, __LINE__) + inline_mysql_mutex_init(M, A, #M, __FILE__, __LINE__) #else #define mysql_mutex_init(K, M, A) \ inline_mysql_mutex_init(M, A) @@ -474,7 +477,7 @@ typedef struct st_mysql_cond mysql_cond_t; Instrumented cond_wait. @c mysql_cond_wait is a drop-in replacement for @c pthread_cond_wait. */ -#ifdef HAVE_PSI_INTERFACE +#if defined(HAVE_PSI_INTERFACE) || defined(SAFE_MUTEX) #define mysql_cond_wait(C, M) \ inline_mysql_cond_wait(C, M, __FILE__, __LINE__) #else @@ -488,7 +491,7 @@ typedef struct st_mysql_cond mysql_cond_t; @c mysql_cond_timedwait is a drop-in replacement for @c pthread_cond_timedwait. */ -#ifdef HAVE_PSI_INTERFACE +#if defined(HAVE_PSI_INTERFACE) || defined(SAFE_MUTEX) #define mysql_cond_timedwait(C, M, W) \ inline_mysql_cond_timedwait(C, M, W, __FILE__, __LINE__) #else @@ -555,7 +558,7 @@ static inline int inline_mysql_mutex_init( mysql_mutex_t *that, const pthread_mutexattr_t *attr #ifdef SAFE_MUTEX - , const char *src_file, uint src_line + , const char *src_name, const char *src_file, uint src_line #endif ) { @@ -566,7 +569,7 @@ static inline int inline_mysql_mutex_init( that->m_psi= NULL; #endif #ifdef SAFE_MUTEX - return safe_mutex_init(&that->m_mutex, attr, src_file, src_line); + return safe_mutex_init(&that->m_mutex, attr, src_name, src_file, src_line); #else return pthread_mutex_init(&that->m_mutex, attr); #endif @@ -960,7 +963,7 @@ static inline int inline_mysql_cond_destroy( static inline int inline_mysql_cond_wait( mysql_cond_t *that, mysql_mutex_t *mutex -#ifdef HAVE_PSI_INTERFACE +#if defined(HAVE_PSI_INTERFACE) || defined(SAFE_MUTEX) , const char *src_file, uint src_line #endif ) @@ -977,7 +980,11 @@ static inline int inline_mysql_cond_wait( PSI_server->start_cond_wait(locker, src_file, src_line); } #endif +#ifdef SAFE_MUTEX + result= safe_cond_wait(&that->m_cond, &mutex->m_mutex, src_file, src_line); +#else result= pthread_cond_wait(&that->m_cond, &mutex->m_mutex); +#endif #ifdef HAVE_PSI_INTERFACE if (likely(locker != NULL)) PSI_server->end_cond_wait(locker, result); @@ -989,7 +996,7 @@ static inline int inline_mysql_cond_timedwait( mysql_cond_t *that, mysql_mutex_t *mutex, const struct timespec *abstime -#ifdef HAVE_PSI_INTERFACE +#if defined(HAVE_PSI_INTERFACE) || defined(SAFE_MUTEX) , const char *src_file, uint src_line #endif ) @@ -1006,7 +1013,12 @@ static inline int inline_mysql_cond_timedwait( PSI_server->start_cond_wait(locker, src_file, src_line); } #endif +#ifdef SAFE_MUTEX + result= safe_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime, + src_file, src_line); +#else result= pthread_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime); +#endif #ifdef HAVE_PSI_INTERFACE if (likely(locker != NULL)) PSI_server->end_cond_wait(locker, result); diff --git a/include/mysql/psi/psi_abi_v1.h.pp b/include/mysql/psi/psi_abi_v1.h.pp index adb3010469b..9f8252473a6 100644 --- a/include/mysql/psi/psi_abi_v1.h.pp +++ b/include/mysql/psi/psi_abi_v1.h.pp @@ -1,4 +1,3 @@ -#include "mysql/psi/psi.h" C_MODE_START struct PSI_mutex; struct PSI_rwlock; diff --git a/include/mysql/psi/psi_abi_v2.h.pp b/include/mysql/psi/psi_abi_v2.h.pp index 63f8c52c50a..9da270e6f8c 100644 --- a/include/mysql/psi/psi_abi_v2.h.pp +++ b/include/mysql/psi/psi_abi_v2.h.pp @@ -1,4 +1,3 @@ -#include "mysql/psi/psi.h" C_MODE_START struct PSI_mutex; struct PSI_rwlock; diff --git a/include/mysql/service_debug_sync.h b/include/mysql/service_debug_sync.h new file mode 100644 index 00000000000..f7bab99ac97 --- /dev/null +++ b/include/mysql/service_debug_sync.h @@ -0,0 +1,354 @@ +#ifndef MYSQL_SERVICE_DEBUG_SYNC_INCLUDED +/* Copyright (c) 2009, 2010, Oracle and/or its affiliates. + Copyright (c) 2012, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +/** + @file + == Debug Sync Facility == + + The Debug Sync Facility allows placement of synchronization points in + the server code by using the DEBUG_SYNC macro: + + open_tables(...) + + DEBUG_SYNC(thd, "after_open_tables"); + + lock_tables(...) + + When activated, a sync point can + + - Emit a signal and/or + - Wait for a signal + + Nomenclature: + + - signal: A value of a global variable that persists + until overwritten by a new signal. The global + variable can also be seen as a "signal post" + or "flag mast". Then the signal is what is + attached to the "signal post" or "flag mast". + + - emit a signal: Assign the value (the signal) to the global + variable ("set a flag") and broadcast a + global condition to wake those waiting for + a signal. + + - wait for a signal: Loop over waiting for the global condition until + the global value matches the wait-for signal. + + By default, all sync points are inactive. They do nothing (except to + burn a couple of CPU cycles for checking if they are active). + + A sync point becomes active when an action is requested for it. + To do so, put a line like this in the test case file: + + SET DEBUG_SYNC= 'after_open_tables SIGNAL opened WAIT_FOR flushed'; + + This activates the sync point 'after_open_tables'. It requests it to + emit the signal 'opened' and wait for another thread to emit the signal + 'flushed' when the thread's execution runs through the sync point. + + For every sync point there can be one action per thread only. Every + thread can request multiple actions, but only one per sync point. In + other words, a thread can activate multiple sync points. + + Here is an example how to activate and use the sync points: + + --connection conn1 + SET DEBUG_SYNC= 'after_open_tables SIGNAL opened WAIT_FOR flushed'; + send INSERT INTO t1 VALUES(1); + --connection conn2 + SET DEBUG_SYNC= 'now WAIT_FOR opened'; + SET DEBUG_SYNC= 'after_abort_locks SIGNAL flushed'; + FLUSH TABLE t1; + + When conn1 runs through the INSERT statement, it hits the sync point + 'after_open_tables'. It notices that it is active and executes its + action. It emits the signal 'opened' and waits for another thread to + emit the signal 'flushed'. + + conn2 waits immediately at the special sync point 'now' for another + thread to emit the 'opened' signal. + + A signal remains in effect until it is overwritten. If conn1 signals + 'opened' before conn2 reaches 'now', conn2 will still find the 'opened' + signal. It does not wait in this case. + + When conn2 reaches 'after_abort_locks', it signals 'flushed', which lets + conn1 awake. + + Normally the activation of a sync point is cleared when it has been + executed. Sometimes it is necessary to keep the sync point active for + another execution. You can add an execute count to the action: + + SET DEBUG_SYNC= 'name SIGNAL sig EXECUTE 3'; + + This sets the signal point's activation counter to 3. Each execution + decrements the counter. After the third execution the sync point + becomes inactive. + + One of the primary goals of this facility is to eliminate sleeps from + the test suite. In most cases it should be possible to rewrite test + cases so that they do not need to sleep. (But this facility cannot + synchronize multiple processes.) However, to support test development, + and as a last resort, sync point waiting times out. There is a default + timeout, but it can be overridden: + + SET DEBUG_SYNC= 'name WAIT_FOR sig TIMEOUT 10 EXECUTE 2'; + + TIMEOUT 0 is special: If the signal is not present, the wait times out + immediately. + + When a wait timed out (even on TIMEOUT 0), a warning is generated so + that it shows up in the test result. + + You can throw an error message and kill the query when a synchronization + point is hit a certain number of times: + + SET DEBUG_SYNC= 'name HIT_LIMIT 3'; + + Or combine it with signal and/or wait: + + SET DEBUG_SYNC= 'name SIGNAL sig EXECUTE 2 HIT_LIMIT 3'; + + Here the first two hits emit the signal, the third hit returns the error + message and kills the query. + + For cases where you are not sure that an action is taken and thus + cleared in any case, you can force to clear (deactivate) a sync point: + + SET DEBUG_SYNC= 'name CLEAR'; + + If you want to clear all actions and clear the global signal, use: + + SET DEBUG_SYNC= 'RESET'; + + This is the only way to reset the global signal to an empty string. + + For testing of the facility itself you can execute a sync point just + as if it had been hit: + + SET DEBUG_SYNC= 'name TEST'; + + + === Formal Syntax === + + The string to "assign" to the DEBUG_SYNC variable can contain: + + {RESET | + <sync point name> TEST | + <sync point name> CLEAR | + <sync point name> {{SIGNAL <signal name> | + WAIT_FOR <signal name> [TIMEOUT <seconds>]} + [EXECUTE <count>] &| HIT_LIMIT <count>} + + Here '&|' means 'and/or'. This means that one of the sections + separated by '&|' must be present or both of them. + + + === Activation/Deactivation === + + The facility is an optional part of the MySQL server. + It is enabled in a debug server by default. + + ./configure --enable-debug-sync + + The Debug Sync Facility, when compiled in, is disabled by default. It + can be enabled by a mysqld command line option: + + --debug-sync-timeout[=default_wait_timeout_value_in_seconds] + + 'default_wait_timeout_value_in_seconds' is the default timeout for the + WAIT_FOR action. If set to zero, the facility stays disabled. + + The facility is enabled by default in the test suite, but can be + disabled with: + + mysql-test-run.pl ... --debug-sync-timeout=0 ... + + Likewise the default wait timeout can be set: + + mysql-test-run.pl ... --debug-sync-timeout=10 ... + + The command line option influences the readable value of the system + variable 'debug_sync'. + + * If the facility is not compiled in, the system variable does not exist. + + * If --debug-sync-timeout=0 the value of the variable reads as "OFF". + + * Otherwise the value reads as "ON - current signal: " followed by the + current signal string, which can be empty. + + The readable variable value is the same, regardless if read as global + or session value. + + Setting the 'debug-sync' system variable requires 'SUPER' privilege. + You can never read back the string that you assigned to the variable, + unless you assign the value that the variable does already have. But + that would give a parse error. A syntactically correct string is + parsed into a debug sync action and stored apart from the variable value. + + + === Implementation === + + Pseudo code for a sync point: + + #define DEBUG_SYNC(thd, sync_point_name) + if (unlikely(opt_debug_sync_timeout)) + debug_sync(thd, STRING_WITH_LEN(sync_point_name)) + + The sync point performs a binary search in a sorted array of actions + for this thread. + + The SET DEBUG_SYNC statement adds a requested action to the array or + overwrites an existing action for the same sync point. When it adds a + new action, the array is sorted again. + + + === A typical synchronization pattern === + + There are quite a few places in MySQL, where we use a synchronization + pattern like this: + + mysql_mutex_lock(&mutex); + thd->enter_cond(&condition_variable, &mutex, new_message); + #if defined(ENABLE_DEBUG_SYNC) + if (!thd->killed && !end_of_wait_condition) + DEBUG_SYNC(thd, "sync_point_name"); + #endif + while (!thd->killed && !end_of_wait_condition) + mysql_cond_wait(&condition_variable, &mutex); + thd->exit_cond(old_message); + + Here some explanations: + + thd->enter_cond() is used to register the condition variable and the + mutex in thd->mysys_var. This is done to allow the thread to be + interrupted (killed) from its sleep. Another thread can find the + condition variable to signal and mutex to use for synchronization in + this thread's THD::mysys_var. + + thd->enter_cond() requires the mutex to be acquired in advance. + + thd->exit_cond() unregisters the condition variable and mutex and + releases the mutex. + + If you want to have a Debug Sync point with the wait, please place it + behind enter_cond(). Only then you can safely decide, if the wait will + be taken. Also you will have THD::proc_info correct when the sync + point emits a signal. DEBUG_SYNC sets its own proc_info, but restores + the previous one before releasing its internal mutex. As soon as + another thread sees the signal, it does also see the proc_info from + before entering the sync point. In this case it will be "new_message", + which is associated with the wait that is to be synchronized. + + In the example above, the wait condition is repeated before the sync + point. This is done to skip the sync point, if no wait takes place. + The sync point is before the loop (not inside the loop) to have it hit + once only. It is possible that the condition variable is signaled + multiple times without the wait condition to be true. + + A bit off-topic: At some places, the loop is taken around the whole + synchronization pattern: + + while (!thd->killed && !end_of_wait_condition) + { + mysql_mutex_lock(&mutex); + thd->enter_cond(&condition_variable, &mutex, new_message); + if (!thd->killed [&& !end_of_wait_condition]) + { + [DEBUG_SYNC(thd, "sync_point_name");] + mysql_cond_wait(&condition_variable, &mutex); + } + thd->exit_cond(old_message); + } + + Note that it is important to repeat the test for thd->killed after + enter_cond(). Otherwise the killing thread may kill this thread after + it tested thd->killed in the loop condition and before it registered + the condition variable and mutex in enter_cond(). In this case, the + killing thread does not know that this thread is going to wait on a + condition variable. It would just set THD::killed. But if we would not + test it again, we would go asleep though we are killed. If the killing + thread would kill us when we are after the second test, but still + before sleeping, we hold the mutex, which is registered in mysys_var. + The killing thread would try to acquire the mutex before signaling + the condition variable. Since the mutex is only released implicitly in + mysql_cond_wait(), the signaling happens at the right place. We + have a safe synchronization. + + === Co-work with the DBUG facility === + + When running the MySQL test suite with the --debug-dbug command line + option, the Debug Sync Facility writes trace messages to the DBUG + trace. The following shell commands proved very useful in extracting + relevant information: + + egrep 'query:|debug_sync_exec:' mysql-test/var/log/mysqld.1.trace + + It shows all executed SQL statements and all actions executed by + synchronization points. + + Sometimes it is also useful to see, which synchronization points have + been run through (hit) with or without executing actions. Then add + "|debug_sync_point:" to the egrep pattern. + + === Further reading === + + For a discussion of other methods to synchronize threads see + http://forge.mysql.com/wiki/MySQL_Internals_Test_Synchronization + + For complete syntax tests, functional tests, and examples see the test + case debug_sync.test. + + See also http://forge.mysql.com/worklog/task.php?id=4259 +*/ + +#ifndef MYSQL_ABI_CHECK +#include <stdlib.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef MYSQL_DYNAMIC_PLUGIN +extern void (*debug_sync_service)(MYSQL_THD, const char *, size_t); +#else +#define debug_sync_service debug_sync_C_callback_ptr +extern void (*debug_sync_C_callback_ptr)(MYSQL_THD, const char *, size_t); +#endif + +#ifdef ENABLED_DEBUG_SYNC +#define DEBUG_SYNC(thd, name) \ + do { \ + if (debug_sync_service) \ + debug_sync_service(thd, name, sizeof(name)-1); \ + } while(0) +#else +#define DEBUG_SYNC(thd,name) do { } while(0) +#endif + +/* compatibility macro */ +#define DEBUG_SYNC_C(name) DEBUG_SYNC(NULL, name) + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_DEBUG_SYNC_INCLUDED +#endif diff --git a/include/mysql/service_kill_statement.h b/include/mysql/service_kill_statement.h new file mode 100644 index 00000000000..995b21f0a9f --- /dev/null +++ b/include/mysql/service_kill_statement.h @@ -0,0 +1,71 @@ +/* Copyright (c) 2013, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef MYSQL_SERVICE_KILL_STATEMENT_INCLUDED +#define MYSQL_SERVICE_KILL_STATEMENT_INCLUDED + +/** + @file + This service provides functions that allow plugins to support + the KILL statement. + + In MySQL support for the KILL statement is cooperative. The KILL + statement only sets a "killed" flag. This function returns the value + of that flag. A thread should check it often, especially inside + time-consuming loops, and gracefully abort the operation if it is + non-zero. + + thd_is_killed(thd) + @return 0 - no KILL statement was issued, continue normally + @return 1 - there was a KILL statement, abort the execution. + + thd_kill_level(thd) + @return thd_kill_levels_enum values +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +enum thd_kill_levels { + THD_IS_NOT_KILLED=0, + THD_ABORT_SOFTLY=50, /**< abort when possible, don't leave tables corrupted */ + THD_ABORT_ASAP=100, /**< abort asap */ +}; + +extern struct kill_statement_service_st { + enum thd_kill_levels (*thd_kill_level_func)(const MYSQL_THD); +} *thd_kill_statement_service; + +/* backward compatibility helper */ +#define thd_killed(THD) (thd_kill_level(THD) == THD_ABORT_ASAP) + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define thd_kill_level(THD) \ + thd_kill_statement_service->thd_kill_level_func(THD) + +#else + +enum thd_kill_levels thd_kill_level(const MYSQL_THD); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/mysql/service_logger.h b/include/mysql/service_logger.h new file mode 100644 index 00000000000..962ab2fbc0b --- /dev/null +++ b/include/mysql/service_logger.h @@ -0,0 +1,105 @@ +/* Copyright (C) 2012 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 */ + +#ifndef MYSQL_SERVICE_LOGGER_INCLUDED +#define MYSQL_SERVICE_LOGGER_INCLUDED + +#ifndef MYSQL_ABI_CHECK +#include <stdarg.h> +#endif + +/** + @file + logger service + + Log file with rotation implementation. + + This service implements logging with possible rotation + of the log files. Interface intentionally tries to be similar to FILE* + related functions. + + So that one can open the log with logger_open(), specifying + the limit on the logfile size and the rotations number. + + Then it's possible to write messages to the log with + logger_printf or logger_vprintf functions. + + As the size of the logfile grows over the specified limit, + it is renamed to 'logfile.1'. The former 'logfile.1' becomes + 'logfile.2', etc. The file 'logfile.rotations' is removed. + That's how the rotation works. + + The rotation can be forced with the logger_rotate() call. + + Finally the log should be closed with logger_close(). + +@notes: + Implementation checks the size of the log file before it starts new + printf into it. So the size of the file gets over the limit when it rotates. + + The access is secured with the mutex, so the log is threadsafe. +*/ + + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct logger_handle_st LOGGER_HANDLE; + +extern struct logger_service_st { + void (*logger_init_mutexes)(); + LOGGER_HANDLE* (*open)(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int (*close)(LOGGER_HANDLE *log); + int (*vprintf)(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int (*printf)(LOGGER_HANDLE *log, const char *fmt, ...); + int (*write)(LOGGER_HANDLE *log, const char *buffer, size_t size); + int (*rotate)(LOGGER_HANDLE *log); +} *logger_service; + +#if MYSQL_DYNAMIC_PLUGIN + +#define logger_init_mutexes logger_service->logger_init_mutexes +#define logger_open(path, size_limit, rotations) \ + (logger_service->open(path, size_limit, rotations)) +#define logger_close(log) (logger_service->close(log)) +#define logger_rotate(log) (logger_service->rotate(log)) +#define logger_vprintf(log, fmt, argptr) (logger_service->\ + vprintf(log, fmt, argptr)) +#define logger_printf (*logger_service->printf) +#define logger_write(log, buffer, size) \ + (logger_service->write(log, buffer, size)) +#else + + void logger_init_mutexes(); + LOGGER_HANDLE *logger_open(const char *path, + unsigned long long size_limit, + unsigned int rotations); + int logger_close(LOGGER_HANDLE *log); + int logger_vprintf(LOGGER_HANDLE *log, const char *fmt, va_list argptr); + int logger_printf(LOGGER_HANDLE *log, const char *fmt, ...); + int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size); + int logger_rotate(LOGGER_HANDLE *log); +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /*MYSQL_SERVICE_LOGGER_INCLUDED*/ + diff --git a/include/mysql/service_my_snprintf.h b/include/mysql/service_my_snprintf.h index d5783faa838..d4ce97076e6 100644 --- a/include/mysql/service_my_snprintf.h +++ b/include/mysql/service_my_snprintf.h @@ -55,7 +55,7 @@ Supported formats are 's' (null pointer is accepted, printed as "(null)"), 'b' (extension, see below), 'c', 'd', 'i', 'u', 'x', 'o', - 'X', 'p' (works as 0x%x). + 'X', 'p' (works as 0x%x), 'f', 'g'. Standard syntax for positional arguments $n is supported. diff --git a/include/mysql/service_progress_report.h b/include/mysql/service_progress_report.h new file mode 100644 index 00000000000..670b1c37630 --- /dev/null +++ b/include/mysql/service_progress_report.h @@ -0,0 +1,82 @@ +#ifndef MYSQL_SERVICE_PROGRESS_REPORT_INCLUDED +/* Copyright (C) 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/** + @file + This service allows plugins to report progress of long running operations + to the server. The progress report is visible in SHOW PROCESSLIST, + INFORMATION_SCHEMA.PROCESSLIST, and is sent to the client + if requested. + + The functions are documented at + http://kb.askmonty.org/en/progress-reporting#how-to-add-support-for-progress-reporting-to-a-storage-engine +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#define thd_proc_info(thd, msg) set_thd_proc_info(thd, msg, \ + __func__, __FILE__, __LINE__) + +extern struct progress_report_service_st { + void (*thd_progress_init_func)(MYSQL_THD thd, unsigned int max_stage); + void (*thd_progress_report_func)(MYSQL_THD thd, + unsigned long long progress, + unsigned long long max_progress); + void (*thd_progress_next_stage_func)(MYSQL_THD thd); + void (*thd_progress_end_func)(MYSQL_THD thd); + const char *(*set_thd_proc_info_func)(MYSQL_THD, const char *info, + const char *func, + const char *file, + unsigned int line); +} *progress_report_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define thd_progress_init(thd,max_stage) (progress_report_service->thd_progress_init_func((thd),(max_stage))) +#define thd_progress_report(thd, progress, max_progress) (progress_report_service->thd_progress_report_func((thd), (progress), (max_progress))) +#define thd_progress_next_stage(thd) (progress_report_service->thd_progress_next_stage_func(thd)) +#define thd_progress_end(thd) (progress_report_service->thd_progress_end_func(thd)) +#define set_thd_proc_info(thd,info,func,file,line) (progress_report_service->set_thd_proc_info_func((thd),(info),(func),(file),(line))) + +#else + +/** + Report progress for long running operations + + @param thd User thread connection handle + @param progress Where we are now + @param max_progress Progress will continue up to this +*/ +void thd_progress_init(MYSQL_THD thd, unsigned int max_stage); +void thd_progress_report(MYSQL_THD thd, + unsigned long long progress, + unsigned long long max_progress); +void thd_progress_next_stage(MYSQL_THD thd); +void thd_progress_end(MYSQL_THD thd); +const char *set_thd_proc_info(MYSQL_THD, const char * info, const char *func, + const char *file, unsigned int line); + +#endif + +#ifdef __cplusplus +} +#endif + +#define MYSQL_SERVICE_PROGRESS_REPORT_INCLUDED +#endif + diff --git a/include/mysql/services.h b/include/mysql/services.h index 84bee7cc8e9..51d3bd1f909 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -22,6 +22,10 @@ extern "C" { #include <mysql/service_thd_alloc.h> #include <mysql/service_thd_wait.h> #include <mysql/service_thread_scheduler.h> +#include <mysql/service_progress_report.h> +#include <mysql/service_debug_sync.h> +#include <mysql/service_kill_statement.h> +#include <mysql/service_logger.h> #ifdef __cplusplus } diff --git a/include/mysql_async.h b/include/mysql_async.h new file mode 100644 index 00000000000..2c84d5bc1b6 --- /dev/null +++ b/include/mysql_async.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2012 MariaDB Services and Kristian Nielsen + + 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 */ + +/* Common definitions for MariaDB non-blocking client library. */ + +#ifndef MYSQL_ASYNC_H +#define MYSQL_ASYNC_H + +extern int my_connect_async(struct mysql_async_context *b, my_socket fd, + const struct sockaddr *name, uint namelen, + uint timeout); +extern ssize_t my_recv_async(struct mysql_async_context *b, int fd, + unsigned char *buf, size_t size, uint timeout); +extern ssize_t my_send_async(struct mysql_async_context *b, int fd, + const unsigned char *buf, size_t size, + uint timeout); +extern my_bool my_poll_read_async(struct mysql_async_context *b, + uint timeout); +#ifdef HAVE_OPENSSL +extern int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, + void *buf, int size); +extern int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, + const void *buf, int size); +#endif + +#endif /* MYSQL_ASYNC_H */ diff --git a/include/mysql_com.h b/include/mysql_com.h index 5cd40915743..df9681e02a4 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. + Copyright (c) 2010, 2013, 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 @@ -23,15 +24,42 @@ #define HOSTNAME_LENGTH 60 #define SYSTEM_CHARSET_MBMAXLEN 3 #define NAME_CHAR_LEN 64 /* Field/table name length */ -#define USERNAME_CHAR_LENGTH 16 +#define USERNAME_CHAR_LENGTH 128 #define NAME_LEN (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN) #define USERNAME_LENGTH (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN) -#define CONNECT_STRING_MAXLEN 1024 +#define DEFINER_CHAR_LENGTH (USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 1) +#define DEFINER_LENGTH (USERNAME_LENGTH + HOSTNAME_LENGTH + 1) #define MYSQL_AUTODETECT_CHARSET_NAME "auto" +#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#" +#define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1) +#define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH) + +/* + MDEV-4088 + + MySQL (and MariaDB 5.x before the fix) was using the first character of the + server version string (as sent in the first handshake protocol packet) to + decide on the replication event formats. And for 10.x the first character + is "1", which the slave thought comes from some ancient 1.x version + (ignoring the fact that the first ever MySQL version was 3.x). + + To support replication to these old clients, we fake the version in the + first handshake protocol packet to start from "5.5.5-" (for example, + it might be "5.5.5-10.0.1-MariaDB-debug-log". + + On the client side we remove this fake version prefix to restore the + correct server version. The version "5.5.5" did not support + pluggable authentication, so any version starting from "5.5.5-" and + claiming to support pluggable auth, must be using this fake prefix. +*/ +/* this version must be the one that *does not* support pluggable auth */ +#define RPL_VERSION_HACK "5.5.5-" + #define SERVER_VERSION_LENGTH 60 #define SQLSTATE_LENGTH 5 +#define LIST_PROCESS_HOST_LEN 64 /* Maximum length of comments @@ -78,7 +106,8 @@ enum enum_server_command COM_END }; - +/* sql type stored in .frm files for virtual fields */ +#define MYSQL_TYPE_VIRTUAL 245 /* Length of random string sent by server on handshake; this is also length of obfuscated password, recieved from client @@ -120,32 +149,39 @@ enum enum_server_command #define FIELD_FLAGS_COLUMN_FORMAT 24 /* Field column format, bit 24-25, reserved by MySQL Cluster */ -#define REFRESH_GRANT 1 /* Refresh grant tables */ -#define REFRESH_LOG 2 /* Start on new log file */ -#define REFRESH_TABLES 4 /* close all tables */ -#define REFRESH_HOSTS 8 /* Flush host cache */ -#define REFRESH_STATUS 16 /* Flush status variables */ -#define REFRESH_THREADS 32 /* Flush thread cache */ -#define REFRESH_SLAVE 64 /* Reset master info and restart slave - thread */ -#define REFRESH_MASTER 128 /* Remove all bin logs in the index - and truncate the index */ -#define REFRESH_ERROR_LOG 256 /* Rotate only the erorr log */ -#define REFRESH_ENGINE_LOG 512 /* Flush all storage engine logs */ -#define REFRESH_BINARY_LOG 1024 /* Flush the binary log */ -#define REFRESH_RELAY_LOG 2048 /* Flush the relay log */ -#define REFRESH_GENERAL_LOG 4096 /* Flush the general log */ -#define REFRESH_SLOW_LOG 8192 /* Flush the slow query log */ +#define REFRESH_GRANT (1UL << 0) /* Refresh grant tables */ +#define REFRESH_LOG (1UL << 1) /* Start on new log file */ +#define REFRESH_TABLES (1UL << 2) /* close all tables */ +#define REFRESH_HOSTS (1UL << 3) /* Flush host cache */ +#define REFRESH_STATUS (1UL << 4) /* Flush status variables */ +#define REFRESH_THREADS (1UL << 5) /* Flush thread cache */ +#define REFRESH_SLAVE (1UL << 6) /* Reset master info and restart slave + thread */ +#define REFRESH_MASTER (1UL << 7) /* Remove all bin logs in the index + and truncate the index */ /* The following can't be set with mysql_refresh() */ -#define REFRESH_READ_LOCK 16384 /* Lock tables for read */ -#define REFRESH_FAST 32768 /* Intern flag */ +#define REFRESH_ERROR_LOG (1UL << 8) /* Rotate only the erorr log */ +#define REFRESH_ENGINE_LOG (1UL << 9) /* Flush all storage engine logs */ +#define REFRESH_BINARY_LOG (1UL << 10) /* Flush the binary log */ +#define REFRESH_RELAY_LOG (1UL << 11) /* Flush the relay log */ +#define REFRESH_GENERAL_LOG (1UL << 12) /* Flush the general log */ +#define REFRESH_SLOW_LOG (1UL << 13) /* Flush the slow query log */ + +#define REFRESH_READ_LOCK (1UL << 14) /* Lock tables for read */ +#define REFRESH_CHECKPOINT (1UL << 15) /* With REFRESH_READ_LOCK: block checkpoints too */ -/* RESET (remove all queries) from query cache */ -#define REFRESH_QUERY_CACHE 65536 -#define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */ -#define REFRESH_DES_KEY_FILE 0x40000L -#define REFRESH_USER_RESOURCES 0x80000L +#define REFRESH_QUERY_CACHE (1UL << 16) /* clear the query cache */ +#define REFRESH_QUERY_CACHE_FREE (1UL << 17) /* pack query cache */ +#define REFRESH_DES_KEY_FILE (1UL << 18) +#define REFRESH_USER_RESOURCES (1UL << 19) + +#define REFRESH_TABLE_STATS (1UL << 20) /* Refresh table stats hash table */ +#define REFRESH_INDEX_STATS (1UL << 21) /* Refresh index stats hash table */ +#define REFRESH_USER_STATS (1UL << 22) /* Refresh user stats hash table */ +#define REFRESH_CLIENT_STATS (1UL << 23) /* Refresh client stats hash table */ + +#define REFRESH_FAST (1UL << 31) /* Intern flag */ #define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ @@ -168,8 +204,18 @@ enum enum_server_command #define CLIENT_PS_MULTI_RESULTS (1UL << 18) /* Multi-results in PS-protocol */ #define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */ +#define CLIENT_PROGRESS (1UL << 29) /* Client support progress indicator */ #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) +/* + It used to be that if mysql_real_connect() failed, it would delete any + options set by the client, unless the CLIENT_REMEMBER_OPTIONS flag was + given. + That behaviour does not appear very useful, and it seems unlikely that + any applications would actually depend on this. So from MariaDB 5.5 we + always preserve any options set in case of failed connect, and this + option is effectively always set. +*/ #define CLIENT_REMEMBER_OPTIONS (1UL << 31) #ifdef HAVE_COMPRESS @@ -200,6 +246,7 @@ enum enum_server_command CLIENT_PS_MULTI_RESULTS | \ CLIENT_SSL_VERIFY_SERVER_CERT | \ CLIENT_REMEMBER_OPTIONS | \ + CLIENT_PROGRESS | \ CLIENT_PLUGIN_AUTH) /* @@ -249,6 +296,8 @@ enum enum_server_command */ #define SERVER_PS_OUT_PARAMS 4096 +#define SERVER_STATUS_ANSI_QUOTES 32768 + /** Server status flags that must be cleared when starting execution of a new SQL statement. @@ -303,8 +352,8 @@ typedef struct st_net { unsigned int *return_status; unsigned char reading_or_writing; char save_char; - my_bool unused1; /* Please remove with the next incompatible ABI change. */ - my_bool unused2; /* Please remove with the next incompatible ABI change */ + char net_skip_rest_factor; + my_bool unused1; /* Please remove with the next incompatible ABI change */ my_bool compress; my_bool unused3; /* Please remove with the next incompatible ABI change. */ /* @@ -325,16 +374,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; @@ -418,14 +457,14 @@ enum mysql_enum_shutdown_level { /* flush InnoDB buffers and other storage engines' buffers*/ SHUTDOWN_WAIT_ALL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1), /* don't flush InnoDB buffers, flush other storage engines' buffers*/ - SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1, - /* Now the 2 levels of the KILL command */ -#if MYSQL_VERSION_ID >= 50000 - KILL_QUERY= 254, -#endif - KILL_CONNECTION= 255 + SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1 }; +/* Compatibility */ +#if !defined(MYSQL_SERVER) && defined(USE_OLD_FUNCTIONS) +#define KILL_QUERY SHUTDOWN_KILL_QUERY +#define KILL_CONNECTION SHUTDOWN_KILL_CONNECTION +#endif enum enum_cursor_type { @@ -470,11 +509,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 } @@ -482,8 +517,11 @@ 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, + TIME_RESULT,IMPOSSIBLE_RESULT +}; typedef struct st_udf_args { @@ -528,10 +566,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); @@ -552,6 +588,7 @@ char *octet2hex(char *to, const char *str, unsigned int len); /* end of password.c */ char *get_tty_password(const char *opt_message); +void get_tty_password_buff(const char *opt_message, char *to, size_t length); const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); /* Some other useful functions */ diff --git a/include/mysql_embed.h b/include/mysql_embed.h index b96083d07db..12b18ff965e 100644 --- a/include/mysql_embed.h +++ b/include/mysql_embed.h @@ -1,7 +1,8 @@ #ifndef MYSQL_EMBED_INCLUDED #define MYSQL_EMBED_INCLUDED -/* 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/mysql_version.h.in b/include/mysql_version.h.in index 21ad15626cf..cceb4e984c7 100644 --- a/include/mysql_version.h.in +++ b/include/mysql_version.h.in @@ -11,8 +11,9 @@ #include <custom_conf.h> #else #define PROTOCOL_VERSION @PROTOCOL_VERSION@ -#define MYSQL_SERVER_VERSION "@VERSION@" +#define MYSQL_SERVER_VERSION "@VERSION@-MariaDB" #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/mysqld_default_groups.h b/include/mysqld_default_groups.h new file mode 100644 index 00000000000..a2e94ddd854 --- /dev/null +++ b/include/mysqld_default_groups.h @@ -0,0 +1,8 @@ +const char *load_default_groups[]= { +#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE +"mysql_cluster", +#endif +"mysqld", "server", MYSQL_BASE_VERSION, +"mariadb", MARIADB_BASE_VERSION, +"client-server", +0, 0}; diff --git a/include/mysys_err.h b/include/mysys_err.h index 35c7890a582..f173ccd7a83 100644 --- a/include/mysys_err.h +++ b/include/mysys_err.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. 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 @@ -66,7 +67,10 @@ extern const char *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 */ @@ -85,9 +89,7 @@ extern const char *globerrs[]; /* my_error_messages is here */ #define EXIT_OPTION_DISABLED 12 #define EXIT_ARGUMENT_INVALID 13 - #ifdef __cplusplus } #endif #endif - diff --git a/include/probes_mysql.h b/include/probes_mysql.h index 191860d0b94..6d44b972cb3 100644 --- a/include/probes_mysql.h +++ b/include/probes_mysql.h @@ -18,12 +18,9 @@ #define PROBES_MYSQL_H -#include <my_global.h> - #if defined(HAVE_DTRACE) && !defined(DISABLE_DTRACE) #include "probes_mysql_dtrace.h" -#else +#else /* no dtrace */ #include "probes_mysql_nodtrace.h" #endif - #endif /* PROBES_MYSQL_H */ diff --git a/include/probes_mysql_nodtrace.h b/include/probes_mysql_nodtrace.h deleted file mode 100644 index bc3b65a00e5..00000000000 --- a/include/probes_mysql_nodtrace.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Generated by dheadgen(1). - */ - -#ifndef _PROBES_MYSQL_D -#define _PROBES_MYSQL_D - -#ifdef __cplusplus -extern "C" { -#endif - -#define MYSQL_CONNECTION_START(arg0, arg1, arg2) -#define MYSQL_CONNECTION_START_ENABLED() (0) -#define MYSQL_CONNECTION_DONE(arg0, arg1) -#define MYSQL_CONNECTION_DONE_ENABLED() (0) -#define MYSQL_COMMAND_START(arg0, arg1, arg2, arg3) -#define MYSQL_COMMAND_START_ENABLED() (0) -#define MYSQL_COMMAND_DONE(arg0) -#define MYSQL_COMMAND_DONE_ENABLED() (0) -#define MYSQL_QUERY_START(arg0, arg1, arg2, arg3, arg4) -#define MYSQL_QUERY_START_ENABLED() (0) -#define MYSQL_QUERY_DONE(arg0) -#define MYSQL_QUERY_DONE_ENABLED() (0) -#define MYSQL_QUERY_PARSE_START(arg0) -#define MYSQL_QUERY_PARSE_START_ENABLED() (0) -#define MYSQL_QUERY_PARSE_DONE(arg0) -#define MYSQL_QUERY_PARSE_DONE_ENABLED() (0) -#define MYSQL_QUERY_CACHE_HIT(arg0, arg1) -#define MYSQL_QUERY_CACHE_HIT_ENABLED() (0) -#define MYSQL_QUERY_CACHE_MISS(arg0) -#define MYSQL_QUERY_CACHE_MISS_ENABLED() (0) -#define MYSQL_QUERY_EXEC_START(arg0, arg1, arg2, arg3, arg4, arg5) -#define MYSQL_QUERY_EXEC_START_ENABLED() (0) -#define MYSQL_QUERY_EXEC_DONE(arg0) -#define MYSQL_QUERY_EXEC_DONE_ENABLED() (0) -#define MYSQL_INSERT_ROW_START(arg0, arg1) -#define MYSQL_INSERT_ROW_START_ENABLED() (0) -#define MYSQL_INSERT_ROW_DONE(arg0) -#define MYSQL_INSERT_ROW_DONE_ENABLED() (0) -#define MYSQL_UPDATE_ROW_START(arg0, arg1) -#define MYSQL_UPDATE_ROW_START_ENABLED() (0) -#define MYSQL_UPDATE_ROW_DONE(arg0) -#define MYSQL_UPDATE_ROW_DONE_ENABLED() (0) -#define MYSQL_DELETE_ROW_START(arg0, arg1) -#define MYSQL_DELETE_ROW_START_ENABLED() (0) -#define MYSQL_DELETE_ROW_DONE(arg0) -#define MYSQL_DELETE_ROW_DONE_ENABLED() (0) -#define MYSQL_READ_ROW_START(arg0, arg1, arg2) -#define MYSQL_READ_ROW_START_ENABLED() (0) -#define MYSQL_READ_ROW_DONE(arg0) -#define MYSQL_READ_ROW_DONE_ENABLED() (0) -#define MYSQL_INDEX_READ_ROW_START(arg0, arg1) -#define MYSQL_INDEX_READ_ROW_START_ENABLED() (0) -#define MYSQL_INDEX_READ_ROW_DONE(arg0) -#define MYSQL_INDEX_READ_ROW_DONE_ENABLED() (0) -#define MYSQL_HANDLER_RDLOCK_START(arg0, arg1) -#define MYSQL_HANDLER_RDLOCK_START_ENABLED() (0) -#define MYSQL_HANDLER_WRLOCK_START(arg0, arg1) -#define MYSQL_HANDLER_WRLOCK_START_ENABLED() (0) -#define MYSQL_HANDLER_UNLOCK_START(arg0, arg1) -#define MYSQL_HANDLER_UNLOCK_START_ENABLED() (0) -#define MYSQL_HANDLER_RDLOCK_DONE(arg0) -#define MYSQL_HANDLER_RDLOCK_DONE_ENABLED() (0) -#define MYSQL_HANDLER_WRLOCK_DONE(arg0) -#define MYSQL_HANDLER_WRLOCK_DONE_ENABLED() (0) -#define MYSQL_HANDLER_UNLOCK_DONE(arg0) -#define MYSQL_HANDLER_UNLOCK_DONE_ENABLED() (0) -#define MYSQL_FILESORT_START(arg0, arg1) -#define MYSQL_FILESORT_START_ENABLED() (0) -#define MYSQL_FILESORT_DONE(arg0, arg1) -#define MYSQL_FILESORT_DONE_ENABLED() (0) -#define MYSQL_SELECT_START(arg0) -#define MYSQL_SELECT_START_ENABLED() (0) -#define MYSQL_SELECT_DONE(arg0, arg1) -#define MYSQL_SELECT_DONE_ENABLED() (0) -#define MYSQL_INSERT_START(arg0) -#define MYSQL_INSERT_START_ENABLED() (0) -#define MYSQL_INSERT_DONE(arg0, arg1) -#define MYSQL_INSERT_DONE_ENABLED() (0) -#define MYSQL_INSERT_SELECT_START(arg0) -#define MYSQL_INSERT_SELECT_START_ENABLED() (0) -#define MYSQL_INSERT_SELECT_DONE(arg0, arg1) -#define MYSQL_INSERT_SELECT_DONE_ENABLED() (0) -#define MYSQL_UPDATE_START(arg0) -#define MYSQL_UPDATE_START_ENABLED() (0) -#define MYSQL_UPDATE_DONE(arg0, arg1, arg2) -#define MYSQL_UPDATE_DONE_ENABLED() (0) -#define MYSQL_MULTI_UPDATE_START(arg0) -#define MYSQL_MULTI_UPDATE_START_ENABLED() (0) -#define MYSQL_MULTI_UPDATE_DONE(arg0, arg1, arg2) -#define MYSQL_MULTI_UPDATE_DONE_ENABLED() (0) -#define MYSQL_DELETE_START(arg0) -#define MYSQL_DELETE_START_ENABLED() (0) -#define MYSQL_DELETE_DONE(arg0, arg1) -#define MYSQL_DELETE_DONE_ENABLED() (0) -#define MYSQL_MULTI_DELETE_START(arg0) -#define MYSQL_MULTI_DELETE_START_ENABLED() (0) -#define MYSQL_MULTI_DELETE_DONE(arg0, arg1) -#define MYSQL_MULTI_DELETE_DONE_ENABLED() (0) -#define MYSQL_NET_READ_START() -#define MYSQL_NET_READ_START_ENABLED() (0) -#define MYSQL_NET_READ_DONE(arg0, arg1) -#define MYSQL_NET_READ_DONE_ENABLED() (0) -#define MYSQL_NET_WRITE_START(arg0) -#define MYSQL_NET_WRITE_START_ENABLED() (0) -#define MYSQL_NET_WRITE_DONE(arg0) -#define MYSQL_NET_WRITE_DONE_ENABLED() (0) -#define MYSQL_KEYCACHE_READ_START(arg0, arg1, arg2, arg3) -#define MYSQL_KEYCACHE_READ_START_ENABLED() (0) -#define MYSQL_KEYCACHE_READ_BLOCK(arg0) -#define MYSQL_KEYCACHE_READ_BLOCK_ENABLED() (0) -#define MYSQL_KEYCACHE_READ_HIT() -#define MYSQL_KEYCACHE_READ_HIT_ENABLED() (0) -#define MYSQL_KEYCACHE_READ_MISS() -#define MYSQL_KEYCACHE_READ_MISS_ENABLED() (0) -#define MYSQL_KEYCACHE_READ_DONE(arg0, arg1) -#define MYSQL_KEYCACHE_READ_DONE_ENABLED() (0) -#define MYSQL_KEYCACHE_WRITE_START(arg0, arg1, arg2, arg3) -#define MYSQL_KEYCACHE_WRITE_START_ENABLED() (0) -#define MYSQL_KEYCACHE_WRITE_BLOCK(arg0) -#define MYSQL_KEYCACHE_WRITE_BLOCK_ENABLED() (0) -#define MYSQL_KEYCACHE_WRITE_DONE(arg0, arg1) -#define MYSQL_KEYCACHE_WRITE_DONE_ENABLED() (0) - -#ifdef __cplusplus -} -#endif - -#endif /* _PROBES_MYSQL_D */ diff --git a/include/probes_mysql_nodtrace.h.in b/include/probes_mysql_nodtrace.h.in new file mode 100644 index 00000000000..a84bf7726c3 --- /dev/null +++ b/include/probes_mysql_nodtrace.h.in @@ -0,0 +1,132 @@ +/* + * Generated by dheadgen(1). + */ + +#ifndef _PROBES_MYSQL_D +#define _PROBES_MYSQL_D + +#ifdef __cplusplus +#define MYSQL_PROBES_FALSE false +extern "C" { +#else +#define MYSQL_PROBES_FALSE 0 +#endif + +#define MYSQL_CONNECTION_START(arg0, arg1, arg2) +#define MYSQL_CONNECTION_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_CONNECTION_DONE(arg0, arg1) +#define MYSQL_CONNECTION_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_COMMAND_START(arg0, arg1, arg2, arg3) +#define MYSQL_COMMAND_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_COMMAND_DONE(arg0) +#define MYSQL_COMMAND_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_START(arg0, arg1, arg2, arg3, arg4) +#define MYSQL_QUERY_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_DONE(arg0) +#define MYSQL_QUERY_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_PARSE_START(arg0) +#define MYSQL_QUERY_PARSE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_PARSE_DONE(arg0) +#define MYSQL_QUERY_PARSE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_CACHE_HIT(arg0, arg1) +#define MYSQL_QUERY_CACHE_HIT_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_CACHE_MISS(arg0) +#define MYSQL_QUERY_CACHE_MISS_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_EXEC_START(arg0, arg1, arg2, arg3, arg4, arg5) +#define MYSQL_QUERY_EXEC_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_QUERY_EXEC_DONE(arg0) +#define MYSQL_QUERY_EXEC_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_ROW_START(arg0, arg1) +#define MYSQL_INSERT_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_ROW_DONE(arg0) +#define MYSQL_INSERT_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_ROW_START(arg0, arg1) +#define MYSQL_UPDATE_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_ROW_DONE(arg0) +#define MYSQL_UPDATE_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_ROW_START(arg0, arg1) +#define MYSQL_DELETE_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_ROW_DONE(arg0) +#define MYSQL_DELETE_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_READ_ROW_START(arg0, arg1, arg2) +#define MYSQL_READ_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_READ_ROW_DONE(arg0) +#define MYSQL_READ_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INDEX_READ_ROW_START(arg0, arg1) +#define MYSQL_INDEX_READ_ROW_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INDEX_READ_ROW_DONE(arg0) +#define MYSQL_INDEX_READ_ROW_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_RDLOCK_START(arg0, arg1) +#define MYSQL_HANDLER_RDLOCK_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_WRLOCK_START(arg0, arg1) +#define MYSQL_HANDLER_WRLOCK_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_UNLOCK_START(arg0, arg1) +#define MYSQL_HANDLER_UNLOCK_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_RDLOCK_DONE(arg0) +#define MYSQL_HANDLER_RDLOCK_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_WRLOCK_DONE(arg0) +#define MYSQL_HANDLER_WRLOCK_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_HANDLER_UNLOCK_DONE(arg0) +#define MYSQL_HANDLER_UNLOCK_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_FILESORT_START(arg0, arg1) +#define MYSQL_FILESORT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_FILESORT_DONE(arg0, arg1) +#define MYSQL_FILESORT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_SELECT_START(arg0) +#define MYSQL_SELECT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_SELECT_DONE(arg0, arg1) +#define MYSQL_SELECT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_START(arg0) +#define MYSQL_INSERT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_DONE(arg0, arg1) +#define MYSQL_INSERT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_SELECT_START(arg0) +#define MYSQL_INSERT_SELECT_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_INSERT_SELECT_DONE(arg0, arg1) +#define MYSQL_INSERT_SELECT_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_START(arg0) +#define MYSQL_UPDATE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_UPDATE_DONE(arg0, arg1, arg2) +#define MYSQL_UPDATE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_UPDATE_START(arg0) +#define MYSQL_MULTI_UPDATE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_UPDATE_DONE(arg0, arg1, arg2) +#define MYSQL_MULTI_UPDATE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_START(arg0) +#define MYSQL_DELETE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_DELETE_DONE(arg0, arg1) +#define MYSQL_DELETE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_DELETE_START(arg0) +#define MYSQL_MULTI_DELETE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_MULTI_DELETE_DONE(arg0, arg1) +#define MYSQL_MULTI_DELETE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_READ_START() +#define MYSQL_NET_READ_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_READ_DONE(arg0, arg1) +#define MYSQL_NET_READ_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_WRITE_START(arg0) +#define MYSQL_NET_WRITE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_NET_WRITE_DONE(arg0) +#define MYSQL_NET_WRITE_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_START(arg0, arg1, arg2, arg3) +#define MYSQL_KEYCACHE_READ_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_BLOCK(arg0) +#define MYSQL_KEYCACHE_READ_BLOCK_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_HIT() +#define MYSQL_KEYCACHE_READ_HIT_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_MISS() +#define MYSQL_KEYCACHE_READ_MISS_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_READ_DONE(arg0, arg1) +#define MYSQL_KEYCACHE_READ_DONE_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_WRITE_START(arg0, arg1, arg2, arg3) +#define MYSQL_KEYCACHE_WRITE_START_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_WRITE_BLOCK(arg0) +#define MYSQL_KEYCACHE_WRITE_BLOCK_ENABLED() (MYSQL_PROBES_FALSE) +#define MYSQL_KEYCACHE_WRITE_DONE(arg0, arg1) +#define MYSQL_KEYCACHE_WRITE_DONE_ENABLED() (MYSQL_PROBES_FALSE) + +#ifdef __cplusplus +} +#endif + +#endif /* _PROBES_MYSQL_D */ diff --git a/include/queues.h b/include/queues.h index 3ece9c2201c..4fef72b149c 100644 --- a/include/queues.h +++ b/include/queues.h @@ -1,23 +1,31 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (C) 2010 Monty Program Ab + All Rights reserved - 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. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the following disclaimer + in the documentation and/or other materials provided with the + distribution. - 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. +*/ /* Code for generell handling of priority Queues. Implemention of queues from "Algoritms in C" by Robert Sedgewick. - Copyright Monty Program KB. - By monty. */ #ifndef _queues_h @@ -34,38 +42,43 @@ typedef struct st_queue { void *first_cmp_arg; uint elements; uint max_elements; - uint offset_to_key; /* compare is done on element+offset */ + uint offset_to_key; /* compare is done on element+offset */ + uint offset_to_queue_pos; /* If we want to store position in element */ + uint auto_extent; int max_at_top; /* Normally 1, set to -1 if queue_top gives max */ int (*compare)(void *, uchar *,uchar *); - uint auto_extent; } QUEUE; +#define queue_first_element(queue) 1 +#define queue_last_element(queue) (queue)->elements #define queue_top(queue) ((queue)->root[1]) -#define queue_element(queue,index) ((queue)->root[index+1]) +#define queue_element(queue,index) ((queue)->root[index]) #define queue_end(queue) ((queue)->root[(queue)->elements]) -#define queue_replaced(queue) _downheap(queue,1) +#define queue_replace_top(queue) _downheap(queue, 1, (queue)->root[1]) #define queue_set_cmp_arg(queue, set_arg) (queue)->first_cmp_arg= set_arg #define queue_set_max_at_top(queue, set_arg) \ (queue)->max_at_top= set_arg ? -1 : 1 +#define queue_remove_top(queue_arg) queue_remove((queue_arg), queue_first_element(queue_arg)) typedef int (*queue_compare)(void *,uchar *, uchar *); int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key, pbool max_at_top, queue_compare compare, - void *first_cmp_arg); -int init_queue_ex(QUEUE *queue,uint max_elements,uint offset_to_key, - pbool max_at_top, queue_compare compare, - void *first_cmp_arg, uint auto_extent); + void *first_cmp_arg, uint offset_to_queue_pos, + uint auto_extent); int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key, pbool max_at_top, queue_compare compare, - void *first_cmp_arg); + void *first_cmp_arg, uint offset_to_queue_pos, + uint auto_extent); int resize_queue(QUEUE *queue, uint max_elements); void delete_queue(QUEUE *queue); void queue_insert(QUEUE *queue,uchar *element); int queue_insert_safe(QUEUE *queue, uchar *element); uchar *queue_remove(QUEUE *queue,uint idx); +void queue_replace(QUEUE *queue,uint idx); + #define queue_remove_all(queue) { (queue)->elements= 0; } #define queue_is_full(queue) (queue->elements == queue->max_elements) -void _downheap(QUEUE *queue,uint idx); +void _downheap(QUEUE *queue, uint idx, uchar *element); void queue_fix(QUEUE *queue); #define is_queue_inited(queue) ((queue)->root != 0) diff --git a/include/service_versions.h b/include/service_versions.h index a014a26abcd..21dc9c8f21d 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -19,7 +19,12 @@ #define SERVICE_VERSION void * #endif -#define VERSION_my_snprintf 0x0100 -#define VERSION_thd_alloc 0x0100 -#define VERSION_thd_wait 0x0100 -#define VERSION_my_thread_scheduler 0x0100 +#define VERSION_my_snprintf 0x0100 +#define VERSION_thd_alloc 0x0100 +#define VERSION_thd_wait 0x0100 +#define VERSION_my_thread_scheduler 0x0100 +#define VERSION_progress_report 0x0100 +#define VERSION_debug_sync 0x1000 +#define VERSION_kill_statement 0x1000 +#define VERSION_logger 0x0100 + diff --git a/include/sql_common.h b/include/sql_common.h index 05bbb5a4f53..a1c9faac82d 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -1,23 +1,21 @@ #ifndef SQL_COMMON_INCLUDED #define SQL_COMMON_INCLUDED +/* Copyright (c) 2003, 2012, Oracle and/or its affiliates. + Copyright (c) 2010, 2012, Monty Program Ab -/* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. - 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#define SQL_COMMON_INCLUDED - #ifdef __cplusplus extern "C" { #endif @@ -28,11 +26,19 @@ extern const char *unknown_sqlstate; extern const char *cant_connect_sqlstate; extern const char *not_error_sqlstate; + +struct mysql_async_context; + struct st_mysql_options_extention { char *plugin_dir; char *default_auth; - my_bool enable_cleartext_plugin; - unsigned int ssl_mode; + void (*report_progress)(const MYSQL *mysql, + unsigned int stage, + unsigned int max_stage, + double progress, + const char *proc_info, + uint proc_info_length); + struct mysql_async_context *async_context; }; typedef struct st_mysql_methods @@ -49,7 +55,7 @@ typedef struct st_mysql_methods MYSQL_DATA *(*read_rows)(MYSQL *mysql,MYSQL_FIELD *mysql_fields, unsigned int fields); MYSQL_RES * (*use_result)(MYSQL *mysql); - void (*fetch_lengths)(unsigned long *to, + void (*fetch_lengths)(unsigned long *to, MYSQL_ROW column, unsigned int field_count); void (*flush_use_result)(MYSQL *mysql, my_bool flush_all_results); int (*read_change_user_result)(MYSQL *mysql); @@ -106,7 +112,10 @@ int mysql_client_plugin_init(); void mysql_client_plugin_deinit(); struct st_mysql_client_plugin; extern struct st_mysql_client_plugin *mysql_client_builtins[]; -extern my_bool libmysql_cleartext_plugin_enabled; + +/* Non-blocking client API. */ +void my_context_install_suspend_resume_hook(struct mysql_async_context *b, + void (*)(my_bool, void *), void *); #ifdef __cplusplus } diff --git a/include/sslopt-case.h b/include/sslopt-case.h index 0fddafc4fa9..2da5ff317e1 100644 --- a/include/sslopt-case.h +++ b/include/sslopt-case.h @@ -1,7 +1,7 @@ #ifndef SSLOPT_CASE_INCLUDED #define SSLOPT_CASE_INCLUDED -/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -28,18 +28,5 @@ */ opt_use_ssl= 1; break; -#ifdef MYSQL_CLIENT - case OPT_SSL_MODE: - if (my_strcasecmp(&my_charset_latin1, argument, "required")) - { - fprintf(stderr, - "Unknown value to --ssl-mode: '%s'. Use --ssl-mode=REQUIRED\n", - argument); - exit(1); - } - else - opt_ssl_mode= SSL_MODE_REQUIRED; - break; -#endif /* MYSQL_CLIENT */ #endif #endif /* SSLOPT_CASE_INCLUDED */ diff --git a/include/sslopt-longopts.h b/include/sslopt-longopts.h index fd42e83eb04..81d03e54016 100644 --- a/include/sslopt-longopts.h +++ b/include/sslopt-longopts.h @@ -1,7 +1,8 @@ #ifndef SSLOPT_LONGOPTS_INCLUDED #define SSLOPT_LONGOPTS_INCLUDED -/* Copyright (c) 2000, 2016, 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 @@ -44,9 +45,6 @@ "when connecting. This option is disabled by default.", &opt_ssl_verify_server_cert, &opt_ssl_verify_server_cert, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"ssl-mode", OPT_SSL_MODE, - "SSL connection mode.", - 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif #endif /* HAVE_OPENSSL */ #endif /* SSLOPT_LONGOPTS_INCLUDED */ diff --git a/include/sslopt-vars.h b/include/sslopt-vars.h index a037538f693..01093feceaf 100644 --- a/include/sslopt-vars.h +++ b/include/sslopt-vars.h @@ -1,7 +1,7 @@ #ifndef SSLOPT_VARS_INCLUDED #define SSLOPT_VARS_INCLUDED -/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -28,14 +28,8 @@ SSL_STATIC char *opt_ssl_capath = 0; SSL_STATIC char *opt_ssl_cert = 0; SSL_STATIC char *opt_ssl_cipher = 0; SSL_STATIC char *opt_ssl_key = 0; - #ifdef MYSQL_CLIENT SSL_STATIC my_bool opt_ssl_verify_server_cert= 0; -SSL_STATIC uint opt_ssl_mode= 0; -#endif /* MYSQL_CLIENT */ - -#else /* HAVE_OPENSSL */ -#define opt_ssl_mode 0 -#endif /* HAVE_OPENSSL */ - +#endif +#endif #endif /* SSLOPT_VARS_INCLUDED */ diff --git a/include/thr_alarm.h b/include/thr_alarm.h index 4d076b6de7f..8de70d4cdb8 100644 --- a/include/thr_alarm.h +++ b/include/thr_alarm.h @@ -34,13 +34,17 @@ extern "C" { typedef struct st_alarm_info { - ulong next_alarm_time; + time_t next_alarm_time; uint active_alarms; uint max_used_alarms; } ALARM_INFO; void thr_alarm_info(ALARM_INFO *info); +extern my_bool my_disable_thr_alarm; +#ifdef _WIN32 +#define DONT_USE_THR_ALARM +#endif #if defined(DONT_USE_THR_ALARM) #define USE_ALARM_THREAD @@ -78,10 +82,11 @@ typedef int thr_alarm_entry; typedef thr_alarm_entry* thr_alarm_t; typedef struct st_alarm { - ulong expire_time; + time_t expire_time; thr_alarm_entry alarmed; /* set when alarm is due */ pthread_t thread; my_thread_id thread_id; + uint index_in_queue; my_bool malloced; } ALARM; diff --git a/include/thr_lock.h b/include/thr_lock.h index c5638ec2cde..3f7a5ca988f 100644 --- a/include/thr_lock.h +++ b/include/thr_lock.h @@ -76,6 +76,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 my_bool thr_lock_inited; extern enum thr_lock_type thr_upgraded_concurrent_insert_lock; @@ -97,10 +103,12 @@ typedef struct st_thr_lock_data { struct st_thr_lock_data *next,**prev; struct st_thr_lock *lock; mysql_cond_t *cond; - enum thr_lock_type type; void *status_param; /* Param to status functions */ - void *debug_print_param; + void *debug_print_param; /* For error messages */ struct PSI_table *m_psi; + enum thr_lock_type type; + enum thr_lock_type org_type; /* Cache for MariaDB */ + uint priority; } THR_LOCK_DATA; struct st_lock_list { @@ -117,11 +125,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; @@ -134,17 +146,12 @@ 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_INFO *owner, - enum thr_lock_type lock_type, - ulong lock_wait_timeout); -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_INFO *owner, ulong lock_wait_timeout); -void thr_multi_unlock(THR_LOCK_DATA **data,uint count); -void -thr_lock_merge_status(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/mysql/thread_pool_priv.h b/include/thread_pool_priv.h index 1da174e5f8b..a199923ff00 100644 --- a/include/mysql/thread_pool_priv.h +++ b/include/thread_pool_priv.h @@ -1,3 +1,4 @@ +#error don't use /* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. @@ -53,7 +54,6 @@ void thd_lock_thread_remove(THD *thd); void thd_unlock_thread_remove(THD *thd); void thd_close_connection(THD *thd); THD *thd_get_current_thd(); -void thd_new_connection_setup(THD *thd, char *stack_start); void thd_lock_data(THD *thd); void thd_unlock_data(THD *thd); bool thd_is_transaction_active(THD *thd); diff --git a/include/typelib.h b/include/typelib.h index 45452175bbc..4504bea4ff7 100644 --- a/include/typelib.h +++ b/include/typelib.h @@ -27,16 +27,18 @@ 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_with_warning(const char *x, TYPELIB *typelib, + const char *option); extern int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option); #define FIND_TYPE_BASIC 0 /** makes @c find_type() require the whole name, no prefix */ #define FIND_TYPE_NO_PREFIX (1 << 0) /** always implicitely on, so unused, but old code may pass it */ -#define FIND_TYPE_NO_OVERWRITE (1 << 1) -/** makes @c find_type() accept a number */ -#define FIND_TYPE_ALLOW_NUMBER (1 << 2) -/** makes @c find_type() treat ',' as terminator */ +#define FIND_TYPE_NO_OVERWRITE 0 +/** makes @c find_type() accept a number. Not used either */ +#define FIND_TYPE_ALLOW_NUMBER 0 +/** makes @c find_type() treat ',' and '=' as terminators */ #define FIND_TYPE_COMMA_TERM (1 << 3) extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags); diff --git a/include/violite.h b/include/violite.h index 817148ca3a1..da58de4373c 100644 --- a/include/violite.h +++ b/include/violite.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. 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 @@ -123,12 +123,15 @@ typedef my_socket YASSL_SOCKET_T; #include <openssl/ssl.h> #include <openssl/err.h> -#ifndef EMBEDDED_LIBRARY +#ifdef HAVE_ERR_remove_thread_state +#define ERR_remove_state(X) ERR_remove_thread_state(NULL) +#endif + enum enum_ssl_init_error { SSL_INITERR_NOERROR= 0, SSL_INITERR_CERT, SSL_INITERR_KEY, SSL_INITERR_NOMATCH, SSL_INITERR_BAD_PATHS, SSL_INITERR_CIPHERS, - SSL_INITERR_MEMFAIL, SSL_INITERR_DHFAIL, SSL_INITERR_LASTERR + SSL_INITERR_MEMFAIL, SSL_INITERR_LASTERR }; const char* sslGetErrString(enum enum_ssl_init_error err); @@ -149,7 +152,6 @@ struct st_VioSSLFd const char *ca_file,const char *ca_path, const char *cipher, enum enum_ssl_init_error* error); void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd); -#endif /* ! EMBEDDED_LIBRARY */ #endif /* HAVE_OPENSSL */ void vio_end(void); @@ -171,12 +173,30 @@ void vio_end(void); #define vio_should_retry(vio) (vio)->should_retry(vio) #define vio_was_interrupted(vio) (vio)->was_interrupted(vio) #define vio_close(vio) ((vio)->vioclose)(vio) +#define vio_shutdown(vio,how) ((vio)->shutdown)(vio,how) #define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen) #define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds) #define vio_poll_read(vio, timeout) (vio)->poll_read(vio, timeout) #define vio_is_connected(vio) (vio)->is_connected(vio) #endif /* !defined(DONT_MAP_VIO) */ +#ifdef _WIN32 + +/* shutdown(2) flags */ +#ifndef SHUT_RD +#define SHUT_RD SD_RECEIVE +#endif + +/* + Set thread id for io cancellation (required on Windows XP only, + and should to be removed if XP is no more supported) +*/ + +#define vio_set_thread_id(vio, tid) if(vio) vio->thread_id= tid +#else +#define vio_set_thread_id(vio, tid) +#endif + /* This enumerator is used in parser - should be always visible */ enum SSL_type { @@ -205,6 +225,8 @@ struct st_vio char *read_pos; /* start of unfetched data in the read buffer */ char *read_end; /* end of unfetched data */ + struct mysql_async_context *async_context; /* For non-blocking API */ + uint read_timeout, write_timeout; /* function pointers. They are similar for socket/SSL/whatever */ void (*viodelete)(Vio*); int (*vioerrno)(Vio*); @@ -222,6 +244,7 @@ struct st_vio void (*timeout)(Vio*, unsigned int which, unsigned int timeout); my_bool (*poll_read)(Vio *vio, uint timeout); my_bool (*is_connected)(Vio*); + int (*shutdown)(Vio *, int); my_bool (*has_data) (Vio*); #ifdef HAVE_OPENSSL void *ssl_arg; @@ -238,6 +261,7 @@ struct st_vio char *shared_memory_pos; #endif /* HAVE_SMEM */ #ifdef _WIN32 + DWORD thread_id; /* Used on XP only by vio_shutdown() */ OVERLAPPED pipe_overlapped; DWORD read_timeout_ms; DWORD write_timeout_ms; diff --git a/include/waiting_threads.h b/include/waiting_threads.h new file mode 100644 index 00000000000..e17874b9611 --- /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 *, mysql_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 0c17b5e650c..cd7cd6692be 100644 --- a/include/welcome_copyright_notice.h +++ b/include/welcome_copyright_notice.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2011, 2017, Oracle and/or its affiliates. + Copyright (c) 2011, 2017, MariaDB 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 @@ -23,14 +24,7 @@ program on start, or on help screen. */ #define ORACLE_WELCOME_COPYRIGHT_NOTICE(first_year) \ - (strcmp(first_year, COPYRIGHT_NOTICE_CURRENT_YEAR) ? \ - "Copyright (c) " first_year ", " COPYRIGHT_NOTICE_CURRENT_YEAR ", " \ - "Oracle and/or its affiliates. All rights reserved.\n\nOracle is a " \ - "registered trademark of Oracle Corporation and/or its\naffiliates. " \ - "Other names may be trademarks of their respective\nowners.\n" : \ - "Copyright (c) " first_year ", Oracle and/or its affiliates. " \ - "All rights reserved.\n\nOracle is a registered trademark of " \ - "Oracle Corporation and/or its\naffiliates. Other names may be " \ - "trademarks of their respective\nowners.\n") + "Copyright (c) " first_year ", " COPYRIGHT_NOTICE_CURRENT_YEAR \ + ", Oracle, MariaDB Corporation 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..e568ab8e91e --- /dev/null +++ b/include/wqueue.h @@ -0,0 +1,40 @@ +/* + Copyright (c) 2007, 2008, Sun Microsystems, Inc, + Copyright (c) 2011, 2012, 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 */ + +#ifndef WQUEUE_INCLUDED +#define WQUEUE_INCLUDED + +#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; + +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, + mysql_mutex_t *lock); +void wqueue_release_queue(WQUEUE *wqueue); +void wqueue_release_one_locktype_from_queue(WQUEUE *wqueue); + +#endif |