perf: replace blocking Path::exists() with async try_exists() in dedup hot path
- store_bytes: blob_path.exists() → fs::try_exists(&blob_path).await - store_from_file: blob_path.exists() → fs::try_exists(&blob_path).await (2 sites) - Prevents synchronous stat() syscalls from blocking Tokio worker threads during concurrent uploads
This commit is contained in:
@@ -244,7 +244,7 @@ impl DedupService {
|
|||||||
// both produce identical files. The rename is atomic on the
|
// both produce identical files. The rename is atomic on the
|
||||||
// same filesystem; if it fails because the other writer won,
|
// same filesystem; if it fails because the other writer won,
|
||||||
// we just discard our temp file — the blob is already there.
|
// we just discard our temp file — the blob is already there.
|
||||||
if !blob_path.exists() {
|
if !fs::try_exists(&blob_path).await.unwrap_or(false) {
|
||||||
// Parent directory (xx/) guaranteed to exist — created by initialize()
|
// Parent directory (xx/) guaranteed to exist — created by initialize()
|
||||||
let temp_path = self.temp_root.join(format!("{}.tmp", uuid::Uuid::new_v4()));
|
let temp_path = self.temp_root.join(format!("{}.tmp", uuid::Uuid::new_v4()));
|
||||||
fs::write(&temp_path, content).await.map_err(|e| {
|
fs::write(&temp_path, content).await.map_err(|e| {
|
||||||
@@ -342,7 +342,7 @@ impl DedupService {
|
|||||||
//
|
//
|
||||||
// If the blob file already exists on disk, the source is simply
|
// If the blob file already exists on disk, the source is simply
|
||||||
// deleted — the file content is identical by definition.
|
// deleted — the file content is identical by definition.
|
||||||
if blob_path.exists() {
|
if fs::try_exists(&blob_path).await.unwrap_or(false) {
|
||||||
// Blob already on disk — discard the source file
|
// Blob already on disk — discard the source file
|
||||||
let _ = fs::remove_file(source_path).await;
|
let _ = fs::remove_file(source_path).await;
|
||||||
} else {
|
} else {
|
||||||
@@ -361,7 +361,7 @@ impl DedupService {
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let _ = fs::remove_file(source_path).await;
|
let _ = fs::remove_file(source_path).await;
|
||||||
} else if blob_path.exists() {
|
} else if fs::try_exists(&blob_path).await.unwrap_or(false) {
|
||||||
// Another writer may have placed the blob concurrently
|
// Another writer may have placed the blob concurrently
|
||||||
let _ = fs::remove_file(source_path).await;
|
let _ = fs::remove_file(source_path).await;
|
||||||
tracing::debug!("Blob file placed by concurrent writer: {}", e);
|
tracing::debug!("Blob file placed by concurrent writer: {}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user