|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimpledb.LogFile
public class LogFile
LogFile implements the recovery subsystem of SimpleDb. This class is able to write different log records as needed, but it is the responsibility of the caller to ensure that write ahead logging and two-phase locking discipline are followed.
Locking note:
Many of the methods here are synchronized (to prevent concurrent log writes from happening); many of the methods in BufferPool are also synchronized (for similar reasons.) Problem is that BufferPool writes log records (on page flushed) and the log file flushes BufferPool pages (on checkpoints and recovery.) This can lead to deadlock. For that reason, any LogFile operation that needs to access the BufferPool must not be declared synchronized and must begin with a block like:
synchronized (Database.getBufferPool()) { synchronized (this) { .. } }
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) 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) java.io.RandomAccessFile |
raf
|
(package private) static int |
UPDATE_RECORD
|
Constructor Summary | |
---|---|
LogFile(java.io.File f,
boolean recover)
Constructor. |
Method Summary | |
---|---|
void |
force()
|
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 |
void |
print()
Print out a human readable represenation of the log |
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.) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
java.io.File logFile
java.io.RandomAccessFile raf
static final int ABORT_RECORD
static final int COMMIT_RECORD
static final int UPDATE_RECORD
static final int BEGIN_RECORD
static final int CHECKPOINT_RECORD
static final long NO_CHECKPOINT_ID
static int INT_SIZE
static int LONG_SIZE
Constructor Detail |
---|
public LogFile(java.io.File f, boolean recover) throws java.io.IOException
f
- The log filerecover
- True if recovery should be initiated immediately after loading.
java.io.IOException
Method Detail |
---|
public void logAbort(TransactionId tid) throws java.io.IOException
tid
- The aborting transaction.
java.io.IOException
public void logCommit(TransactionId tid) throws java.io.IOException
tid
- The committing transaction.
java.io.IOException
public void logWrite(TransactionId tid, Page before, Page after) throws java.io.IOException
tid
- The transaction performing the writebefore
- The before image of the pageafter
- The after image of the page
java.io.IOException
Page.getBeforeImage()
public void logXactionBegin(TransactionId tid) throws java.io.IOException
tid
- The transaction that is beginning
java.io.IOException
public void logCheckpoint() throws java.io.IOException
java.io.IOException
public void logTruncate() throws java.io.IOException
java.io.IOException
public void rollback(TransactionId tid) throws java.util.NoSuchElementException, java.io.IOException
tid
- The transaction to rollback
java.util.NoSuchElementException
java.io.IOException
public void shutdown()
public void recover() throws java.io.IOException
java.io.IOException
public void print() throws java.io.IOException
java.io.IOException
public void force() throws java.io.IOException
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |