CLASS DB

#include <db.h>

DB is the class that implements the low level database. It maintains a list of files, allocates and deallocates pages on the disk, and performs read/write to disk. There is a global variable (it's actually a macro) of type DB defined in "system_defs.h" :

MINIBASE_DB

Only methods that need to be used in implementing the buffer manager and B+ tree are shown here.

Methods

Status AddFileEntry(const char* filename, PageID startPid)

Given a filename of a file, and the page id of the first page of the file, add the file into the database.

Status DeleteFileEntry(const char* fname)

Given a filename, delete the file from the database.

Status GetFileEntry(const char* filename, PageID& start_pg)

Given a filename, find the file in the database, and return the page id of the first page of the file.

StatusReadPage(PageID pid, Page* pageptr)

Read the page whose page id = pid, into the memory area pointed to by pageptr.

Status WritePage(PageID pageno, Page* pageptr)

Write the page whose page id = pid, from the memory area pointed to by pageptr to disk.

Status AllocatePage(PageID& pid, int n = 1)

Allocate n pages, (n is optional and default to 1) on the disk, and set pid to the first page id of the pages allocated. The page id of the pages allocated will be pid, pid + 1, ... pid + n - 1.

Status DeallocatePage(PageID pid, int n = 1)

Deallocate n pages, (n is optional and default to 1) on the disk, starting with the page with page id = pid. All pages with page id pid, pid + 1, pud + n - 1 will be deallocate

 

Examples