bufferpool

package
v0.22.20 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const INVALID_PAGE int = -1
View Source
const PAGE_FREE_SPACE_OFFSET = 10 // offset 10, length 2, end 12
View Source
const PAGE_LOCAL_DEPTH_OFFSET = 8 // offset 8, length 2, end 10
View Source
const PAGE_NEXT_POINTER_OFFSET = 16 // offset 16, length 4, end 20
View Source
const PAGE_NUMBER_OFFSET = 0 // offset 0, length 4, end 4
View Source
const PAGE_PREV_POINTER_OFFSET = 12 // offset 12, length 4, end 16
View Source
const PAGE_SIZE int = 8192
View Source
const PAGE_SLOTS_START_OFFSET = 20 // offset 20
View Source
const PAGE_SLOT_COUNT_OFFSET = 6 // offset 6, length 2, end 8
View Source
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

View Source
const PAGE_TYPE_BTREE_INTERNAL = 10
View Source
const PAGE_TYPE_BTREE_LEAF = 11
View Source
const PAGE_TYPE_HASH_TABLE = 12
View Source
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) Close

func (b *BufferPool) Close()

Close closes the buffer pool

func (*BufferPool) DeletePage

func (b *BufferPool) DeletePage(pageID PageID) error

DeletePage deletes a page from the buffer pool

func (*BufferPool) Dump

func (b *BufferPool) Dump()

Dumps all the pages in 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) Size

func (c *ClockReplacer) Size() int

Size returns the size of the clock

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 FrameID

type FrameID int

FrameID is the type for frame id

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) Dump

func (pg *Page) Dump(label string)

func (*Page) FreeSpace

func (p *Page) FreeSpace() int16

func (*Page) ID

func (p *Page) ID() PageID

func (*Page) PinCount

func (p *Page) PinCount() int

func (*Page) ReadChunk

func (p *Page) ReadChunk(offset int16) PageChunk

func (*Page) ReadFreeSpaceOffset

func (p *Page) ReadFreeSpaceOffset() int16

func (*Page) ReadLocalDepth

func (p *Page) ReadLocalDepth() int16

func (*Page) ReadNextPointer

func (p *Page) ReadNextPointer() int

func (*Page) ReadPageNumber

func (p *Page) ReadPageNumber() int

func (*Page) ReadPageType

func (p *Page) ReadPageType() int16

func (*Page) ReadPrevPointer

func (p *Page) ReadPrevPointer() int

func (*Page) ReadSlot

func (p *Page) ReadSlot(slot int16) PageSlot

func (*Page) ReadSlotCount

func (p *Page) ReadSlotCount() int16

func (*Page) WriteChunk

func (p *Page) WriteChunk(offset int16, chunk PageChunk)

func (*Page) WriteFreeSpaceOffset

func (p *Page) WriteFreeSpaceOffset(offset int16)

func (*Page) WriteKeyValueInSlot

func (p *Page) WriteKeyValueInSlot(slotNumber int16, key []byte, value []byte) error

func (*Page) WriteLocalDepth

func (p *Page) WriteLocalDepth(localDepth int16)

func (*Page) WriteNextPointer

func (p *Page) WriteNextPointer(nextPointer int32)

func (*Page) WritePage

func (p *Page) WritePage(page *Page)

func (*Page) WritePageNumber

func (p *Page) WritePageNumber(pageNumber int32)

func (*Page) WritePageType

func (p *Page) WritePageType(pageType int16)

func (*Page) WritePrevPointer

func (p *Page) WritePrevPointer(prevPointer int32)

func (*Page) WriteSlot

func (p *Page) WriteSlot(slot int16, value PageSlot)

func (*Page) WriteSlotCount

func (p *Page) WriteSlotCount(slotCount int16)

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 (pc *PageChunk) ComputeKeyOffset(pageOffset int) int

func (*PageChunk) ComputeValueOffset

func (pc *PageChunk) ComputeValueOffset(pageOffset int) int

func (*PageChunk) Length

func (pc *PageChunk) Length() int

type PageID

type PageID int

PageID is the type for page id

type PageSlot

type PageSlot struct {
	KeyOffset   int16
	ValueOffset int16
}

func (*PageSlot) KeyAsInt

func (s *PageSlot) KeyAsInt(page *Page) int32

func (*PageSlot) KeyBytes

func (s *PageSlot) KeyBytes(page *Page) []byte

func (*PageSlot) ValueAsPagePointer

func (s *PageSlot) ValueAsPagePointer(page *Page) int32

func (*PageSlot) ValueBytes

func (s *PageSlot) ValueBytes(page *Page) []byte

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

Jump to

Keyboard shortcuts

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