[pve-devel] [PATCH pve-manager 1/3] replication: save list of used storage IDs

Dietmar Maurer dietmar at proxmox.com
Tue Jun 6 13:02:33 CEST 2017


Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/Replication.pm             | 13 ++++++++++--
 bin/test/ReplicationTestEnv.pm | 17 +++++++++++++++
 bin/test/replication_test2.pl  | 48 ++++++++++++++++++++----------------------
 bin/test/replication_test5.log |  1 +
 4 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index 326ca6e9..71e2624d 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -201,7 +201,7 @@ sub delete_job {
 }
 
 sub replicate {
-    my ($jobcfg, $last_sync, $start_time, $logfunc) = @_;
+    my ($jobcfg, $state, $start_time, $logfunc) = @_;
 
     $logfunc = sub {} if !$logfunc; # log nothing by default
 
@@ -220,6 +220,7 @@ sub replicate {
 
     my $jobid = $jobcfg->{id};
     my $storecfg = PVE::Storage::config();
+    my $last_sync = $state->{last_sync};
 
     die "start time before last sync ($start_time <= $last_sync) - abort sync\n"
 	if $start_time <= $last_sync;
@@ -284,6 +285,13 @@ sub replicate {
     my $last_snapshots = prepare(
 	$storecfg, $sorted_volids, $jobid, $last_sync, $start_time, $logfunc);
 
+    my $storeid_hash = {};
+    foreach my $volid (@$sorted_volids) {
+	my ($storeid) = PVE::Storage::parse_volume_id($volid);
+	$storeid_hash->{$storeid} = 1;
+    }
+    $state->{storeid_list} = [ sort keys %$storeid_hash ];
+
     # freeze filesystem for data consistency
     if ($qga) {
 	$logfunc->("$jobid: freeze guest filesystem");
@@ -371,13 +379,14 @@ my $run_replication_nolock = sub {
 	$state->{last_node} = PVE::INotify::nodename();
 	$state->{last_try} = $start_time;
 	$state->{last_iteration} = $iteration;
+	$state->{storeid_list} //= [];
 
 	PVE::ReplicationState::write_job_state($jobcfg, $state);
 
 	$logfunc->("$jobcfg->{id}: start replication job") if $logfunc;
 
 	eval {
-	    replicate($jobcfg, $state->{last_sync}, $start_time, $logfunc);
+	    replicate($jobcfg, $state, $start_time, $logfunc);
 	};
 	my $err = $@;
 
diff --git a/bin/test/ReplicationTestEnv.pm b/bin/test/ReplicationTestEnv.pm
index 7a9055fa..1359fb47 100755
--- a/bin/test/ReplicationTestEnv.pm
+++ b/bin/test/ReplicationTestEnv.pm
@@ -293,6 +293,7 @@ sub track_jobs {
 	}
 
 	my $oldstate = $oldcfg->{state};
+
 	my $state = $jobcfg->{state};
 
 	my $changes = '';
@@ -306,6 +307,22 @@ sub track_jobs {
 	}
 	$logmsg->("$jobid: changed state $changes") if $changes;
 
+	my $old_storeid_list = $oldstate->{storeid_list};
+	my $storeid_list = $state->{storeid_list};
+
+	my $storeid_list_changes = 0;
+	foreach my $storeid (@$storeid_list) {
+	    next if grep { $_ eq $storeid } @$old_storeid_list;
+	    $storeid_list_changes = 1;
+	}
+
+	foreach my $storeid (@$old_storeid_list) {
+	    next if grep { $_ eq $storeid } @$storeid_list;
+	    $storeid_list_changes = 1;
+	}
+
+	$logmsg->("$jobid: changed storeid list " . join(',', @$storeid_list))
+	    if $storeid_list_changes;
     }
     $status = $new;
 }
diff --git a/bin/test/replication_test2.pl b/bin/test/replication_test2.pl
index 6f25e1dd..9bdc8e87 100755
--- a/bin/test/replication_test2.pl
+++ b/bin/test/replication_test2.pl
@@ -19,12 +19,13 @@ $ReplicationTestEnv::mocked_nodename = 'node1';
 my $schedule = [];
 
 my $mocked_replicate = sub {
-    my ($jobcfg, $start_time) = @_;
+    my ($jobcfg, $state, $start_time, $logfunc) = @_;
 
     push @$schedule, {
 	id => $jobcfg->{id},
 	guest => $jobcfg->{guest},
 	vmtype => $jobcfg->{vmtype},
+	last_sync => $state->{last_sync},
 	start => $start_time,
     };
 };
@@ -32,13 +33,6 @@ my $mocked_replicate = sub {
 my $pve_replication_module = Test::MockModule->new('PVE::Replication');
 $pve_replication_module->mock(replicate => $mocked_replicate);
 
-
-my $testjob = {
-    'type'  => 'local',
-    'target' => 'node1',
-    'guest' => 900,
-};
-
 $ReplicationTestEnv::mocked_replication_jobs = {
     job_900_to_node2 => {
 	'type'  => 'local',
@@ -72,28 +66,32 @@ for (my $i = 0; $i < 61; $i++) {
 
 my $exptected_schedule = [
     {
-	'start' => 0,
-	'vmtype' => 'qemu',
-	'id' => 'job_900_to_node2',
-	'guest' => 900
+	last_sync => 0,
+	start => 900,
+	vmtype => 'qemu',
+	id => 'job_900_to_node2',
+	guest => 900
     },
     {
-	'guest' => 900,
-	'id' => 'job_900_to_node2',
-	'vmtype' => 'qemu',
-	'start' => 900
-    },
+	last_sync => 900,
+	start => 1800,
+	vmtype => 'qemu',
+	id => 'job_900_to_node2',
+	guest => 900,
+   },
     {
-	'start' => 1800,
-	'vmtype' => 'qemu',
-	'id' => 'job_900_to_node2',
-	'guest' => 900
+	last_sync => 1800,
+	start => 2700,
+	vmtype => 'qemu',
+	id => 'job_900_to_node2',
+	guest => 900
     },
     {
-	'vmtype' => 'qemu',
-	'start' => 2700,
-	'id' => 'job_900_to_node2',
-	'guest' => 900
+	last_sync => 2700,
+	start => 3600,
+	vmtype => 'qemu',
+	id => 'job_900_to_node2',
+	guest => 900
     }
 ];
 
diff --git a/bin/test/replication_test5.log b/bin/test/replication_test5.log
index e47f23db..45cdad87 100644
--- a/bin/test/replication_test5.log
+++ b/bin/test/replication_test5.log
@@ -7,6 +7,7 @@
 1000 job_900_to_node2: end replication job
 1000 job_900_to_node2: changed config next_sync => 1800
 1000 job_900_to_node2: changed state last_node => node1, last_try => 1000, last_sync => 1000
+1000 job_900_to_node2: changed storeid list local-zfs
 1840 job_900_to_node2: start replication job
 1840 job_900_to_node2: guest => 900, type => qemu, running => 0
 1840 job_900_to_node2: volumes => local-zfs:vm-900-disk-1
-- 
2.11.0




More information about the pve-devel mailing list