readPageForWrite reads a page into buf for modification. Must be called with f.mu held.
(pgno uint32, buf []byte)
| 1600 | // readPageForWrite reads a page into buf for modification. |
| 1601 | // Must be called with f.mu held. |
| 1602 | func (f *VFSFile) readPageForWrite(pgno uint32, buf []byte) error { |
| 1603 | pageSize := uint32(len(buf)) |
| 1604 | |
| 1605 | // Check cache first (cache is thread-safe, but we hold the lock anyway) |
| 1606 | if data, ok := f.cache.Get(pgno); ok { |
| 1607 | copy(buf, data) |
| 1608 | return nil |
| 1609 | } |
| 1610 | |
| 1611 | // Get page index element |
| 1612 | elem, ok := f.index[pgno] |
| 1613 | if !ok { |
| 1614 | return fmt.Errorf("page not found: %d", pgno) |
| 1615 | } |
| 1616 | |
| 1617 | // Fetch from remote |
| 1618 | _, data, err := FetchPage(f.ctx, f.client, elem.Level, elem.MinTXID, elem.MaxTXID, elem.Offset, elem.Size) |
| 1619 | if err != nil { |
| 1620 | return err |
| 1621 | } |
| 1622 | |
| 1623 | if uint32(len(data)) != pageSize { |
| 1624 | return fmt.Errorf("page size mismatch: got %d, expected %d", len(data), pageSize) |
| 1625 | } |
| 1626 | |
| 1627 | copy(buf, data) |
| 1628 | f.cache.Add(pgno, data) |
| 1629 | return nil |
| 1630 | } |
| 1631 | |
| 1632 | func (f *VFSFile) Truncate(size int64) error { |
| 1633 | f.logger.Debug("truncating file", "size", size) |