Skip to content

Commit 6f912ef

Browse files
committed
Unlock the LOCK files on drop, so we can open them again in the same process
Signed-off-by: Yang Zhang <yang.zhang@pingcap.com>
1 parent 7e12385 commit 6f912ef

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/file_pipe_log/pipe.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::sync::Arc;
77

88
use crossbeam::utils::CachePadded;
99
use fail::fail_point;
10+
use fs2::FileExt;
1011
use log::error;
1112
use parking_lot::{Mutex, MutexGuard, RwLock};
1213

@@ -464,7 +465,17 @@ impl<F: FileSystem> SinglePipe<F> {
464465
pub struct DualPipes<F: FileSystem> {
465466
pipes: [SinglePipe<F>; 2],
466467

467-
_dir_locks: Vec<StdFile>,
468+
dir_locks: Vec<StdFile>,
469+
}
470+
471+
impl<F: FileSystem> Drop for DualPipes<F> {
472+
fn drop(&mut self) {
473+
for lock in &self.dir_locks {
474+
if let Err(e) = FileExt::unlock(lock) {
475+
error!("error while unlocking directory: {e}");
476+
}
477+
}
478+
}
468479
}
469480

470481
impl<F: FileSystem> DualPipes<F> {
@@ -481,7 +492,7 @@ impl<F: FileSystem> DualPipes<F> {
481492

482493
Ok(Self {
483494
pipes: [appender, rewriter],
484-
_dir_locks: dir_locks,
495+
dir_locks,
485496
})
486497
}
487498

0 commit comments

Comments
 (0)