[pve-devel] [PATCH pve-guest-common 2/2] Delete unused states.

Wolfgang Link w.link at proxmox.com
Mon Jun 26 13:09:51 CEST 2017


Delete all state object, which has no config entry and not updated in the last 24 hours.
---
 PVE/ReplicationState.pm | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/PVE/ReplicationState.pm b/PVE/ReplicationState.pm
index 952d474..ba9d0e1 100644
--- a/PVE/ReplicationState.pm
+++ b/PVE/ReplicationState.pm
@@ -249,10 +249,44 @@ sub job_status {
 
 	$jobs->{$jobid} = $jobcfg;
     }
-
+    delet_all_old_states($cfg, $stateobj);
     return $jobs;
 }
 
+sub delet_all_old_states {
+    my ($cfg) = @_;
+
+    my $stateobj = read_state();
+    my $vms = PVE::Cluster::get_vmlist();
+    my $local_node = PVE::INotify::nodename();
+
+    foreach my $jobid (keys %{$cfg->{ids}}) {
+
+	my $jobcfg = $cfg->{ids}->{$jobid};
+	my $plugin = PVE::ReplicationConfig->lookup($jobcfg->{type});
+	my $tid = $plugin->get_unique_target_id($jobcfg);
+	my $vmid = $jobcfg->{guest};
+
+	#remove all states with a config and resist on this node.
+	delete $stateobj->{$vmid}->{$tid}
+		if $vms->{ids}->{$vmid}->{node} eq $local_node;
+	delete $stateobj->{$vmid} if !%{$stateobj->{$vmid}};
+
+    }
+
+    my $delete_time = time();
+    foreach my $vmid (keys %$stateobj) {
+	delete_jobs_in_state($vmid) if !%{$stateobj->{$vmid}};
+	foreach my $tid (keys %{$stateobj->{$vmid}}) {
+
+	    # delete state if last_iteration is older then 24 houres
+	    delete_jobs_in_state($vmid, $tid)
+		if ($stateobj->{$vmid}->{$tid}->{last_iteration} + (24*60*60)) < $delete_time;
+	}
+    }
+}
+
+
 sub get_next_job {
     my ($iteration, $start_time) = @_;
 
-- 
2.11.0





More information about the pve-devel mailing list