Skip to content

[SE-4101] fix: address VisibleBlocks caching race condition - #27359

Merged
nsprenkle merged 5 commits into
openedx:masterfrom
open-craft:gabor/persistent-grades-patch
May 5, 2021
Merged

[SE-4101] fix: address VisibleBlocks caching race condition#27359
nsprenkle merged 5 commits into
openedx:masterfrom
open-craft:gabor/persistent-grades-patch

Conversation

@gabor-boros

Copy link
Copy Markdown
Contributor

This PR is trying to address a hard-to-reproduce VisibleBlocks per-user caching issue in which case bulk create results an IntegrityError, though it shouldn't

Discussions: Forum post

Dependencies: None

Sandbox URL: N/A - We were not able to produce a sandbox which can "consistently" show the issue.

Merge deadline: None

Testing instructions:

  1. Read through the code

Author notes and concerns:

This fix is deployed for one of our clients and it is working well. We did no see issues since we applied the patch.

  1. The issue is really hard to reproduce as it is based on a possible race condition

Reviewers

@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @gabor-boros! I've created OSPR-5743 to keep track of it in JIRA, where we prioritize reviews. Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added needs triage open-source-contribution PR author is not from Axim or 2U labels Apr 15, 2021
@gabor-boros gabor-boros changed the title fix: address VisibleBlocks caching race condition [SE-4101] fix: address VisibleBlocks caching race condition Apr 15, 2021
@natabene

Copy link
Copy Markdown
Contributor

@gabor-boros Thank you for your contribution. Please let me know once it is ready for our review.

@gabor-boros

Copy link
Copy Markdown
Contributor Author

@natabene This is ready for your review, thank you! 🎉

@nedbat

nedbat commented Apr 29, 2021

Copy link
Copy Markdown
Contributor

Let me know when this merges, it could be applied to Koa and Lilac.

@natabene

Copy link
Copy Markdown
Contributor

@nsprenkle Hi Nathan, this is good for your review when you have a moment.

@nsprenkle

Copy link
Copy Markdown
Contributor

@gabor-boros, in PROD this is probably caused by a race condition. In dev environments, I can reliably reproduce by doing some database manipulation.

TL;DR - we need to force a creation that conflicts with an existing visible blocks cache entry. A way to do this is turning off the assume_zero_if_absent functionality and deleting a user's grade data from the database.

Steps to reproduce

  1. As a student, visit a course set up with Persistent grades enabled (default) and submit some graded responses.
  2. This creates some subsection grades and visible block entries. Verify with the queries below:
    1. Get user ID: select id from auth_user where username = <username>
    2. Verify that there subsection grade entries for user: select id, created, modified, usage_key from grades_persistentsubsectiongrade where user_id = <user-id> and course_id = <course-id>;
  3. As the student, visit the progress page. It should load normally with grades.
  4. As staff, disable assume zero flag from Django admin:
    1. Django-waffle > Switches > grades.assume_zero_if_absent = inactive
  5. As super user, delete persisted course grade and subsection grades for user
    1. Go to SQL shell. For Devstack: make mysql-shell-edxapp
    2. Delete course grades for user (see queries): delete from grades_persistentcoursegrade where user_id = <user-id> and course_id =<course-id>;
    3. Get subsection grade IDs for user: select id from grades_persistentsubsectiongrade where user_id = <user-id> and course_id = <course-id>;
    4. Delete subsection grade overrides for user: delete from grades_persistentsubsectiongradeoverride where grade_id in(<subsection-grade-ids>);
    5. Delete subsection grades for user: delete from grades_persistentsubsectiongrade where user_id = <user-id> and course_id = <course-id>;
  6. As a student, revisit the progress page. This will see missing persisted grades and try to create (instead of update) existing cache entry, causing a collision.

@nsprenkle

Copy link
Copy Markdown
Contributor

From testing, this does appear to fix the issue. It also only runs once when the error condition first occurs (instead of every re-query for course grade) which is nice. So, although it slows the query down one time during these race conditions (which I still don't understand well), it should be a one-time impact.

@nsprenkle
nsprenkle self-requested a review April 30, 2021 17:33
@nsprenkle

Copy link
Copy Markdown
Contributor

@mattcarter, since we had talked about this briefly, I'm comfortable approving insofar as this appears to fix the issue but wanted to bring you in for any further DB related concerns.

@nsprenkle

Copy link
Copy Markdown
Contributor

@gabor-boros, this looks good for fixing the bug 👍

One request: can you add a log statement at the top level of the except IntegrityError with user/course? I think it might be helpful to start gathering data on when/where this error occurs.

@gabor-boros

gabor-boros commented May 4, 2021

Copy link
Copy Markdown
Contributor Author

@nsprenkle
First of all, thank you for reviewing the Pull Request!

One request: can you add a log statement at the top level of the except IntegrityError with user/course?

That's actually a pretty good idea, I'll add that change today

@gabor-boros

Copy link
Copy Markdown
Contributor Author

@nsprenkle added the logging statement. The wording may not the best. If you have an idea about a better message, feel free to let me know and I'll adjust the log message.

@edx-status-bot

Copy link
Copy Markdown

Your PR has finished running tests. There were no failures.

@nsprenkle nsprenkle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fabulous :)

@nsprenkle
nsprenkle merged commit 6ccdaca into openedx:master May 5, 2021
@openedx-webhooks

Copy link
Copy Markdown

@gabor-boros 🎉 Your pull request was merged!

Please take a moment to answer a two question survey so we can improve your experience in the future.

@nsprenkle

Copy link
Copy Markdown
Contributor

@nedbat, resurfacing for possible inclusion into Koa & Lilac

@gabor-boros
gabor-boros deleted the gabor/persistent-grades-patch branch May 5, 2021 14:41
gabor-boros added a commit to open-craft/openedx-platform that referenced this pull request May 5, 2021
…27359)

* fix: address VisibleBlocks caching race condition
* sets visual block creation in an atomic transaction
* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
gabor-boros added a commit to open-craft/openedx-platform that referenced this pull request May 5, 2021
…27359) (#349)

* fix: address VisibleBlocks caching race condition
* sets visual block creation in an atomic transaction
* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>

Co-authored-by: Raul Gallegos <raul@opencraft.com>
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

EdX Release Notice: This PR has been deployed to the production environment.

nedbat pushed a commit that referenced this pull request May 14, 2021
* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
(cherry picked from commit 6ccdaca)
nedbat pushed a commit that referenced this pull request May 14, 2021
* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
(cherry picked from commit 6ccdaca)
@nedbat

nedbat commented May 14, 2021

Copy link
Copy Markdown
Contributor

@nsprenkle thanks, I've cherry-picked this onto Koa and Lilac.

sambapete added a commit to EDUlib/edx-platform that referenced this pull request May 17, 2021
…27359)

* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
(cherry picked from commit 6ccdaca)
gabor-boros added a commit to open-craft/openedx-platform that referenced this pull request Jul 14, 2021
* [SE-4101] fix: address VisibleBlocks caching race condition (openedx#27359) (#349)

* fix: address VisibleBlocks caching race condition
* sets visual block creation in an atomic transaction
* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>

Co-authored-by: Raul Gallegos <raul@opencraft.com>

* BB-3954 Add toggle for enrollment behavior (#351)

Adds toggle REDIRECT_UNAUTHENTICATED_USER_TO_LOGIN_ON_ENROLL
for enrollment behaviour for unauthenticated user.
If true, the user will be redirected to 'signin_user' route.

Co-authored-by: Arjun Singh Yadav <arjun@opencraft.com>

* [BB-3622] feat:Restrict user create course (#319) (#352)

* Add course creation condition for organization

The condition added to ensure that if the feature is enabled
user will not be able to create the course outside of the organization
in which they belong.

Signed-off-by: Farhaan Bukhsh <farhaan@opencraft.com>

* fix: update the xblock-lti-consumer commit

* Added new setting CERTIFICATE_DATE_FORMAT for easy customization of (#354)

certificate issued date

(cherry picked from commit 421e661)

* fix: Produce grade report when subsections have future start dates

When getting a subsection grade for a user, instead of failing
if the user can't access that subsection,
fallback to the collected structure.

* Revert "Unhide student-generated certificates toggle"

This reverts commit 8910ccf.

Our clients are no longer using this feature, and edX won't accept this
upstream as-is currently.  See https://github.com/edx/edx-platform/pull/23735 for more information.

Reverting to reduce code drift from upstream.

* chore: update Arabic translations

* fix:Fix function call to check MFE (#359)

Signed-off-by: Farhaan Bukhsh <farhaan@opencraft.com>

* fix: don't cache ajax request

* feat: add site language config

Cherry-picked from: https://github.com/edx/edx-platform/pull/27696

* Revert "[FAL-1813] fix: codejail issue when using matplotlib (#343)" (#365)

This reverts commit 2143f84.

* Update celery routing for celery 4+ (openedx#25567)

* Update celery routing

- Used routing function instead of class
- Move task queues dictionary to Django settings
- Removed routing_key parameter
- Refactored routing for singleton celery instantiation

Co-authored-by: Awais Qureshi <awais.qureshi@arbisoft.com>
(cherry picked from commit e3b4d23)

* fix: add missing set_code_owner_attribute imports

(cherry picked from commit d1060d2)

* chore: bump edx-django-utils to 3.12.0

The required `set_code_owner_attribute` decorator was introduced in
v3.12.0, therefore we need to bump the dependency.

(cherry picked from commit f52b84e)

* [SE-4482] Allow delete course content in Studio only for admin users (#360)

Co-authored-by: Nizar Mahmoud <nizarmah@hotmail.com>

* fix: Password reset page throwing not found error (#364)

Signed-off-by: Farhaan Bukhsh <farhaan@opencraft.com>

* fix: change buttons in wiki modal to anchor tags

The action buttons in wiki modal have href attribute
but does not have an event listener for click.
This PR changes the buttons to anchor tags so that they
work as expected when clicked.

* fix: use high priority queue for celery heartbeat check

Makes HIGH_PRIORITY_QUEUE a derived setting, which allows
HEARTBEAT_CELERY_ROUTING_KEY to use the correct config variant default.

(cherry picked from commit 2a9067a)

* fix: prevent invalidation of allowlisted certificates

The allowlisted certificates were getting invalidated upon visiting the Course
Progress page by users.

This is a rough backport of the Lilac fix (edx#26356). In Lilac, this is gated
by the `certificates_revamp.use_allowlist` Waffle flag. In post-Lilac branches,
this is working out of the box (the flag has been removed in edx#27576).

Jira ticket: BB-4287

* feat: add celery beat configuration

Co-authored-by: Raul Gallegos <raul@opencraft.com>
Co-authored-by: Farhaan Bukhsh <farhaan@opencraft.com>
Co-authored-by: Arjun Singh Yadav <arjun@opencraft.com>
Co-authored-by: pkulkark <pooja@opencraft.com>
Co-authored-by: Shimul Chowdhury <shimul@opencraft.com>
Co-authored-by: João Cabrita <joao.cabrita@opencraft.com>
Co-authored-by: Samuel Walladge <samuel@opencraft.com>
Co-authored-by: Giovanni Cimolin da Silva <giovannicimolin@gmail.com>
Co-authored-by: 0x29a <demid@opencraft.com>
Co-authored-by: Dmitry Gamanenko <dmitry.gamanenko@raccoongang.com>
Co-authored-by: Jillian Vogel <jill@opencraft.com>
Co-authored-by: Muhammad Soban Javed <58461728+iamsobanjaved@users.noreply.github.com>
Co-authored-by: Sandeep Choudhary <sandeep@opencraft.com>
Co-authored-by: Nizar Mahmoud <nizarmah@hotmail.com>
Co-authored-by: Agrendalath <piotr@surowiec.it>
asadali145 pushed a commit to OmnipreneurshipAcademy/edx-platform that referenced this pull request Jul 27, 2021
…27359)

* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
asadali145 added a commit to OmnipreneurshipAcademy/edx-platform that referenced this pull request Jul 27, 2021
…port

BACKPORT: SE-4101 fix: address VisibleBlocks caching race condition (openedx#27359)
harris-irfan added a commit to OmnipreneurshipAcademy/edx-platform that referenced this pull request Jul 27, 2021
…port

[SE-4101] fix: address VisibleBlocks caching race condition (openedx#27359)
sambapete added a commit to EDUlib/edx-platform that referenced this pull request Aug 9, 2021
…27359)

* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
etechdevai pushed a commit to edly-io/edx-platform that referenced this pull request Aug 30, 2021
…27359)

* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
(cherry picked from commit 6ccdaca)
etechdevai added a commit to edly-io/edx-platform that referenced this pull request Aug 30, 2021
…27359) (#267)

* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
(cherry picked from commit 6ccdaca)

Co-authored-by: Gábor Boros <gabor@opencraft.com>
melvinsoft pushed a commit to appsembler/edx-platform that referenced this pull request Dec 29, 2021
…27359)

* fix: address VisibleBlocks caching race condition

* sets visual block creation in an atomic transaction

* refactor: add logging statement to bulk create

Co-authored-by: Raul Gallegos <raul@opencraft.com>
(cherry picked from commit 6ccdaca)
melvinsoft added a commit to appsembler/edx-platform that referenced this pull request Dec 29, 2021
…ypick

[SE-4101] fix: address VisibleBlocks caching race condition (openedx#27359)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged open-source-contribution PR author is not from Axim or 2U

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants