MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / open

Method open

crates/commitlog/src/commitlog.rs:57–93  ·  view source on GitHub ↗
(repo: R, opts: Options)

Source from the content-addressed store, hash-verified

55
56impl<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 ///

Callers

nothing calls this directly

Calls 7

resume_segment_writerFunction · 0.85
create_segment_writerFunction · 0.85
OkFunction · 0.50
existing_offsetsMethod · 0.45
is_emptyMethod · 0.45
remove_segmentMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected