[pve-devel] [PatchV3 guest-common 4/6] Get snapshots when no state is available.

Wolfgang Bumiller w.bumiller at proxmox.com
Tue May 8 10:33:16 CEST 2018


On Tue, May 08, 2018 at 08:29:59AM +0200, Wolfgang Link wrote:
> 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 | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/PVE/Replication.pm b/PVE/Replication.pm
> index bae04ef..d2f9ade 100644
> --- a/PVE/Replication.pm
> +++ b/PVE/Replication.pm
> @@ -54,6 +54,16 @@ sub find_common_replication_snapshot {
>  		     ($last_snapshots->{$volid}->{$parent_snapname} &&
>  		      $remote_snapshots->{$volid}->{$parent_snapname})) {
>  		$base_snapshots->{$volid} = $parent_snapname;
> +	    } elsif ($last_sync == 0) {
> +		foreach my $remote_snap (sort {$b cmp $a} keys %{$remote_snapshots->{$volid}}) {

`cmp` sorts alphabetically - would be safe to add a sort function
specifically for replication snapshots which compares only the timestamp
via <=> instead

> +		    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