Skip to content

Commit 47aaa18

Browse files
hold lock across sync
1 parent c1d7a99 commit 47aaa18

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

runtime/src/storage/tokio/fallback.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,28 @@ impl crate::Blob for Blob {
102102
offset: u64,
103103
bufs: impl Into<IoBufs> + Send,
104104
) -> Result<(), Error> {
105-
let bufs = bufs.into();
105+
let mut bufs = bufs.into();
106106
if !bufs.has_remaining() {
107107
return Ok(());
108108
}
109109

110-
self.write_at(offset, bufs).await?;
111-
self.sync().await
110+
let mut file = self.file.lock().await;
111+
let offset = offset
112+
.checked_add(Header::SIZE_U64)
113+
.ok_or(Error::OffsetOverflow)?;
114+
file.seek(SeekFrom::Start(offset))
115+
.await
116+
.map_err(|_| Error::WriteFailed)?;
117+
118+
if let Some(buf) = bufs.as_single() {
119+
Self::write_single_at(&mut file, buf.as_ref()).await?;
120+
} else {
121+
Self::write_vectored_at(&mut file, &mut bufs).await?;
122+
}
123+
124+
file.sync_all()
125+
.await
126+
.map_err(|e| Error::BlobSyncFailed(self.partition.clone(), hex(&self.name), e))
112127
}
113128

114129
async fn resize(&self, len: u64) -> Result<(), Error> {

0 commit comments

Comments
 (0)