org.neo4j.kernel.impl.transaction
Class TxLog

java.lang.Object
  extended by org.neo4j.kernel.impl.transaction.TxLog

public class TxLog
extends Object

This class is made public for testing purposes only, do not use.

The TxManager uses this class to keep a transaction log for transaction recovery.


Nested Class Summary
static class TxLog.Record
          Made public for testing only.
 
Field Summary
static byte BRANCH_ADD
           
static byte MARK_COMMIT
           
static byte TX_DONE
           
static byte TX_START
           
 
Constructor Summary
TxLog(String fileName)
          Initializes a transaction log using filename.
 
Method Summary
 void addBranch(byte[] globalId, byte[] branchId)
          Writes a BRANCH_ADD record to the file.
 void close()
          Closes the file representing the transaction log.
 void force()
          Forces the log file (with metadata).
 Iterator<List<TxLog.Record>> getDanglingRecords()
          Returns an array of lists, each list contains dangling records (transactions that han't been completed yet) grouped after global by transaction id.
 String getName()
          Returns the name of the transaction log.
 int getRecordCount()
          Returns the number of records (one of TX_START,BRANCH_ADD,MARK_COMMIT or TX_DONE) written since this instance was created or truncated.
 void markAsCommitting(byte[] globalId)
          Writes a MARK_COMMIT record to the file and forces the file to disk.
 void switchToLogFile(String newFile)
          Switches log file.
 void truncate()
          Truncates the file to zero size and sets the record count to zero.
 void txDone(byte[] globalId)
          Writes a TX_DONE record to the file.
 void txStart(byte[] globalId)
          Writes a TX_START record to the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TX_START

public static final byte TX_START
See Also:
Constant Field Values

BRANCH_ADD

public static final byte BRANCH_ADD
See Also:
Constant Field Values

MARK_COMMIT

public static final byte MARK_COMMIT
See Also:
Constant Field Values

TX_DONE

public static final byte TX_DONE
See Also:
Constant Field Values
Constructor Detail

TxLog

public TxLog(String fileName)
      throws IOException
Initializes a transaction log using filename. If the file isn't empty the position will be set to size of file so new records will be appended.

Parameters:
fileName - Filename of file to use
Throws:
IOException - If unable to open file
Method Detail

getName

public String getName()
Returns the name of the transaction log.


getRecordCount

public int getRecordCount()
Returns the number of records (one of TX_START,BRANCH_ADD,MARK_COMMIT or TX_DONE) written since this instance was created or truncated.


close

public void close()
           throws IOException
Closes the file representing the transaction log.

Throws:
IOException

force

public void force()
           throws IOException
Forces the log file (with metadata). Useful when switching log.

Throws:
IOException

truncate

public void truncate()
              throws IOException
Truncates the file to zero size and sets the record count to zero.

Throws:
IOException

txStart

public void txStart(byte[] globalId)
             throws IOException
Writes a TX_START record to the file.

Parameters:
globalId - The global id of the new transaction
Throws:
IOException - If unable to write

addBranch

public void addBranch(byte[] globalId,
                      byte[] branchId)
               throws IOException
Writes a BRANCH_ADD record to the file.

Parameters:
globalId - The global id of the transaction
branchId - The branch id for the enlisted resource
Throws:
IOException - If unable to write

markAsCommitting

public void markAsCommitting(byte[] globalId)
                      throws IOException
Writes a MARK_COMMIT record to the file and forces the file to disk.

Parameters:
globalId - The global id of the transaction
Throws:
IOException - If unable to write

txDone

public void txDone(byte[] globalId)
            throws IOException
Writes a TX_DONE record to the file.

Parameters:
globalId - The global id of the transaction completed
Throws:
IOException - If unable to write

getDanglingRecords

public Iterator<List<TxLog.Record>> getDanglingRecords()
                                                throws IOException
Returns an array of lists, each list contains dangling records (transactions that han't been completed yet) grouped after global by transaction id.

Throws:
IOException

switchToLogFile

public void switchToLogFile(String newFile)
                     throws IOException
Switches log file. Copies the dangling records in current log file to the newFile and the makes the switch closing the old log file.

Parameters:
newFile - The filename of the new file to switch to
Throws:
IOException - If unable to switch log file


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.