-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: split Studio search into separate course and library indexes #39103
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
Open
blarghmatey
wants to merge
5
commits into
openedx:master
Choose a base branch
from
mitodl:tmacey/split-studio-content-index
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+730
−197
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1bcc5d7
feat: split Studio search into separate course and library indexes
blarghmatey 4baff25
docs: drop multi-index frontend claim from index split ADR
blarghmatey b5ad584
fix: abort library index rebuild on Meilisearch write failures
blarghmatey 019008f
fix: drop pre-split library checkpoints from incremental reindex state
blarghmatey 38a2568
refactor: rename reconcile_index to reconcile_indexes
blarghmatey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
...apps/content/search/docs/decisions/0002-separate-course-and-library-indexes.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| Separate Meilisearch Indexes for Course and Library Content | ||
| ############################################################ | ||
|
|
||
| Status | ||
| ****** | ||
|
|
||
| Accepted | ||
|
|
||
|
|
||
| Context | ||
| ******* | ||
|
|
||
| `0001-meilisearch.rst`_ put all Studio content into one Meilisearch index, | ||
| ``studio_content``: course blocks (``type = course_block``) plus Libraries V2 | ||
| components, containers and collections. | ||
|
|
||
| Library authoring updates that index synchronously so the frontend sees the | ||
| change on its next query. Meilisearch's per-document indexing cost grows with | ||
| index size, and course blocks dominate the index on large instances. One | ||
| instance reported 1.3 million documents (11.9 GiB) of which 99.93% were course | ||
| blocks, and saw Studio time out when creating library components | ||
| (`openedx-platform#38993`_). | ||
|
|
||
| Course content is indexed asynchronously by Celery tasks, so it does not need to | ||
| share an index with library content. | ||
|
|
||
| .. _0001-meilisearch.rst: ./0001-meilisearch.rst | ||
| .. _openedx-platform#38993: https://github.com/openedx/openedx-platform/issues/38993 | ||
|
|
||
|
|
||
| Decision | ||
| ******** | ||
|
|
||
| Studio content is stored in two indexes: | ||
|
|
||
| * ``<MEILISEARCH_INDEX_PREFIX>studio_content``: course blocks | ||
| (``DocType.course_block``). This is the original index name, so upgrading does | ||
| not require reindexing course content. | ||
| * ``<MEILISEARCH_INDEX_PREFIX>studio_library_content``: library blocks, library | ||
| containers and collections. | ||
|
|
||
| Both indexes use the same settings. Every write is routed by document type or by | ||
| the learning context of its key. Rebuild locks and temporary ``_new`` indexes | ||
| are per index. | ||
|
|
||
| Every modulestore block is indexed as a ``course_block`` document, including | ||
| course blocks that link to upstream library content, so those stay in the | ||
| course index. | ||
|
|
||
| ``GET /api/content_search/v2/studio/`` returns ``course_index_name`` and | ||
| ``library_index_name``, and one tenant token whose search rules cover both | ||
| indexes with the same access filter. Each Studio search surface already | ||
| searches either course content or library content, never both, so each one | ||
| picks the matching index. ``index_name`` is still returned (equal to | ||
| ``course_index_name``) for one release, for frontends that predate the split. | ||
|
|
||
|
|
||
| Upgrading | ||
| ********* | ||
|
|
||
| On an instance that already has a populated ``studio_content`` index: | ||
|
|
||
| #. ``./manage.py cms migrate``. The ``post_migrate`` reconciliation creates and | ||
| configures the empty library index. | ||
| #. ``./manage.py cms reindex_studio --libraries-only``. This enqueues a Celery | ||
| task that rebuilds the library index, then deletes every document with | ||
| ``type != "course_block"`` from the course index. Courses are not reindexed. | ||
|
|
||
| Deploy a frontend that reads ``library_index_name`` at the same time. A frontend | ||
| that only knows ``index_name`` searches the course index, so it stops finding | ||
| library content once step 2 has run. | ||
|
|
||
| A full ``./manage.py cms reindex_studio`` also populates both indexes and runs | ||
| the same cleanup, but it reindexes every course. | ||
|
|
||
|
|
||
| Consequences | ||
| ************ | ||
|
|
||
| * Library writes no longer pay for the size of the course index. | ||
| * A future search across courses and libraries together would need a | ||
| multi-index search request. | ||
| * The Meilisearch API key used by Studio must be allowed to manage both index | ||
| names (and their ``_new`` temporary indexes). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../djangoapps/content/search/migrations/0003_clear_library_incremental_index_checkpoints.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from django.db import migrations | ||
| from opaque_keys.edx.locator import LibraryLocatorV2 | ||
|
|
||
|
|
||
| def clear_library_checkpoints(apps, schema_editor): | ||
| """ | ||
| Checkpoints written before the course/library index split record libraries indexed into the course index. | ||
| An incremental rebuild would skip those libraries and never add them to the new library index. | ||
| """ | ||
| IncrementalIndexCompleted = apps.get_model("search", "IncrementalIndexCompleted") | ||
| library_ids = [ | ||
| checkpoint.id | ||
| for checkpoint in IncrementalIndexCompleted.objects.all() | ||
| if isinstance(checkpoint.context_key, LibraryLocatorV2) | ||
| ] | ||
| IncrementalIndexCompleted.objects.filter(id__in=library_ids).delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("search", "0002_incrementalindexcompleted"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(clear_library_checkpoints, migrations.RunPython.noop), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.