From a7aa559528284002c8469891c043a0222d79eaea Mon Sep 17 00:00:00 2001 From: "keroroxx520@gmail.com" Date: Thu, 12 Dec 2024 22:53:47 +0800 Subject: [PATCH 1/2] perf: skip lockfile exist checking when disable-lock enabled --- crates/storage/db/src/lockfile.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/storage/db/src/lockfile.rs b/crates/storage/db/src/lockfile.rs index b28a83f11ca4..dea5289a780d 100644 --- a/crates/storage/db/src/lockfile.rs +++ b/crates/storage/db/src/lockfile.rs @@ -3,7 +3,6 @@ #![cfg_attr(feature = "disable-lock", allow(dead_code))] use reth_storage_errors::lockfile::StorageLockError; -use reth_tracing::tracing::error; use std::{ path::{Path, PathBuf}, process, @@ -47,14 +46,14 @@ impl StorageLock { let file_path = path.join(LOCKFILE_NAME); if let Some(process_lock) = ProcessUID::parse(&file_path)? { if process_lock.pid != (process::id() as usize) && process_lock.is_active() { - error!( + reth_tracing::tracing::error!( target: "reth::db::lockfile", path = ?file_path, pid = process_lock.pid, start_time = process_lock.start_time, "Storage lock already taken." ); - return Err(StorageLockError::Taken(process_lock.pid)) + return Err(StorageLockError::Taken(process_lock.pid)); } } @@ -64,12 +63,14 @@ impl StorageLock { impl Drop for StorageLock { fn drop(&mut self) { + // The lockfile is not created in disable-lock mode, so we don't need to delete it. + #[cfg(not(feature = "disable-lock"))] if Arc::strong_count(&self.0) == 1 && self.0.file_path.exists() { // TODO: should only happen during tests that the file does not exist: tempdir is // getting dropped first. However, tempdir shouldn't be dropped // before any of the storage providers. if let Err(err) = reth_fs_util::remove_file(&self.0.file_path) { - error!(%err, "Failed to delete lock file"); + reth_tracing::tracing::error!(%err, "Failed to delete lock file"); } } } From 8df8909ca3495fac5161f8d361acee37f1d53fcd Mon Sep 17 00:00:00 2001 From: "keroroxx520@gmail.com" Date: Sat, 14 Dec 2024 09:42:11 +0800 Subject: [PATCH 2/2] chore: make fmt --- crates/storage/db/src/lockfile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/db/src/lockfile.rs b/crates/storage/db/src/lockfile.rs index dea5289a780d..63962bc4a4a8 100644 --- a/crates/storage/db/src/lockfile.rs +++ b/crates/storage/db/src/lockfile.rs @@ -53,7 +53,7 @@ impl StorageLock { start_time = process_lock.start_time, "Storage lock already taken." ); - return Err(StorageLockError::Taken(process_lock.pid)); + return Err(StorageLockError::Taken(process_lock.pid)) } }