5.4.1 class Rawfile



next up previous
Next: 5.4.2 log::log (The Create Up: 5.4 class log Previous: 5.4 class log

5.4.1 class Rawfile

 

At the lowest level, the log is maintained in a Unix file. However, to emulate the way a real log is read/written, access to this file should be in units of a page. We also need the forced write semantics -- when a write succeeds, it should be guaranteed that the changes have made it to disk. Further, changing over to a duplex-disk setup or to a raw disk interface should change the least amount of code.

Class DB [Murthy & Narasimhan 95] was a candidate for this low level file maintenance. It provided pagefile semantics and provided a forced-write semantics. However, it also managed a space map and allowed multiple page files to reside within the DB. This functionality was needed because DB was used to store the database itself. We did not need this extra functionality. Besides, it was not natural to treat a log as a DB. Therefore, we implemented Rawfile (see rawfile.h and rawfile.C), which provides a page file view of a Unix file.

Rawfile implements bounded file semantics as follows: when the log is created, the number of pages it contains is specified. Rawfile::Rawfile (the create constructor) allocates the required space by lseeking [see lseek(2)] to the end of the file and write-ing [see write(2)] a single byte there. This has the advantage that the log file does not occupy disk space until actually written to. In addition, we need not keep track of the size of the file. We can find it any time by using the stat(2) or fstat(2) system calls. Rawfile::write_page never allows a write to go beyond the current size of the file.

Rawfile::read_page and Rawfile::write_page are straightforward. They use the read(2) and write(2) system calls to read and write a page at a time. Rawfile::write_page also forces the write to disk by calling the fsync(2) system call.



next up previous
Next: 5.4.2 log::log (The Create Up: 5.4 class log Previous: 5.4 class log



ajitk@cs.wisc.edu, cjin@cs.wisc.edu