更新 `djcelery_periodictask` 时死锁 table
Deadlock when updating `djcelery_periodictask` table
我有两个简单的周期性芹菜任务,运行 在晚上,一个在凌晨 2 点,另一个在凌晨 3 点,然后从时间开始抛出关于 djcelery_periodictask
[=19= 死锁的异常] 这我不太明白。似乎一个任务试图更新 djcelery_periodictask
而另一个任务仍然持有共享锁:
deadlock detected Detail: Process 32353 waits for ShareLock on transaction 39280165; blocked by process 32306. Process 32306 waits for ShareLock on transaction 39280166; blocked by process 32353.
Process 32353:
UPDATE "djcelery_periodictask" SET "name" = 'app.tasks.task1', "task" = 'app.tasks.task1', "interval_id" = NULL, "crontab_id" = 4, "args" = '[]', "kwargs" = '{}', "queue" = NULL, "exchange" = NULL, "routing_key" = NULL, "expires" = NULL, "enabled" = true, "last_run_at" = '2015-02-10 03:00:00.001297+01:00', "total_run_count" = 117, "date_changed" = '2015-02-10 02:00:00.010033+00:00', "description" = '' WHERE "djcelery_periodictask"."id" = 4
Process 32306:
UPDATE "djcelery_periodictask" SET "name" = 'app.tasks.task2', "task" = 'app.tasks.task2', "interval_id" = NULL, "crontab_id" = 6, "args" = '[]', "kwargs" = '{}', "queue" = NULL, "exchange" = NULL, "routing_key" = NULL, "expires" = NULL, "enabled" = true, "last_run_at" = '2015-02-10 02:00:00.014189+01:00', "total_run_count" = 63, "date_changed" = '2015-02-10 02:00:00.015097+00:00', "description" = '' WHERE "djcelery_periodictask"."id" = 6
Hint: See server log for query details. Query:
UPDATE "djcelery_periodictask" SET "name" = 'app.tasks.task2', "task" = 'appt.tasks.task2', "interval_id" = NULL, "crontab_id" = 4, "args" = '[]', "kwargs" = '{}', "queue" = NULL, "exchange" = NULL, "routing_key" = NULL, "expires" = NULL, "enabled" = true, "last_run_at"
table 上仅包含几行的两个简单更新怎么会陷入死锁?
我的问题是我让我的所有工作人员都以 -B
参数开始,这使每个工作人员都处于周期性任务调度程序中:
-B, --beat Also run the celery beat periodic task scheduler.
Please note that there must only be one instance of
this service.
因此,计划任务启动了多次,全部同时启动,在尝试更新 djcelery_periodictask
table.
时造成死锁
我有两个简单的周期性芹菜任务,运行 在晚上,一个在凌晨 2 点,另一个在凌晨 3 点,然后从时间开始抛出关于 djcelery_periodictask
[=19= 死锁的异常] 这我不太明白。似乎一个任务试图更新 djcelery_periodictask
而另一个任务仍然持有共享锁:
deadlock detected Detail: Process 32353 waits for ShareLock on transaction 39280165; blocked by process 32306. Process 32306 waits for ShareLock on transaction 39280166; blocked by process 32353.
Process 32353:
UPDATE "djcelery_periodictask" SET "name" = 'app.tasks.task1', "task" = 'app.tasks.task1', "interval_id" = NULL, "crontab_id" = 4, "args" = '[]', "kwargs" = '{}', "queue" = NULL, "exchange" = NULL, "routing_key" = NULL, "expires" = NULL, "enabled" = true, "last_run_at" = '2015-02-10 03:00:00.001297+01:00', "total_run_count" = 117, "date_changed" = '2015-02-10 02:00:00.010033+00:00', "description" = '' WHERE "djcelery_periodictask"."id" = 4
Process 32306:
UPDATE "djcelery_periodictask" SET "name" = 'app.tasks.task2', "task" = 'app.tasks.task2', "interval_id" = NULL, "crontab_id" = 6, "args" = '[]', "kwargs" = '{}', "queue" = NULL, "exchange" = NULL, "routing_key" = NULL, "expires" = NULL, "enabled" = true, "last_run_at" = '2015-02-10 02:00:00.014189+01:00', "total_run_count" = 63, "date_changed" = '2015-02-10 02:00:00.015097+00:00', "description" = '' WHERE "djcelery_periodictask"."id" = 6
Hint: See server log for query details. Query:
UPDATE "djcelery_periodictask" SET "name" = 'app.tasks.task2', "task" = 'appt.tasks.task2', "interval_id" = NULL, "crontab_id" = 4, "args" = '[]', "kwargs" = '{}', "queue" = NULL, "exchange" = NULL, "routing_key" = NULL, "expires" = NULL, "enabled" = true, "last_run_at"
table 上仅包含几行的两个简单更新怎么会陷入死锁?
我的问题是我让我的所有工作人员都以 -B
参数开始,这使每个工作人员都处于周期性任务调度程序中:
-B, --beat Also run the celery beat periodic task scheduler.
Please note that there must only be one instance of
this service.
因此,计划任务启动了多次,全部同时启动,在尝试更新 djcelery_periodictask
table.