@@ -10,7 +10,9 @@ use log::Level;
1010
1111use crate :: directory:: directory_lock:: Lock ;
1212use crate :: directory:: error:: { DeleteError , LockError , OpenReadError , OpenWriteError } ;
13- use crate :: directory:: { FileHandle , FileSlice , WatchCallback , WatchHandle , WritePtr } ;
13+ use crate :: directory:: {
14+ FileHandle , FileSlice , TerminatingWrite , WatchCallback , WatchHandle , WritePtr ,
15+ } ;
1416use crate :: index:: SegmentMetaInventory ;
1517use crate :: IndexMeta ;
1618
@@ -143,6 +145,10 @@ pub trait Directory: DirectoryClone + fmt::Debug + Send + Sync + 'static {
143145 /// Returns true if and only if the file exists
144146 fn exists ( & self , path : & Path ) -> Result < bool , OpenReadError > ;
145147
148+ /// Returns a boxed `TerminatingWrite` object, to be passed into `open_write`
149+ /// which wraps it in a `BufWriter`
150+ fn open_write_inner ( & self , path : & Path ) -> Result < Box < dyn TerminatingWrite > , OpenWriteError > ;
151+
146152 /// Opens a writer for the *virtual file* associated with
147153 /// a [`Path`].
148154 ///
@@ -169,7 +175,12 @@ pub trait Directory: DirectoryClone + fmt::Debug + Send + Sync + 'static {
169175 /// panic! if `flush` was not called.
170176 ///
171177 /// The file may not previously exist.
172- fn open_write ( & self , path : & Path ) -> Result < WritePtr , OpenWriteError > ;
178+ fn open_write ( & self , path : & Path ) -> Result < WritePtr , OpenWriteError > {
179+ Ok ( io:: BufWriter :: with_capacity (
180+ self . bufwriter_capacity ( ) ,
181+ self . open_write_inner ( path) ?,
182+ ) )
183+ }
173184
174185 /// Reads the full content file that has been written using
175186 /// [`Directory::atomic_write()`].
@@ -296,6 +307,10 @@ pub trait Directory: DirectoryClone + fmt::Debug + Send + Sync + 'static {
296307 fn log ( & self , message : & str ) {
297308 log ! ( Level :: Info , "{message}" ) ;
298309 }
310+
311+ fn bufwriter_capacity ( & self ) -> usize {
312+ 8192
313+ }
299314}
300315
301316/// DirectoryClone
0 commit comments