openForRead will open pack file n for read and keep a handle to it in s.fds. os.IsNotExist returned if n >= the number of pack files in s.root. This function is not thread safe, s.mu should be locked by the caller.
(n int)
| 225 | // s.fds. os.IsNotExist returned if n >= the number of pack files in s.root. |
| 226 | // This function is not thread safe, s.mu should be locked by the caller. |
| 227 | func (s *storage) openForRead(n int) error { |
| 228 | if n > len(s.fds) { |
| 229 | panic(fmt.Sprintf("openForRead called out of order got %d, expected %d", n, len(s.fds))) |
| 230 | } |
| 231 | |
| 232 | fn := s.filename(n) |
| 233 | f, err := os.Open(fn) |
| 234 | if err != nil { |
| 235 | return err |
| 236 | } |
| 237 | openFdsVar.Add(s.root, 1) |
| 238 | debug.Printf("diskpacked: opened for read %q", fn) |
| 239 | s.fds = append(s.fds, f) |
| 240 | return nil |
| 241 | } |
| 242 | |
| 243 | // openForWrite will create or open pack file n for writes, create a lock |
| 244 | // visible external to the process and seek to the end of the file ready for |