From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CF7EE70D68 for ; Wed, 9 Jun 2021 11:19:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CD3832249E for ; Wed, 9 Jun 2021 11:19:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 3C56522495 for ; Wed, 9 Jun 2021 11:19:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0E111428D3 for ; Wed, 9 Jun 2021 11:19:04 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Wed, 9 Jun 2021 11:18:58 +0200 Message-Id: <20210609091858.27219-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210609091858.27219-1-f.ebner@proxmox.com> References: <20210609091858.27219-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.953 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [replicationconfig.pm, abstractconfig.pm] Subject: [pve-devel] [PATCH v2 guest-common 2/2] fix 3111: replicate guest on rollback if there are replication jobs for it X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jun 2021 09:19:10 -0000 so that there will be a valid replication snapshot again. Otherwise, replication will be broken after a rollback if the last (non-replication) snapshot is removed before replication can run again. Signed-off-by: Fabian Ebner --- No changes from v1 (except rebase). Not a huge fan of this, but the alternatives I could come up with don't seem much better IMHO: 1. Invalidate/remove replicated volumes after a rollback altogether and require a full sync on the next replication job afterwards. 2. Another one is to disallow removing the last non-replication snapshot if: * there is a replication job configured * no replication snapshot for that job currently exists (which likely means it was removed by a previous rollback operation, but can also happen for a new job that didn't run yet). 3. Hope not very many people immediately delete their snapshots after rollback. Pick a favorite or suggest your own ;) src/PVE/AbstractConfig.pm | 19 +++++++++++++++++-- src/PVE/ReplicationConfig.pm | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm index 6542ae4..6cc0537 100644 --- a/src/PVE/AbstractConfig.pm +++ b/src/PVE/AbstractConfig.pm @@ -951,6 +951,9 @@ sub snapshot_rollback { my $storecfg = PVE::Storage::config(); + my $repl_conf = PVE::ReplicationConfig->new(); + my $logfunc = sub { my $line = shift; chomp $line; print "$line\n"; }; + my $data = {}; my $get_snapshot_config = sub { @@ -972,7 +975,6 @@ sub snapshot_rollback { $snap = $get_snapshot_config->($conf); if ($prepare) { - my $repl_conf = PVE::ReplicationConfig->new(); if ($repl_conf->check_for_existing_jobs($vmid, 1)) { # remove replication snapshots on volumes affected by rollback *only*! my $volumes = $class->get_replicatable_volumes($storecfg, $vmid, $snap, 1); @@ -989,7 +991,6 @@ sub snapshot_rollback { }); # remove all local replication snapshots (jobid => undef) - my $logfunc = sub { my $line = shift; chomp $line; print "$line\n"; }; PVE::Replication::prepare($storecfg, $volids, undef, 1, undef, $logfunc); } @@ -1047,6 +1048,20 @@ sub snapshot_rollback { $prepare = 0; $class->lock_config($vmid, $updatefn); + + my $replication_jobs = $repl_conf->list_guests_replication_jobs($vmid); + for my $job (@{$replication_jobs}) { + my $target = $job->{target}; + $logfunc->("replicating rolled back guest to node '$target'"); + + my $start_time = time(); + eval { + PVE::Replication::run_replication($class, $job, $start_time, $start_time, $logfunc); + }; + if (my $err = $@) { + warn "unable to replicate rolled back guest to node '$target' - $err"; + } + } } # bash completion helper diff --git a/src/PVE/ReplicationConfig.pm b/src/PVE/ReplicationConfig.pm index fd856a0..84a718f 100644 --- a/src/PVE/ReplicationConfig.pm +++ b/src/PVE/ReplicationConfig.pm @@ -228,6 +228,20 @@ sub find_local_replication_job { return undef; } +sub list_guests_replication_jobs { + my ($cfg, $vmid) = @_; + + my $jobs = []; + + for my $job (values %{$cfg->{ids}}) { + next if $job->{type} ne 'local' || $job->{guest} != $vmid; + + push @{$jobs}, $job; + } + + return $jobs; +} + # makes old_target the new source for all local jobs of this guest # makes new_target the target for the single local job with target old_target sub switch_replication_job_target_nolock { -- 2.30.2