[pve-devel] [Patch V4 4/6] Get snapshots when no state is available.

Wolfgang Link w.link at proxmox.com
Tue May 8 15:33:42 CEST 2018


With this patch we can restore the state of a state less job.
It may happen that there are more replication snapshots,
because no job state is known can not delete any snapshot.
Existing multiple replication-snapshot happens
when a node fails in middel of a replication
and then the VM is moved to another node.
That's why we have to test if we have a common base on both nodes.
Given this, we take this as a replica state.
After we have a state again, the rest of the snapshots can be deleted on the next run.
---
 PVE/Replication.pm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index 3ebf682..493b77d 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -54,6 +54,21 @@ sub find_common_replication_snapshot {
 		     ($last_snapshots->{$volid}->{$parent_snapname} &&
 		      $remote_snapshots->{$volid}->{$parent_snapname})) {
 		$base_snapshots->{$volid} = $parent_snapname;
+	    } elsif ($last_sync == 0) {
+		my @desc_sorted_snap =
+		    map { $_->[1] } sort { $b->[0] <=> $a->[0] }
+		    map { [ ($_ =~ /__replicate_\Q$jobid\E_(\d+)_/)[0] || 0, $_ ] }
+		    keys %{$remote_snapshots->{$volid}};
+
+		foreach my $remote_snap (@desc_sorted_snap) {
+		    if (defined($last_snapshots->{$volid}->{$remote_snap})) {
+			$base_snapshots->{$volid} = $remote_snap;
+			last;
+		    }
+		}
+		die "No common base to restore the job state\n".
+		    "please delete jobid: $jobid and create the job again\n"
+		    if !defined($base_snapshots->{$volid});
 	    }
 	}
     }
-- 
2.11.0




More information about the pve-devel mailing list