Search code examples
mysqlsqlruby-on-railslockingsidekiq

Mysql lock with parallel update on same entry (with sidekiq)


I have a concurrency problem of access to my mysql db when using parallel workers with Sidekiq :

I have in my output sidekiq console a freeze during 50 seconds in average (after this, the job is done: "INFO: done: 50.954 sec", and the others can begin). I have a problem of lock, I don't understand why and how resolve it?

Error in output : "WARN: Mysql::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE actors SET x = ? WHERE actor_id = 1"

There are simultaneous write in same entry in my db, but why lock system don't manage it to do update sql, one by one, in order of arival ? Why wait 50 seconds !!??

How can I resolve this problem?

thx.


Solution

  • for people who vote +1 on question :

    I slove my problem when I see the stupid misstake: I scheduled job with variable, but without put the good value into, so I scheduled job with 0 second, and in each job, I reenque a scheduled job in 0s... etc

    that a infinite loop causing irremediably a conflict on db access.