Add appropriate fsync() calls in write_block
to ensure that data is persisted properly
This commit is contained in:
parent
68b2693cd4
commit
9125a57234
1 changed files with 13 additions and 2 deletions
|
@ -862,9 +862,11 @@ impl BlockManagerLocked {
|
||||||
let data = data.inner_buffer();
|
let data = data.inner_buffer();
|
||||||
|
|
||||||
let mut path = mgr.block_dir(hash);
|
let mut path = mgr.block_dir(hash);
|
||||||
fs::create_dir_all(&path).await?;
|
let directory = path.clone();
|
||||||
|
|
||||||
path.push(hex::encode(hash));
|
path.push(hex::encode(hash));
|
||||||
|
|
||||||
|
fs::create_dir_all(&directory).await?;
|
||||||
|
|
||||||
let to_delete = match (mgr.is_block_compressed(hash).await, compressed) {
|
let to_delete = match (mgr.is_block_compressed(hash).await, compressed) {
|
||||||
(Ok(true), _) => return Ok(BlockRpc::Ok),
|
(Ok(true), _) => return Ok(BlockRpc::Ok),
|
||||||
(Ok(false), false) => return Ok(BlockRpc::Ok),
|
(Ok(false), false) => return Ok(BlockRpc::Ok),
|
||||||
|
@ -885,6 +887,7 @@ impl BlockManagerLocked {
|
||||||
path2.set_extension("tmp");
|
path2.set_extension("tmp");
|
||||||
let mut f = fs::File::create(&path2).await?;
|
let mut f = fs::File::create(&path2).await?;
|
||||||
f.write_all(data).await?;
|
f.write_all(data).await?;
|
||||||
|
f.sync_all().await?;
|
||||||
drop(f);
|
drop(f);
|
||||||
|
|
||||||
fs::rename(path2, path).await?;
|
fs::rename(path2, path).await?;
|
||||||
|
@ -892,6 +895,14 @@ impl BlockManagerLocked {
|
||||||
fs::remove_file(to_delete).await?;
|
fs::remove_file(to_delete).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let dir = fs::OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.mode(0)
|
||||||
|
.open(directory)
|
||||||
|
.await?;
|
||||||
|
dir.sync_all().await?;
|
||||||
|
drop(dir);
|
||||||
|
|
||||||
Ok(BlockRpc::Ok)
|
Ok(BlockRpc::Ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue