mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
improve data sync reliability to underlying storage medium
This commit is contained in:
committed by
Aiden McClelland
parent
690324e68d
commit
f84637b89d
@@ -83,8 +83,7 @@ impl Store {
|
|||||||
backup_file.flush()?;
|
backup_file.flush()?;
|
||||||
backup_file.sync_all()?;
|
backup_file.sync_all()?;
|
||||||
std::fs::rename(&bak_tmp, &bak)?;
|
std::fs::rename(&bak_tmp, &bak)?;
|
||||||
nix::unistd::ftruncate(std::os::unix::io::AsRawFd::as_raw_fd(&*f), 0)
|
f.set_len(0)?;
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
|
||||||
serde_cbor::to_writer(&mut *f, &revision)?;
|
serde_cbor::to_writer(&mut *f, &revision)?;
|
||||||
serde_cbor::to_writer(&mut *f, &data)?;
|
serde_cbor::to_writer(&mut *f, &data)?;
|
||||||
f.flush()?;
|
f.flush()?;
|
||||||
@@ -187,7 +186,7 @@ impl Store {
|
|||||||
async fn sync_to_disk(file: &mut File, patch_bin: &[u8]) -> Result<(), IOError> {
|
async fn sync_to_disk(file: &mut File, patch_bin: &[u8]) -> Result<(), IOError> {
|
||||||
file.write_all(patch_bin).await?;
|
file.write_all(patch_bin).await?;
|
||||||
file.flush().await?;
|
file.flush().await?;
|
||||||
file.sync_data().await?;
|
file.sync_all().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
if let Err(e) = sync_to_disk(&mut *self.file, &patch_bin).await {
|
if let Err(e) = sync_to_disk(&mut *self.file, &patch_bin).await {
|
||||||
|
|||||||
Reference in New Issue
Block a user