Minimize unrelated changes

This commit is contained in:
Pascal Seitz
2026-09-16 23:39:47 +08:00
committed by PSeitz
parent a9d3f1a026
commit dfe904667e
7 changed files with 24 additions and 21 deletions
+2 -4
View File
@@ -65,7 +65,7 @@ pub struct AntiCallToken(());
///
/// Thread-safety is enforced at the call sites that require it.
pub trait TerminatingWrite: Write {
/// Indicates that the writer will no longer be used. Internally calls `terminate_ref`.
/// Indicate that the writer will no longer be used. Internally call terminate_ref.
fn terminate(mut self) -> io::Result<()>
where Self: Sized {
self.terminate_ref(AntiCallToken(()))
@@ -84,9 +84,7 @@ impl<W: TerminatingWrite + ?Sized> TerminatingWrite for Box<W> {
impl<W: TerminatingWrite> TerminatingWrite for BufWriter<W> {
fn terminate_ref(&mut self, a: AntiCallToken) -> io::Result<()> {
if !self.buffer().is_empty() {
self.flush()?;
}
self.flush()?;
self.get_mut().terminate_ref(a)
}
}
+13 -7
View File
@@ -139,15 +139,21 @@ pub trait Directory: DirectoryClone + fmt::Debug + Send + Sync + 'static {
/// Opens a writer for the *virtual file* associated with
/// a [`Path`].
///
/// Depending on the directory implementation, [`Directory::sync_directory()`] may be required
/// after terminating the writer to ensure that the file is durably created.
/// After the writer is terminated, the file should be created and any subsequent call to
/// [`Directory::open_read()`] for the same path should return a [`FileSlice`].
///
/// Write operations may be aggressively buffered. The client must call
/// [`TerminatingWrite::terminate()`] to finalize the file and make all writes available to
/// subsequent reads. The directory implementation owns its buffering strategy; clients should
/// not rely on `flush()` making an incomplete file available.
/// However, depending on the directory implementation,
/// it might be required to call [`Directory::sync_directory()`] to ensure
/// that the file is durably created.
/// (The semantics here are the same when dealing with
/// a POSIX filesystem.)
///
/// The user shall not rely on [`Drop`] finalizing the file.
/// Write operations may be aggressively buffered.
/// The client of this trait is responsible for calling terminate
/// to ensure that subsequent `read` operations
/// will take into account preceding `write` operations.
///
/// The user shall not rely on [`Drop`] triggering terminate.
///
/// The file may not previously exist.
fn open_write(&self, path: &Path) -> Result<WritePtr, OpenWriteError>;
+2 -2
View File
@@ -126,9 +126,9 @@ impl Footer {
}
pub(crate) struct FooterProxy<W: TerminatingWrite> {
/// Always `Some` except after `terminate()` is called.
/// always Some except after terminate call
hasher: Option<Hasher>,
/// Always `Some` except after `terminate()` is called.
/// always Some except after terminate call
writer: Option<W>,
}
+2 -1
View File
@@ -318,7 +318,8 @@ impl Drop for ReleaseLockFile {
}
}
/// Wraps a file and syncs its data when the writer is terminated.
/// This Write wraps a File, but has the specificity of
/// calling `sync_all` on terminate.
struct SafeFileWriter(File);
impl SafeFileWriter {
+1 -3
View File
@@ -60,7 +60,7 @@ impl Drop for MemoryUsageTracker {
/// Writer associated with the [`RamDirectory`].
///
/// The writer stores its buffer in the directory when terminated.
/// The Writer just writes a buffer.
struct VecWriter {
path: PathBuf,
shared_directory: RamDirectory,
@@ -109,8 +109,6 @@ impl Write for VecWriter {
Ok(buf.len())
}
/// Nothing to flush since the data is stored in memory. The memory usage is updated on each
/// write.
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
+1 -1
View File
@@ -8,7 +8,7 @@ use crate::DocId;
/// Write an alive `BitSet`
///
/// where `alive_bitset` is the set of alive `DocId`.
/// Warning: this function does not call `terminate()`. The caller is in charge of
/// Warning: this function does not call terminate. The caller is in charge of
/// closing the writer properly.
pub fn write_alive_bitset<T: Write>(alive_bitset: &BitSet, writer: &mut T) -> io::Result<()> {
alive_bitset.serialize(writer)?;
+3 -3
View File
@@ -86,8 +86,8 @@ impl<W: io::Write> PositionSerializer<W> {
Ok(())
}
/// Close the positions for this field.
pub fn close(self) -> io::Result<()> {
Ok(())
/// Close the positions for this term and flushes the data.
pub fn close(mut self) -> io::Result<()> {
self.positions_wrt.flush()
}
}