simpledb
Class LogFile

java.lang.Object
  extended by simpledb.LogFile

public class LogFile
extends java.lang.Object

The format of the log file is as follows:


Field Summary
(package private) static int ABORT_RECORD
           
(package private) static int BEGIN_RECORD
           
(package private) static int CHECKPOINT_RECORD
           
(package private) static int COMMIT_RECORD
           
(package private)  long currentOffset
           
(package private) static int INT_SIZE
           
(package private)  java.io.File logFile
           
(package private) static int LONG_SIZE
           
(package private) static long NO_CHECKPOINT_ID
           
(package private)  int pageSize
           
(package private)  java.io.RandomAccessFile raf
           
(package private)  java.lang.Boolean recoveryUndecided
           
(package private)  java.util.HashMap<java.lang.Long,java.lang.Long> tidToFirstLogRecord
           
(package private)  int totalRecords
           
(package private) static int UPDATE_RECORD
           
 
Constructor Summary
LogFile(java.io.File f)
          Constructor.
 
Method Summary
 void force()
           
 int getTotalRecords()
           
 void logAbort(TransactionId tid)
          Write an abort record to the log for the specified tid, force the log to disk, and perform a rollback
 void logCheckpoint()
          Checkpoint the log and write a checkpoint record.
 void logCommit(TransactionId tid)
          Write a commit record to disk for the specified tid, and force the log to disk.
 void logTruncate()
          Truncate any unneeded portion of the log to reduce its space consumption
 void logWrite(TransactionId tid, Page before, Page after)
          Write an UPDATE record to disk for the specified tid and page (with provided before and after images.)
 void logXactionBegin(TransactionId tid)
          Write a BEGIN record for the specified transaction
(package private)  void preAppend()
           
 void print()
          Print out a human readable represenation of the log
(package private)  Page readPageData(java.io.RandomAccessFile raf)
           
 void recover()
          Recover the database system by ensuring that the updates of committed transactions are installed and that the updates of uncommitted transactions are not installed.
 void rollback(TransactionId tid)
          Rollback the specified transaction, setting the state of any of pages it updated to their pre-updated state.
 void shutdown()
          Shutdown the logging system, writing out whatever state is necessary so that start up can happen quickly (without extensive recovery.)
(package private)  void writePageData(java.io.RandomAccessFile raf, Page p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logFile

java.io.File logFile

raf

java.io.RandomAccessFile raf

recoveryUndecided

java.lang.Boolean recoveryUndecided

ABORT_RECORD

static final int ABORT_RECORD
See Also:
Constant Field Values

COMMIT_RECORD

static final int COMMIT_RECORD
See Also:
Constant Field Values

UPDATE_RECORD

static final int UPDATE_RECORD
See Also:
Constant Field Values

BEGIN_RECORD

static final int BEGIN_RECORD
See Also:
Constant Field Values

CHECKPOINT_RECORD

static final int CHECKPOINT_RECORD
See Also:
Constant Field Values

NO_CHECKPOINT_ID

static final long NO_CHECKPOINT_ID
See Also:
Constant Field Values

INT_SIZE

static int INT_SIZE

LONG_SIZE

static int LONG_SIZE

currentOffset

long currentOffset

pageSize

int pageSize

totalRecords

int totalRecords

tidToFirstLogRecord

java.util.HashMap<java.lang.Long,java.lang.Long> tidToFirstLogRecord
Constructor Detail

LogFile

public LogFile(java.io.File f)
        throws java.io.IOException
Constructor. Initialize and back the log file with the specified file. We're not sure yet whether the caller is creating a brand new DB, in which case we should ignore the log file, or whether the caller will eventually want to recover (after populating the Catalog). So we make this decision lazily: if someone calls recover(), then do it, while if someone starts adding log file entries, then first throw out the initial log file contents.

Parameters:
f - The log file's name
Throws:
java.io.IOException
Method Detail

preAppend

void preAppend()
         throws java.io.IOException
Throws:
java.io.IOException

getTotalRecords

public int getTotalRecords()

logAbort

public void logAbort(TransactionId tid)
              throws java.io.IOException
Write an abort record to the log for the specified tid, force the log to disk, and perform a rollback

Parameters:
tid - The aborting transaction.
Throws:
java.io.IOException

logCommit

public void logCommit(TransactionId tid)
               throws java.io.IOException
Write a commit record to disk for the specified tid, and force the log to disk.

Parameters:
tid - The committing transaction.
Throws:
java.io.IOException

logWrite

public void logWrite(TransactionId tid,
                     Page before,
                     Page after)
              throws java.io.IOException
Write an UPDATE record to disk for the specified tid and page (with provided before and after images.)

Parameters:
tid - The transaction performing the write
before - The before image of the page
after - The after image of the page
Throws:
java.io.IOException
See Also:
Page.getBeforeImage()

writePageData

void writePageData(java.io.RandomAccessFile raf,
                   Page p)
             throws java.io.IOException
Throws:
java.io.IOException

readPageData

Page readPageData(java.io.RandomAccessFile raf)
            throws java.io.IOException
Throws:
java.io.IOException

logXactionBegin

public void logXactionBegin(TransactionId tid)
                     throws java.io.IOException
Write a BEGIN record for the specified transaction

Parameters:
tid - The transaction that is beginning
Throws:
java.io.IOException

logCheckpoint

public void logCheckpoint()
                   throws java.io.IOException
Checkpoint the log and write a checkpoint record.

Throws:
java.io.IOException

logTruncate

public void logTruncate()
                 throws java.io.IOException
Truncate any unneeded portion of the log to reduce its space consumption

Throws:
java.io.IOException

rollback

public void rollback(TransactionId tid)
              throws java.util.NoSuchElementException,
                     java.io.IOException
Rollback the specified transaction, setting the state of any of pages it updated to their pre-updated state. To preserve transaction semantics, this should not be called on transactions that have already committed (though this may not be enforced by this method.)

Parameters:
tid - The transaction to rollback
Throws:
java.util.NoSuchElementException
java.io.IOException

shutdown

public void shutdown()
Shutdown the logging system, writing out whatever state is necessary so that start up can happen quickly (without extensive recovery.)


recover

public void recover()
             throws java.io.IOException
Recover the database system by ensuring that the updates of committed transactions are installed and that the updates of uncommitted transactions are not installed.

Throws:
java.io.IOException

print

public void print()
           throws java.io.IOException
Print out a human readable represenation of the log

Throws:
java.io.IOException

force

public void force()
           throws java.io.IOException
Throws:
java.io.IOException