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

TP2000-1407 Sqlite dump failure fix #1265

Merged
merged 40 commits into from
Jul 23, 2024

Conversation

paulpepper-trade
Copy link
Collaborator

@paulpepper-trade paulpepper-trade commented Jul 16, 2024

TP2000-1407 Sqlite dump failure fix

Why

Until recently, the SQLite export to S3 capability was taking over four hours to complete. With a continued increase in database size, export performance had sharply degraded and was taking in the region of three days to complete. Performance improvements were required.

What

This PR:

  • Reduces the time to create a SQLite export and upload to S3 down to approximately six minutes.
  • Refactors methods on storage classes that are used to save SQLite export files to allow multiple strategies to be applied for different export situations (e.g. exporting to local file system from a command line, or exporting to S3 via a Celery Beat initiated task).
  • Add new storage classes SQLiteLocalStorage and SQLiteS3Storage to apply the different storage strategies.
  • Adds a decorator that is used to log the start time, end time and total elapsed time taken for a function to execute. This was useful for comparing the performance of different storage strategies and discovering the issue that this PR fixes, but has been placed under the common application for wider use.
  • Added command-line support for generating exports to the local file system.
  • Refactored some (but not all) of the export code in order to simplify the process - more could be done, but the prospect of a more radical replacement means a fuller refactor (and simplification) is probably not worthwhile.
  • Added docstrings to export classes and functions in place of the fuller refactor that could otherwise have been carried out.
  • Added config support to enable / disable scheduled (via Celery Beat) SQLite exports.
  • Added unit tests for the newly added storage classes and updated existing tests.
  • Added unit test for dump_sqlite Django management command.
  • Applied incidental minor fixes and corrections.

Checklist

  • Requires migrations? No
  • Requires dependency updates? No
  • Ensure sufficient disk quota is available on instance from which the export is performed.

@paulpepper-trade paulpepper-trade requested a review from a team as a code owner July 16, 2024 17:08
"""

@log_timing(logger_function=logger.info)
def export_database(self, filename: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to test this function?

Copy link
Collaborator Author

@paulpepper-trade paulpepper-trade Jul 19, 2024

Choose a reason for hiding this comment

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

It's implicitly tested as part of test_s3_export_task_uploads() - called within the export_and_upload_sqlite() function, which I think gives it full and sufficient coverage.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's showing up for me as red in codecov. Is that right? Can you check it on your end as well and confirm?

@@ -11,20 +11,39 @@


class Command(BaseCommand):
help = (
"Create a snapshot of the application database to a file in SQLite "
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this command tested? This whole file is not showing up in the coverage report. Not sure if that's a bug with codecov or not

Copy link
Collaborator Author

@paulpepper-trade paulpepper-trade Jul 19, 2024

Choose a reason for hiding this comment

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

It looks as though there's never been a test for this command. I can only guess that's because it's fairly simple and the function it executes is tested by exporter/tests/test_sqlite.py.

Test now added. Btw, export_and_upload_sqlite() is mocked in that test because it's tested elsewhere and is relatively expensive to execute - each execution performs a manage.py makemigrations followed by a manage.py migrate amongst other things!

@paulpepper-trade paulpepper-trade requested a review from a team July 19, 2024 18:15
@paulpepper-trade paulpepper-trade merged commit 5624528 into master Jul 23, 2024
8 checks passed
@paulpepper-trade paulpepper-trade deleted the TP2000-1407--sqlite-dump-failure branch July 23, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants