[pbs-devel] [PATCH proxmox-backup 1/5] backup: don't validate chunk existance if base was recently verified

Stefan Reiter s.reiter at proxmox.com
Wed Sep 30 15:42:50 CEST 2020


On 9/30/20 3:32 PM, Thomas Lamprecht wrote:
> On 30.09.20 15:25, Stefan Reiter wrote:
>> If the base was successfully verified within the last 7 days, we assume
>> that it is okay and all chunks exist, so we don't have to check.
>>
>> Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
>> ---
>>   src/api2/backup/environment.rs | 29 ++++++++++++++++++++++++++++-
>>   1 file changed, 28 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
>> index d515bf30..be06d1dc 100644
>> --- a/src/api2/backup/environment.rs
>> +++ b/src/api2/backup/environment.rs
>> @@ -457,6 +457,31 @@ impl BackupEnvironment {
>>           Ok(())
>>       }
>>   
>> +    fn last_backup_has_recent_verify(&self) -> Result<bool, Error> {
>> +        match &self.last_backup {
>> +            Some(last_backup) => {
>> +                let last_dir = &last_backup.backup_dir;
>> +                let (manifest, _) = self.datastore.load_manifest(last_dir)?;
>> +                let verify = manifest.unprotected["verify_state"].clone();
>> +                match serde_json::from_value::<Option<SnapshotVerifyState>>(verify) {
>> +                    Ok(verify) => match verify {
>> +                        Some(verify) => {
>> +                            let cutoff = unsafe { libc::time(std::ptr::null_mut()) };
>> +                            let cutoff = cutoff - 60*60*24*7; // one week back
> 
> Why unsafe and why not our `proxmox::tools::time::epoch_i64()` ?
> 

Didn't know that exists, I've seen that unsafe a few times so I thought 
that was the usual way. I'll send v2.

> 
> on another note: we should probably add some helper for getting the
> verify state
> 

I'll see if it's feasible. So far we only have two sites that both do 
different things on individual errors, so I'm not sure how much that 
would simplify things.

>> +                            Ok(verify.state == VerifyState::Ok && verify.upid.starttime > cutoff)
>> +                        },
>> +                        None => Ok(false)
>> +                    },
>> +                    Err(err) => {
>> +                        self.worker.warn(format!("error parsing base verification state : '{}'", err));
>> +                        Ok(false)
>> +                    }
>> +                }
>> +            },
>> +            None => Ok(false)
>> +        }
>> +    }
>> +
>>       /// Ensure all chunks referenced in this backup actually exist.
>>       /// Only call *after* all writers have been closed, to avoid race with GC.
>>       /// In case of error, mark the previous backup as 'verify failed'.
>> @@ -534,7 +559,9 @@ impl BackupEnvironment {
>>               }
>>           }
>>   
>> -        self.verify_chunk_existance(&state.known_chunks)?;
>> +        if !self.last_backup_has_recent_verify()? {
>> +            self.verify_chunk_existance(&state.known_chunks)?;
>> +        }
>>   
>>           // marks the backup as successful
>>           state.finished = true;
>>
> 
> 





More information about the pbs-devel mailing list