Skip to content

Commit

Permalink
add freelist interface unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jungblut <[email protected]>
  • Loading branch information
tjungblu committed Jul 22, 2024
1 parent d72e6bf commit 23d74f2
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 52 deletions.
1 change: 1 addition & 0 deletions internal/freelist/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (f *array) mergeSpans(ids common.Pgids) {
func NewArrayFreelist() Interface {
a := &array{
shared: newShared(),
ids: []common.Pgid{},
}
a.Interface = a
return a
Expand Down
7 changes: 4 additions & 3 deletions internal/freelist/freelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ReadWriter interface {
// Write writes the freelist into the given page.
Write(page *common.Page)

// EstimatedWritePageSize returns the size of the freelist after serialization in Write.
// EstimatedWritePageSize returns the size in bytes of the freelist after serialization in Write.
// This should never underestimate the size.
EstimatedWritePageSize() int
}
Expand Down Expand Up @@ -46,13 +46,14 @@ type Interface interface {
ReleasePendingPages()

// Free releases a page and its overflow for a given transaction id.
// If the page is already free then a panic will occur.
// If the page is already free or is one of the meta pages, then a panic will occur.
Free(txId common.Txid, p *common.Page)

// Freed returns whether a given page is in the free list.
Freed(pgId common.Pgid) bool

// Rollback removes the pages from a given pending tx.
// Should always be followed by Reload or NoSyncReload from last freelist state.
Rollback(txId common.Txid)

// Copyall copies a list of all free ids and all pending ids in one sorted list.
Expand All @@ -65,7 +66,7 @@ type Interface interface {
// NoSyncReload reads the freelist from Pgids and filters out pending items.
NoSyncReload(pgIds common.Pgids)

// freePageIds returns the IDs of all free pages.
// freePageIds returns the IDs of all free pages. No free pages returns an empty slice.
freePageIds() common.Pgids

// pendingPageIds returns all pending pages by transaction id.
Expand Down
Loading

0 comments on commit 23d74f2

Please sign in to comment.