diff options
author | Alex Auvolat <alex@adnab.me> | 2022-03-01 11:52:12 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-03-14 11:51:32 +0100 |
commit | dc5ec4ecf9df1664d79200dc9c41f86173ef7e07 (patch) | |
tree | 49339ca53026726146f5fe23d7b91a8d53e283e5 /src/model/block.rs | |
parent | fe62d01b7efd878d291d9830f530c769eeeb62ec (diff) | |
download | garage-dc5ec4ecf9df1664d79200dc9c41f86173ef7e07.tar.gz garage-dc5ec4ecf9df1664d79200dc9c41f86173ef7e07.zip |
Add appropriate fsync() calls in write_block
to ensure that data is persisted properly
Diffstat (limited to 'src/model/block.rs')
-rw-r--r-- | src/model/block.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/model/block.rs b/src/model/block.rs index ec1890bf..c7c178af 100644 --- a/src/model/block.rs +++ b/src/model/block.rs @@ -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) } |