pagerv3

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: 2 Imported by: 0

README

Reading a page from the pager

graph
    A[Give me page N] --> B{Is it in the pager?}
    B -- Yes --> C[Return page]
    B -- No --> D[Search the disk]
    D --> E{Can we load it into pager?}    
    E -- Yes --> F[Load and return page]
    E -- No, no room --> G[Evict a page from pager]
    G --> F
sequenceDiagram
    participant API
    participant Pager
    participant Disk
    API-->>Pager: Give me page 3
    Pager-->>API: Okay here is page 3
    #loop PagingProcess
    #    Pager<<-->>Disk: 
    #end
    API-->>Pager: Give me page 5
    Note right of Pager: Pager doesn't have page 5 or any<br>more room (evicting a page)
    Pager-->>Disk: Give me page 5 
    Disk-->>Pager: Okay here is page 5
    Pager-->>API: Okay here is page 5

Documentation

Index

Constants

View Source
const DiskMaxNumPages = 15

DiskMaxNumPages sets the disk capacity

Variables

This section is empty.

Functions

func NewCQPrinter

func NewCQPrinter(c *cQueue) *printer

func NewCQueue

func NewCQueue(size int) *cQueue

Types

type DiskManager

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

DiskManager is responsible for interacting with disk

func NewDiskManager

func NewDiskManager() *DiskManager

NewDiskManager returns a in-memory mock of disk manager

func (*DiskManager) AllocatePage

func (d *DiskManager) AllocatePage() *PageID

AllocatePage allocates one more page

func (*DiskManager) DeallocatePage

func (d *DiskManager) DeallocatePage(pid *PageID)

DeallocatePage removes page from disk

func (*DiskManager) ReadPage

func (d *DiskManager) ReadPage(pageID *PageID) (*Page, error)

ReadPage reads a page from pages

func (*DiskManager) WritePage

func (d *DiskManager) WritePage(p *Page) error

WritePage writes a page in memory to pages

type FrameID

type FrameID uint32

type Manager

type Manager interface {

	// NewPage allocates a new page and pins it to a frame. If we did not
	// find an open frame we will proceed by attempting to victimize the
	// current frame.
	NewPage() *Page

	// FetchPage fetches the requested page from the buffer pool. If the
	// page is in cache, it is returned immediately. If not, it will be
	// found on disk, loaded into the cache and returned.
	FetchPage(pid PageID) *Page

	// UnpinPage unpins the target page from the buffer pool. It indicates
	// that the page is not used any more for the current requesting thread.
	// If no more threads are using this page, the page is considered for
	// eviction (victim).
	UnpinPage(pid PageID) error

	// FlushPage flushes the target page that is in the cache onto the
	// underlying medium. It also decrements the pin count and unpins it
	// from the holding frame and unsets the dirty bit.
	FlushPage(pid PageID) bool

	// DeletePage deletes a page from the buffer pool. Once removed, it
	// marks the holding fame as free to use.
	DeletePage(pid PageID) error

	// GetFrameID returns a frame ID from the free list, or by using the
	// replacement policy if the free list is full along with a boolean
	// indicating true if the frame ID was returned using the free list
	// and false if it was returned by using the replacement policy.
	GetFrameID() (FrameID, bool)
}

type Page

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

type PageID

type PageID uint32

type Pager

type Pager interface {

	// WritePage takes the data provided and writes it to the
	// page using the PageID provided. If successful a nil
	// error is returned.
	WritePage(d []byte, pid PageID) error

	// ReadPage attempts to read the contents of the page using
	// the PageID provided. If successful a nil error is returned.
	ReadPage(pid PageID) ([]byte, error)

	// SyncPage performs a file system fsync which forces the OS
	// and disk controller to flush the buffered contents of the
	// page found using the PageID provided onto the physical media.
	// If successful, a nil error is returned.
	SyncPage(pid PageID) error

	// FreePage attempts to free the page found using the PageID
	// provided. If the page is currently dirty, it first attempts
	// to call fsync. A boolean indicating the success of the free
	// call will be returned along with a nil error, if successful.
	FreePage(pid PageID) (bool, error)

	// WriteRecord takes the record data provided and writes it to
	// the page using the PageID provided. If successful a RecordID
	// will be returned along with a nil error. The RecordID can be
	// used at a later time to delete or update the specific record.
	WriteRecord(d []byte, pid PageID) (RecordID, error)

	// ReadRecord attempts to read and return a copy of the contents
	// of the selected record using the PageID and RecordID provided.
	// If successful, a nil error will be returned.
	ReadRecord(pid PageID, rid RecordID) ([]byte, error)

	// DeleteRecord attempts to delete the contents of the selected
	// record using the PageID and RecordID provided. A boolean will
	// be returned indicating the success of the call to delete and
	// if successful, a nil error will be returned.
	DeleteRecord(pid PageID, rid RecordID) error
}

Pager represents the main API of a page buffer or cache. Individual implementations may differ quite a bit.

type RecordID

type RecordID uint32

Jump to

Keyboard shortcuts

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