From: Stefan Sterz <s.sterz@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 3/4] fix #3935: datastore: move manifest locking to new locking method
Date: Wed, 13 Apr 2022 11:11:50 +0200 [thread overview]
Message-ID: <20220413091151.150019-4-s.sterz@proxmox.com> (raw)
In-Reply-To: <20220413091151.150019-1-s.sterz@proxmox.com>
adds double stat'ing and removes directory hierarchy to bring manifest
locking in-line with other locks used by the datastore trait.
Signed-off-by: Stefan Sterz <s.sterz@proxmox.com>
---
pbs-datastore/src/datastore.rs | 56 +++++++++++++---------------------
1 file changed, 21 insertions(+), 35 deletions(-)
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index 92d544e5..803dcef1 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -32,9 +32,7 @@ use crate::dynamic_index::{DynamicIndexReader, DynamicIndexWriter};
use crate::fixed_index::{FixedIndexReader, FixedIndexWriter};
use crate::index::IndexFile;
use crate::manifest::{
- MANIFEST_BLOB_NAME, MANIFEST_LOCK_NAME, CLIENT_LOG_BLOB_NAME,
- ArchiveType, BackupManifest,
- archive_type,
+ archive_type, ArchiveType, BackupManifest, CLIENT_LOG_BLOB_NAME, MANIFEST_BLOB_NAME,
};
use crate::task_tracking::update_active_operations;
@@ -403,10 +401,7 @@ impl DataStore {
})?;
// the manifest does not exists anymore, we do not need to keep the lock
- if let Ok(path) = self.manifest_lock_path(backup_dir) {
- // ignore errors
- let _ = std::fs::remove_file(path);
- }
+ let _ = std::fs::remove_file(self.manifest_lock_path(backup_dir));
let _ = std::fs::remove_file(self.snapshot_lock_path(backup_dir));
@@ -858,41 +853,32 @@ impl DataStore {
))
}
- /// Returns the filename to lock a manifest
+ /// Returns the filename to lock a manifest.
///
- /// Also creates the basedir. The lockfile is located in
- /// '/run/proxmox-backup/locks/{datastore}/{type}/{id}/{timestamp}.index.json.lck'
- fn manifest_lock_path(
- &self,
- backup_dir: &BackupDir,
- ) -> Result<String, Error> {
- let mut path = format!(
- "/run/proxmox-backup/locks/{}/{}/{}",
- self.name(),
+ /// The lock file will be located in:
+ /// `${DATASTORE_LOCKS_DIR}/${datastore name}/${lock_file_name_helper(rpath)}`
+ /// where rpath is the relative path of the snapshot appended with "manifest".
+ fn manifest_lock_path(&self, backup_dir: &BackupDir) -> PathBuf {
+ let path = Path::new(DATASTORE_LOCKS_DIR).join(self.name());
+
+ let rpath = format!(
+ "{}/{}/{}-manifest",
backup_dir.group().backup_type(),
backup_dir.group().backup_id(),
+ backup_dir.backup_time_string(),
);
- std::fs::create_dir_all(&path)?;
- use std::fmt::Write;
- write!(path, "/{}{}", backup_dir.backup_time_string(), &MANIFEST_LOCK_NAME)?;
- Ok(path)
+ path.join(self.lock_file_name_helper(&rpath))
}
- fn lock_manifest(
- &self,
- backup_dir: &BackupDir,
- ) -> Result<BackupLockGuard, Error> {
- let path = self.manifest_lock_path(backup_dir)?;
-
- // update_manifest should never take a long time, so if someone else has
- // the lock we can simply block a bit and should get it soon
- open_backup_lockfile(&path, Some(Duration::from_secs(5)), true)
- .map_err(|err| {
- format_err!(
- "unable to acquire manifest lock {:?} - {}", &path, err
- )
- })
+ fn lock_manifest(&self, backup_dir: &BackupDir) -> Result<BackupLockGuard, Error> {
+ self.lock_helper(&self.manifest_lock_path(backup_dir), |p| {
+ // update_manifest should never take a long time, so if
+ // someone else has the lock we can simply block a bit
+ // and should get it soon
+ open_backup_lockfile(&p, Some(Duration::from_secs(5)), true)
+ .map_err(|err| format_err!("unable to acquire manifest lock {:?} - {}", &p, err))
+ })
}
/// Load the manifest without a lock. Must not be written back.
--
2.30.2
next prev parent reply other threads:[~2022-04-13 9:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-13 9:11 [pbs-devel] [PATCH proxmox-backup v2 0/4] refactor datastore locking to use tmpfs Stefan Sterz
2022-04-13 9:11 ` [pbs-devel] [PATCH proxmox-backup v2 1/4] fix #3935: datastore/api/backup: add locking helpers to datastore Stefan Sterz
2022-04-13 9:11 ` [pbs-devel] [PATCH proxmox-backup v2 2/4] fix #3935: datastore/api/backup: move datastore locking to '/run' Stefan Sterz
2022-04-13 9:11 ` Stefan Sterz [this message]
2022-04-13 9:11 ` [pbs-devel] [PATCH proxmox-backup v2 4/4] fix: api: avoid race condition in set_backup_owner Stefan Sterz
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=20220413091151.150019-4-s.sterz@proxmox.com \
--to=s.sterz@proxmox.com \
--cc=pbs-devel@lists.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