




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





This original assignment is designed by University of Wisconsin-Madison. In our revised assignment, you will implement a simplified version of the Buffer Manager layer, without support for concurrency control or recovery. You will be given the code for the lower layer, the Disk Space Manager. You should begin by reading the chapter on Disks and Files, to get an overview of buffer management. This material will also be covered in class. In addition, HTML documentation is available for Minibase, which you can read using Internet Browser. In particular, you should read the description of the DB class, which you will call extensively in this assignment. The Java documentation for the diskmgr package can be found at javaminibase/javamini hwk/handout/BufMgr/javadoc/packages.html. You should also read the code under diskmgr/ carefully to learn how package is declared and how Exceptions are handled in Minibase. This assignment is designed for LINUX-SPECIFIC platform. The java codes you turn in should work on LINUX machine. We will only accept the codes that work on LINUX machine. You can see the particular code in BMTest.java, etc.
The simplified Buffer Manager interface that you will implement in this assignment allows a client (a higher level program that calls the Buffer Manager) to allocate/de-allocate pages on disk, to bring a disk page into the buffer pool and pin it, and to unpin a page in the buffer pool. The methods that you have to implement are described below:
public class BufMgr {
Create the BufMgr object.
Allocate pages (frames) for the buffer pool in main memory and
make the buffer manager aware that the replacement policy is
specified by replacerArg (i.e. Clock, LRU, MRU etc.).
@param numbufs: number of buffers in the buffer pool.
@param replacerArg: name of the buffer replacement policy. */
public BufMgr(int numbufs, String replacerArg) {}; /*----------------------------------------------------------/
/**
public void pinPage(PageId pin_pgid, Page page, boolean emptyPage) {}; /*----------------------------------------------------------/
public void flushPage(PageId pageid) {}; /*----------------------------------------------------------/ };
The buffer pool is a collection of frames (page-sized sequence of main memory bytes) that is managed by the Buffer Manager. Conceptually, it should be stored as an array bufPool[numbuf] of Page objects. However, due to the limitation of Java language, it is not feasible to declare an array of Page objects and later on writing string (or other primitive values) to the defined Page. To get around the problem, we have defined our Page as an array of bytes and deal with buffer pool at the byte array level. There- fore, when implementing your constructor for the BufMgr class, you should declare the buffer pool as bufpool[numbuf ][page size]. Note that the size of minibase pages is defined in the interface GlobalConst of the global package. Before coding, please make sure that you understand how Page object is defined and manipulated in Java minibase. In addition, you should maintain an array bufDescr[numbuf] of descriptors, one per frame. Each descriptor is a record with the following fields:
page number, pin count, dirtybit.
The pin count field is an integer, page number is a PageId object, and dirtybit is a boolean. This describes the page that is stored in the corresponding frame. A page is identified by a page number that is generated by the DB class when the page is allocated, and is unique over all pages in the database. The PageId type is defined as an integer type in minirel.h. A simple hash table should be used to figure out what frame a given disk page occupies. The hash table should be implemented (entirely in main memory) by using an array of pointers to lists of 〈 page number, frame number 〉 pairs. The array is called the directory and each list of pairs is called a bucket. Given a page number, you should apply a hash function to find the directory entry pointing to the bucket
Figure 1: Hash Table
that contains the frame number for this page, if the page is in the buffer pool. If you search the bucket and don’t find a pair containing this page number, the page is not in the pool. If you find such a pair, it will tell you the frame in which the page resides. This is illustrated in Figure 1. The hash function must distribute values in the domain of the search field uniformly over the collection of buckets. If we have HTSIZE buckets, numbered 0 through M-1, a hash function h of the form h(value) = (a ∗ value + b) mod HT SIZE works well in practice. HTSIZE should be chosen to be a prime number. When a page is requested the buffer manager should do the following:
(a) Choose a frame for replacement, using the Clock replacement policy. (b) If the frame chosen for replacement is dirty, flush it (i.e., write out the page that it contains to disk, using the appropriate DB class method). (c) Read the requested page (again, by calling the DB class) into the frame chosen for replacement; the pin count and dirtybit for the frame should be initialized to 0 and FALSE, respectively. (d) Delete the entry for the old page from the Buffer Manager’s hash table and insert an entry for the new page. Also, update the entry for this frame in the bufDescr array to reflect these changes.
For example: (when try to pin page from diskmgr layer)
try { SystemDefs.JavabaseBM.pinPage(pageId, page, true); } catch (Exception e) { throw new DiskMgrException(e, "DB.java: pinPage() failed"); }
For example: (when try to unpin a page that is not pinned)
if (pin_count == 0) { throw new PageUnpinnedException (null, "BUFMGR: PAGE_NOT_PINNED."); }
Basically, the ChainException class keeps track of all the exceptions thrown accross the different lay- ers. Any exceptions that you decide to throw in your bufmgr package should extend the ChainException class.
For testing purposes, we ask you to throw the following exceptions in case of error (use the exact same name, please):
Feel free to throw other new exceptions as you see fit. But make sure that you follow the error protocol when you catch an exception. Also, think carefully about what else you need to do in the catch phase. Sometimes you do need to unroll the previous operations when failure happens.
You should turn in copies of your code together with copies of the output produced by running the tests. Also, you should email the code packages to Jason before the due the day. The assignment is due on March 24th before class. The solution will be made public after that time, and solutions turned in after that time will not receive any credit. So be sure to turn in whatever you have, even if it is not working fully, at that time.