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

Method write

crates/commitlog/src/repo/mem/segment.rs:102–129  ·  view source on GitHub ↗
(&mut self, buf: &[u8])

Source from the content-addressed store, hash-verified

100
101impl io::Write for Segment {
102 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
103 let mut storage = self.storage.write().unwrap();
104
105 let mut remaining = (storage.alloc - self.pos) as usize;
106 // If we don't have enough space, allocate some.
107 // If not enough space to write all of `buf` can be allocated,
108 // just write as much as we can. The next `write` call will return
109 // ENOSPC then.
110 if remaining == 0 {
111 let mut avail = self.space.lock().unwrap();
112 if *avail == 0 {
113 return Err(enospc());
114 }
115
116 let want = (buf.len() - remaining).next_multiple_of(PAGE_SIZE);
117 let have = want.min(*avail as usize);
118
119 storage.alloc += have as u64;
120 *avail -= have as u64;
121 remaining = (storage.alloc - self.pos) as usize;
122 }
123
124 let read = buf.len().min(remaining);
125 storage.buf.extend(&buf[..read]);
126 self.pos += read as u64;
127
128 Ok(read)
129 }
130
131 fn flush(&mut self) -> io::Result<()> {
132 Ok(())

Callers 9

create_segmentMethod · 0.45
open_segment_writerMethod · 0.45
create_segmentMethod · 0.45
remove_segmentMethod · 0.45
modify_byte_atMethod · 0.45
modify_bytes_atMethod · 0.45
ftruncateMethod · 0.45
fallocateMethod · 0.45
poll_writeMethod · 0.45

Calls 7

enospcFunction · 0.85
lockMethod · 0.80
ErrFunction · 0.50
OkFunction · 0.50
unwrapMethod · 0.45
lenMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected