Skip to content

Commit

Permalink
docs: add pruning-related warning messages in MongoDB connection
Browse files Browse the repository at this point in the history
We migrated the source of truth for what the active draft and published
versions of course and v1 library content are to the
SplitModulestoreCourseIndex Django model. But the contentpruning
code (structures.py) that was developed in tubular and will be moved to
edx-platform is not aware of this newer model, and still only pulls its
source of truth from MongoDB. So we *must* continue to do writes to
MongoDB, or the pruning code will start pruning live versions.

The longer term fix for this is to make the pruning code aware of
SplitModulestoreCourseIndex, which will be easier once it's moved into
edx-platform.
  • Loading branch information
ormsbee committed Mar 4, 2024
1 parent 3ffaa3d commit 8bb2f31
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions xmodule/modulestore/split_mongo/mongo_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,9 @@ def insert_course_index(self, course_index, course_context=None): # pylint: dis
course_index['last_update'] = datetime.datetime.now(pytz.utc)
new_index = SplitModulestoreCourseIndex(**SplitModulestoreCourseIndex.fields_from_v1_schema(course_index))
new_index.save()
# TEMP: Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well:
# Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well.
# NOTE: This is REQUIRED for pruning (structures.py) to run safely. Don't remove this write until
# pruning is modified to read from SplitModulestoreCourseIndex to get active versions.
super().insert_course_index(course_index, course_context)

def update_course_index(self, course_index, from_index=None, course_context=None): # pylint: disable=arguments-differ
Expand Down Expand Up @@ -755,7 +757,10 @@ def update_course_index(self, course_index, from_index=None, course_context=None

# Save the course index entry and create a historical record:
index_obj.save()
# TEMP: Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well:

# Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well.
# NOTE: This is REQUIRED for pruning (structures.py) to run safely. Don't remove this write until
# pruning is modified to read from SplitModulestoreCourseIndex to get active versions.
super().update_course_index(course_index, from_index, course_context)

def delete_course_index(self, course_key):
Expand All @@ -764,7 +769,9 @@ def delete_course_index(self, course_key):
"""
RequestCache(namespace="course_index_cache").clear()
SplitModulestoreCourseIndex.objects.filter(course_id=course_key).delete()
# TEMP: Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well:
# Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well.
# NOTE: This is REQUIRED for pruning (structures.py) to run safely. Don't remove this write until
# pruning is modified to read from SplitModulestoreCourseIndex to get active versions.
super().delete_course_index(course_key)

def _drop_database(self, database=True, collections=True, connections=True):
Expand All @@ -782,5 +789,7 @@ def _drop_database(self, database=True, collections=True, connections=True):
"post-test cleanup failed with TransactionManagementError. "
"Use 'with self.allow_transaction_exception():' from ModuleStoreTestCase/...IsolationMixin to fix it."
) from err
# TEMP: Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well:
# Also write to MongoDB, so we can switch back to using it if this new MySQL version doesn't work well.
# NOTE: This is REQUIRED for pruning (structures.py) to run safely. Don't remove this write until
# pruning is modified to read from SplitModulestoreCourseIndex to get active versions.
super()._drop_database(database, collections, connections)

0 comments on commit 8bb2f31

Please sign in to comment.