Skip to content

Commit 6b2927e

Browse files
committed
Change redis worker task pickup algo to respect FIFO shared resources
fixes: #7616
1 parent 653a3b3 commit 6b2927e

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

CHANGES/7616.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed RedisWorker not always respecting FIFO order of tasks with shared resources.

pulpcore/tasking/redis_worker.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ def fetch_task(self):
439439
fetch_limit = FETCH_TASK_LIMIT
440440

441441
while True:
442-
blocked_exclusive = set()
443-
blocked_shared = set()
442+
taken_exclusive = set()
443+
taken_shared = set()
444444

445445
waiting_tasks = list(
446446
Task.objects.filter(state=TASK_STATES.WAITING, app_lock=None)
@@ -455,39 +455,33 @@ def fetch_task(self):
455455
for task in waiting_tasks:
456456
try:
457457
exclusive_resources, shared_resources = extract_task_resources(task)
458-
459458
should_skip = False
460459

461460
for resource in exclusive_resources:
462-
if resource in blocked_exclusive or resource in blocked_shared:
461+
if resource in taken_exclusive or resource in taken_shared:
463462
should_skip = True
464463
break
465464

466465
if not should_skip:
467466
for resource in shared_resources:
468-
if resource in blocked_shared:
467+
if resource in taken_exclusive:
469468
should_skip = True
470469
break
471470

471+
taken_exclusive.update(exclusive_resources)
472+
taken_shared.update(shared_resources)
472473
if should_skip:
473474
continue
474475

475476
task_lock_key = get_task_lock_key(task.pk)
476-
477477
blocked_resource_list = acquire_locks(
478478
self.redis_conn,
479479
self.name,
480480
task_lock_key,
481481
exclusive_resources,
482482
shared_resources,
483483
)
484-
485484
if blocked_resource_list:
486-
if "__task_lock__" not in blocked_resource_list:
487-
blocked_exclusive.update(exclusive_resources)
488-
for resource in shared_resources:
489-
if resource in blocked_resource_list:
490-
blocked_shared.add(resource)
491485
continue
492486

493487
rows = Task.objects.filter(

0 commit comments

Comments
 (0)