mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-14 03:50:39 +00:00
fix: win cli lock (#8049)
Signed-off-by: jeremyhi <fengjiachun@gmail.com>
This commit is contained in:
@@ -234,7 +234,7 @@ pub(crate) fn try_acquire_import_state_lock(path: &Path) -> Result<ImportStateLo
|
||||
path: lock_path.display().to_string(),
|
||||
})?;
|
||||
file.try_lock_exclusive().map_err(|error| {
|
||||
if error.kind() == std::io::ErrorKind::WouldBlock {
|
||||
if is_lock_contention(&error) {
|
||||
ImportStateLockedSnafu {
|
||||
path: lock_path.display().to_string(),
|
||||
}
|
||||
@@ -250,6 +250,11 @@ pub(crate) fn try_acquire_import_state_lock(path: &Path) -> Result<ImportStateLo
|
||||
Ok(ImportStateLockGuard { file })
|
||||
}
|
||||
|
||||
fn is_lock_contention(error: &std::io::Error) -> bool {
|
||||
error.kind() == std::io::ErrorKind::WouldBlock
|
||||
|| error.raw_os_error() == fs2::lock_contended_error().raw_os_error()
|
||||
}
|
||||
|
||||
fn unique_tmp_path(path: &Path) -> PathBuf {
|
||||
let pid = std::process::id();
|
||||
let seq = IMPORT_STATE_TMP_ID.fetch_add(1, Ordering::Relaxed);
|
||||
@@ -435,6 +440,13 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lock_contention_detection_accepts_platform_error() {
|
||||
let error = fs2::lock_contended_error();
|
||||
|
||||
assert!(is_lock_contention(&error));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_acquire_import_state_lock_rejects_second_holder() {
|
||||
let dir = tempdir().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user