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