Documentation ¶
Index ¶
- Constants
- type BufferPool
- func (b *BufferPool) Close()
- func (b *BufferPool) DeletePage(pageID PageID) error
- func (b *BufferPool) Dump()
- func (b *BufferPool) FetchPage(pageID PageID) (*Page, error)
- func (b *BufferPool) FlushAllpages()
- func (b *BufferPool) FlushPage(pageID PageID) bool
- func (b *BufferPool) NewPage() (*Page, error)
- func (b *BufferPool) OnDiskSize() int64
- func (b *BufferPool) ScratchPage() *Page
- func (b *BufferPool) UnpinPage(pageID PageID) error
- type ClockReplacer
- type DiskManager
- type FrameID
- type InMemDiskSpillingDiskManager
- func (d *InMemDiskSpillingDiskManager) AllocatePage() (PageID, error)
- func (d *InMemDiskSpillingDiskManager) Close()
- func (d *InMemDiskSpillingDiskManager) DeallocatePage(pageID PageID) error
- func (d *InMemDiskSpillingDiskManager) FileSize() int64
- func (d *InMemDiskSpillingDiskManager) ReadPage(pageID PageID) (*Page, error)
- func (d *InMemDiskSpillingDiskManager) WritePage(page *Page) error
- type Page
- func (p *Page) DecPinCount()
- func (pg *Page) Dump(label string)
- func (p *Page) FreeSpace() int16
- func (p *Page) ID() PageID
- func (p *Page) PinCount() int
- func (p *Page) ReadChunk(offset int16) PageChunk
- func (p *Page) ReadFreeSpaceOffset() int16
- func (p *Page) ReadLocalDepth() int16
- func (p *Page) ReadNextPointer() int
- func (p *Page) ReadPageNumber() int
- func (p *Page) ReadPageType() int16
- func (p *Page) ReadPrevPointer() int
- func (p *Page) ReadSlot(slot int16) PageSlot
- func (p *Page) ReadSlotCount() int16
- func (p *Page) WriteChunk(offset int16, chunk PageChunk)
- func (p *Page) WriteFreeSpaceOffset(offset int16)
- func (p *Page) WriteKeyValueInSlot(slotNumber int16, key []byte, value []byte) error
- func (p *Page) WriteLocalDepth(localDepth int16)
- func (p *Page) WriteNextPointer(nextPointer int32)
- func (p *Page) WritePage(page *Page)
- func (p *Page) WritePageNumber(pageNumber int32)
- func (p *Page) WritePageType(pageType int16)
- func (p *Page) WritePrevPointer(prevPointer int32)
- func (p *Page) WriteSlot(slot int16, value PageSlot)
- func (p *Page) WriteSlotCount(slotCount int16)
- type PageChunk
- type PageID
- type PageSlot
- type PageSlotIterator
Constants ¶
const INVALID_PAGE int = -1
const PAGE_FREE_SPACE_OFFSET = 10 // offset 10, length 2, end 12
const PAGE_LOCAL_DEPTH_OFFSET = 8 // offset 8, length 2, end 10
const PAGE_NEXT_POINTER_OFFSET = 16 // offset 16, length 4, end 20
const PAGE_NUMBER_OFFSET = 0 // offset 0, length 4, end 4
const PAGE_PREV_POINTER_OFFSET = 12 // offset 12, length 4, end 16
const PAGE_SIZE int = 8192
const PAGE_SLOTS_START_OFFSET = 20 // offset 20
const PAGE_SLOT_COUNT_OFFSET = 6 // offset 6, length 2, end 8
const PAGE_SLOT_LENGTH = 4
PAGE_SLOT_LENGTH is the size of the page slot key/value.
key offset int16 //offset 0, length 2, end 2 value offset int16 //offset 2, length 2, end 4
const PAGE_TYPE_BTREE_INTERNAL = 10
const PAGE_TYPE_BTREE_LEAF = 11
const PAGE_TYPE_HASH_TABLE = 12
const PAGE_TYPE_OFFSET = 4 // offset 4, length 2, end 6
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool represents a buffer pool of pages
func NewBufferPool ¶
func NewBufferPool(maxSize int, diskManager DiskManager) *BufferPool
NewBufferPool returns a buffer pool
func (*BufferPool) DeletePage ¶
func (b *BufferPool) DeletePage(pageID PageID) error
DeletePage deletes a page from the buffer pool
func (*BufferPool) FetchPage ¶
func (b *BufferPool) FetchPage(pageID PageID) (*Page, error)
FetchPage fetches the requested page from the buffer pool.
func (*BufferPool) FlushAllpages ¶
func (b *BufferPool) FlushAllpages()
FlushAllpages flushes all the pages in the buffer pool to disk Yeah, never call this unless you know what you are doing
func (*BufferPool) FlushPage ¶
func (b *BufferPool) FlushPage(pageID PageID) bool
FlushPage Flushes the target page to disk
func (*BufferPool) NewPage ¶
func (b *BufferPool) NewPage() (*Page, error)
NewPage allocates a new page in the buffer pool with the disk manager help
func (*BufferPool) OnDiskSize ¶
func (b *BufferPool) OnDiskSize() int64
OnDiskSize exposes the on disk size of the backing store behind this buffer pool
func (*BufferPool) ScratchPage ¶
func (b *BufferPool) ScratchPage() *Page
ScratchPage returns a page outside the buffer pool - do not use if you intend the page to be in the buffer pool (use NewPage() for that) ScratchPage is intended to be used in cases where you need the Page primitives and will copy the scratch page back over a real page later
func (*BufferPool) UnpinPage ¶
func (b *BufferPool) UnpinPage(pageID PageID) error
UnpinPage unpins the target page from the buffer pool
type ClockReplacer ¶
type ClockReplacer struct {
// contains filtered or unexported fields
}
ClockReplacer implements a clock replacer algorithm
func NewClockReplacer ¶
func NewClockReplacer(poolSize int) *ClockReplacer
NewClockReplacer instantiates a new clock replacer
func (*ClockReplacer) Pin ¶
func (c *ClockReplacer) Pin(id FrameID)
Pin pins a frame, indicating that it should not be victimized until it is unpinned
func (*ClockReplacer) Unpin ¶
func (c *ClockReplacer) Unpin(id FrameID)
Unpin unpins a frame, indicating that it can now be victimized
func (*ClockReplacer) Victim ¶
func (c *ClockReplacer) Victim() (FrameID, error)
Victim removes the victim frame as defined by the replacement policy
type DiskManager ¶
type DiskManager interface { // reads a page from the disk ReadPage(PageID) (*Page, error) // writes a page to the disk WritePage(*Page) error // allocates a page AllocatePage() (PageID, error) // deallocates a page DeallocatePage(PageID) error // returns on disk file size FileSize() int64 // closes and does any clean up Close() }
DiskManager is responsible for interacting with disk
type InMemDiskSpillingDiskManager ¶
type InMemDiskSpillingDiskManager struct {
// contains filtered or unexported fields
}
InMemDiskSpillingDiskManager is a memory implementation for a DiskManager interface that can spill to disk when a threshold is reached
func NewInMemDiskSpillingDiskManager ¶
func NewInMemDiskSpillingDiskManager(thresholdPages int) *InMemDiskSpillingDiskManager
NewInMemDiskSpillingDiskManager returns a in-memory version of disk manager
func (*InMemDiskSpillingDiskManager) AllocatePage ¶
func (d *InMemDiskSpillingDiskManager) AllocatePage() (PageID, error)
AllocatePage allocates a page and returns the page number
func (*InMemDiskSpillingDiskManager) Close ¶
func (d *InMemDiskSpillingDiskManager) Close()
func (*InMemDiskSpillingDiskManager) DeallocatePage ¶
func (d *InMemDiskSpillingDiskManager) DeallocatePage(pageID PageID) error
DeallocatePage removes page from disk
func (*InMemDiskSpillingDiskManager) FileSize ¶
func (d *InMemDiskSpillingDiskManager) FileSize() int64
func (*InMemDiskSpillingDiskManager) ReadPage ¶
func (d *InMemDiskSpillingDiskManager) ReadPage(pageID PageID) (*Page, error)
ReadPage reads a page from pages
func (*InMemDiskSpillingDiskManager) WritePage ¶
func (d *InMemDiskSpillingDiskManager) WritePage(page *Page) error
WritePage writes a page in memory to pages
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page represents a page on disk
func (*Page) DecPinCount ¶
func (p *Page) DecPinCount()
func (*Page) ReadFreeSpaceOffset ¶
func (*Page) ReadLocalDepth ¶
func (*Page) ReadNextPointer ¶
func (*Page) ReadPageNumber ¶
func (*Page) ReadPageType ¶
func (*Page) ReadPrevPointer ¶
func (*Page) ReadSlotCount ¶
func (*Page) WriteChunk ¶
func (*Page) WriteFreeSpaceOffset ¶
func (*Page) WriteKeyValueInSlot ¶
func (*Page) WriteLocalDepth ¶
func (*Page) WriteNextPointer ¶
func (*Page) WritePageNumber ¶
func (*Page) WritePageType ¶
func (*Page) WritePrevPointer ¶
func (*Page) WriteSlotCount ¶
type PageChunk ¶
type PageChunk struct { KeyLength int16 KeyBytes []byte // TODO(pok) ValueBytes can be up to int32 long // this requires an overflow page mechanism, that is not implemented // yet, so be aware of this when storing stuff... ValueLength int32 ValueBytes []byte }
func (*PageChunk) ComputeKeyOffset ¶
func (*PageChunk) ComputeValueOffset ¶
type PageSlotIterator ¶
type PageSlotIterator struct {
// contains filtered or unexported fields
}
func NewPageSlotIterator ¶
func NewPageSlotIterator(page *Page, fromSlot int16) *PageSlotIterator
func (*PageSlotIterator) Cursor ¶
func (i *PageSlotIterator) Cursor() int16
func (*PageSlotIterator) Next ¶
func (i *PageSlotIterator) Next() *PageSlot