loopbackio / loopbackio/loopback-datasource-juggler

concurrent transaction throw deadlock error

オープン
#1,905 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug needs grooming
主要言語
JavaScript
スター
282
フォーク
366
平均マージ
17時間 4分
マージ済み PR(30日)
10

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue のトランザクションコードから始め、2 つの pm2 インスタンス、MySQL、および指定された JMeter の同時実行数を使って、報告されたワークロードを再現します。すべてのパスでトランザクションが一貫してコミットまたはロールバックされるかを確認します。deadlock の原因を特定するか、アプリケーションコードが原因ではないことを確認できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, mysql
領域
backend, database
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。