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

Reduce the chance of database locks interrupting soud syncing. #11886

Merged

Conversation

rtibbles
Copy link
Member

Summary

Wraps the SyncQueue save method in the retry_on_db_lock decorator to reduce the chances of interrupting the SOUD sync queue because of a database locked error.

References

Based on database locked errors seen in #11816 (comment)

Addresses the general case seen in this error traceback from the above:

ERROR 2024-02-14 13:38:00,638 kolibri.core.tasks.job Job 50 raised an exception: Traceback (most recent call last):
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/backends/utils.py", line 64, in execute
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/backends/sqlite3/base.py", line 328, in execute
sqlite3.OperationalError: database is locked

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/core/tasks/job.py", line 329, in execute
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/core/tasks/registry.py", line 238, in __call__
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/core/auth/tasks.py", line 433, in soud_sync_processing
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/core/device/soud.py", line 360, in execute_syncs
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/core/device/soud.py", line 264, in request_sync
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/base.py", line 807, in save
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/base.py", line 846, in save_base
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/dispatch/dispatcher.py", line 191, in send
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/dispatch/dispatcher.py", line 192, in <listcomp>
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/core/device/signals.py", line 24, in sync_queue_save_update_user_sync_status
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/core/device/models.py", line 554, in update_status
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/manager.py", line 85, in manager_method
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/query.py", line 489, in update_or_create
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/base.py", line 807, in save
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/base.py", line 838, in save_base
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/base.py", line 904, in _save_table
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/base.py", line 955, in _do_update
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/query.py", line 667, in _update
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/sql/compiler.py", line 1204, in execute_sql
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/sql/compiler.py", line 899, in execute_sql
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/models/sql/compiler.py", line 889, in execute_sql
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/backends/utils.py", line 64, in execute
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/utils.py", line 94, in __exit__
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/utils/six.py", line 685, in reraise
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/backends/utils.py", line 64, in execute
  File "/home/runner/work/kolibri/kolibri/python-for-android/build/python-installs/kolibri/arm64-v8a/kolibri/dist/django/db/backends/sqlite3/base.py", line 328, in execute
django.db.utils.OperationalError: database is locked

Reviewer guidance

Could this have any unexpected negative side effects? This feels like the right thing to do, as we already use exactly the same decoration mechanism to protect sync queue update or create from database locked errors in the sync hooks.


Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@rtibbles rtibbles added the TODO: needs review Waiting for review label Feb 15, 2024
@rtibbles rtibbles requested a review from bjester February 15, 2024 20:33
@github-actions github-actions bot added DEV: backend Python, databases, networking, filesystem... SIZE: very small labels Feb 15, 2024
@rtibbles rtibbles force-pushed the locks_no_spoil_the_queue branch from 31149a3 to 587fdcf Compare February 15, 2024 20:53
@rtibbles rtibbles marked this pull request as ready for review February 15, 2024 20:54
@rtibbles rtibbles merged commit 3fd5c1e into learningequality:release-v0.16.x Feb 15, 2024
34 checks passed
@rtibbles rtibbles deleted the locks_no_spoil_the_queue branch February 15, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem... SIZE: very small TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants