docs: the SWMR follow loop stops for a writer that died, not only one that closed
The README example looped while swmr_writer_active(), which never ends when the writer crashed or was killed: libhdf5 clears the SWMR-write flag only on close (the mid-write fixture keeps it set for good). The loop now also stops after a minute without growth, and the README, the swmr_writer_active docs (with the same loop as a compiled no_run doctest) and the design say why. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
@@ -616,10 +616,34 @@ impl File {
|
||||
self.swmr.retries()
|
||||
}
|
||||
|
||||
/// Whether a SWMR writer has the file open now: the superblock is read
|
||||
/// again and its SWMR-write flag returned. libhdf5 clears the flag when
|
||||
/// the writer closes the file, so a reader can stop following it then
|
||||
/// (and one last [`Dataset::refresh`] sees the final extents).
|
||||
/// Whether a SWMR writer has the file open now, as far as the file
|
||||
/// says: the superblock is read again and its SWMR-write flag returned.
|
||||
/// libhdf5 clears the flag when the writer closes the file, so a reader
|
||||
/// can stop following it then (and one last [`Dataset::refresh`] sees
|
||||
/// the final extents). A writer that crashed or was killed never clears
|
||||
/// it, so the flag alone is not a stop condition: give the loop another
|
||||
/// one, such as a time without growth.
|
||||
///
|
||||
/// ```no_run
|
||||
/// # fn main() -> Result<(), clawhdf5::Error> {
|
||||
/// use std::time::{Duration, Instant};
|
||||
///
|
||||
/// let file = clawhdf5::File::open_swmr("live.h5")?;
|
||||
/// let mut ds = file.dataset("samples")?;
|
||||
/// let (mut seen, mut last_growth) = (0, Instant::now());
|
||||
/// while file.swmr_writer_active()? && last_growth.elapsed() < Duration::from_secs(60) {
|
||||
/// ds.refresh()?;
|
||||
/// let n = ds.shape()?[0];
|
||||
/// if n > seen {
|
||||
/// // read rows seen..n ...
|
||||
/// (seen, last_growth) = (n, Instant::now());
|
||||
/// }
|
||||
/// std::thread::sleep(Duration::from_millis(100));
|
||||
/// }
|
||||
/// ds.refresh()?; // the final extent
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn swmr_writer_active(&self) -> Result<bool, Error> {
|
||||
self.retry(|| {
|
||||
let sb = Superblock::parse_in(&self.data, 0)?;
|
||||
|
||||
Reference in New Issue
Block a user