gpt4 book ai didi

mysql - ActiveRecord::StatementInvalid: Mysql2::Error: 超过锁定等待超时

转载 作者:可可西里 更新时间:2023-11-01 07:43:53 31 4
gpt4 key购买 nike

在我的rails项目中,我使用sidekiq处理耗时任务,但是在sidekiq中记录了一个错误:

ActiveRecord::StatementInvalid: Mysql2::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `marker_layers` SET `show_fields` = 'title,desc', `sort_col` = 'title,desc', `updated_at` = '2016-05-17 07:36:02' WHERE `marker_layers`.`id` = 16021210
Processor: iZ23edse84Z:29310

enter image description heresidekiq.yml

# Options here can still be overridden by cmd line args.
# setsid sidekiq -d -C config/sidekiq.yml -e production
---
:concurrency: 5
:pidfile: tmp/pids/sidekiq.pid
:logfile: log/sidekiq.log
staging:
:concurrency: 10
production:
:concurrency: 40
:queues:
- ['critical', 3]
- ['default', 2]
- ['low', 1]

数据库.yml

production:
adapter: mysql2
encoding: utf8mb4
collation: utf8mb4_bin
reconnect: false
database: database_name
pool: 48
username: password
password: password
host: locahost

最佳答案

发生此错误的原因是当不同的工作人员试图修改同一资源时发生事务超时,基本上是数据库死锁。

如果您像 SomeModel.transaction { SomeModel.task_that_takes_too_much_time } 那样显式使用事务,或者使用修改记录的普通 ActiveRecord 方法,就会发生这种情况,因为所有内容都包含在事务中。

我能给你的唯一建议是探索让你的 worker 独一无二的替代方案,比如使用https://github.com/mhenrixon/sidekiq-unique-jobs并让您的作业使用 .perform_in

关于mysql - ActiveRecord::StatementInvalid: Mysql2::Error: 超过锁定等待超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37270485/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com