Skip to content

Commit 68bbe72

Browse files
committed
hack out bufwriter capacity
1 parent 881344e commit 68bbe72

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/directory/directory.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ pub trait Directory: DirectoryClone + fmt::Debug + Send + Sync + 'static {
296296
fn log(&self, message: &str) {
297297
log!(Level::Info, "{message}");
298298
}
299+
300+
fn bufwriter_capacity(&self) -> usize {
301+
8192
302+
}
299303
}
300304

301305
/// DirectoryClone

src/directory/managed_directory.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,16 @@ impl Directory for ManagedDirectory {
313313
fn open_write(&self, path: &Path) -> result::Result<WritePtr, OpenWriteError> {
314314
self.register_file_as_managed(path)
315315
.map_err(|io_error| OpenWriteError::wrap_io_error(io_error, path.to_path_buf()))?;
316-
Ok(io::BufWriter::new(Box::new(FooterProxy::new(
317-
self.directory
318-
.open_write(path)?
319-
.into_inner()
320-
.map_err(|_| ())
321-
.expect("buffer should be empty"),
322-
))))
316+
Ok(io::BufWriter::with_capacity(
317+
self.bufwriter_capacity(),
318+
Box::new(FooterProxy::new(
319+
self.directory
320+
.open_write(path)?
321+
.into_inner()
322+
.map_err(|_| ())
323+
.expect("buffer should be empty"),
324+
)),
325+
))
323326
}
324327

325328
fn atomic_write(&self, path: &Path, data: &[u8]) -> io::Result<()> {
@@ -380,6 +383,10 @@ impl Directory for ManagedDirectory {
380383
fn log(&self, message: &str) {
381384
self.directory.log(message);
382385
}
386+
387+
fn bufwriter_capacity(&self) -> usize {
388+
self.directory.bufwriter_capacity()
389+
}
383390
}
384391

385392
impl Clone for ManagedDirectory {

src/directory/mmap_directory.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ impl Directory for MmapDirectory {
443443
// sync_directory() is called.
444444

445445
let writer = SafeFileWriter::new(file);
446-
Ok(BufWriter::new(Box::new(writer)))
446+
Ok(BufWriter::with_capacity(
447+
self.bufwriter_capacity(),
448+
Box::new(writer),
449+
))
447450
}
448451

449452
fn atomic_read(&self, path: &Path) -> Result<Vec<u8>, OpenReadError> {

src/directory/ram_directory.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ impl Directory for RamDirectory {
206206
if exists {
207207
Err(OpenWriteError::FileAlreadyExists(path_buf))
208208
} else {
209-
Ok(BufWriter::new(Box::new(vec_writer)))
209+
Ok(BufWriter::with_capacity(
210+
self.bufwriter_capacity(),
211+
Box::new(vec_writer),
212+
))
210213
}
211214
}
212215

0 commit comments

Comments
 (0)