buffer

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package buffer provides buffer pool management for XxSql storage engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferFrame

type BufferFrame struct {
	Page     *page.Page
	PinCount int32
	Dirty    bool
	Element  *list.Element // LRU list element
}

BufferFrame represents a frame in the buffer pool.

type BufferPool

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

BufferPool manages a pool of cached pages.

func NewBufferPool

func NewBufferPool(config BufferPoolConfig) *BufferPool

NewBufferPool creates a new buffer pool.

func (*BufferPool) Clear

func (bp *BufferPool) Clear() error

Clear removes all pages from the buffer pool.

func (*BufferPool) DeletePage

func (bp *BufferPool) DeletePage(id page.PageID) error

DeletePage removes a page from the buffer pool.

func (*BufferPool) FlushAll

func (bp *BufferPool) FlushAll() error

FlushAll flushes all dirty pages to disk.

func (*BufferPool) FlushPage

func (bp *BufferPool) FlushPage(id page.PageID) error

FlushPage flushes a specific page to disk.

func (*BufferPool) GetPage

func (bp *BufferPool) GetPage(id page.PageID) (*page.Page, error)

GetPage retrieves a page from the buffer pool or loads it from disk.

func (*BufferPool) IsDirty

func (bp *BufferPool) IsDirty(id page.PageID) bool

IsDirty returns whether a page is dirty.

func (*BufferPool) MarkDirty

func (bp *BufferPool) MarkDirty(id page.PageID)

MarkDirty marks a page as dirty.

func (*BufferPool) NewPage

func (bp *BufferPool) NewPage() (*page.Page, error)

NewPage creates a new page and adds it to the buffer pool.

func (*BufferPool) PinPage

func (bp *BufferPool) PinPage(id page.PageID) error

PinPage increments the pin count of a page.

func (*BufferPool) SetDiskManager

func (bp *BufferPool) SetDiskManager(dm DiskManager)

SetDiskManager sets the disk manager.

func (*BufferPool) Size

func (bp *BufferPool) Size() int

Size returns the number of pages in the buffer.

func (*BufferPool) Stats

func (bp *BufferPool) Stats() BufferPoolStats

Stats returns buffer pool statistics.

func (*BufferPool) UnpinPage

func (bp *BufferPool) UnpinPage(id page.PageID, isDirty bool) error

UnpinPage decrements the pin count of a page.

type BufferPoolConfig

type BufferPoolConfig struct {
	PoolSize    int
	PageSize    int
	DiskManager DiskManager
}

BufferPoolConfig holds buffer pool configuration.

type BufferPoolStats

type BufferPoolStats struct {
	PoolSize    int    `json:"pool_size"`
	PageCount   int    `json:"page_count"`
	DirtyPages  int    `json:"dirty_pages"`
	PinnedPages int    `json:"pinned_pages"`
	Hits        uint64 `json:"hits"`
	Misses      uint64 `json:"misses"`
	Evictions   uint64 `json:"evictions"`
}

BufferPoolStats holds buffer pool statistics.

func (BufferPoolStats) HitRate

func (s BufferPoolStats) HitRate() float64

HitRate returns the buffer pool hit rate.

type DiskManager

type DiskManager interface {
	ReadPage(id page.PageID) (*page.Page, error)
	WritePage(p *page.Page) error
	AllocatePage() (page.PageID, error)
	DeallocatePage(id page.PageID) error
}

DiskManager provides disk I/O operations for the buffer pool.

Jump to

Keyboard shortcuts

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