-
Notifications
You must be signed in to change notification settings - Fork 90
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
Use raw sql to execute deletes #2953
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2953 +/- ##
=======================================
Coverage 95.0% 95.1%
=======================================
Files 297 298 +1
Lines 23647 23759 +112
Branches 2632 2632
=======================================
+ Hits 22475 22585 +110
- Misses 703 704 +1
- Partials 469 470 +1 |
@Red-HAP Can this be extended to cover the flow for removing a provider here: koku/koku/api/provider/provider_manager.py Line 208 in 13b91d6
This is what is called when a source is destroyed and is the path in which we are suspecting the Django ORM being inefficient at managing the foreign key relationships while deleting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work HAP!
Jira Ticket
COST-1490
Description
Use raw sql vs ORM to do deletes. This change takes the ORM query and uses django's own SQLDeleteCompiler to get the text of the SQL statement plus the parameters. This is then processed directly via
connection
andcursor
objects without using django ORM to attempt to verify and handle the foreign keys.Provider().delete()
is now tuned up as well to call a func namedcascade_delete
that will walk ORM relations and execute SQL to delete related records bottom-up.Testing
The resulting delete action should be no different from usual. But the memory usage should not expand to OOM state during delete operations for expired data or anything else that a
db_cleaner
would be called for.If you run
make docker-reinitdb-with-sources
then run a django shell, you can watch the cascade delete work.How-To-Do-It Lessons:
make docker-reinitdb-with-sources
make load-test-customer-data
cd koku
export KOKU_LOG_LEVEL=DEBUG
python ./manage.py shell
from api.provider.models import Provider
p = Provider.objects.first()
(orp = Provider.objects.get(pk=<UUID>)
if you have identified a provider to use.)p.delete()
Level
andCascade
in them. With logging set to debug, you'll also see the formatted SQL statements that are being executed.ctrl+d
to exit the shell