MySQL Race Conditions

后端 未结 4 899
半阙折子戏
半阙折子戏 2021-01-07 06:15

Does this cause a race condition with MySQL (InnoDB):

  1. Start Transaction.

  2. Try to get record.

  3. If record doesn\'t exist, return

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 06:55

    Use 'select for update' at step 2. Only one process will be able to get a lock on the row thus avoiding the scenario you described.

提交回复
热议问题