mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(vmbackups): eighth audit: retention reads each VM once, no reload while typing
- The backups' default ordering put created_at into the SELECT DISTINCT of the retention pass and of the checkpoint pruning, so a VM came once per backup: the pass read every backup's chain again. The ordering is cleared before both. - A page with a backup being made or deleted reloads every 4 s; it now waits while a field is focused, so a filter or the backup form being filled in is not lost.
This commit is contained in:
parent
348628f13d
commit
810abe7475
4 changed files with 10 additions and 4 deletions
|
|
@ -219,7 +219,7 @@ def _prune_checkpoints(op, proxy, plan):
|
|||
one, the base of its next incremental backup."""
|
||||
backups = Backup.objects.filter(vm_uuid=op.intent["uuid"]).exclude(checkpoint="").exclude(uuid=op.intent["backup"])
|
||||
keep = set()
|
||||
for policy_id in backups.filter(policy__full_every__gt=1).values_list("policy", flat=True).distinct():
|
||||
for policy_id in backups.filter(policy__full_every__gt=1).order_by().values_list("policy", flat=True).distinct():
|
||||
newest = backups.filter(policy=policy_id, state=Backup.READY).order_by("-created_at").first()
|
||||
if newest is not None:
|
||||
keep.add(newest.checkpoint)
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ def retain():
|
|||
if policy.target_id in tried or not _active_superuser(policy.owner):
|
||||
continue
|
||||
vms = (Backup.objects.filter(policy=policy, state=Backup.READY, instance__isnull=False)
|
||||
.values_list("instance_id", flat=True).distinct())
|
||||
.order_by().values_list("instance_id", flat=True).distinct()) # no created_at in the distinct
|
||||
for instance_id in vms:
|
||||
# a chain goes when all of it is beyond keep, newest first: only a backup nothing builds on is deleted
|
||||
beyond = [b for b in beyond_keep(policy, instance_id) if not b.depended_on()]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
// A backup being made or deleted: the page reads it again until it is done,
|
||||
// while the backups are in view (the VM page's Backups tab, the Backups page)
|
||||
// and nothing is open on them (a menu, a dialog).
|
||||
// and nothing is open on them (a menu, a dialog) or being typed into.
|
||||
(function () {
|
||||
if (!document.querySelector("[data-backup-pending]")) return;
|
||||
var check = function () {
|
||||
var pane = document.getElementById("backups");
|
||||
var hidden = pane && pane.classList.contains("tab-pane") && !pane.classList.contains("active");
|
||||
var busy = document.querySelector(".dropdown-menu.show, .modal.show");
|
||||
var busy = document.querySelector(".dropdown-menu.show, .modal.show, input:focus, select:focus, textarea:focus");
|
||||
if (hidden || busy || document.hidden) {
|
||||
setTimeout(check, 4000);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -367,6 +367,12 @@ class ScheduleTests(TransactionTestCase):
|
|||
schedule.retain()
|
||||
self.assertEqual(self.deletes()[-1].params["backup"], str(older.uuid))
|
||||
|
||||
def test_retention_reads_each_vm_once(self):
|
||||
self.backups(*[Backup.READY] * 4)
|
||||
with patch("vmbackups.schedule.beyond_keep", return_value=[]) as beyond:
|
||||
schedule.retain()
|
||||
self.assertEqual(beyond.call_count, 1)
|
||||
|
||||
def chained(self, *backups):
|
||||
for parent, child in zip(backups, backups[1:]):
|
||||
Backup.objects.filter(pk=child.pk).update(parent=parent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue