feat/prune age#1970
Conversation
e5c35c3 to
552bcc4
Compare
|
|
||
| # Values are always passed as query parameters; only static SQL fragments are | ||
| # interpolated. Named parameters let us reuse the same dict across every query. | ||
| params = {"cutoff": cutoff, "batch_size": options["batch_size"]} |
There was a problem hiding this comment.
a minor but I think that would be nice to validate the batch_size. Currently we are able to pass a negative value to the database.
django.db.utils.DataError: LIMIT must not be negative
| """ | ||
| Management command to prune old builds, tests and checkouts. | ||
|
|
||
| Removes checkouts, builds and tests older than a given age. To keep referential | ||
| integrity, deletion cascades manually (models use DO_NOTHING): a removed | ||
| checkout drags its builds, and a removed build drags its tests, even when those | ||
| children are newer than the cutoff. | ||
| """ |
There was a problem hiding this comment.
Worth noting in docs that aggregate tables are not touched by this command.
|
@nuclearcat how long/far-back do we keep the raw KCIDB json payloads? |
| @@ -0,0 +1,25 @@ | |||
| from datetime import datetime, timedelta | |||
There was a problem hiding this comment.
Django has a built-in parser django.utils.dateparse.parse_duration that could be used here
There was a problem hiding this comment.
I took a look on the built-in parser. Unfortunately it has different standards from what we are following.
- standard: "30 00:00:00" (%d %H:%M:%S)
- ISO 8601: "P30D"
- postgres: "3 days 04:05:06" (only works for days)
I believe we might benefit more of keeping our custom parser, we could even extend it to include weeks or months, especially in a scenario where we are working with longer ranges.
What you think?
|
Each batch re-evaluates the full nested predicate. Add on top batch might be too small (we need to check how many tests per day we have, how long take deletion of 10k). |
d37dc83 to
9a454fa
Compare
* Delete rows older than a given age with manual cascade (checkout -> builds -> tests) * --origins scoping, --dry-run and a --yes confirmation. Extract parse_interval into a shared helper and add integration tests. Closes kernelci#1969 Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
…tests. * Delete rows older than a given age with manual cascade (checkout -> builds -> tests) * --origins scoping, --dry-run and a --yes confirmation. Extract parse_interval into a shared helper and add integration tests.
* Add tables parameter.
* Protect issue related rows by default, and add parameter to
bypass.
Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
…tests. * Delete rows older than a given age with manual cascade (checkout -> builds -> tests) * --origins scoping, --dry-run and a --yes confirmation. Extract parse_interval into a shared helper and add integration tests.
* Add tables parameter.
* Protect issue related rows by default, and add parameter to
bypass.
Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
…tests. * Delete rows older than a given age with manual cascade (checkout -> builds -> tests) * --origins scoping, --dry-run and a --yes confirmation. Extract parse_interval into a shared helper and add integration tests.
* Add tables parameter.
* Protect issue related rows by default, and add parameter to
bypass.
Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
9a454fa to
6995fc0
Compare
Nice catch @nuclearcat . I have included a temp table to store ids before batch deleting. |
Summary
Add
prune_db, a manual management command to delete old data and reclaim space.--older-than "30 days").DO_NOTHING): pruning a checkout removes its builds, pruning a build removes its tests — even when children are newer.--originsscopes the age filter; cascade stays origin-agnostic so no orphans are left.--batch-size) that each commit on their own to keep locks short.--dry-runand a per-table confirmation prompt showing exactly how many rows will be affected (skip with--yes).parse_intervalfromupdate_dbinto a shared helper.Usage
How to Test
poetry run python3 manage.py seed_data --clear --yespoetry run python3 manage.py prune_db --dry-runwith different arguments for older-than parameter.poetry run python3 manage.py prune_dbwith different arguments for older-than parameter.