Page

source: bluebase/pf/page.py


class PfPageView(page: PfPage, *, offset: int, limit: int)[source]

Bases: ABC

An abstract base class that provides a memory view of page data.

Variables:
  • page (PfPage) – the target page

  • offset (int) – the offset of the view

  • limit (int) – the size of the view

  • view (memoryview) – a memory view of the page data

  • buffer (bytearray) – a buffer for the view, applied to the view by commit

commit() → None[source]

Commit the buffer to the view.

Raises:

PfUnpinnedPageAccessError – if the page is not pinned

class PfPageHeader(page: PfPage, *, offset: int, limit: int)[source]

Bases: PfPageView, LayoutMixin

A layout view for managing a page header.

Layout

Offset

Size

Name

Format

0

1

free

'<B'

1

4

next_free_pid

'<i'

NO_NEXT_FREE_PAGE: ClassVar[PfPageId] = -1

A constant indicating that there is no next free page.

size: ClassVar[int] = 5

The total size of the layout, automatically calculated from fields.

class PfPage(pid: PfPageId, file: PfFile, data: PfPageData)[source]

Bases: object

Variables:
  • pid (PfPageId) – the ID of the page

  • file (PfFile) – the file that contains the page

  • data (PfPageData) – the page data

  • dirty (bool) – whether the page is dirty

  • pin_count (int) – the pin count of the page

property size: intread-only

The size of the page.

property header_offset: intread-only

The offset of the page header.

property header_size: intread-only

The size of the page header.

property payload_offset: intread-only

The offset of the page payload.

property payload_size: intread-only

The size of the page payload.

property free: boolread-write

Whether the page is free.

property next_free_pid: PfPageId | Noneread-write

The ID of the next free page.

validate_pinned() → None[source]

Validate whether the page is pinned.

Raises:

PfUnpinnedPageAccessError – if the page is not pinned

get_header() → PfPageHeader[source]

Return the page header.

is_dirty() → bool[source]

Return whether the page is dirty.

mark_dirty() → None[source]

Mark the page as dirty.

clear_dirty() → None[source]

Clear the dirty state of the page.

is_pinned() → bool[source]

Return whether the page is pinned.

pin() → None[source]

Pin the page.

touch() → None[source]

Notify to the page cache that the page has been accessed.

recycle() → None[source]

Reset the state and data of a free page for reuse.

assignmentunpin() → None[source]

Unpin the page.

Raises:

PfUnpinnedPageAccessError – if the page is not pinned

Hint

Always validate the page is pinned before unpinning. Then, decrease the pin count.

assignmentget_data(offset: int, limit: int) → PfPageData[source]

Return page data.

Raises:

Hint

Always validate the page is pinned before getting data. Also, validate the data range. Then, touch the page to notify the page cache. Finally, return the sliced data.

assignmentset_data(offset: int, data: PfPageData) → None[source]

Set page data.

Raises:

Hint

Always validate the page is pinned before setting data. Also, validate the data range. Then, set the sliced data and mark the page as dirty. Finally, touch the page to notify the page cache.