[BE] Move the competency authoring mutex off the shared Tag row onto a CBE-owned lock row

Aperta
#935 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
django, mysql, python
Ambito
backend, databases

Direzione di ricerca

Start with the four criteria writers that call Tag.objects.select_for_update() (associate_competency_criterion, create_competency_criterion, bulk_update_competency_criteria, update_competency_criteria_group, delete_or_archive_competency_criterion) and the CompetencyCourseRun model as the pattern to copy. Read test_criterion_concurrency.py and the run_when_tag_lock_is_taken fixture in the CBE test conftest, since the SQLite lock-point tests pin the old call and must be rewritten. Done when all writers lock the new per-competency row, the MySQL two-connection tests pass, and ADR-0004's Decision 6 note is updated.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

User Story

As an Open edX operator, I want competency authoring requests to serialize on a row the CBE app owns, in order to keep other parts of the platform from waiting on a lock they know nothing about.

Description

The four competency criteria writers (create criterion, bulk update criteria, update group, delete criterion) serialize per competency by taking a select_for_update() lock on the competency's Tag row in openedx_tagging. We need the same serialization on a CBE-owned per-competency row instead, so that inserts referencing the Tag row elsewhere in the platform stop waiting on authoring transactions.

Low priority: the Tag lock is accepted for MVP, and the cost is small (waiters hold for one authoring transaction, and the known deadlock cycles fail one request loudly with no corruption).

Context

Acceptance Criteria

Scenario: authoring requests for one competency still run one at a time
  Given two concurrent authoring requests for the same competency, one deleting a criterion and one bulk-updating it
  When both run to completion
  Then one waits for the other and neither fails with a deadlock error

Scenario: tagging content with a competency no longer waits for an authoring request
  Given an authoring request for a competency is holding its per-competency lock
  When another request tags unrelated content with that competency through the tagging API
  Then the tagging request completes without waiting for the authoring request to commit

Scenario: authoring requests for different competencies do not serialize on each other
  Given two concurrent authoring requests for two different competencies
  When both run
  Then neither waits on the other's lock

Technical Details

Technical Details

This is a suggested approach, not the source of truth. The User Story, Description, and Acceptance Criteria define what must be true when the work is done.

Summary

Add a CBE-owned per-competency lock row, created with get_or_create() and locked with select_for_update(), and point all four writers at it instead of the Tag row, following the CompetencyCourseRun pattern.

Approach

  • A small model (for example CompetencyLock, a OneToOne on the competency's Tag) whose only job is to be the lock target; get_or_create() before the locking read, since a locking read of a row that doesn't exist locks nothing.
  • Replace the Tag.objects.select_for_update() reads in associate_competency_criterion, create_competency_criterion, bulk_update_competency_criteria, update_competency_criteria_group, and delete_or_archive_competency_criterion.
  • The two-connection MySQL tests in test_criterion_concurrency.py assert outcomes, so they must stay green and survive the move (the lock-probe test asserts the lock target and changes with the model). The SQLite lock-point tests built on the run_when_tag_lock_is_taken fixture in the CBE test conftest pin Tag.objects.select_for_update as the call being made, so they all need rewriting against the new lock target; the reviewer on https://github.com/openedx/openedx-core/pull/879 flagged exactly this and advised leaning on the MySQL outcome tests rather than adding more call-site pins.
  • ADR-0004's Decision 6 note on the authoring writers moves to the new row.
Lingua principale
Python
Stelle
10
Fork
35
Merge medio
5g 2h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openedx/openedx-core

Tutte le issue di openedx/openedx-core

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.