10:29:07,903 [31505] Scheduler - ERROR - Error cleaning up
10:29:07,904 [31505] Scheduler - ERROR - (1213, u'Deadlock found when trying to get lock; try restarting transaction')
10:29:07,904 [31499] Scheduler - ERROR - Error retrieving status
10:29:07,904 [31499] Scheduler - ERROR - (1213, u'Deadlock found when trying to get lock; try restarting transaction')
------------------------
LATEST DETECTED DEADLOCK
------------------------
...
LOCK WAIT 3 lock struct(s), heap size 1184, 2 row lock(s)
...
UPDATE scheduler_worker SET status='ACTIVE',last_heartbeat='2016-10-27 10:10:22',worker_stats='{"status": "ACTIVE", "errors": 0, "workers": 0, "queue": 0, "empty_runs": 3, "sleep": 5, "distribution": null, "total": 152}' WHERE (scheduler_worker.worker_name = 'aradev2.ad-00.ent-01.adgroup#31499')
...
DELETE FROM scheduler_worker WHERE (((scheduler_worker.last_heartbeat < '2016-10-27 10:10:07') AND (scheduler_worker.status = 'ACTIVE')) OR ((scheduler_worker.last_heartbeat < '2016-10-27 10:06:37') AND (scheduler_worker.status <> 'ACTIVE')))
------------------------
LATEST DETECTED DEADLOCK
------------------------
...
LOCK WAIT 3 lock struct(s), heap size 1184, 2 row lock(s)
...
UPDATE scheduler_worker SET status='ACTIVE',last_heartbeat='2016-10-27 11:03:06',worker_stats='{"status": "ACTIVE", "errors": 0, "workers": 0, "queue": 0, "empty_runs": 4, "sleep": 5, "distribution": null, "total": 60}' WHERE (scheduler_worker.worker_name = 'aradev2.ad-00.ent-01.adgroup#14665')
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 915 page no 3 n bits 80 index `PRIMARY` of table `arm`.`scheduler_worker` trx table locks 1 total table locks 3 trx id 14202929 lock_mode X locks rec but not gap waiting lock hold time 0 wait time before grant 0
*** (2) TRANSACTION:
TRANSACTION 14202927, ACTIVE 0 sec fetching rows
mysql tables in use 1, locked 1
7 lock struct(s), heap size 1184, 47 row lock(s)
MySQL thread id 60199, OS thread handle 0x7f73df089b00, query id 13827564 aradev2.ad-00.ent-01.adgroup 10.220.43.234 armdba updating
DELETE FROM scheduler_worker WHERE (((scheduler_worker.last_heartbeat < '2016-10-27 11:02:51') AND (scheduler_worker.status = 'ACTIVE')) OR ((scheduler_worker.last_heartbeat < '2016-10-27 10:59:21') AND (scheduler_worker.status <> 'ACTIVE')))
The use of explicit locking can increase the likelihood of deadlocks, wherein two (or more) transactions each hold locks that the other wants. For example, if transaction 1 acquires an exclusive lock on table A and then tries to acquire an exclusive lock on table B, while transaction 2 has already exclusive-locked table B and now wants an exclusive lock on table A, then neither one can proceed. PostgreSQL automatically detects deadlock situations and resolves them by aborting one of the transactions involved, allowing the other(s) to complete. (Exactly which transaction will be aborted is difficult to predict and should not be relied upon.)
/*-----------------------------------------------------------------------------------------------------------*/
if len(db.executesql(dead_workers_name)) > 0:
db(
(st.assigned_worker_name.belongs(dead_workers_name)) &
(st.status == RUNNING)
).update(assigned_worker_name='', status=QUEUED)
dead_workers.delete()