PageLog

Transaction log mechanism. The stream contains a list of records. The data format for a record is:
  • type (0: no-op, 1: undo, 2: commit, ...)
  • data
The transaction log is split into sections. A checkpoint starts a new section.

Methods
static Row readRow(RowFactory rowFactory, DataReader in, Data data)
Read a row from an input stream.
static Row readRow(RowFactory rowFactory, DataReader in, Data data) throws IOException
Read a row from an input stream.
Parameters:
rowFactory - the row factory
in - the input stream
data - a temporary buffer
Returns:
the row
void addUndo(int pageId, Data page)
Add an undo entry to the log.
void addUndo(int pageId, Data page)
Add an undo entry to the log. The page data is only written once until the next checkpoint.
Parameters:
pageId - the page id
page - the old page data
void checkpoint()
Switch to a new log section.
void checkpoint()
Switch to a new log section.
void close()
Close without further writing.
void close()
Close without further writing.
void commit(int sessionId)
Mark a transaction as committed.
void commit(int sessionId)
Mark a transaction as committed.
Parameters:
sessionId - the session
void flush()
Flush the transaction log.
void flush()
Flush the transaction log.
void free()
Free up all pages allocated by the log.
void free()
Free up all pages allocated by the log.
ArrayList getInDoubtTransactions()
ArrayList getInDoubtTransactions()
int getLogFirstSectionId()
int getLogFirstSectionId()
int getLogPos()
int getLogPos()
int getLogSectionId()
int getLogSectionId()
int getMinPageId()
Get the smallest possible page id used.
int getMinPageId()
Get the smallest possible page id used. This is the trunk page if only appending at the end of the file, or 0.
Returns:
the smallest possible page.
long getSize()
long getSize()
boolean getUndo(int pageId)
Check if the undo entry was already written for the given page.
boolean getUndo(int pageId)
Check if the undo entry was already written for the given page.
Parameters:
pageId - the page
Returns:
true if it was written
void logAddOrRemoveRow(Session session, int tableId, Row row, boolean add)
A record is added to a table, or removed from a table.
void logAddOrRemoveRow(Session session, int tableId, Row row, boolean add)
A record is added to a table, or removed from a table.
Parameters:
session - the session
tableId - the table id
row - the row to add
add - true if the row is added, false if it is removed
void logTruncate(Session session, int tableId)
A table is truncated.
void logTruncate(Session session, int tableId)
A table is truncated.
Parameters:
session - the session
tableId - the table id
void openForReading(int newLogKey, int newFirstTrunkPage, int newFirstDataPage)
Open the log for reading.
void openForReading(int newLogKey, int newFirstTrunkPage, int newFirstDataPage)
Open the log for reading.
Parameters:
newLogKey - the first expected log key
newFirstTrunkPage - the first trunk page
newFirstDataPage - the index of the first data page
void openForWriting(int newFirstTrunkPage, boolean atEnd)
Open the log for writing.
void openForWriting(int newFirstTrunkPage, boolean atEnd)
Open the log for writing. For an existing database, the recovery must be run first.
Parameters:
newFirstTrunkPage - the first trunk page
atEnd - whether only pages at the end of the file should be used
void prepareCommit(Session session, String transaction)
Prepare a transaction.
void prepareCommit(Session session, String transaction)
Prepare a transaction.
Parameters:
session - the session
transaction - the name of the transaction
boolean recover(int stage)
Run one recovery stage.
boolean recover(int stage)
Run one recovery stage. There are three recovery stages: 0: only the undo steps are run (restoring the state before the last checkpoint). 1: the pages that are used by the transaction log are allocated. 2: the committed operations are re-applied.
Parameters:
stage - the recovery stage
Returns:
whether the transaction log was empty
void recoverEnd()
Called after the recovery has been completed.
void recoverEnd()
Called after the recovery has been completed.
void removeUntil(int firstUncommittedSection)
Remove all pages until the given log (excluding).
void removeUntil(int firstUncommittedSection)
Remove all pages until the given log (excluding).
Parameters:
firstUncommittedSection - the first log section to keep
void setInDoubtTransactionState(int sessionId, int pageId, boolean commit)
Set the state of an in-doubt transaction.
void setInDoubtTransactionState(int sessionId, int pageId, boolean commit)
Set the state of an in-doubt transaction.
Parameters:
sessionId - the session
pageId - the page where the commit was prepared
commit - whether the transaction should be committed

Fields
static int ADD = 5
static int CHECKPOINT = 8
static int COMMIT = 2
static int FREE_LOG = 9
static int NOOP = 0
static int PREPARE_COMMIT = 3
static int RECOVERY_STAGE_ALLOCATE = 1
static int RECOVERY_STAGE_REDO = 2
static int RECOVERY_STAGE_UNDO = 0
static int REMOVE = 6
static int ROLLBACK = 4
static int TRUNCATE = 7
static int UNDO = 1

NOOP = 0

No operation.

RECOVERY_STAGE_UNDO = 0

The recovery stage to undo changes (re-apply the backup).

RECOVERY_STAGE_ALLOCATE = 1

The recovery stage to allocate pages used by the transaction log.

UNDO = 1

An undo log entry. Format: page id: varInt, size, page. Size 0 means uncompressed, size 1 means empty page, otherwise the size is the number of compressed bytes.

COMMIT = 2

A commit entry of a session. Format: session id: varInt.

RECOVERY_STAGE_REDO = 2

The recovery stage to redo operations.

PREPARE_COMMIT = 3

A prepare commit entry for a session. Format: session id: varInt, transaction name: string.

ROLLBACK = 4

Roll back a prepared transaction. Format: session id: varInt.

ADD = 5

Add a record to a table. Format: session id: varInt, table id: varInt, row.

REMOVE = 6

Remove a record from a table. Format: session id: varInt, table id: varInt, row.

TRUNCATE = 7

Truncate a table. Format: session id: varInt, table id: varInt.

CHECKPOINT = 8

Perform a checkpoint. The log section id is incremented. Format: -

FREE_LOG = 9

Free a log page. Format: count: varInt, page ids: varInt