- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 sqlalchemy 的 InnoDB 表中遇到死锁是个大问题。
sqlalchemy.exc.InternalError: (mysql.connector.errors.InternalError) 1213 (40001): Deadlock found when trying to get lock; try restarting transaction.
我已经序列化了访问,但仍然出现死锁错误。
此代码在每个函数的第一次调用时执行。每个线程和进程都应该在这里等待,直到它获得锁。它被简化了,因为选择器被删除了。
# The work with the index -1 always exists.
f = s.query(WorkerInProgress).with_for_update().filter(
WorkerInProgress.offset == -1).first()
我已将我的代码减少到最小状态。我目前只对 next_slice 方法运行并发调用。 session 处理、回滚和死锁处理在外部处理。
即使所有访问都是序列化的,我也会遇到死锁。我也尝试在 offset == -1 实体中增加一个重试计数器。
def next_slice(self, s, processgroup_id, itemcount):
f = s.query(WorkerInProgress).with_for_update().filter(
WorkerInProgress.offset == -1).first()
#Take first matching object if available / Maybe some workers failed
item = s.query(WorkerInProgress).with_for_update().filter(
WorkerInProgress.processgroup_id != processgroup_id,
WorkerInProgress.processgroup_id != 'finished',
WorkerInProgress.processgroup_id != 'finished!locked',
WorkerInProgress.offset != -1
).order_by(WorkerInProgress.offset.asc()).limit(1).first()
# *****
# Some code is missing here. as it's not executed in my testcase
# Fetch the latest item and add a new one
item = s.query(WorkerInProgress).with_for_update().order_by(
WorkerInProgress.offset.desc()).limit(1).first()
new = WorkerInProgress()
new.offset = item.offset + item.count
new.count = itemcount
new.maxtries = 3
new.processgroup_id = processgroup_id
s.add(new)
s.commit()
return new.offset, new.count
我不明白为什么会出现死锁。
我通过在一个查询中获取所有项目减少了死锁,但仍然遇到死锁。也许有人可以帮助我。
最佳答案
终于解决了我的问题。文档里都有,但是我得先了解一下。
Always be prepared to re-issue a transaction if it fails due to deadlock. Deadlocks are not dangerous. Just try again.
Source: http://dev.mysql.com/doc/refman/5.7/en/innodb-deadlocks-handling.html
我已经通过更改这部分的架构解决了我的问题。我仍然遇到很多死锁,但它们几乎出现在短运行方法中。我已将我的工作表拆分为锁定部分和非锁定部分。锁定部分的操作现在非常短,在 get_slice、finish_slice 和 fail_slice 操作期间没有处理任何数据。
具有数据处理的事务部分现在处于非锁定部分并且不能并发访问表行。结果存储在 finish_slice 和 fail_slice 到锁定表中。
最后我在 stackoverflow 上也找到了一个很好的描述。确定正确的搜索词后。 https://stackoverflow.com/a/2596101/5532934
关于python - SQLAlchemy/MySQL 序列化访问死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39190752/
我有类似下面的代码: ... id: myComponent signal updateState() property variant modelList: [] Repeater { mo
我正在处理一些我无法展示的私有(private)代码,但我已经制作了一些示例代码来描述我的问题: 主.c: #include #include #include #include typede
这个问题在这里已经有了答案: 关闭10 年前。 Possible Duplicate: what are the differences in die() and exit() in PHP? 我想
在编写 Perl 模块时,在模块内部使用 croak/die 是一个好习惯吗? 毕竟,如果调用者不使用 eval block ,模块可能会使调用它的程序崩溃。 在这些情况下,最佳做法是什么? 最佳答案
我有一些搜索线程正在存储结果。我知道当线程启动时,JVM native 代码会代理在操作系统上创建新 native 线程的请求。这需要 JVM 之外的一些内存。当线程终止并且我保留对它的引用并将其用作
我刚刚花了很多时间调试一个我追溯到 wantarray() 的问题。 .我已将其提炼为这个测试用例。 (忽略 $! 在这种情况下不会有任何有用信息的事实)。我想知道为什么wantarray在第二个示例
我看到一些代码是这样做的: if(something){ echo 'exit from program'; die; } ...more code 和其他只使用 die 的人: if
我正在尝试将此表格用于: 如果任何 $_POST 变量等于任何其他 $_POST 变量抛出错误。 如果只有几个,那不是问题,但我有大约 20 个左右所以如果我想这样做,我将不得不像这样 但这
每次我运行: hadoop dfsadmin -report 我得到以下输出: Configured Capacity: 0 (0 KB) Present Capacity: 0 (0 KB) DFS
我是一名优秀的程序员,十分优秀!