public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Stoiko Ivanov <s.ivanov@proxmox.com>, pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-api 5/5] backup: pbs: prevent race in concurrent backups
Date: Thu, 25 Feb 2021 11:14:29 +0100	[thread overview]
Message-ID: <41302765-2bd4-28cc-bb6b-ed91cd46e23c@proxmox.com> (raw)
In-Reply-To: <20210224183109.29014-6-s.ivanov@proxmox.com>

On 24.02.21 19:31, Stoiko Ivanov wrote:
> If two pbs backup-creation calls happen simultaenously, it is possible

s/simultaenously/simultaneously/

> that the first removes the backup dir before the other is done
> creating or sending it to the pbs remote.
> 
> non-PBS backups are not affected, since they create the files for
> tar in a tempdir (indexed by PID and current time).

seems like that has a proven track record and avoids issues this one has,
see below.

> 
> Noticed while having 2 schedules to different PBS instances with the
> same interval and w/o random delay.
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
>  src/PMG/API2/PBS/Job.pm | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/PMG/API2/PBS/Job.pm b/src/PMG/API2/PBS/Job.pm
> index 279afbc..e5dcb9c 100644
> --- a/src/PMG/API2/PBS/Job.pm
> +++ b/src/PMG/API2/PBS/Job.pm
> @@ -303,13 +303,14 @@ __PACKAGE__->register_method ({
>  
>  	my $pbs = PVE::PBSClient->new($remote_config, $remote, $conf->{secret_dir});
>  	my $backup_dir = "/var/lib/pmg/backup/current";
> +	my $lockfile = "/var/lock/pmg-pbs-backup.lck";
>  
>  	my $worker = sub {
>  	    my $upid = shift;
>  
>  	    my $log = "starting update of current backup state\n";
>  
> -	    eval {
> +	    my $create_backup = sub {
>  		-d $backup_dir || mkdir $backup_dir;
>  		PMG::Backup::pmg_backup($backup_dir, $param->{statistic});
>  
> @@ -317,6 +318,10 @@ __PACKAGE__->register_method ({
>  
>  		rmtree $backup_dir;
>  	    };
> +
> +	    eval {
> +		PVE::Tools::lock_file($lockfile, undef, $create_backup);

lock_file times out in 10s, as we have multiple people running into a 20s timeout
in PBS I guess this does not solves the problem at all, as the backup coming
second to the lock acquire can still always fail if backup always needs more than
10s (maybe unlikely in your fast local setup, not so unlikely if PBS is external
both are slow and/or high loaded).

Instead of bumping that timeout to dice-roll-times-100 I'd rather use different
target backups as mentioned yesterday in our lighthearted off-list lunch talk
about this.

Between same-backup job locking could be an idea, but not to sure how many people
plan to have jobs requiring minutes and setting up schedules minutely.

That could be something one could warn about in the backup task log at the end
if wanted, (there we now the duration and could check time between next run)

> +	    };
>  	    my $err = $@;
>  	    $log .= $err if $err;
>  
> 





  reply	other threads:[~2021-02-25 10:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 18:30 [pmg-devel] [PATCH pmg-api/gui/docs] small improvments for PBS integration Stoiko Ivanov
2021-02-24 18:30 ` [pmg-devel] [PATCH pmg-api 1/5] backup: fix die invocation Stoiko Ivanov
2021-02-25  9:40   ` [pmg-devel] applied: " Thomas Lamprecht
2021-02-24 18:30 ` [pmg-devel] [PATCH pmg-api 2/5] backup: fix #3154 add 'include-statistics' to pbs Stoiko Ivanov
2021-02-25  9:40   ` [pmg-devel] applied: " Thomas Lamprecht
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-api 3/5] backup: fix #3146 add email notifications Stoiko Ivanov
2021-02-25 10:04   ` Thomas Lamprecht
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-api 4/5] backup: add notify parameter to 'classic' backup Stoiko Ivanov
2021-02-25 10:06   ` Thomas Lamprecht
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-api 5/5] backup: pbs: prevent race in concurrent backups Stoiko Ivanov
2021-02-25 10:14   ` Thomas Lamprecht [this message]
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-gui 1/4] backup: pbs: add onlineHelp anchors Stoiko Ivanov
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-gui 2/4] backup: fix #3154: make statistic backup optional Stoiko Ivanov
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-gui 3/4] backup: pbs: fix #3154: add statistic setting to remote Stoiko Ivanov
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-gui 4/4] backup: pbs: fix #3146 add notify " Stoiko Ivanov
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-docs 1/3] backup: fix typos Stoiko Ivanov
2021-02-25 10:15   ` [pmg-devel] applied: " Thomas Lamprecht
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-docs 2/3] backup: add anchors to pbs sections Stoiko Ivanov
2021-02-25 10:15   ` [pmg-devel] applied: " Thomas Lamprecht
2021-02-24 18:31 ` [pmg-devel] [PATCH pmg-docs 3/3] backup: shortly document #3146 and #3154 Stoiko Ivanov

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=41302765-2bd4-28cc-bb6b-ed91cd46e23c@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    --cc=s.ivanov@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