M.I.T. DEPARTMENT OF EECS

6.033 - Computer System Engineering Handout 30 - April 30, 2003

Hands-on 8: Write Ahead Log System

Intro to Trans

This hands-on assignment will give you some experience using a Write Ahead Log (WAL) system (as described in Chapter 8 of the course notes). You can do this hands-on on any computer that has a Perl language interpreter, but we will be able to answer your questions more easily if you run this on an Athena workstation. You can download the WAL system from here (if your browser displays the file in a window instead of saving it, use "File -> Save As" to save the file). The downloaded file is a Perl script named trans. Before trying to run it, change its permissions to make it executable, for example by typing:

athena% chmod +x trans

The trans command can be run as follows:

trans [-reset]

Trans is a simple WAL system that models a bank's central database. Trans implements intention logging for error-recovery (without shadow files) as presented in the System R paper and the class notes. Trans creates and uses two files, named LOG and DB, in the current working directory. The "LOG" file contains the log entries, and the "DB" file contains the last state of the database. All the updates to the "LOG" file are forced to the disk. In contrast, all the updates to the "DB" are buffered in RAM, you can use the flush command (described below) to force the current committed updates of "DB" to the disk.

After you run ./trans you can enter commands to manage transactions and accounts. There are also commands to simulate a system crash and to force file updates to the disk. All the commands to trans are case sensitive. Since trans uses the standard input stream, you can use the system in batch mode. To do this, place your commands in a file ("cmd.in" for example) and redirect the file to trans's standard input:

athena% ./trans -reset < cmd.in.

When using batch mode, make sure that each command is followed by a newline character (including the last one).

When you restart trans, it will perform a log-based recovery of the "DB" file using the "LOG" file it finds in the current working directory. The -reset option tells trans to discard the contents of any previous "DB" and "LOG" files so that it can start with a clean initial state.

Commands interpreted by Trans

Following commands are used for managing transactions and accounts:

Following commands help us understand the dynamics of the WAL system:

Using Trans

Start trans with a reset:
./trans -reset
and run the following commands (sequence 1):
begin 1
init 1 studentA 1000
commit 1
begin 2
init 2 studentB 2000
begin 3
flush
init 3 studentC 3000
write 3 studentC 3001
write 2 studentB 2001
commit 3
print
crash
trans should print out what its doing, and then exit.

Use a text editor to examine the "DB" file and answer the following questions:

1) When the database recovers, which accounts should be active, and what values should they contain?

2) Trans prints out the database contents after you type print. Why doesn't the database show studentB?

3) Can you explain why "DB" file does not contain a record for studentC?

4) What differences would you see if the flush command was not there?

Recovering the database

When you run trans without the -reset option it recovers the database "DB". To recover the database and then look at the results, type:
./trans
print
crash

5)Run trans again to recover the database. Examine the "DB" file. Did trans recover the database correctly?

6)Explain the "Losers" and "Winners" reported during the recovery.

Checkpoints

Start trans with a reset:
./trans -reset
and run the following commands (sequence 2):
begin 1
init 1 studentA 1000
commit 1
begin 2
init 2 studentB 2000
checkpoint
begin 3
init 3 studentC 3000
write 3 studentC 3001
write 2 studentB 2001
commit 3
print
crash

Examine the "LOG" output file. Note that the CHECKPOINT entry lists the uncommitted TID's at that point in time.

7) What is the advantage of using checkpoints?

8) Run trans again to recover the database and use the print command to look at the recovered database. Note down the list of "Losers". Does "DB" recover correctly? The checkpoint command does a flush command internally. Why is this important for the correct execution of the checkpoint?

9) Using a text editor, manually edit the "LOG" file and replace the line "CHECKPOINT 2" with "CHECKPOINT 2 1 ". Run trans again by typing the following:

./trans
print
crash

10) Examine the list of "Losers" and compare this with the list in question (8), why are these lists different?

11) Which line would you move to the end of "LOG" in question (10) to make the list of "Losers" identical to that in question (8)?



Go to 6.033 Home Page Questions or Comments: 6.033-tas@mit.edu