Repository navigation
Description
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
- The Tag lock and the one-lock writer rule landed with feat: add endpoint to delete or archive a CompetencyCriterion (#674) #879 ([BE] Delete Competency Criterion #674); that PR's review accepted the Tag row for MVP and asked for this follow-up.
- Alezconsultant/665 criterion endpoint on 846 #847 first added the Tag lock, and the maintainer asked there not to rely on locking the Tag long term. Its earlier follow-up, [BE] Enforce one root Competency Criteria Group per competency in the database #872, replaced the lock's one-root guarantee with a database constraint (feat: enforce one root criteria group per competency in the database #900) but kept the lock for the duplicate-criterion check, which no constraint can express.
CompetencyCourseRunis the repo's precedent for this pattern: CBE locks its own row rather than the catalog'sCourseRun, so other apps' writes don't block.- While an authoring request holds the Tag lock, every insert referencing that
Tagrow waits on InnoDB's foreign-key shared lock: object tags from ordinary Studio tagging, child tags from a taxonomy import, andStudentCompetencyStatusrows.
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 lockTechnical 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'sTag) 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 inassociate_competency_criterion,create_competency_criterion,bulk_update_competency_criteria,update_competency_criteria_group, anddelete_or_archive_competency_criterion. - The two-connection MySQL tests in
test_criterion_concurrency.pyassert 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 therun_when_tag_lock_is_takenfixture in the CBE test conftest pinTag.objects.select_for_updateas the call being made, so they all need rewriting against the new lock target; the reviewer on feat: add endpoint to delete or archive a CompetencyCriterion (#674) #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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNeeds additional details
Activity
feat: add endpoint to delete or archive a CompetencyCriterion (opened…
feat: add endpoint to delete or archive a CompetencyCriterion (#674) (#…