Hands-on 6: WAL

Due: 11:59pm April 18, 2018

Complete the following hands-on assignment. Do the activities described, and submit your solutions using the Gradescope before 11:59p.

Intro to wal-sys

This hands-on assignment will give you some experience using a Write Ahead Log (WAL) system. This system corresponds to the WAL scheme described in Section 9.3 of the textbook. You should carefully read that section before attempting this assignment. You can do this hands-on on any computer that has a Python 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 Python script named wal-sys. Before trying to run it, change its permissions to make it executable, for example by typing:

chmod +x wal-sys.py

The wal-sys script can be run as follows:

./wal-sys.py [-reset]

Alternatively, you can run the script as:

python ./wal-sys.py [-reset]

Wal-sys is a simple WAL system that models a bank's central database, implementing redo logging for error-recovery. Wal-sys 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 all of the installed changes to the database.

After you start wal-sys, you can enter commands to manage recoverable actions and accounts. There are also commands to simulate a system crash and to print the contents of the LOG and DB files. All the commands to wal-sys are case sensitive. Since wal-sys 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 wal-sys's standard input:

./wal-sys.py -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 wal-sys, 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 wal-sys to discard the contents of any previous DB and LOG files so that it can start with a clean initial state.

Commands interpreted by wal-sys

The following commands are used for managing recoverable actions and accounts:

  • begin action_id
    Begin a recoverable action denoted by action_id. The action_id is a positive integer that uniquely identifies a given recoverable action.

  • create_account action_id account_name starting_balance
    Create a new account with the given account_name and starting_balance. The first argument specifies that this operation is part of recoverable action action_id. The account_name can be any character string with no white spaces.

  • credit_account action_id account_name credit_amount
    Add credit_amount to account_name's balance. This command logs the credit and holds it in a buffer until an end command is executed for recoverable action action_id.

  • debit_account action_id account_name debit_amount
    Reduce account_name's balance by debit_amount. Like credit, this command logs the debit and holds it in a buffer until an end command is executed for recoverable action action_id.

  • commit action_id
    Commit the recoverable action action_id. This command logs a commit record.

  • checkpoint
    Log a checkpoint record.

  • end action_id
    End recoverable action action_id. This command installs the results of recoverable action action_id to the "DB". It also logs an end record.

The following commands help us understand the dynamics of the WAL system:

  • show_state
    Print out the current state of the database. This command displays the contents of the "DB" and "LOG" files.

  • crash
    Crash the system. In this hands-on, we are only concerned about crash recovery, so this is the only command we will use to exit the program.


Now you're ready for this week's questions.

Like before, the questions are in a read-only google doc. Make sure to enter quesitons in the page indicated (please do not erase the question text) and upload them as a PDF to Gradescope. See more detailed instructions at the end of the first week's hands-on. If you are having Gradescope problems, please post a question on Piazza!