mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
e63b5546c5
It includes speed optimizations for HANDLER READ by caching as much as possible in HANDLER OPEN Other things: - Added mysqld option --disable-thr-alarm to be able to benchmark things without thr_alarm - Changed 'Locked' state to 'System lock' and 'Table lock' (these where used in the code but never shown to end user) - Better error message if mysql_install_db.sh fails - Moved handler function prototypes to sql_handler.h - Remove not anymore used 'thd->locked' member include/thr_alarm.h: Added my_disable_thr_alarm include/thr_lock.h: Add new member to THR_LOCK_DATA to remember original lock type state. This is needed as thr_unlock() resets type to TL_UNLOCK. mysql-test/include/check_no_concurrent_insert.inc: Locked -> Table lock mysql-test/include/handler.inc: Locked -> Table lock mysql-test/r/handler_innodb.result: Updated results for new tests mysql-test/r/handler_myisam.result: Updated results for new tests mysql-test/r/sp-threads.result: Locked -> Table lock mysql-test/suite/binlog/t/binlog_stm_row.test: Locked -> Table lock mysql-test/suite/funcs_1/datadict/processlist_val.inc: Locked -> Table lock mysql-test/suite/pbxt/t/lock_multi.test: Locked -> Table lock mysql-test/suite/sys_vars/r/concurrent_insert_func.result: Locked -> Table lock mysql-test/suite/sys_vars/t/concurrent_insert_func.test: Locked -> Table lock mysql-test/suite/sys_vars/t/delayed_insert_limit_func.test: Locked -> Table lock mysql-test/suite/sys_vars/t/query_cache_wlock_invalidate_func.test: Locked -> Table lock mysql-test/suite/sys_vars/t/sql_low_priority_updates_func.test: Locked -> Table lock mysql-test/t/insert_notembedded.test: Locked -> Table lock mysql-test/t/lock_multi.test: Locked -> Table lock mysql-test/t/merge-big.test: Locked -> Table lock mysql-test/t/multi_update.test: Locked -> Table lock mysql-test/t/query_cache_28249.test: Locked -> Table lock mysql-test/t/sp_notembedded.test: Locked -> Table lock mysql-test/t/sp_sync.test: Locked -> Table lock mysql-test/t/status.test: Locked -> Table lock mysql-test/t/trigger_notembedded.test: Locked -> Table lock mysys/thr_alarm.c: Added option to disable thr_alarm mysys/thr_lock.c: Detect loops scripts/mysql_install_db.sh: Give better error message if something goes wrong sql/Makefile.am: Added sql_handler.h sql/lock.cc: Split functions to allow one to cache value if store_lock() (for HANDLER functions). - Split mysql_lock_tables() into two functions, where first one allocates MYSQL_LOCK and other other one uses it. - Made get_lock_data() an external function. - Added argument to mysql_unlock_tables() to not free sql_lock. - Added argument to reset_lock_data() to reset lock structure to initial state (as after get_lock_data()) sql/mysql_priv.h: Moved handler function prototypes to sql_handler.h Added new lock functions. sql/mysqld.cc: Added --thread-alarm startup option sql/net_serv.cc: Don't call vio_blocking() if not needed sql/sql_base.cc: include sql_handler.h sql/sql_class.cc: include sql_handler.h Remove not anymore used 'thd->locked' member sql/sql_class.h: Remove not anymore used 'thd->locked' member sql/sql_db.cc: include sql_handler.h sql/sql_delete.cc: include sql_handler.h sql/sql_handler.cc: Rewrote all code to use SQL_HANDLER instead of TABLE_LIST (original interface) Rewrote mysql_ha_open() to cache all things from TABLE_LIST and items for field list, where etc. In mysql_ha_open() also cache MYSQL_LOCK structure from get_lock_data(). Split functions into smaller sub functions (needed to be able to implement mysql_ha_read_prepare()) Added mysql_ha_read_prepare() to allow one to prepare HANDLER READ. sql/sql_handler.h: Interface to sql_handler.cc sql/sql_parse.cc: include sql_handler.h sql/sql_prepare.cc: Added mysql_test_handler_read(), prepare for HANDLER READ sql/sql_rename.cc: include sql_handler.h sql/sql_show.cc: Removed usage of thd->locked sql/sql_table.cc: include sql_handler.h sql/sql_trigger.cc: include sql_handler.h
184 lines
6.3 KiB
C
184 lines
6.3 KiB
C
/* Copyright 2000-2008 MySQL AB, 2008 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 */
|
|
|
|
/* For use with thr_lock:s */
|
|
|
|
#ifndef _thr_lock_h
|
|
#define _thr_lock_h
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <my_pthread.h>
|
|
#include <my_list.h>
|
|
|
|
struct st_thr_lock;
|
|
extern ulong locks_immediate,locks_waited ;
|
|
|
|
/*
|
|
Important: if a new lock type is added, a matching lock description
|
|
must be added to sql_test.cc's lock_descriptions array.
|
|
*/
|
|
enum thr_lock_type { TL_IGNORE=-1,
|
|
TL_UNLOCK, /* UNLOCK ANY LOCK */
|
|
/*
|
|
Parser only! At open_tables() becomes TL_READ or
|
|
TL_READ_NO_INSERT depending on the binary log format
|
|
(SBR/RBR) and on the table category (log table).
|
|
Used for tables that are read by statements which
|
|
modify tables.
|
|
*/
|
|
TL_READ_DEFAULT,
|
|
TL_READ, /* Read lock */
|
|
TL_READ_WITH_SHARED_LOCKS,
|
|
/* High prior. than TL_WRITE. Allow concurrent insert */
|
|
TL_READ_HIGH_PRIORITY,
|
|
/* READ, Don't allow concurrent insert */
|
|
TL_READ_NO_INSERT,
|
|
/*
|
|
Write lock, but allow other threads to read / write.
|
|
Used by BDB tables in MySQL to mark that someone is
|
|
reading/writing to the table.
|
|
*/
|
|
TL_WRITE_ALLOW_WRITE,
|
|
/*
|
|
Write lock, but allow other threads to read.
|
|
Used by ALTER TABLE in MySQL to allow readers
|
|
to use the table until ALTER TABLE is finished.
|
|
*/
|
|
TL_WRITE_ALLOW_READ,
|
|
/*
|
|
WRITE lock used by concurrent insert. Will allow
|
|
READ, if one could use concurrent insert on table.
|
|
*/
|
|
TL_WRITE_CONCURRENT_INSERT,
|
|
/* Write used by INSERT DELAYED. Allows READ locks */
|
|
TL_WRITE_DELAYED,
|
|
/*
|
|
parser only! Late bound low_priority flag.
|
|
At open_tables() becomes thd->update_lock_default.
|
|
*/
|
|
TL_WRITE_DEFAULT,
|
|
/* WRITE lock that has lower priority than TL_READ */
|
|
TL_WRITE_LOW_PRIORITY,
|
|
/* Normal WRITE lock */
|
|
TL_WRITE,
|
|
/* Abort new lock request with an error */
|
|
TL_WRITE_ONLY};
|
|
|
|
enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
|
|
THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
|
|
|
|
|
|
/* Priority for locks */
|
|
#define THR_LOCK_LATE_PRIV 1 /* For locks to be merged with org lock */
|
|
#define THR_LOCK_MERGE_PRIV 2 /* For merge tables */
|
|
|
|
#define THR_UNLOCK_UPDATE_STATUS 1
|
|
|
|
extern ulong max_write_lock_count;
|
|
extern ulong table_lock_wait_timeout;
|
|
extern my_bool thr_lock_inited;
|
|
extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
|
|
|
|
/*
|
|
A description of the thread which owns the lock. The address
|
|
of an instance of this structure is used to uniquely identify the thread.
|
|
*/
|
|
|
|
typedef struct st_thr_lock_info
|
|
{
|
|
pthread_t thread;
|
|
my_thread_id thread_id;
|
|
ulong n_cursors;
|
|
} THR_LOCK_INFO;
|
|
|
|
/*
|
|
Lock owner identifier. Globally identifies the lock owner within the
|
|
thread and among all the threads. The address of an instance of this
|
|
structure is used as id.
|
|
*/
|
|
|
|
typedef struct st_thr_lock_owner
|
|
{
|
|
THR_LOCK_INFO *info;
|
|
} THR_LOCK_OWNER;
|
|
|
|
|
|
typedef struct st_thr_lock_data {
|
|
THR_LOCK_OWNER *owner;
|
|
struct st_thr_lock_data *next,**prev;
|
|
struct st_thr_lock *lock;
|
|
pthread_cond_t *cond;
|
|
void *status_param; /* Param to status functions */
|
|
enum thr_lock_type type;
|
|
|
|
enum thr_lock_type org_type; /* Cache for MariaDB */
|
|
void *debug_print_param; /* For error messages */
|
|
uint priority;
|
|
} THR_LOCK_DATA;
|
|
|
|
struct st_lock_list {
|
|
THR_LOCK_DATA *data,**last;
|
|
};
|
|
|
|
typedef struct st_thr_lock {
|
|
LIST list;
|
|
pthread_mutex_t mutex;
|
|
struct st_lock_list read_wait;
|
|
struct st_lock_list read;
|
|
struct st_lock_list write_wait;
|
|
struct st_lock_list write;
|
|
/* 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*, 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 */
|
|
my_bool (*start_trans)(void*); /* When all locks are taken */
|
|
my_bool (*check_status)(void *);
|
|
void (*fix_status)(void *, void *);/* For thr_merge_locks() */
|
|
my_bool allow_multiple_concurrent_insert;
|
|
} THR_LOCK;
|
|
|
|
|
|
extern LIST *thr_lock_thread_list;
|
|
extern pthread_mutex_t THR_LOCK_lock;
|
|
|
|
my_bool init_thr_lock(void); /* Must be called once/thread */
|
|
#define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
|
|
void thr_lock_info_init(THR_LOCK_INFO *info);
|
|
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);
|
|
void thr_unlock(THR_LOCK_DATA *data, uint unlock_flags);
|
|
enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
|
|
uint count, THR_LOCK_OWNER *owner);
|
|
void thr_multi_unlock(THR_LOCK_DATA **data,uint count, 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 */
|
|
my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
|
|
enum thr_lock_type new_lock_type);
|
|
void thr_downgrade_write_lock(THR_LOCK_DATA *data,
|
|
enum thr_lock_type new_lock_type);
|
|
my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* _thr_lock_h */
|