Documentation ¶
Index ¶
- Constants
- Variables
- func BinarySearch(set []int, find int) int
- func BtoGB(b uint64) uint64
- func BtoKB(b uint64) uint64
- func BtoMB(b uint64) uint64
- func Pack2U32(dst *uint64, src1, src2 uint32)
- func PrintMemUsage2()
- func PrintStats(mem runtime.MemStats)
- func PrintStatsTab(mem runtime.MemStats)
- func Remove(path string) error
- func Sizeof(objs ...interface{}) (sz uint64)
- func Unpack2U32(dst *uint64) (uint32, uint32)
- type Cache
- type File
- type LRU
- type Page
- func (p *Page) AddRecord(r []byte) (*RecordID, error)
- func (p *Page) CheckRecord(recordSize uint16) error
- func (p *Page) DelRecord(rid *RecordID) error
- func (p *Page) GetRecord(rid *RecordID) ([]byte, error)
- func (p *Page) Len() int
- func (p *Page) Less(i, j int) bool
- func (p *Page) Link(next *Page) *Page
- func (p *Page) NextID() uint32
- func (p *Page) PageID() uint32
- func (p *Page) PrevID() uint32
- func (p *Page) Range(fn func(rid *RecordID) bool)
- func (p *Page) Reset()
- func (p *Page) SortRecords()
- func (p *Page) String() string
- func (p *Page) Swap(i, j int)
- type PageBuffer
- func (pb *PageBuffer) AddRecord(r []byte) (*RecordID, error)
- func (pb *PageBuffer) Close() error
- func (pb *PageBuffer) DelRecord(rid *RecordID) error
- func (pb *PageBuffer) DirtyPages() int
- func (pb *PageBuffer) Flush() error
- func (pb *PageBuffer) FreeSpace() int
- func (pb *PageBuffer) GetRecord(rid *RecordID) ([]byte, error)
- func (pb *PageBuffer) Range(fn func(rid *RecordID) bool)
- type PageManager
- func (f *PageManager) AllocatePage() *Page
- func (f *PageManager) Close() error
- func (f *PageManager) DeletePage(pid uint32) error
- func (f *PageManager) GetFreeOrAllocate() *Page
- func (f *PageManager) GetFreePageIDs() []uint32
- func (f *PageManager) PageCount() int
- func (f *PageManager) Range(start uint32, fn func(rid *RecordID) bool)
- func (f *PageManager) ReadPage(pid uint32) (*Page, error)
- func (f *PageManager) ReadPages(pid uint32) ([]*Page, error)
- func (f *PageManager) WritePage(p *Page) error
- func (f *PageManager) WritePages(ps []*Page) error
- type PageReader
- type PageWriter
- type RecordID
Constants ¶
const ( MinRecordSize = pageSlotSize MaxRecordSize = pageSize - pageHeaderSize - pageSlotSize )
Variables ¶
var ( ErrBadAlignmentSize = errors.New("pageManagerFile: bad alignment size") ErrNoMoreRoomInPage = errors.New("Page: there is not enough room left in the Page") ErrInvalidRecordID = errors.New("Page: invalid record id") ErrRecordHasBeenMarkedFree = errors.New("Page: record has been marked free (aka, removed)") ErrRecordNotFound = errors.New("Page: record could not be found") ErrPageNotFound = errors.New("pageManagerFile: Page could not be found") ErrWritingPage = errors.New("pageManagerFile: error writing Page") ErrDeletingPage = errors.New("pageManagerFile: error deleting Page") ErrMinRecordSize = errors.New("Page: record is smaller than the min record size allowed") ErrMaxRecordSize = errors.New("Page: record is larger than the max record size allowed") ErrRecordMaxKeySize = errors.New("record: record key is longer than max size allowed (255)") ErrPageIsNotOverflow = errors.New("pagemanager: error Page is not an overflow Page") )
Functions ¶
func BinarySearch ¶
func PrintMemUsage2 ¶
func PrintMemUsage2()
PrintMemUsage outputs the current, total and OS memory being used. As well as the number of garage collection cycles completed.
func PrintStats ¶
func PrintStatsTab ¶
func Remove ¶
Remove is somewhat of a helper function to facilitate easier removing of a PageManager
func Sizeof ¶
func Sizeof(objs ...interface{}) (sz uint64)
Sizeof returns the estimated memory usage of object(s) not just the size of the type. On 64bit Sizeof("test") == 12 (8 = sizeof(StringHeader) + 4 bytes).
func Unpack2U32 ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a page table cache [https://en.wikipedia.org/wiki/Page_table]
func (*Cache) Lookup ¶
Lookup attempts to acquire a page if it is already in the in-memory cache. It does not read the page from disk. It will return nil if it is not found.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is mainly just a synchronized abstraction on top of a PageManager
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page is a pageSized data Page structure that may contain one or more data records
func LinkPages ¶
LinkPages links Page "a" with Page "b"; they are marked as overflow pages and have their nextPageID and prevPageID linked to each other. The next and prev pageID's can be used to traverse linked pages in the same fashion that a linked list allows you to traverse nodes.
func (*Page) AddRecord ¶
AddRecord adds a new record to the Page, if there is not enough room for the record to fit within the Page or the remaining Page's available space, an error will be returned.
**It should be noted that (on insertion of a record) all pages slots are sorted lexicography by the prefix of the record data that they point to.
func (*Page) CheckRecord ¶
CheckRecord checks if there is room for the record but, it also checks if the recordSize is outside the bounds of the minimum or maximum record size and returns an applicable error if so
func (*Page) DelRecord ¶
DelRecord removes a record from a Page. It will preserve the slot for later use.
func (*Page) GetRecord ¶
GetRecord attempts to return the record data for a record found within this *Page using the provided *RecordID. If the record cannot be located, nil data and an error will be returned
func (*Page) Len ¶
Len is here to satisfy the sort interface for sorting the Page slots by the record prefix
func (*Page) Less ¶
Less is here to satisfy the sort interface for sorting the Page slots by the record prefix
func (*Page) Link ¶
Link links the calling Page to the next Page and is provided as an alternate method to LinkPages. All the same specs apply.
func (*Page) Reset ¶
func (p *Page) Reset()
Reset resets the Page, all data and header information will return to the same state it was in when it was created.
func (*Page) SortRecords ¶
func (p *Page) SortRecords()
SortRecords is a convenience wrapper for the internal sortSlotsByRecordPrefix call
type PageBuffer ¶
type PageBuffer struct {
// contains filtered or unexported fields
}
func NewPageBuffer ¶
func NewPageBuffer(pm *PageManager) (*PageBuffer, error)
func NewPageBufferSize ¶
func NewPageBufferSize(pm *PageManager, np int) (*PageBuffer, error)
func (*PageBuffer) Close ¶
func (pb *PageBuffer) Close() error
func (*PageBuffer) DelRecord ¶
func (pb *PageBuffer) DelRecord(rid *RecordID) error
func (*PageBuffer) DirtyPages ¶
func (pb *PageBuffer) DirtyPages() int
func (*PageBuffer) Flush ¶
func (pb *PageBuffer) Flush() error
func (*PageBuffer) FreeSpace ¶
func (pb *PageBuffer) FreeSpace() int
func (*PageBuffer) Range ¶
func (pb *PageBuffer) Range(fn func(rid *RecordID) bool)
type PageManager ¶
type PageManager struct {
// contains filtered or unexported fields
}
PageManager is a slotted Page PageManager manager
func OpenPageManager ¶
func OpenPageManager(path string) (*PageManager, error)
OpenPageManager opens an existing PageManager at the location provided, or creates and returns a new PageManager at the path provided.
func (*PageManager) AllocatePage ¶
func (f *PageManager) AllocatePage() *Page
AllocatePage allocates and returns a new Page. The newly allocated Page is not persisted unless a call to WritePage is made
func (*PageManager) Close ¶
func (f *PageManager) Close() error
Close closes the underlying PageManager, after flushing any buffers to disk.
func (*PageManager) DeletePage ¶
func (f *PageManager) DeletePage(pid uint32) error
DeletePage marks the Page with the matching pageID provided as "free" and writes zeros to the underlying Page on disk
func (*PageManager) GetFreeOrAllocate ¶
func (f *PageManager) GetFreeOrAllocate() *Page
GetFreeOrAllocate attempts to find a free Page (a Page that is not in use that can be reused) and if one cannot be found, it will allocate and return a new one. Any alterations to the returned Page are not persisted unless a call to WritePage is made
func (*PageManager) GetFreePageIDs ¶
func (f *PageManager) GetFreePageIDs() []uint32
GetFreePageIDs returns a list of any Page id's that are marked "free"
func (*PageManager) PageCount ¶
func (f *PageManager) PageCount() int
PageCount returns the total number of pages in the PageManager (including "free" pages)
func (*PageManager) ReadPage ¶
func (f *PageManager) ReadPage(pid uint32) (*Page, error)
ReadPage attempts to read the Page located at the offset calculated by the provided pageID. It returns an error if a Page could not be located
func (*PageManager) ReadPages ¶
func (f *PageManager) ReadPages(pid uint32) ([]*Page, error)
ReadPages attempts to read the pages located at the offset calculated by the provided pageID. It returns an error if a Page could not be located
func (*PageManager) WritePage ¶
func (f *PageManager) WritePage(p *Page) error
WritePage writes the provided Page to the underlying PageManager on disk. If something goes wrong it returns a non-nil error
func (*PageManager) WritePages ¶
func (f *PageManager) WritePages(ps []*Page) error
WritePages writes the provided pages to the underlying PageManager on disk. If something goes wrong it returns a non-nil error
type PageReader ¶
PageReader reads a pageSize of bytes into p starting at offset off in the underlying input source. It returns the number of bytes read and any error encountered
If ReadPage is reading from an input source with a seek offset, ReadPage should not affect nor be affected by the underlying seek offset.
type PageWriter ¶
PageWriter writes a pageSize of bytes from p to the under- lying data stream at offset off. It returns the number of bytes written from p and any error encountered that caused the write to stop early. WritePage must return a non-nil error if it returns n < a pageSize.
If WritePage is writing to a destination with a seek offset, WritePage should not affect nor be affected by the underlying seek offset.