MCPcopy
hub / github.com/benbjohnson/litestream / writeToBuffer

Method writeToBuffer

vfs.go:2118–2138  ·  view source on GitHub ↗

writeToBuffer writes a dirty page to the write buffer for durability. If the page already exists in the buffer, it overwrites at the same offset. Otherwise, it appends to the end of the file. Must be called with f.mu held.

(pgno uint32, data []byte)

Source from the content-addressed store, hash-verified

2116// Otherwise, it appends to the end of the file.
2117// Must be called with f.mu held.
2118func (f *VFSFile) writeToBuffer(pgno uint32, data []byte) error {
2119 var writeOffset int64
2120 if existingOff, ok := f.dirty[pgno]; ok {
2121 // Page already exists - overwrite at same offset
2122 writeOffset = existingOff
2123 } else {
2124 // New page - append to end of file
2125 writeOffset = f.bufferNextOff
2126 f.bufferNextOff += int64(len(data))
2127 }
2128
2129 // Write page data (no header, just raw page data)
2130 if _, err := f.bufferFile.WriteAt(data, writeOffset); err != nil {
2131 return fmt.Errorf("write page to buffer: %w", err)
2132 }
2133
2134 // Update dirty map with offset
2135 f.dirty[pgno] = writeOffset
2136
2137 return nil
2138}
2139
2140// clearWriteBuffer clears and resets the write buffer after successful sync.
2141func (f *VFSFile) clearWriteBuffer() error {

Callers 1

WriteAtMethod · 0.95

Calls 1

WriteAtMethod · 0.45

Tested by

no test coverage detected