diskmgr
Class DiskMgr

java.lang.Object
  extended by diskmgr.DiskMgr
All Implemented Interfaces:
GlobalConst

public class DiskMgr
extends java.lang.Object
implements GlobalConst

Minibase Disk Manager

The disk manager is the component of Minibase that takes care of the allocation and deallocation of pages within the database. It also performs reads and writes of pages to and from disk, providing a logical file layer.


Field Summary
 
Fields inherited from interface global.GlobalConst
EMPTY_SLOT, FIRST_PAGEID, INVALID_PAGEID, MAX_COLSIZE, MAX_TUPSIZE, NAME_MAXLEN, PAGE_SIZE, PIN_DISKIO, PIN_MEMCPY, UNPIN_CLEAN, UNPIN_DIRTY
 
Constructor Summary
DiskMgr()
           
 
Method Summary
 void add_file_entry(java.lang.String fname, PageId start_pageno)
          Adds a file entry to the header page(s); each entry contains the name of the file and the PageId of the file's first page.
 PageId allocate_page()
          Allocates a single page (i.e.
 PageId allocate_page(int run_size)
          Allocates a set of pages on disk, given the run size.
 void closeDB()
          Closes the database file.
 void createDB(java.lang.String fname, int num_pgs)
          Creates and opens a new database with the given file name and specified number of pages.
 void deallocate_page(PageId pageno)
          Deallocates a single page (i.e.
 void deallocate_page(PageId firstid, int run_size)
          Deallocates a set of pages on disk, given the run size.
 void delete_file_entry(java.lang.String fname)
          Deletes a file entry from the header page(s).
 void destroyDB()
          Destroys the database, removing the file that stores it.
 PageId get_file_entry(java.lang.String fname)
          Looks up the entry for the given file name.
 int getAllocCount()
          Gets the number of allocated disk pages.
 int getReadCount()
          Gets the number of disk reads since construction.
 int getWriteCount()
          Gets the number of disk writes since construction.
 void openDB(java.lang.String fname)
          Open the database with the given file name.
 void print_space_map()
          Print out the database's space map, a bitmap showing which pages are currently allocated.
 void read_page(PageId pageno, Page page)
          Reads the contents of the specified page from disk.
 void write_page(PageId pageno, Page page)
          Writes the contents of the given page to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiskMgr

public DiskMgr()
Method Detail

getReadCount

public int getReadCount()
Gets the number of disk reads since construction.


getWriteCount

public int getWriteCount()
Gets the number of disk writes since construction.


getAllocCount

public int getAllocCount()
Gets the number of allocated disk pages.


createDB

public void createDB(java.lang.String fname,
                     int num_pgs)
Creates and opens a new database with the given file name and specified number of pages.


openDB

public void openDB(java.lang.String fname)
Open the database with the given file name.


closeDB

public void closeDB()
Closes the database file.


destroyDB

public void destroyDB()
Destroys the database, removing the file that stores it.


allocate_page

public PageId allocate_page()
Allocates a single page (i.e. run size 1) on disk.

Returns:
The new page's id
Throws:
java.lang.IllegalStateException - if the database is full

allocate_page

public PageId allocate_page(int run_size)
Allocates a set of pages on disk, given the run size.

Returns:
The new page's id
Throws:
java.lang.IllegalArgumentException - if run_size is invalid
java.lang.IllegalStateException - if the database is full

deallocate_page

public void deallocate_page(PageId pageno)
Deallocates a single page (i.e. run size 1) on disk.

Parameters:
pageno - identifies the page to deallocate
Throws:
java.lang.IllegalArgumentException - if firstid is invalid

deallocate_page

public void deallocate_page(PageId firstid,
                            int run_size)
Deallocates a set of pages on disk, given the run size.

Parameters:
firstid - identifies the first page to deallocate
run_size - number of pages to deallocate
Throws:
java.lang.IllegalArgumentException - if firstid or run_size is invalid

read_page

public void read_page(PageId pageno,
                      Page page)
Reads the contents of the specified page from disk.

Parameters:
pageno - identifies the page to read
page - output param to hold the contents of the page
Throws:
java.lang.IllegalArgumentException - if pageno is invalid

write_page

public void write_page(PageId pageno,
                       Page page)
Writes the contents of the given page to disk.

Parameters:
pageno - identifies the page to write
page - holds the contents of the page
Throws:
java.lang.IllegalArgumentException - if pageno is invalid

add_file_entry

public void add_file_entry(java.lang.String fname,
                           PageId start_pageno)
Adds a file entry to the header page(s); each entry contains the name of the file and the PageId of the file's first page.

Throws:
java.lang.IllegalArgumentException - if fname or start_pageno is invalid

delete_file_entry

public void delete_file_entry(java.lang.String fname)
Deletes a file entry from the header page(s).

Throws:
java.lang.IllegalArgumentException - if fname is invalid

get_file_entry

public PageId get_file_entry(java.lang.String fname)
Looks up the entry for the given file name.

Returns:
PageId of the file's first page, or null if the file doesn't exist

print_space_map

public void print_space_map()
Print out the database's space map, a bitmap showing which pages are currently allocated.