lock with timeout
clumsy, but I have node idea how to make it better
This commit is contained in:
parent
2989f6bf20
commit
022fb421b2
|
@ -109,12 +109,34 @@ impl ChunkStore {
|
||||||
|
|
||||||
let fd = lockfile.as_raw_fd();
|
let fd = lockfile.as_raw_fd();
|
||||||
|
|
||||||
// fixme: lock with timeout
|
let now = std::time::SystemTime::now();
|
||||||
flock(fd, FlockArg::LockExclusive)?;
|
let timeout = 10;
|
||||||
|
let mut print_msg = true;
|
||||||
|
loop {
|
||||||
|
match flock(fd, FlockArg::LockExclusiveNonblock) {
|
||||||
|
Ok(_) => break,
|
||||||
|
Err(_) => {
|
||||||
|
if print_msg {
|
||||||
|
print_msg = false;
|
||||||
|
eprintln!("trying to aquire lock...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Got LOCK {:?}", fd);
|
match now.elapsed() {
|
||||||
|
Ok(elapsed) => {
|
||||||
//std::thread::sleep_ms(30000);
|
if elapsed.as_secs() >= timeout {
|
||||||
|
bail!("unable to aquire chunk store lock {:?} - got timeout",
|
||||||
|
lockfile_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
bail!("unable to aquire chunk store lock {:?} - clock problems - {}",
|
||||||
|
lockfile_path, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::thread::sleep_ms(100);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(ChunkStore {
|
Ok(ChunkStore {
|
||||||
base,
|
base,
|
||||||
|
|
Loading…
Reference in New Issue