pagerv2

package
v0.0.0-...-fc425af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIllegalPageAccess = errors.New("illegal page access")
	ErrRecordTooLarge    = errors.New("record too large")
	ErrPageIsFull        = errors.New("page is full")
)

Functions

func OpenFile

func OpenFile(path string) (*os.File, error)

Types

type BitSet

type BitSet struct {
	// contains filtered or unexported fields
}

BitSet is a bit set data type

func NewBitSet

func NewBitSet(bits uint) *BitSet

NewBitSet sets up and returns a new *BitSet

func (*BitSet) GetRawSet

func (b *BitSet) GetRawSet() []uint

func (*BitSet) IsSet

func (b *BitSet) IsSet(i uint) bool

IsSet tests and returns a boolean if bit i is set

func (*BitSet) Len

func (b *BitSet) Len() uint

Len returns the number of bits in the bitset

func (*BitSet) PercentageFull

func (b *BitSet) PercentageFull() (int, float64)

func (*BitSet) Set

func (b *BitSet) Set(i uint) *BitSet

Set sets bit i to 1. The capacity of the bitset grows accordingly

func (*BitSet) SetMany

func (b *BitSet) SetMany(ii ...uint) *BitSet

SetMany is identical to calling Set repeatedly

func (*BitSet) String

func (b *BitSet) String() string

print binary value of bitset

func (*BitSet) Unset

func (b *BitSet) Unset(i uint) *BitSet

Unset clears bit i, aka sets it to 0

func (*BitSet) Value

func (b *BitSet) Value(i uint) uint

Value returns the value

type Pager

type Pager struct {
	// contains filtered or unexported fields
}

func NewPager

func NewPager(path string, pages int) *Pager

func (*Pager) GetFreePageID

func (p *Pager) GetFreePageID() uint32

func (*Pager) GetFreeRecordID

func (p *Pager) GetFreeRecordID(pid uint32, rsize int) (uint16, error)

func (*Pager) Read

func (p *Pager) Read(pid uint32) ([]byte, error)

func (*Pager) ReadRecord

func (p *Pager) ReadRecord(pid uint32, rid uint16) ([]byte, error)

func (*Pager) Sync

func (p *Pager) Sync() error

func (*Pager) Write

func (p *Pager) Write(d []byte, pid uint32) error

func (*Pager) WriteRecord

func (p *Pager) WriteRecord(r []byte, pid uint32, rid uint16) error

type Pagerer

type Pagerer interface {

	// Read takes the provided page ID and returns the
	// contents of the page. If the page cannot be
	// found in memory, it searches on the disk. If it
	// cannot be found on the disk, an "illegal page
	// access" error is returned. On success, it will
	// return a nil error.
	Read(pid uint32) ([]byte, error)

	// ReadRecord takes the provided page ID and record
	// ID and returns the contents of the record. If the
	// page cannot be found in memory, it searches on the
	// disk. If it cannot be found on the disk an "illegal
	// page access" error is returned. On success, it will
	// return a nil error.
	ReadRecord(pid uint32, rid uint16) ([]byte, error)

	// Write takes data and a page ID and attempts to
	// write the data provided to the page specified
	// using the provided page ID. It returns any
	// potential errors it encounters. On success,
	// it will return a nil error. (Any write made to
	// a page will not be persisted to disk until an
	// explicit call to Sync is made.)
	Write(d []byte, pid uint32) error

	// WriteRecord takes data, a page ID and a record ID
	// and attempts to write the record data to the page
	// specified using the provided page and record IDs.
	// It returns and potential errors it encounters. On
	// success, it will return a nil error. (Any write
	// made to a page or record will not be persisted to
	// disk until an explicit call to Sync is made.)
	WriteRecord(r []byte, pid uint32, rid uint16) error

	// GetFreePageID searches through the pager and returns
	// the first free page ID it finds. If none can be
	// found then dirty pages are flushed to disk to make
	// room, or old pages that are not dirty are evicted
	// to make room. It will always return a free page ID
	// one way or another.
	GetFreePageID() uint32

	// GetFreeRecordID takes a page ID and a required record
	// size and attempts to return a free slot for a record
	// that would fit within the specified page and record
	// size. If a slot cannot be found or if the page is full
	// a "record too large" or "page is full" error will be
	// returned. On success, it will return a nil error.
	GetFreeRecordID(pid uint32, rsize int) (uint16, error)

	// Sync commits the current contents of the pager
	// to stable storage. This means flushing cache's
	// in-memory copy of recently written data to disk.
	Sync() error
}

Pagerer is a page cache interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL