[MDEV-7660] MySQL WL#6671 "Improve scalability by not using thr_lock.c locks for InnoDB tables" Created: 2015-03-04  Updated: 2022-10-03  Resolved: 2016-11-03

Status: Closed
Project: MariaDB Server
Component/s: Locking, Storage Engine - InnoDB, Storage Engine - XtraDB
Fix Version/s: 10.2.3

Type: Task Priority: Blocker
Reporter: Sergey Vojtovich Assignee: Sergey Vojtovich
Resolution: Fixed Votes: 0
Labels: foundation

Issue Links:
Duplicate
duplicates MDEV-7191 optimizations for THR_LOCK and mdl Closed
PartOf
includes MDEV-7894 ALTER TABLE ... IMPORT/DISCARD TABLES... Closed
includes MDEV-7895 HANDLER READ doesn't upgrade metadata... Closed
Problem/Incident
causes MDEV-11227 mysqlimport -l doesn't issue UNLOCK T... Closed
Relates
relates to MDEV-10245 Two concurrent OPTIMIZE on InnoDB tab... Closed
relates to MDEV-10719 'create temporary table as select' ge... Open
Sprint: 10.2.1-1, 10.2.1-2, 10.2.1-3, 10.2.1-4, 10.2.1-5, 10.2.2-1, 10.2.2-1, 10.2.2-2, 10.2.2-3, 10.2.2-4, 10.2.3-2, 10.0.28, 10.2.4-1

 Comments   
Comment by Sergey Vojtovich [ 2016-05-06 ]

jplindst, could you review last patch in bb-10.2-mdev7660?

All tests except for handler.innodb succeeded. The latter failed because LOCK TABLE ... WRITE didn't protect table from HANDLER ... READ.

I need your help to complete this patch, specifically:

  • fix LOCK TABLE ... WRITE to block concurrent HANDLER ... READ
  • fix LOCK TABLE ... READ to block concurrent DML

Test for handler (should hang):

--source include/have_xtradb.inc
 
CREATE TABLE t1(a INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES(1);
 
connect(con1, localhost, root);
HANDLER t1 OPEN;
 
connection default;
LOCK TABLE t1 WRITE;
 
connection con1;
HANDLER t1 READ NEXT;
disconnect con1;
 
connection default;
UNLOCK TABLES;
DROP TABLE t1;

Test for lock table read (should hang):

CREATE TABLE t1(a INT) ENGINE=InnoDB;
LOCK TABLE t1 READ;
 
connect(con1, localhost, root);
INSERT INTO t1 VALUES(1);
disconnect con1;
 
connection default;
UNLOCK TABLES;
DROP TABLE t1;

Comment by Sergey Vojtovich [ 2016-05-06 ]

Apparently LOCK TABLE ... WRITE blocks concurrent DML at MDL level. HANDLER ... READ is not blocked because it doesn't upgrade MDL lock.

It likely means that neither LOCK TABLE ... WRITE nor LOCK TABLE ... READ is currently handled by InnoDB.

Comment by Jan Lindström (Inactive) [ 2016-05-09 ]

Remember that InnoDB table locks are transactional, see http://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html , I see correct

dberr_t	error = row_lock_table_for_mysql(prebuilt, NULL, 0);

calls on ::external_lock(). I do not know about HANDLER ... xxx things.

Comment by Sergey Vojtovich [ 2016-05-09 ]

We can disregard LOCK TABLE ... WRITE as it is handled by MDL. We can also disregard HANDLER READ issue, since it is easily fixable at MDL level.

But what we should about LOCK TABLE ... READ? It doesn't block DML.

Comment by Jan Lindström (Inactive) [ 2016-05-12 ]

Why LOCK TABLE .. READ can't be handled on MDL level ?

Comment by Jan Lindström (Inactive) [ 2016-05-12 ]

Changes look ok.

Comment by Sergey Vojtovich [ 2016-05-12 ]

We discussed it in Berlin: we did want to let InnoDB handle LOCK TABLES. The reason is: LOCK TABLE ... READ requires substantial change to MDL.

Comment by Jan Lindström (Inactive) [ 2016-05-12 ]

ok, problem is that autocommit=1 at lock table read; i.e. correct way to use is:

--source include/have_innodb.inc
 
CREATE TABLE t1(a INT) ENGINE=InnoDB;
set autocommit=0;
LOCK TABLE t1 READ;
 
connect(con1, localhost, root);
INSERT INTO t1 VALUES(1);
disconnect con1;
 
connection default;
UNLOCK TABLES;
DROP TABLE t1;

Comment by Sergey Vojtovich [ 2016-05-12 ]

serg, with my patch returining 0 from ha_innobase::lock_count():

  • DDL works
  • DML works
  • LOCK TABLE ... WRITE is handled by MDL and works in all cases except for concurrent HANDLER READ
  • LOCK TABLE ... READ works reasonably when autocommit=0
  • LOCK TABLE ... READ has no effect when autocommit=1

Do you have any idea how can we fix the last point? Ignore it? Let LOCK TABLES start transaction?

Comment by Sergei Golubchik [ 2016-05-17 ]

Let LOCK TABLE start a transaction. Just make sure, please, it's clearly documented.

Comment by Sergey Vojtovich [ 2016-05-18 ]

jplindst, serg, should we start InnoDB internal transaction or call something like trans_begin()?

Comment by Sergei Golubchik [ 2016-05-18 ]

I think it's enough to disable auto-commit. Then if any innodb table was mentioned, it will open a transaction automatically.

Comment by Sergey Vojtovich [ 2016-05-24 ]

serg, please review 4 patches in bb-10.2-mdev7660. Please note that I don't feel confident about the last patch, which disables autocommit. I can't foresee all possible side effects.

Comment by Sergey Vojtovich [ 2016-07-05 ]

serg, please review my last comments, specifically what should we do about deadlock? Fix this particular thing on MDL level?

Comment by Sergei Golubchik [ 2016-09-02 ]

Will deadlock timeout in 50 seconds?

One simple workaround would be to have an option, like, --innodb-locks-unsafe-for-handler, and only use this optimization if it's true.

Ideally, the server should be able to break InnoDB locks.

Comment by Sergey Vojtovich [ 2016-10-13 ]

serg, please review latest patch at https://github.com/MariaDB/server/commit/c90bd38809582b27696a68058fbd57c57d6dbf6d

Generated at Thu Feb 08 07:21:18 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.