Documentation ¶
Overview ¶
Package stor is used to access physical storage, normally by memory mapped file access.
Storage is chunked. Allocations may not straddle chunks.
Stor has an impl(ementation) of either heapstor or mmapstor. OS dependent parts of mmapstor are in mmap_nonwin.go and mmap_windows.go.
Index ¶
- Constants
- func AppendSmallOffset(buf []byte, offset uint64) []byte
- func LenStr(s string) int
- func LenStrs(ss []string) int
- func ReadSmallOffset(buf []byte) uint64
- func WriteSmallOffset(buf []byte, offset uint64)
- type Mode
- type Offset
- type Reader
- type SmallOffset
- type Stor
- func (s *Stor) Alloc(n int) (Offset, []byte)
- func (s *Stor) Close(unmap bool, callback ...func(uint64))
- func (s *Stor) Data(offset Offset) []byte
- func (s *Stor) FirstOffset(off uint64, str string) uint64
- func (s *Stor) FlushTo(offset uint64)
- func (s *Stor) LastOffset(off uint64, str string) uint64
- func (s *Stor) Reader(off uint64) *Reader
- func (s *Stor) Size() uint64
- func (s *Stor) Write(off uint64, data []byte)
- type Writer
- func (w *Writer) Len() int
- func (w *Writer) Put1(n int) *Writer
- func (w *Writer) Put2(n int) *Writer
- func (w *Writer) Put3(n int) *Writer
- func (w *Writer) Put4(n int) *Writer
- func (w *Writer) Put5(n uint64) *Writer
- func (w *Writer) PutStr(s string) *Writer
- func (w *Writer) PutStrs(ss []string) *Writer
Constants ¶
const MaxSmallOffset = 1<<40 - 1
const SmallOffsetLen = 5
Variables ¶
This section is empty.
Functions ¶
func AppendSmallOffset ¶
func ReadSmallOffset ¶
func WriteSmallOffset ¶
Types ¶
type SmallOffset ¶
type SmallOffset [SmallOffsetLen]byte
SmallOffset is used to store database offsets in the database file to save space rather than using int64. 5 bytes = 40 bits = 1tb In memory we use int64. Beware of padding or you won't actually save space.
type Stor ¶
type Stor struct {
// contains filtered or unexported fields
}
Stor is the externally visible storage
func (*Stor) Alloc ¶
Alloc allocates n bytes of storage and returns its Offset and byte slice Returning data here allows slicing to the correct length and capacity to prevent erroneously writing too far. If insufficient room in the current chunk, advance to next (allocations may not straddle chunks). Usual case is just an atomic increment, and an atomic load to check if hit the end of the chunk. Locking is only used to extend the storage.
func (*Stor) Data ¶
Data returns a byte slice starting at the given offset and extending to the end of the chunk since we don't know the size of the original alloc.
func (*Stor) FirstOffset ¶
FirstOffset searches forewards from a given offset for a given byte slice and returns the offset, or 0 if not found
func (*Stor) FlushTo ¶
Flush writes change to disk in the background. It is called by persist (e.g. once per minute).
func (*Stor) LastOffset ¶
LastOffset searches backwards from a given offset for a given byte slice and returns the offset, or 0 if not found. It is used by repair and by asof/history.