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

Function create_segment_writer

crates/commitlog/src/repo/mod.rs:231–261  ·  view source on GitHub ↗

Create a new segment [`Writer`] with `offset`. Immediately attempts to write the segment header with the supplied `log_format_version`. If the segment already exists, [`io::ErrorKind::AlreadyExists`] is returned.

(
    repo: &R,
    opts: Options,
    epoch: u64,
    offset: u64,
)

Source from the content-addressed store, hash-verified

229///
230/// If the segment already exists, [`io::ErrorKind::AlreadyExists`] is returned.
231pub fn create_segment_writer<R: Repo>(
232 repo: &R,
233 opts: Options,
234 epoch: u64,
235 offset: u64,
236) -> io::Result<Writer<R::SegmentWriter>> {
237 let mut storage = repo.create_segment(
238 offset,
239 Header {
240 log_format_version: opts.log_format_version,
241 checksum_algorithm: Commit::CHECKSUM_ALGORITHM,
242 },
243 )?;
244 // Ensure we have enough space for this segment.
245 fallocate(&mut storage, &opts)?;
246
247 Ok(Writer {
248 commit: Commit {
249 min_tx_offset: offset,
250 n: 0,
251 records: Vec::new(),
252 epoch,
253 },
254 inner: io::BufWriter::with_capacity(opts.write_buffer_size, storage),
255
256 min_tx_offset: offset,
257 bytes_written: Header::LEN as u64,
258
259 offset_index_head: create_offset_index_writer(repo, offset, opts),
260 })
261}
262
263/// Outcome of [resume_segment_writer].
264pub enum ResumedSegment<W: io::Write> {

Callers 6

write_read_roundtripFunction · 0.85
metadataFunction · 0.85
commitsFunction · 0.85
transactionsFunction · 0.85
openMethod · 0.85
start_new_segmentMethod · 0.85

Calls 5

fallocateFunction · 0.70
OkFunction · 0.50
newFunction · 0.50
create_segmentMethod · 0.45

Tested by 4

write_read_roundtripFunction · 0.68
metadataFunction · 0.68
commitsFunction · 0.68
transactionsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…