[pve-devel] [PATCH v4 pve-zsync 3/4] Detect other running instances of the same job

Fabian Ebner f.ebner at proxmox.com
Thu Oct 10 11:55:16 CEST 2019


A 'waiting' state is introduced and other 'waiting' and 'syncing'
instances of the same job are now detected by moving the check out
from the sync lock.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 pve-zsync | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/pve-zsync b/pve-zsync
index cfd8c08..abaa225 100755
--- a/pve-zsync
+++ b/pve-zsync
@@ -585,22 +585,33 @@ sub destroy_job {
 sub sync {
     my ($param) = @_;
 
+    my $job;
+
+    locked("$CONFIG_PATH/cron_and_state.lock", sub {
+	eval { $job = get_job($param) };
+
+	if ($job) {
+	    if (defined($job->{state}) && ($job->{state} eq "syncing" || $job->{state} eq "waiting")) {
+		die "Job --source $param->{source} --name $param->{name} is already scheduled to sync\n";
+	    }
+
+	    $job->{state} = "waiting";
+	    update_state($job);
+	}
+    });
+
     locked("$CONFIG_PATH/sync.lock", sub {
 
 	my $date = get_date();
-	my $job;
 
 	my $dest;
 	my $source;
 	my $vm_type;
 
 	locked("$CONFIG_PATH/cron_and_state.lock", sub {
+	    #job might've changed while we waited for the sync lock, but we can be sure it's not syncing
 	    eval { $job = get_job($param); };
 
-	    if ($job && defined($job->{state}) && $job->{state} eq "syncing") {
-		die "Job --source $param->{source} --name $param->{name} is syncing at the moment";
-	    }
-
 	    $dest = parse_target($param->{dest});
 	    $source = parse_target($param->{source});
 
-- 
2.20.1





More information about the pve-devel mailing list