simpledb.log
Class LogMgr

java.lang.Object
  extended by simpledb.log.LogMgr
All Implemented Interfaces:
Iterable<BasicLogRecord>

public class LogMgr
extends Object
implements Iterable<BasicLogRecord>

The low-level log manager. This log manager is responsible for writing log records into a log file. A log record can be any sequence of integer and string values. The log manager does not understand the meaning of these values, which are written and read by the recovery manager.

Author:
Edward Sciore

Field Summary
static int LAST_POS
          The location where the pointer to the last integer in the page is.
 
Constructor Summary
LogMgr(String logfile)
          Creates the manager for the specified log file.
 
Method Summary
 int append(Object[] rec)
          Appends a log record to the file.
 void flush(int lsn)
          Ensures that the log records corresponding to the specified LSN has been written to disk.
 Iterator<BasicLogRecord> iterator()
          Returns an iterator for the log records, which will be returned in reverse order starting with the most recent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAST_POS

public static final int LAST_POS
The location where the pointer to the last integer in the page is. A value of 0 means that the pointer is the first value in the page.

See Also:
Constant Field Values
Constructor Detail

LogMgr

public LogMgr(String logfile)
Creates the manager for the specified log file. If the log file does not yet exist, it is created with an empty first block. This constructor depends on a FileMgr object that it gets from the method SimpleDB.fileMgr(). That object is created during system initialization. Thus this constructor cannot be called until SimpleDB.initFileMgr(String) is called first.

Parameters:
logfile - the name of the log file
Method Detail

flush

public void flush(int lsn)
Ensures that the log records corresponding to the specified LSN has been written to disk. All earlier log records will also be written to disk.

Parameters:
lsn - the LSN of a log record

iterator

public Iterator<BasicLogRecord> iterator()
Returns an iterator for the log records, which will be returned in reverse order starting with the most recent.

Specified by:
iterator in interface Iterable<BasicLogRecord>
See Also:
Iterable.iterator()

append

public int append(Object[] rec)
Appends a log record to the file. The record contains an arbitrary array of strings and integers. The method also writes an integer to the end of each log record whose value is the offset of the corresponding integer for the previous log record. These integers allow log records to be read in reverse order.

Parameters:
rec - the list of values
Returns:
the LSN of the final value


Copyright © 2011. All Rights Reserved.