Lab 3: Page Formatter

  • Course: COSC 460 Databases Fall 2018
  • Instructor: Michael Hay
  • Assignment: Lab 3: Page Formatter
  • Due: Mon, Sep 24 at 11:59 PM
  • Starter code: lab3.zip

Introduction

This lab is a direct continuation of last week where you implement methods for reading a page from bytes and writing a page to bytes.

(Quick aside: the starter code for this lab also contains some additional tests for the code submitted as part of lab2 – see SlottedPageMoreTest. You are strongly encouraged to fix any lingering bugs in your lab2 submission!)

Please refer to these code quality criteria as a guideline as you do your work.

Environment setup

Please follow similar instructions as on lab 2 (download the starter code, and unzip). Here is a walkthrough for setting up IntelliJ.

Saving and accessing your files

You can gain access to this room during open lab hours. However, you are strongly encouraged to save a copy of your work on your Colgate network drive, Google Drive, Dropbox, etc. so you can easily access it from elsewhere.

Assignment overview

This lab continues where SlottedPage left off. You will finish off the implementation of a slotted page by implementing methods for reading a page from bytes and writing a page to bytes. This requires making a few modifications to SlottedPage but most of the coding will be in a new class, SlottedPageFormatter.

Tip: This lab requires manipulating invididual bits. You are expected to know about binary representation and logic operators (and, or, not, etc.) from COSC 201 and COSC 290 respectively. But you may not know how to manipulate data stored in bytes to extract out individual bit values. Here is the official page from Oracle describing the bitwise operators in Java. There are also decent tutorials online.

Note: The book uses the term “slotted page organization” to refer specifically to the format used for variable-length records in Ch. 9.6.2, even though the page organization for fixed-length records also places tuples in slots. To be clear, ColgateDB’s SlottedPage is intended to hold records of fixed-length.

The ColgateDB slotted page format is most similar to the “Unpacked, bitmap” format in Figure 9.6 of the Cow book. The main differences are that no space is used to store the number of slots and the header is stored in the first bytes of the page (in contrast the figure in the book makes it look as though the “header” comes at the page’s end). For more details on the format of a slotted page in ColgateDB, see the javadoc for SlottedPageFormatter.

Starter code

You are expected to modify these files:

  • SlottedPageFormatter.java

You are expected to read, use, but not modify the remaining files.

Tasks

Task 1 Implement the computePageCapacity static method in SlottedPageFormatter and update the getNumSlots method in SlottedPage. After you implement these methods, you should be able to pass the computePageCapacity and slottedPageNumSlots tests in SlottedPageFormatterTest.

Task 2 Implement the getHeaderSize static method in SlottedPageFormatter and pass the testHeaderSize test in SlottedPageFormatterTest.

Task 3 Now comes the challenging part, reading a page from bytes and writing a page as bytes. First, read the javadoc at the top of SlottedPageFormatter so that you understand how a page is formatted. Then implement the static methods pageToBytes and bytesToPage. (You might find it helpful to implement the helper methods isSlotUsed and markSlot in SlottedPageFormatter. These methods are optional; you are not required to implement them.) You will need to call the pageToBytes and bytesToPage methods from the appropriate places in SlottedPage. After you implement pageToBytes and call it appropriately in SlottedPage, you should be able to pass the writeToBytes series of unit tests in SlottedPageFormatterTest. Similarly, bytesToPage is associated with the readFromBytes series of unit tests in SlottedPageFormatterTest.

Finally, once you have written both pageToBytes and bytesToPage, you should be able to pass the remaining tests in SlottedPageFormatterTest.

Milestone

The milestone for this lab will be to complete the above tasks and pass the tests described above.

Submission instructions

Upload your files to Gradescope.