【问题标题】:MySQL Cluster Error: Lock wait timeout exceededMySQL 集群错误:超过锁定等待超时
【发布时间】:2013-09-06 09:37:00
【问题描述】:

我试图将一个约 200G 的文件加载到具有 4 个数据节点的 MySQL 集群中,而我的目标表的 DDL 是这样的:

CREATE TABLE  XXXXXX
(
     ID BIGINT AUTO_INCREMENT PRIMARY KEY,
     COL1...,
     COL2...,
     .......
)
ENGINE = NDB PARTITION BY KEY();

加载几分钟后,我收到以下错误:

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

我发现一些记录加载到目标表中。我应该怎么做才能克服这个问题?

一些可能有用的变量值:

wait_timeout      : 28800
ndb_wait_connected: 30
ndb_wait_setup    : 30

【问题讨论】:

    标签: mysql mysql-cluster


    【解决方案1】:

    我已经看到带有 BLOB/TEXT 条目 + 长时间运行选择的表的问题。 NDB 使用隐藏表来存储较大对象的块,并作为副作用唯一键 SELECT 为表创建共享读锁。见http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-limitations-transactions.html

    所以在一个两节点集群上

    node2> show create table test;
    
    | test  | CREATE TABLE `test` (
      `id` bigint(20) NOT NULL AUTO_INCREMENT,
      `i` int(11) DEFAULT NULL,
      `v1` text,
      PRIMARY KEY (`id`),
      UNIQUE KEY `i` (`i`)
    ) ENGINE=ndbcluster AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 |
    
    node2> set @@autocommit=0;
    Query OK, 0 rows affected (0.00 sec)
    
    node2> set @@tx_isolation='READ-COMMITTED';
    Query OK, 0 rows affected (0.00 sec)
    
    node2> start transaction;
    node2> select v1 from test where i=2;  #shared lock is created
    

    在第二个节点上,表的更新可能会失败。

    node1>  set @@autocommit=0;
    Query OK, 0 rows affected (0.00 sec)
    
    node1> set @@tx_isolation='READ-COMMITTED';
    Query OK, 0 rows affected (0.00 sec)
    
    node1> update test set v1='a' where i=2;
    ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
    node1> load data infile '/tmp/data' replace into table test;
    ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
    

    根据版本,您可能会看到不同的错误,例如

    mysql> load data infile '/tmp/data' replace into table test;
    ERROR 1296 (HY000): Got error 4350 'Transaction already aborted' from NDBCLUSTER
    

    【讨论】:

    • Attila,你是如何在数据节点中设置 autocommit=0 的?我有四个数据节点和 1 个 sql 节点。
    • @MikA:术语自动提交仅适用于 sql 节点。
    • set @@tx_isolation='READ-COMMITTED'; 没有意义,因为 NDBCLUSTER 存储引擎支持 READ COMMITTED 事务隔离级别。 Documentation.
    • @Slava: 当然可以,但是使用tx_isolation='READ_UNCOMMITTED' 你可能没有这个锁定问题
    • MySQL 集群不支持 READ-UNCOMMITTED。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 2017-12-26
    • 2015-07-18
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多