Skip to content

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

Open

Description

@ufedaseyeuconsultant

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 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions