pub struct OutputDir { /* private fields */ }Expand description
A directory that holds, or is about to hold, the results of one sweep, locked against other writers.
The lock is the operating system’s advisory lock on the file LOCK_FILE, released when the value is dropped. The
file stays in the directory, and the next writer locks it again. The lock is released when the process that holds it
ends, even when the process is killed.
A writer creates afresh each file it replaces. It appends to runs.csv and series.csv, and cuts them, only after
Self::open has checked that neither table is a symbolic link.
Implementations§
Source§impl OutputDir
impl OutputDir
Sourcepub fn check_free(path: &Path) -> Result<(), OutputError>
pub fn check_free(path: &Path) -> Result<(), OutputError>
Checks that the directory at path holds no results, without creating it.
A symbolic link under the name of a file counts as that file, even a link that points nowhere.
§Errors
Returns OutputError::HoldsResults when the directory holds a file that a sweep or a search writes,
including a staged table or the marker of staged tables.
Sourcepub fn create(path: &Path) -> Result<Self, OutputError>
pub fn create(path: &Path) -> Result<Self, OutputError>
Creates the directory at path and its parents, or uses an existing directory that holds no results, and
locks it.
§Errors
Returns OutputError::HoldsResults when the directory holds a file that a sweep or a search writes,
OutputError::Locked when another writer holds its lock, and OutputError::Write when it cannot be
created.
Sourcepub fn holds_results(path: &Path) -> bool
pub fn holds_results(path: &Path) -> bool
Returns whether the directory at path holds a file that a sweep or a search writes.
Sourcepub fn open(path: &Path) -> Result<Self, OutputError>
pub fn open(path: &Path) -> Result<Self, OutputError>
Locks the existing directory at path, finishing a table replacement that a process left behind.
§Errors
Returns OutputError::Locked when another writer holds the directory’s lock, OutputError::Link when
runs.csv or series.csv is a symbolic link, and OutputError::Write when the replacement cannot be
finished or discarded.
Sourcepub fn check_unlocked(path: &Path) -> Result<(), OutputError>
pub fn check_unlocked(path: &Path) -> Result<(), OutputError>
Checks that no writer holds the lock of the directory at path, without taking it.
§Errors
Returns OutputError::Locked when another writer holds the lock.
Sourcepub fn open_writer(
&self,
plan: &Arc<Plan>,
params: &[ParamDescriptor],
measure: &MeasurePlan,
) -> Result<OutputWriter<BufWriter<File>>, OutputError>
pub fn open_writer( &self, plan: &Arc<Plan>, params: &[ParamDescriptor], measure: &MeasurePlan, ) -> Result<OutputWriter<BufWriter<File>>, OutputError>
Creates runs.csv and series.csv, and returns a writer for the runs of plan.
params are the model’s parameters, and measure fixes the stat and reducer columns.
§Errors
Returns OutputError::Write when a file exists already or cannot be created, or its header cannot be written.
Sourcepub fn append_writer(
&self,
plan: &Arc<Plan>,
params: &[ParamDescriptor],
) -> Result<OutputWriter<BufWriter<File>>, OutputError>
pub fn append_writer( &self, plan: &Arc<Plan>, params: &[ParamDescriptor], ) -> Result<OutputWriter<BufWriter<File>>, OutputError>
Opens runs.csv and series.csv, whose headers are already written, and returns a writer that adds the runs
of plan to them.
§Errors
Returns OutputError::Write when a file cannot be opened.
Sourcepub fn replace_tables(
&self,
write_runs: impl FnOnce(&mut dyn Write) -> Result<()>,
write_series: impl FnOnce(&mut dyn Write) -> Result<()>,
) -> Result<(), OutputError>
pub fn replace_tables( &self, write_runs: impl FnOnce(&mut dyn Write) -> Result<()>, write_series: impl FnOnce(&mut dyn Write) -> Result<()>, ) -> Result<(), OutputError>
Replaces runs.csv and series.csv with the text that write_runs and write_series write.
Each table is written in full beside the original with a .staged suffix. A marker file then records that both
tables are complete, both tables are renamed into place, and the marker is removed. A process that ends between
the marker and its removal leaves the replacement for Self::open to finish.
§Errors
Returns OutputError::Write when a write, a rename or a removal fails. The originals stay in place until
both new tables are complete.
Sourcepub fn order_tables(&self) -> Result<(), OutputError>
pub fn order_tables(&self) -> Result<(), OutputError>
Rewrites runs.csv and series.csv with their runs in order of their ids, leaving tables already in order
alone.
§Errors
Returns OutputError::Table when a table cannot be read back, and OutputError::Write when the
replacement fails.
Sourcepub fn create_table(&self, file: &str) -> Result<BufWriter<File>, OutputError>
pub fn create_table(&self, file: &str) -> Result<BufWriter<File>, OutputError>
Creates the table file afresh, removing any existing file of that name, and returns a buffered writer over it.
§Errors
Returns OutputError::Write when the file cannot be removed or created.
Sourcepub fn write_manifest(&self, manifest: &Manifest) -> Result<(), OutputError>
pub fn write_manifest(&self, manifest: &Manifest) -> Result<(), OutputError>
Writes manifest to manifest.json. An earlier manifest is replaced by a single rename, so a reader sees
either the old or the new manifest whole.
§Errors
Returns OutputError::Manifest when the manifest cannot be serialized, and OutputError::Write when a
write or the rename fails.
Sourcepub fn write_summary(&self) -> Result<(), OutputError>
pub fn write_summary(&self) -> Result<(), OutputError>
Rebuilds summary.csv from runs.csv.
§Errors
Returns OutputError::Read when runs.csv cannot be read, OutputError::Write when summary.csv
cannot be written, and OutputError::Summary when runs.csv cannot be summarized.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OutputDir
impl RefUnwindSafe for OutputDir
impl Send for OutputDir
impl Sync for OutputDir
impl Unpin for OutputDir
impl UnsafeUnpin for OutputDir
impl UnwindSafe for OutputDir
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more