simpledb.tx
Class Transaction

java.lang.Object
  extended by simpledb.tx.Transaction

public class Transaction
extends Object

Provides transaction management for clients, ensuring that all transactions are serializable, recoverable, and in general satisfy the ACID properties.

Author:
Edward Sciore

Constructor Summary
Transaction()
          Creates a new transaction and its associated recovery and concurrency managers.
 
Method Summary
 Block append(String filename, PageFormatter fmtr)
          Appends a new block to the end of the specified file and returns a reference to it.
 void commit()
          Commits the current transaction.
 int getInt(Block blk, int offset)
          Returns the integer value stored at the specified offset of the specified block.
 String getString(Block blk, int offset)
          Returns the string value stored at the specified offset of the specified block.
 void pin(Block blk)
          Pins the specified block.
 void recover()
          Flushes all modified buffers.
 void rollback()
          Rolls back the current transaction.
 void setInt(Block blk, int offset, int val)
          Stores an integer at the specified offset of the specified block.
 void setString(Block blk, int offset, String val)
          Stores a string at the specified offset of the specified block.
 int size(String filename)
          Returns the number of blocks in the specified file.
 void unpin(Block blk)
          Unpins the specified block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Transaction

public Transaction()
Creates a new transaction and its associated recovery and concurrency managers. This constructor depends on the file, log, and buffer managers that it gets from the class SimpleDB. Those objects are created during system initialization. Thus this constructor cannot be called until either SimpleDB.init(String) or SimpleDB.initFileLogAndBufferMgr(String) or is called first.

Method Detail

commit

public void commit()
Commits the current transaction. Flushes all modified buffers (and their log records), writes and flushes a commit record to the log, releases all locks, and unpins any pinned buffers.


rollback

public void rollback()
Rolls back the current transaction. Undoes any modified values, flushes those buffers, writes and flushes a rollback record to the log, releases all locks, and unpins any pinned buffers.


recover

public void recover()
Flushes all modified buffers. Then goes through the log, rolling back all uncommitted transactions. Finally, writes a quiescent checkpoint record to the log. This method is called only during system startup, before user transactions begin.


pin

public void pin(Block blk)
Pins the specified block. The transaction manages the buffer for the client.

Parameters:
blk - a reference to the disk block

unpin

public void unpin(Block blk)
Unpins the specified block. The transaction looks up the buffer pinned to this block, and unpins it.

Parameters:
blk - a reference to the disk block

getInt

public int getInt(Block blk,
                  int offset)
Returns the integer value stored at the specified offset of the specified block. The method first obtains an SLock on the block, then it calls the buffer to retrieve the value.

Parameters:
blk - a reference to a disk block
offset - the byte offset within the block
Returns:
the integer stored at that offset

getString

public String getString(Block blk,
                        int offset)
Returns the string value stored at the specified offset of the specified block. The method first obtains an SLock on the block, then it calls the buffer to retrieve the value.

Parameters:
blk - a reference to a disk block
offset - the byte offset within the block
Returns:
the string stored at that offset

setInt

public void setInt(Block blk,
                   int offset,
                   int val)
Stores an integer at the specified offset of the specified block. The method first obtains an XLock on the block. It then reads the current value at that offset, puts it into an update log record, and writes that record to the log. Finally, it calls the buffer to store the value, passing in the LSN of the log record and the transaction's id.

Parameters:
blk - a reference to the disk block
offset - a byte offset within that block
val - the value to be stored

setString

public void setString(Block blk,
                      int offset,
                      String val)
Stores a string at the specified offset of the specified block. The method first obtains an XLock on the block. It then reads the current value at that offset, puts it into an update log record, and writes that record to the log. Finally, it calls the buffer to store the value, passing in the LSN of the log record and the transaction's id.

Parameters:
blk - a reference to the disk block
offset - a byte offset within that block
val - the value to be stored

size

public int size(String filename)
Returns the number of blocks in the specified file. This method first obtains an SLock on the "end of the file", before asking the file manager to return the file size.

Parameters:
filename - the name of the file
Returns:
the number of blocks in the file

append

public Block append(String filename,
                    PageFormatter fmtr)
Appends a new block to the end of the specified file and returns a reference to it. This method first obtains an XLock on the "end of the file", before performing the append.

Parameters:
filename - the name of the file
fmtr - the formatter used to initialize the new page
Returns:
a reference to the newly-created disk block


Copyright © 2011. All Rights Reserved.