Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sometimes, changes to subsections are not reflected in the Studio Search Index #34800

Conversation

bradenmacdonald
Copy link
Contributor

@bradenmacdonald bradenmacdonald commented May 14, 2024

Description

There is a race condition that causes some changes to not be reflected in the Studio search index.

Technical Details

What's happening is that the XBlock is updated with modulestore.update_item() in the initial request, that function immediately triggers the XBLOCK_UPDATED signal. However, when our handler processes that in a worker, even though there is no active MySQL transaction, the modulestore "bulk operation" may still be active, so the actual modulestore data in mongo/mysql hasn't been updated yet. The data only gets committed when the outermost bulk operation scope is exited.

I couldn't find any existing mechanism to listen for that "actual commit" of draft content, because the code seems to assume that other parts of the system only need to know when new content has been published, not when new draft content has been committed to the DB. So I had to add that as a new capability.

Testing instructions

In cms/envs/devstack.py set CELERY_ALWAYS_EAGER = False.

  1. Rename any subsection in a course
  2. Open the course search (from the header of the course authoring MFE, while viewing the same course outline)
  3. Search for the name of the subsection
  4. In some cases (especially if it's not the first time you've made a change since the CMS and CMS worker were restarted), you will see that the name of the subsection in the search index is out of date.

We have focused testing on renaming subsections, but this likely affects other types of edits.

Deadline

TBD

@openedx-webhooks
Copy link

Thanks for the pull request, @bradenmacdonald! 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 as you can:

  • 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 the open-source-contribution PR author is not from Axim or 2U label May 14, 2024
@bradenmacdonald bradenmacdonald force-pushed the braden/fix-index-not-updating-when-xblock-updates branch from 87b52e1 to 807fc26 Compare May 14, 2024 21:31
@yusuf-musleh yusuf-musleh force-pushed the braden/fix-index-not-updating-when-xblock-updates branch from d11a5de to 3b28599 Compare May 17, 2024 07:15
Initially we used `_get_bulk_ops_record()` however that had side-effects of creating records since it uses a defaultdict internally. So we swapped the implementation similar how we check in `_clear_bulk_ops_record()`
@bradenmacdonald
Copy link
Contributor Author

@ormsbee Would you be able to review this PR? We'd also like to backport it to Redwood, as it's a bugfix.

Copy link
Contributor

@ChrisChV ChrisChV left a comment

Choose a reason for hiding this comment

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

@yusuf-musleh Looks good 👍

  • I tested this: I followed the testing instructions with: Sections, Units and components
  • I read through the code and considered the security, stability and performance implications of the changes.
  • I tested that the UI can be used with a keyboard only (tab order, keyboard controls).
  • Includes tests for bugfixes and/or features added.
  • Includes documentation

Copy link
Contributor

@ormsbee ormsbee left a comment

Choose a reason for hiding this comment

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

Nice! This is honestly a lot cleaner than I thought it would be when you described the problem. 😛

@bradenmacdonald
Copy link
Contributor Author

Haha yeah @ormsbee I'm happy with how the fix shaped up; we were able to implement it without needing to change too much.

@bradenmacdonald bradenmacdonald merged commit 749e18b into openedx:master May 22, 2024
47 checks passed
@bradenmacdonald bradenmacdonald deleted the braden/fix-index-not-updating-when-xblock-updates branch May 22, 2024 17:29
@openedx-webhooks
Copy link

@bradenmacdonald 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
Contributor

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

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants