concurrent transaction throw deadlock error

未关闭
#1,905 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
javascript, mysql
领域
backend, database

调研方向

从 issue 中的事务代码开始,使用两个 pm2 实例、MySQL 以及所述的 JMeter 并发数复现报告的工作负载。检查事务在每条路径上是否始终一致地提交或回滚;完成的标准是确定 deadlock 的原因,或确认应用程序代码不负责任。

由索引模型根据 Issue 内容生成。

描述

bug needs grooming
pm2 start server with two instance ,
two instance connect one mysql server.

1637033091(1)

  Component.queue = async (obj, appId, projectId, accessToken) => {
    const Project = Component.app.models.project;
    const Page = Component.app.models.page;
    const tx = await Project.beginTransaction({
      isolationLevel: Project.Transaction.REPEATABLE_READ
    });
    const options = { transaction: tx };
    try {
      const userId = accessToken.userId;
      const { pageId, data = [] } = obj;
      const project = await Project.findOne({
        where: { id: projectId, appId, ownerId: userId }
      }, options);
      const info = await Project.updateAll(
        { id: projectId },
        { lastUpdate: new Date() },
        options
      );

      let page = await Page.findById(pageId, options);
      let pages = await Page.find({
        where: { projectId }
      }, options)

      pages.forEach(page => {
        if (page.uuid)
          idMap[page.uuid] = page.id;
      })
      let components = await Component.find(
        {
          where: { projectId, pageId: page.id },
          fields: ["id", "uuid"]
        }, options
      )
      await Page.updateAll({ id: page.id }, { isNeedGenerate: true }, options);
      await tx.commit();
      return { success: true };
    } catch (err) {
      if (tx) {
        await tx.rollback();
      }
  };

i use Jmeter test it , with 50 threads / sec, then throw error
but threads number small for example less than 10, they work well,
mysql deallock

1637032830(1)

error

1637033134(1)

so,did i write the code ok ? thanks

it seem miss commit or rollback while concurrent

主要语言
JavaScript
星标
279
派生
362
平均合并
21 小时 14 分钟
30 天内合并 PR
16

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

loopbackio/loopback-datasource-juggler 的其他 Issue

查看 loopbackio/loopback-datasource-juggler 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。