(repo: R, opts: Options)
| 55 | |
| 56 | impl<R: Repo, T> Generic<R, T> { |
| 57 | pub fn open(repo: R, opts: Options) -> io::Result<Self> { |
| 58 | let mut tail = repo.existing_offsets()?; |
| 59 | if !tail.is_empty() { |
| 60 | debug!("segments: {tail:?}"); |
| 61 | } |
| 62 | |
| 63 | // Resume the last segment for writing, or |
| 64 | // create a new segment starting from the last good commit + 1. |
| 65 | let head = loop { |
| 66 | if let Some(last) = tail.pop() { |
| 67 | info!("repo {}: resuming last segment: {}", repo, last); |
| 68 | match repo::resume_segment_writer(&repo, opts, last)? { |
| 69 | repo::ResumedSegment::Empty => { |
| 70 | repo.remove_segment(last)?; |
| 71 | continue; |
| 72 | } |
| 73 | repo::ResumedSegment::Resumed(writer) => break writer, |
| 74 | repo::ResumedSegment::Sealed(meta) | repo::ResumedSegment::Corrupted(meta) => { |
| 75 | tail.push(meta.tx_range.start); |
| 76 | break repo::create_segment_writer(&repo, opts, meta.max_epoch, meta.tx_range.end)?; |
| 77 | } |
| 78 | } |
| 79 | } else { |
| 80 | info!("repo {}: starting fresh log", repo); |
| 81 | break repo::create_segment_writer(&repo, opts, Commit::DEFAULT_EPOCH, 0)?; |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | Ok(Self { |
| 86 | repo, |
| 87 | head, |
| 88 | tail, |
| 89 | opts, |
| 90 | _record: PhantomData, |
| 91 | panicked: false, |
| 92 | }) |
| 93 | } |
| 94 | |
| 95 | /// Get the current epoch. |
| 96 | /// |
nothing calls this directly
no test coverage detected