Commit graph

65 commits

Author SHA1 Message Date
Sergey Vojtovich
3bdd93c10a tc_contention_warning_reported transition to std::atomic 2018-12-29 14:19:08 +04:00
Sergey Vojtovich
dc90234bda MDEV-17441 - InnoDB transition to C++11 atomics
Added lf_hash_size() macro, so that callers don't need to use atomic
operations.
2018-12-28 13:24:11 +04:00
Monty
7fb9d64989 Changed FLUSH TABLES to not change share version
Part of MDEV-5336 Implement LOCK FOR BACKUP

Originally both table metadata lock and global read lock protection
were acquired before getting TABLE from table cache. This will be
reordered in a future commit with MDL_BACKUP_XXX locks so that we
first take table metadata lock, then get TABLE from table cache, then
acquire analogue of global read lock.

This patch both simplifies FLUSH TABLES code, makes FLUSH TABLES to
lock less and also enables FLUSH TABLES code to be used with backup
locks.

The usage of FLUSH TABLES changes slightly:
- FLUSH TABLES without any arguments will now only close not used tables
  and tables locked by the FLUSH TABLES connection.  All not used table
  shares will be closed.
  Tables locked by the FLUSH TABLES connection will be reopened and
  re-locked after all others has stoped using the table (as before).
  If there was no locked tables, then FLUSH TABLES is instant and will
  not cause any waits.
  FLUSH TABLES will not wait for any in use table.
- FLUSH TABLES with a table list, will ensure that the tables are closed
  before statement returns. The code is now only using MDL locks and not
  table share versions, which simplices the code greatly. One visible
  change is that the server will wait for the end of the transaction that
  are using the tables. Before FLUSH TABLES only waited for the statements
  to end.

Signed-off-by: Monty <monty@mariadb.org>
2018-12-09 22:12:26 +02:00
Monty
163b34fe25 Optimize flush tables with read lock (FTWRL) to not wait for select's
Part of MDEV-5336 Implement LOCK FOR BACKUP

The idea is that instead of waiting in close_cached_tables() for all
tables to be closed, we instead call flush_tables() that does:
- Flush not used objects in table cache to free memory
- Collect all tables that are open
- Call HA_EXTRA_FLUSH on the objects, to get them into "closed state"
- Added HA_EXTRA_FLUSH support to archive and CSV
- Added multi-user protection to HA_EXTRA_FLUSH in MyISAM and Aria

The benefit compared to old code is:
- FTWRL doesn't have to wait for long running read operations or
  open HANDLER's
2018-12-09 22:12:25 +02:00
Monty
ae58cd6b87 Simple cleanups (no logic changes) 2018-12-09 20:49:05 +02:00
Marko Mäkelä
444c380ceb Merge 10.3 into 10.4 2018-10-05 08:09:49 +03:00
Sergei Golubchik
57e0da50bb Merge branch '10.2' into 10.3 2018-09-28 16:37:06 +02:00
Sergei Golubchik
5ae8fce50b Merge branch '10.1' into 10.2 2018-09-24 11:46:08 +02:00
Sergei Golubchik
1fc5a6f30c Merge branch '10.0' into 10.1 2018-09-23 12:58:11 +02:00
Sergey Vojtovich
327b271721 MDEV-14410 - Assertion `table->pos_in_locked_tables == __null ||
table->pos_in_locked_tables->table == table'
             failed in mark_used_tables_as_free_for_reuse

Assertion failure can be triggered by some DDL executed under LOCK TABLES
that holds lock for DDL target table multiple times (either explicitly or
implcitly).

When closing all table instances for given table (e.g. when preparing for
table removal during CREATE OR REPLACE), only one instance was removed
from m_locked_tables list.

Later we attempt to re-insert one of the instances in mysql_create_table()/
add_back_last_deleted_lock(), which wasn't actually removed. This leads
to m_locks_tables corruption, specifically loss of all following elements.

Then UNLOCK TABLE won't reset some table instances properly (specifically
pos_in_locked_tables), since they're not present in m_locked_tables.

Eventually such table instance gets released to table cache and then
re-used by subsequent statement, which triggers this assertion failure.
2018-09-18 16:24:09 +04:00
Oleksandr Byelkin
28f08d3753 Merge branch '10.1' into 10.2 2018-09-14 08:47:22 +02:00
Sergey Vojtovich
e76c4c06f1 MDEV-16773 - Assertion failed in tdc_remove_table
This assertion fails in thread that removes all table instances for
particular table from table cache (e.g. "DROP TABLE") while another
thread evicts table instance of the same table from table cache
concurrently.

After "MDEV-10296 - Multi-instance table cache" there is a gap in
eviction code of tc_add_table() between removing table from free_tables
and all_tables not protected by any mutexes.

This is now valid table cache state, however assertion wasn't amended
along with original patch. Moved assertion down, after waiting for such
table instances to get closed.
2018-09-10 18:31:14 +04:00
Oleksandr Byelkin
31081593aa Merge branch '11.0' into 10.1 2018-09-06 22:45:19 +02:00
Sergey Vojtovich
4cf75706b3 MDEV-16757 Memory leak after adding manually min/max statistical data
for blob column

Moved delete_stat_values_for_table_share() call to proper place.
2018-09-05 17:14:20 +04:00
Marko Mäkelä
734db318ac Merge 10.3 into 10.4 2018-08-16 10:08:30 +03:00
Michael Widenius
d6d63f4844 MDEV-16421 Make system tables crash safe
Make all system tables in mysql directory of type
engine=Aria

Privilege tables are using transactional=1
Statistical tables are using transactional=0, to allow them
to be quickly updated with low overhead.
Help tables are also using transactional=0 as these are only
updated at init time.

Other changes:
- Aria store engine is now a required engine
- Update comment for Aria tables to reflect their new usage
- Fixed that _ma_reset_trn_for_table() removes unlocked table
  from transaction table list. This was needed to allow one
  to lock and unlock system tables separately from other
  tables, for example when reading a procedure from mysql.proc
- Don't give a warning when using transactional=1 for engines
  that is using transactions. This is both logical and also
  to avoid warnings/errors when doing an alter of a privilege
  table to InnoDB.
- Don't abort on warnings from ALTER TABLE for changes that
  would be accepted by CREATE TABLE.
- New created Aria transactional tables are marked as not movable
  (as they include create_rename_lsn).
- bootstrap.test was changed to kill orignal server, as one
  can't anymore have two servers started at same time on same
  data directory and data files.
- Disable maria.small_blocksize as one can't anymore change
  aria block size after system tables are created.
- Speed up creation of help tables by using lock tables.
- wsrep_sst_resync now also copies Aria redo logs.
2018-08-14 12:18:38 +03:00
Marko Mäkelä
05459706f2 Merge 10.2 into 10.3 2018-08-03 15:57:23 +03:00
Marko Mäkelä
ef3070e997 Merge 10.1 into 10.2 2018-08-02 08:19:57 +03:00
Igor Babaev
095dc81158 MDEV-16757 Memory leak after adding manually min/max statistical data
for blob column

ANALYZE TABLE <table> does not collect statistical data on min/max values
for BLOB columns of <table>. However these values can be added into
mysql.column_stats manually by executing proper statements.
Unfortunately this led to a memory leak because the memory allocated
for these values was never freed.
This patch provides the server with a function to free memory allocated
for min/max statistical values of BLOB types.

Temporarily changed the test case until MDEV-16711 is fixed as without
this fix the test case for MDEV-16757 did not fail only for 10.0.
2018-07-15 16:24:24 -07:00
Igor Babaev
c89bb15c31 MDEV-16757 Memory leak after adding manually min/max statistical data
for blob column

ANALYZE TABLE <table> does not collect statistical data on min/max values
for BLOB columns of <table>. However these values can be added into
mysql.column_stats manually by executing proper statements.
Unfortunately this led to a memory leak because the memory allocated
for these values was never freed.
This patch provides the server with a function to free memory allocated
for min/max statistical values of BLOB types.
2018-07-13 17:48:45 -07:00
Michael Widenius
9d6dc39ad9 Add checking of correct likely/unlikely
To use:
- Compile with -DUSE_MY_LIKELY
- Change (with replace) all likely/unlikely to my_likely/my_/unlikely
  replace likely my_likely unlikely my_unlikely -- *c *h
- Start mysqld with -T
- run some test
- When mysqld has shut down cleanely, report will be on stderr
2018-05-07 00:07:32 +03:00
Monty
30ebc3ee9e Add likely/unlikely to speed up execution
Added to:
- if (error)
- Lex
- sql_yacc.yy and sql_yacc_ora.yy
- In header files to alloc() calls
- Added thd argument to thd_net_is_killed()
2018-05-07 00:07:32 +03:00
Monty
cd93eeeb1d MDEV-15149 Assert upon concurrent creating / querying sequences
Problem was that sequence_insert closed and reopened the like table
without proper locking.  Fixed by ensuring that the like table is
not reopened in sequence_insert
2018-03-29 14:20:11 +03:00
Vladislav Vaintroub
6c279ad6a7 MDEV-15091 : Windows, 64bit: reenable and fix warning C4267 (conversion from 'size_t' to 'type', possible loss of data)
Handle string length as size_t, consistently (almost always:))
Change function prototypes to accept size_t, where in the past
ulong or uint were used. change local/member variables to size_t
when appropriate.

This fix excludes rocksdb, spider,spider, sphinx and connect for now.
2018-02-06 12:55:58 +00:00
Alexander Barkov
217fc122c8 Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2018-02-04 18:40:06 +04:00
Monty
d69642dedd Added name to MEM_ROOT for esier debugging
This will make it easier to how memory allocation is done when debugging
with either DBUG or gdb.

Will especially help when debugging stored procedures

Main change is a name argument as second argument to init_alloc_root()
init_sql_alloc()

Other things:
- Added DBUG_ENTER/EXIT to some Virtual_tmp_table functions
2018-02-02 11:08:36 +02:00
Monty
a7e352b54d Changed database, tablename and alias to be LEX_CSTRING
This was done in, among other things:
- thd->db and thd->db_length
- TABLE_LIST tablename, db, alias and schema_name
- Audit plugin database name
- lex->db
- All db and table names in Alter_table_ctx
- st_select_lex db

Other things:
- Changed a lot of functions to take const LEX_CSTRING* as argument
  for db, table_name and alias. See init_one_table() as an example.
- Changed some function arguments from LEX_CSTRING to const LEX_CSTRING
- Changed some lists from LEX_STRING to LEX_CSTRING
- threads_mysql.result changed because process list_db wasn't always
  correctly updated
- New append_identifier() function that takes LEX_CSTRING* as arguments
- Added new element tmp_buff to Alter_table_ctx to separate temp name
  handling from temporary space
- Ensure we store the length after my_casedn_str() of table/db names
- Removed not used version of rename_table_in_stat_tables()
- Changed Natural_join_column::table_name and db_name() to never return
  NULL (used for print)
- thd->get_db() now returns db as a printable string (thd->db.str or "")
2018-01-30 21:33:55 +02:00
Sergey Vojtovich
613dd62a76 MDEV-11153 - Introduce status variables for table cache monitoring and tuning
Status variables added: Table_open_cache_hits, Table_open_cache_misses,
Table_open_cache_overflows, Table_open_cache_active_instances.
2017-10-31 19:13:20 +04:00
Marko Mäkelä
2c1067166d Merge bb-10.2-ext into 10.3 2017-10-04 08:24:06 +03:00
Vladislav Vaintroub
24d9664ad0 In table cache code, fix casts from longlong to long for
'version' variables.

The warnings occur on Windows build, yet they are also are valid
on 32bit Unix.

Fix is to consistently use 64bit integer on all platforms.
2017-09-29 17:27:21 +00:00
Vladislav Vaintroub
7354dc6773 MDEV-13384 - misc Windows warnings fixed 2017-09-28 17:20:46 +00:00
Vladislav Vaintroub
eba44874ca MDEV-13844 : Fix Windows warnings. Fix DBUG_PRINT.
- Fix win64 pointer truncation warnings
(usually coming from misusing 0x%lx and long cast in DBUG)

- Also fix printf-format warnings

Make the above mentioned warnings fatal.

- fix pthread_join on Windows to set return value.
2017-09-28 17:20:46 +00: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
4a5d25c338 Merge branch '10.1' into 10.2 2016-12-29 13:23:18 +01:00
Sergei Golubchik
66d9696596 Merge branch '10.0' into 10.1 2016-09-28 17:55:28 +02:00
Sergey Vojtovich
e56a53920b MDEV-10315 - Online ALTER TABLE may get stuck in tdc_remove_table
There was race condition between online ALTER TABLE and statements performing
TABLE_SHARE release without marking it flushed (e.g. in case of table cache
overflow, SET @@global.table_open_cache, manager thread purging table cache).

The reason was missing mysql_cond_broadcast().
2016-09-22 10:21:12 +04:00
Sergey Vojtovich
0d88b97e1e MDEV-10296 - Multi-instance table cache
Fixed type cast.
2016-09-16 19:07:59 +04:00
Sergey Vojtovich
a2b1c58c19 MDEV-10296 - Multi-instance table cache
Fixed sysvars_server_[not]embedded failure: changed type of
table_open_cache_instances from ulong to uint.

Added casts foratomic operations around tc_active_instances and
tc_contention_warning_reported: needed on some platforms.
2016-09-16 18:41:21 +04:00
Sergey Vojtovich
8613633f26 MDEV-10296 - Multi-instance table cache
Table cache instances autosizing.
2016-09-16 15:46:15 +04:00
Sergey Vojtovich
7e9ac7b8ac MDEV-10296 - Multi-instance table cache
Improve scalability by implementing multi-instance table cache.
2016-09-16 15:46:15 +04:00
Nirbhay Choubey
7305be2f7e MDEV-5535: Cannot reopen temporary table
mysqld maintains a list of TABLE objects for all temporary
tables created within a session in THD. Here each table is
represented by a TABLE object.

A query referencing a particular temporary table for more
than once, however, failed with ER_CANT_REOPEN_TABLE error
because a TABLE_SHARE was allocate together with the TABLE,
so temporary tables always had only one TABLE per TABLE_SHARE.

This patch lift this restriction by separating TABLE and
TABLE_SHARE objects and storing TABLE_SHAREs for temporary
tables in a list in THD, and TABLEs in a list within their
respective TABLE_SHAREs.
2016-06-10 18:39:43 -04:00
Nirbhay Choubey
78d4276788 Some trivial changes. 2016-06-10 18:00:23 -04:00
Sergey Vojtovich
7ecb304996 Code cleanups
- unused TABLE_SHARE::deleting and TABLE_LIST::deleting flags were removed
- kill_delayed_threads_for_table() and intern_close_table() are now private
  methods of table cache
- removed free_share flag of closefrm(): it was never used for temporary
  tables and was rarely useful for regular tables
2016-06-10 17:37:12 +04:00
Sergey Vojtovich
d6d4011211 Move wait_for_mdl_deadlock_detector() call to tc_remove_table()
As a side effect tc_remove_all_unused_tables() has to call
tc_wait_for_mdl_deadlock_detector() once per TABLE object now, while it called
it only once before. This should be acceptable since actual wait will still be
performed only once. It only adds redundant checks for all_tables_refs.
2016-06-01 17:54:23 +04:00
Sergey Vojtovich
41dc2fc129 Move table cache private functions out of header
This is mostly needed to hide all references to free_tables, so that further
implementation of multi-instance list can be done completely inside
table_cache.cc
2016-06-01 17:14:43 +04:00
Sergey Vojtovich
f7048e9a92 Move common code to a separate function 2016-06-01 16:43:22 +04:00
Sergey Vojtovich
c42ffc1ca8 Cleanup All_share_tables_list definition 2016-03-22 18:01:40 +04:00
Sergey Vojtovich
c1d1c59888 MDEV-9488 - Table cache cleanups
Remove tdc_acquire_share() helpers: they don't actually make things simpler.
2016-02-26 18:35:14 +04:00
Sergey Vojtovich
d3af894235 MDEV-9488 - Table cache cleanups
tdc_assign_new_table_id() does not relate to table cache, move it out of
table_cache.cc.
2016-02-26 18:35:14 +04:00
Sergey Vojtovich
f4f37533a0 Replaced lf-hash element_size hack with initializer function. 2015-03-04 13:34:53 +04:00