Commit graph

57 commits

Author SHA1 Message Date
Marko Mäkelä
826f9d4f7e Merge 10.4 into 10.5 2019-05-23 10:32:21 +03:00
Sergey Vojtovich
a61baa7a25 Maintain connection_count atomically
Removed LOCK_connection_count.

Removed duplicate denied_connections and connection_errors_max_connection
increment from create_new_thread(). Another increment done by
CONNECT::close_with_error().

Simplified away CONNECT::thread_count_incremented. Now close_with_error()
is always called with connection_count incremented.

Part of MDEV-19515 - Improve connect speed
2019-05-21 17:55:09 +04:00
Sergey Vojtovich
ebc55c8577 Simplified away scheduler_functions::end_thread()
Code properly integrated into callers instead.

do_handle_one_connection(): no need to reset thd and thd->thread_stack
as they're not updated by cache_thread().

Part of MDEV-19515 - Improve connect speed
2019-05-21 17:55:09 +04:00
Sergey Vojtovich
6900aaf417 Simplified away init_new_connection_thread()
It was meaningful only for one-thread-per-connection scheduler anyway,
so call init_new_connection_handler_thread() directly from
handle_one_connection().

It was somewhat harmful for no-threads scheduler, because it'd attempt to
detach main thread on AIX_3_2 and Siemens unix (and DEC OSF/1 3.2 too).
Also it does duplicate my_thread_init() call, which may produce a warning
under EXTRA_DEBUG_THREADS.

start_wsrep_THD() shouldn't have called it at all: it already detached
and called my_thread_init().

Part of MDEV-19515 - Improve connect speed
2019-05-21 17:55:09 +04:00
Marko Mäkelä
be85d3e61b Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
Marko Mäkelä
26a14ee130 Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
Vicențiu Ciorbaru
cb248f8806 Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
Vicențiu Ciorbaru
5543b75550 Update FSF Address
* Update wrong zip-code
2019-05-11 21:29:06 +03:00
Michael Widenius
4aaa38d26e Enusure that my_global.h is included first
- Added sql/mariadb.h file that should be included first by files in sql
  directory, if sql_plugin.h is not used (sql_plugin.h adds SHOW variables
  that must be done before my_global.h is included)
- Removed a lot of include my_global.h from include files
- Removed include's of some files that my_global.h automatically includes
- Removed duplicated include's of my_sys.h
- Replaced include my_config.h with my_global.h
2017-08-24 01:05:44 +02:00
Sergei Golubchik
562c1df7d9 cleanup: thread_count
move thread_count handling into THD:
* increment thread_count in THD constructor
* decrement thread_count in THD destructor
* never modify thread_count directly!
2016-06-04 09:06:00 +02:00
Sergei Golubchik
7425610c81 decrement thead_count *after* THD is destroyed
because thread_count means just that: number of THDs
and shutdown code looks at it to know when to free
shared data structures that THD uses.

This fixes random crashes in ~THD on shutdown
2016-06-04 09:06:00 +02:00
Monty
89685d55d7 Reuse THD for new user connections
- To ensure that mallocs are marked for the correct THD, even if it's
  allocated in another thread, I added the thread_id to the THD constructor
- Added st_my_thread_var to thr_lock_info_init() to avoid a call to my_thread_var
- Moved things from THD::THD() to THD::init()
- Moved some things to THD::cleanup()
- Added THD::free_connection() and THD::reset_for_reuse()
- Added THD to CONNECT::create_thd()
- Added THD::thread_dbug_id and st_my_thread_var->dbug_id. These are needed
  to ensure that we have a constant thread_id used for debugging with a THD,
  even if it changes thread_id (=connection_id)
- Set variables.pseudo_thread_id in constructor. Removed not needed sets.
2016-06-04 09:06:00 +02:00
Monty
3d4a7390c1 MDEV-6150 Speed up connection speed by moving creation of THD to new thread
Creating a CONNECT object on client connect and pass this to the working thread which creates the THD.
Split LOCK_thread_count to different mutexes
Added LOCK_thread_start to syncronize threads
Moved most usage of LOCK_thread_count to dedicated functions
Use next_thread_id() instead of thread_id++

Other things:
- Thread id now starts from 1 instead of 2
- Added cast for thread_id as thread id is now of type my_thread_id
- Made THD->host const (To ensure it's not changed)
- Removed some DBUG_PRINT() about entering/exiting mutex as these was already logged by mutex code
- Fixed that aborted_connects and connection_errors_internal are counted in all cases
- Don't take locks for current_linfo when we set it (not needed as it was 0 before)
2016-02-07 10:34:03 +02:00
Daniel Black
98274e6842 comment spelling Initailize -> Initialize 2015-12-11 15:21:42 +01:00
Sergei Golubchik
1c6ad62a26 mysql-5.5.39 merge
~40% bugfixed(*) applied
~40$ bugfixed reverted (incorrect or we're not buggy)
~20% bugfixed applied, despite us being not buggy
(*) only changes in the server code, e.g. not cmakefiles
2014-08-02 21:26:16 +02:00
Sergei Golubchik
6fb17a0601 5.5.39 merge 2014-08-07 18:06:56 +02:00
Venkatesh Duggirala
2870bd7423 Bug#17283409 4-WAY DEADLOCK: ZOMBIES, PURGING BINLOGS,
SHOW PROCESSLIST, SHOW BINLOGS

Problem:  A deadlock was occurring when 4 threads were
involved in acquiring locks in the following way
Thread 1: Dump thread ( Slave is reconnecting, so on
              Master, a new dump thread is trying kill
              zombie dump threads. It acquired thread's
              LOCK_thd_data and it is about to acquire
              mysys_var->current_mutex ( which LOCK_log)
Thread 2: Application thread is executing show binlogs and
               acquired LOCK_log and it is about to acquire
               LOCK_index.
Thread 3: Application thread is executing Purge binary logs
               and acquired LOCK_index and it is about to
               acquire LOCK_thread_count.
Thread 4: Application thread is executing show processlist
               and acquired LOCK_thread_count and it is
               about to acquire zombie dump thread's
               LOCK_thd_data.
Deadlock Cycle:
     Thread 1 -> Thread 2 -> Thread 3-> Thread 4 ->Thread 1

The same above deadlock was observed even when thread 4 is
executing 'SELECT * FROM information_schema.processlist' command and
acquired LOCK_thread_count and it is about to acquire zombie
dump thread's LOCK_thd_data.

Analysis:
There are four locks involved in the deadlock.  LOCK_log,
LOCK_thread_count, LOCK_index and LOCK_thd_data.
LOCK_log, LOCK_thread_count, LOCK_index are global mutexes
where as LOCK_thd_data is local to a thread.
We can divide these four locks in two groups.
Group 1 consists of LOCK_log and LOCK_index and the order
should be LOCK_log followed by LOCK_index.
Group 2 consists of other two mutexes
LOCK_thread_count, LOCK_thd_data and the order should
be LOCK_thread_count followed by LOCK_thd_data.
Unfortunately, there is no specific predefined lock order defined
to follow in the MySQL system when it comes to locks across these
two groups. In the above problematic example,
there is no problem in the way we are acquiring the locks
if you see each thread individually.
But If you combine all 4 threads, they end up in a deadlock.

Fix: 
Since everything seems to be fine in the way threads are taking locks,
In this patch We are changing the duration of the locks in Thread 4
to break the deadlock. i.e., before the patch, Thread 4
('show processlist' command) mysqld_list_processes()
function acquires LOCK_thread_count for the complete duration
of the function and it also acquires/releases
each thread's LOCK_thd_data.

LOCK_thread_count is used to protect addition and
deletion of threads in global threads list. While show
process list is looping through all the existing threads,
it will be a problem if a thread is exited but there is no problem
if a new thread is added to the system. Hence a new mutex is
introduced "LOCK_thd_remove" which will protect deletion
of a thread from global threads list. All threads which are
getting exited should acquire LOCK_thd_remove
followed by LOCK_thread_count. (It should take LOCK_thread_count
also because other places of the code still thinks that exit thread
is protected with LOCK_thread_count. In this fix, we are changing
only 'show process list' query logic )
(Eg: unlink_thd logic will be protected with
LOCK_thd_remove).

Logic of mysqld_list_processes(or file_schema_processlist)
will now be protected with 'LOCK_thd_remove' instead of
'LOCK_thread_count'.

Now the new locking order after this patch is:
LOCK_thd_remove -> LOCK_thd_data -> LOCK_log ->
LOCK_index -> LOCK_thread_count
2014-05-08 18:13:01 +05:30
Sergei Golubchik
0dc23679c8 10.0-base merge 2014-02-26 15:28:07 +01:00
Sergei Golubchik
0b9a0a3517 5.5 merge 2014-02-25 16:04:35 +01:00
Sergei Golubchik
fb27ce22f7 5.3 merge 2014-02-14 14:09:29 +01:00
Sergei Golubchik
913beda8c8 5.2 merge 2014-02-13 10:15:03 +01:00
Sergei Golubchik
48445f3556 5.1 merge 2014-02-13 08:25:33 +01:00
Sergei Golubchik
5f5d2db141 fix embedded tests
(mainly by backporting 5.5. changes)

mysql-test/suite/maria/t/distinct.test:
  Remove the test that requires SSL. One test case for a bug is enough.
sql/scheduler.cc:
  make it the same as in 5.5
storage/innodb_plugin/row/row0mysql.c:
  make it the same as in 5.5
storage/innodb_plugin/row/row0sel.c:
  make it the same as in 5.5
storage/xtradb/row/row0mysql.c:
  make it the same as in 5.5
storage/xtradb/row/row0sel.c:
  make it the same as in 5.5
2014-02-13 08:09:07 +01:00
Sergei Golubchik
a9035be5b7 10.0-base merge 2013-04-15 15:09:22 +02:00
Sergei Golubchik
48bb551328 remove the service for installing the closed-source mysql thread pool plugin 2013-04-07 14:50:01 +02:00
Vladislav Vaintroub
41013f16a0 MDEV-156 Threadpool - add thd_wait_begin/thd_wait_end to the network IO functions 2013-02-19 20:44:33 +01:00
Vladislav Vaintroub
21b4fda3a5 MDEV-3945 - do not hold LOCK_thread_count when freeing THD.
The patch decreases the duration of LOCK_thread_count, so it is not hold during THD destructor and freeing memory.
This mutex  now only protects the integrity of threads list, when removing THD from it,  and thread_count variable.
  
The add_to_status() function that updates global status during client disconnect,  is now correctly protected by the LOCK_status mutex.

Benchmark : in a  "non-persistent" sysbench test (oltp_ro with reconnect after each query),  ~ 25% more connects/disconnects were measured
2012-12-21 00:12:37 +01:00
Vladislav Vaintroub
4ffc9c3b01 MDEV-531 : Warning: Forcing close of thread ... in rpl_binlog_index
Use post_kill_notification in for one_thread_per_connection scheduler, 
the same as already used in threadpool, to reliably wake a thread  stuck in 
read() or in different poll() variations.
2012-11-02 10:43:52 +01:00
Vladislav Vaintroub
4e8bb265fe Update copyright notices 2012-02-28 18:53:05 +01:00
Vladislav Vaintroub
58c3e32dbd Simplify thd_wait_begin. given how seldom they are called, calling current_thd one more time is not going to be anything performance relevant.
Also use thd_wait_begin/end for thr_lock and sync callbacks.
2012-02-17 23:33:18 +01:00
Vladislav Vaintroub
cfa56f900a address second round review comments 2012-02-16 16:59:04 +01:00
Igor Babaev
7b79d8a33f Merge 5.2->5.3 in preparation for the release of mariadb-5.3.4-rc. 2012-02-01 15:48:02 -08:00
Sergei Golubchik
a1e3fa93c7 lp:893522 more problems found by PVS Studio 2012-01-12 20:13:22 +01:00
Vladislav Vaintroub
e91bbca5fb Initial threadpool implementation for MariaDB 5.5 2011-12-08 19:17:49 +01:00
Sergei Golubchik
0e007344ea mysql-5.5.18 merge 2011-11-03 19:17:05 +01:00
Michael Widenius
22e793639a Added new options to KILL. New syntax is KILL [HARD|SOFT] [CONNECTION|QUERY] [ID | USER user_name]
- If USER is given, all threads for that user is signaled
- If SOFT is used then the KILL will not be sent to the handler. This can be used to not interrupt critical things in the handler like 'REPAIR'.

Internally added more kill signals. This gives us more information of why a query/connection was killed.
- KILL_SERVER is used when server is going down. In this case the users gets ER_SHUTDOWN as the reason connection was killed.
- Changed signals to number in correct order, which makes it easier to test how the signal should affect the code.
- New error message ER_CONNECTION_KILLED if connection was killed by 'KILL CONNECTION'. Before we got error ER_SHUTDOWN.

Changed names of not used parameters KILL_QUERY & KILL_CONNCTION to mysql_kill() to not conflict with defines in the server


include/mysql.h.pp:
  Updated file
include/mysql_com.h:
  Changed names of not used parameters KILL_QUERY & KILL_CONNCTION to mysql_kill() to not conflict with defines in the server
mysql-test/r/kill.result:
  Added test of KILL USER
mysql-test/suite/rpl/r/rpl_stm_000001.result:
  Updated error code
mysql-test/suite/rpl/t/rpl_stm_000001.test:
  Updated error codes
mysql-test/t/flush_read_lock_kill.test:
  Updated error codes
mysql-test/t/kill.test:
  Added test of KILL USER
plugin/handler_socket/handlersocket/database.cpp:
  Removed THD:: from KILL
sql/debug_sync.cc:
  Removed THD:: from KILL
sql/event_scheduler.cc:
  Removed THD:: from KILL
sql/filesort.cc:
  Removed THD:: from KILL
sql/ha_ndbcluster_binlog.cc:
  Removed THD:: from KILL
sql/handler.cc:
  Removed THD:: from KILL
  Simplify code.
sql/lex.h:
  Added new keywords HARD | SOFT
sql/log.cc:
  Removed THD:: from KILL
  Added testing of new error ER_CONNECTION_KILLED
sql/log_event.cc:
  Removed THD:: from KILL
  Added testing of new error ER_CONNECTION_KILLED
sql/mysql_priv.h:
  Added new prototypes
sql/mysqld.cc:
  Removed THD:: from KILL
  Use KILL_SERVER_HARD signal on shutdown.
sql/scheduler.cc:
  Removed THD:: from KILL
  Simplify test if connection should be killed
sql/share/errmsg.txt:
  New error message ER_CONNECTION_KILLED
sql/slave.cc:
  Removed THD:: from KILL
sql/sp_head.cc:
  Removed THD:: from KILL
sql/sql_base.cc:
  Removed THD:: from KILL
sql/sql_cache.cc:
  Removed THD:: from KILL
sql/sql_class.cc:
  Removed THD:: from KILL
  Added killed_errno()
  Only signal kill to storage engine if HARD bit is set.
sql/sql_class.h:
  Move KILL options out from THD to make them easier to use in sql_yacc.yy
sql/sql_connect.cc:
  Removed THD:: from KILL
sql/sql_delete.cc:
  Removed THD:: from KILL
sql/sql_error.cc:
  Removed THD:: from KILL
sql/sql_insert.cc:
  Removed THD:: from KILL
  Simplifed testing if thread is killed.
sql/sql_lex.h:
  Added kill options to st_lex
sql/sql_load.cc:
  Removed THD:: from KILL
sql/sql_parse.cc:
  Added kill options to st_lex
  Simplifed and optimzed testing of thd->killed at end of query
  Added support for KILL USER
  Extended sql_kill() to allow use of more kill signals.
sql/sql_repl.cc:
  Removed THD:: from KILL
sql/sql_show.cc:
  Removed THD:: from KILL
  Simplied testing if query/connection was killed
sql/sql_table.cc:
  Removed THD:: from KILL
sql/sql_update.cc:
  Removed THD:: from KILL
sql/sql_yacc.yy:
  Added support for new KILL syntax: KILL [HARD|SOFT] [CONNECTION|QUERY] [ID | USER user_name]
storage/archive/ha_archive.cc:
  Simplify compilation
storage/maria/ha_maria.cc:
  Removed THD:: from KILL
2011-09-23 01:13:38 +03:00
Michael Widenius
8fb10c24d7 Fixed that automatic killing of delayed insert thread (in flush, alter table etc) will not abort auto-repair of MyISAM table.
Give more information when finding an error in a MyISAM table.
When killing system thread, use KILL_SYSTEM_THREAD instead of KILL_CONNECTION to make it easier to ignore the signal in sensitive context (like auto-repair)
Added new kill level: KILL_SERVER that will in the future to be used to signal killed by shutdown.
Add more warnings about killed connections when warning level > 3

include/myisamchk.h:
  Added counting of printed info/notes
mysys/mf_iocache.c:
  Remove duplicate assignment
sql/handler.cc:
  Added test of KILL_SERVER
sql/log.cc:
  Ignore new 'kill' error ER_NEW_ABORTING_CONNECTION when requesting query error code.
sql/mysqld.cc:
  Add more warnings for killed connections when warning level > 3
sql/scheduler.cc:
  Added checks for new kill signals
sql/slave.cc:
  Ignore new kill signal ER_NEW_ABORTING_CONNECTION
sql/sp_head.cc:
  Fixed assignment to bool
  Added testing of new kill signals
sql/sql_base.cc:
  Use KILL_SYSTEM_THREAD to auto-kill system threads
sql/sql_class.cc:
  Add more warnings for killed connections when warning level > 3
  thd_killed() now ignores KILL_BAD_DATA and THD::KILL_SYSTEM_THREAD as these should not abort sensitive operations.
sql/sql_class.h:
  Added KILL_SYSTEM_THREAD and KILL_SERVER
sql/sql_connect.cc:
  Added handling of KILL_SERVER
sql/sql_insert.cc:
  Use KILL_SYSTEM_THREAD to auto-kill system threads
  Added handling of KILL_SERVER
sql/sql_parse.cc:
  Add more warnings for killed connections when warning level > 3
  Added checking that thd->abort_on_warning is reset at end of query.
sql/sql_show.cc:
  Update condition for when a query is 'killed'
storage/myisam/ha_myisam.cc:
  Added counting of info/notes printed
storage/myisam/mi_check.c:
  Always print an an error if we find data errors when checking/repairing a MyISAM table.
  When a repair was killed, don't retry repair.
  Added assert if sort_get_next_record() returned an error without an error message.
  Removed nonsence check "if (sort_param->read_cache.error < 0)" in repair.
storage/myisam/myisamchk.c:
  Added counting of notes printed
storage/pbxt/src/thread_xt.cc:
  Better error message.
2011-09-09 19:44:07 +03:00
Sergei Golubchik
2005689700 sys_vars changes and cleanups 2011-07-11 20:33:39 +02:00
Sergei Golubchik
b4a0b2c2f8 post-merge fixes.
most tests pass.
5.3 merge is next
2011-07-02 22:12:12 +02:00
Sergei Golubchik
9809f05199 5.5-merge 2011-07-02 22:08:51 +02:00
Kent Boortz
02e07e3b51 Updated/added copyright headers 2011-06-30 17:46:53 +02:00
Sergei Golubchik
0accbd0364 lots of post-merge changes 2011-04-25 17:22:25 +02:00
Mikael Ronstrom
b14adc3921 More review fixes 2011-03-04 13:12:31 +01:00
Mikael Ronström
1d6945a017 more fixes of scheduler interface changes 2011-02-10 19:38:36 +01:00
Mikael Ronström
8d319b1f29 Simplifications of server interface to scheduler 2011-02-10 19:24:31 +01:00
Sergei Golubchik
65ca700def merge.
checkpoint.
does not compile.
2010-11-25 18:17:28 +01:00
Mikael Ronstrom
c0854c3e17 Added reporting of fsync to THD wait interface 2010-10-28 18:27:25 +02:00
Mikael Ronstrom
4dff0296f4 Added more wait states for THD wait service 2010-10-27 20:29:09 +02:00
Mats Kindahl
7017775fd1 WL#5363: Thread Pool Service Interface
Fixes to ensure that it builds with the embedded server as well.
2010-06-15 09:44:26 +02:00
Mats Kindahl
aaf2bdde94 WL#5363: Thread Pool Service Interface
In order to allow thread schedulers to be dynamically loaded,
it is necessary to make the following changes to the server:

- Two new service interfaces

- Modifications to InnoDB to inform the thread scheduler of state changes.

- Changes to the VIO subsystem for checking if data is available on a socket.

- Elimination of remains of the old thread pool implementation.

The two new service interfaces introduces are:

my_thread_scheduler
  A service interface to register a thread
  scheduler.

thd_wait
  A service interface to inform thread scheduler
  that the thread is about to start waiting.

In addition, the patch adds code that:

- Add a call to thd_wait for table locks in mysys
  thd_lock.c by introducing a set function that
  can be used to set a callback to be used when
  waiting on a lock and resuming from waiting.

- Calling the mysys set function from the server
  to set the callbacks correctly.
2010-06-07 16:01:39 +02:00