public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: [pve-devel] applied-series: [PATCH guest-common 2/2] replication: prepare: simplify code
Date: Mon, 29 Nov 2021 11:18:51 +0100	[thread overview]
Message-ID: <1638181115.2n67xqu2tx.astroid@nora.none> (raw)
In-Reply-To: <20211126105232.436044-2-f.ebner@proxmox.com>

On November 26, 2021 11:52 am, Fabian Ebner wrote:
> No functional change is intended.
> 
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
>  src/PVE/Replication.pm | 46 +++++++++++++++++++-----------------------
>  1 file changed, 21 insertions(+), 25 deletions(-)
> 
> diff --git a/src/PVE/Replication.pm b/src/PVE/Replication.pm
> index de652f2..31cabec 100644
> --- a/src/PVE/Replication.pm
> +++ b/src/PVE/Replication.pm
> @@ -176,32 +176,28 @@ sub prepare {
>      foreach my $volid (@$volids) {
>  	my $info = PVE::Storage::volume_snapshot_info($storecfg, $volid);
>  	for my $snap (keys $info->%*) {
> -	    if ((defined($snapname) && ($snap eq $snapname)) ||
> -		(defined($parent_snapname) && ($snap eq $parent_snapname))) {
> -		$last_snapshots->{$volid}->{$snap} = $info->{$snap};
> -	    } elsif ($snap =~ m/^\Q$prefix\E/) {
> -		if ($last_sync != 0) {
> -		    $logfunc->("delete stale replication snapshot '$snap' on $volid");
> -		    eval {
> -			PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap);
> -			$cleaned_replicated_volumes->{$volid} = 1;
> -		    };
> -
> -		    # If deleting the snapshot fails, we can not be sure if it was due to an error or a timeout.
> -		    # The likelihood that the delete has worked out is high at a timeout.
> -		    # If it really fails, it will try to remove on the next run.
> -		    if (my $err = $@) {
> -			# warn is for syslog/journal.
> -			warn $err;
> -
> -			# logfunc will written in replication log.
> -			$logfunc->("delete stale replication snapshot error: $err");
> -		    }		
> -		# Last_sync=0 and a replication snapshot only occur, if the VM was stolen
> -		} else {
> -		    $last_snapshots->{$volid}->{$snap} = $info->{$snap};
> +	    if ( # check if it's a stale replication snapshot
> +		!(defined($snapname) && $snap eq $snapname) &&
> +		!(defined($parent_snapname) && $snap eq $parent_snapname) &&
> +		$snap =~ m/^\Q$prefix\E/ &&
> +		$last_sync != 0 # last_sync is 0 if the VM was stolen
> +	    ) {
> +		$logfunc->("delete stale replication snapshot '$snap' on $volid");
> +		eval {
> +		    PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap);
> +		    $cleaned_replicated_volumes->{$volid} = 1;
> +		};
> +
> +		# If deleting the snapshot fails, we can not be sure if it was due to an error or a timeout.
> +		# The likelihood that the delete has worked out is high at a timeout.
> +		# If it really fails, it will try to remove on the next run.
> +		if (my $err = $@) {
> +		    # warn is for syslog/journal.
> +		    warn $err;
> +
> +		    # logfunc will written in replication log.
> +		    $logfunc->("delete stale replication snapshot error: $err");
>  		}
> -	    # Other snapshots might need to serve as replication base after rollback
>  	    } else {
>  		$last_snapshots->{$volid}->{$snap} = $info->{$snap};
>  	    }
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




      reply	other threads:[~2021-11-29 10:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-26 10:52 [pve-devel] [PATCH guest-common 1/2] replication: update last_sync before removing old replication snapshots Fabian Ebner
2021-11-26 10:52 ` [pve-devel] [PATCH guest-common 2/2] replication: prepare: simplify code Fabian Ebner
2021-11-29 10:18   ` Fabian Grünbichler [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1638181115.2n67xqu2tx.astroid@nora.none \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal