org.neo4j.kernel.impl.transaction.xaframework
Class XaLogicalLog
java.lang.Object
org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog
- All Implemented Interfaces:
- LogExtractor.LogLoader
- Direct Known Subclasses:
- InterceptingXaLogicalLog
public class XaLogicalLog
- extends Object
- implements LogExtractor.LogLoader
XaLogicalLog
is a transaction and logical log combined. In
this log information about the transaction (such as started, prepared and
committed) will be written. All commands participating in the transaction
will also be written to the log.
Normally you don't have to do anything with this log except open it after it
has been instanciated (see XaContainer
). The only method that may be
of use when implementing a XA compatible resource is the
getCurrentTxIdentifier()
. Leave everything else be unless you know
what you're doing.
When the log is opened it will be scaned for uncompleted transactions and
those transactions will be re-created. When scan of log is complete all
transactions that hasn't entered prepared state will be marked as done
(implies rolledback) and dropped. All transactions that have been prepared
will be held in memory until the transaction manager tells them to commit.
Transaction that already started commit but didn't get flagged as done will
be re-committed.
Method Summary |
void |
applyTransaction(ReadableByteChannel byteChannel)
|
void |
applyTransactionWithoutTxId(ReadableByteChannel byteChannel,
long nextTxId)
|
void |
close()
|
void |
commitOnePhase(int identifier,
long txId)
|
void |
commitTwoPhase(int identifier,
long txId)
|
boolean |
deleteLogicalLog(long version)
|
void |
done(int identifier)
|
String |
getBaseFileName()
|
int |
getCurrentTxIdentifier()
If the current thread is committing a transaction the identifier of that
XaTransaction can be obtained invoking this method. |
String |
getFileName(long version)
|
static long |
getHighestHistoryLogVersion(File storeDir,
String baseFileName)
|
long |
getHighestLogVersion()
|
Pattern |
getHistoryFileNamePattern()
|
static Pattern |
getHistoryFileNamePattern(String baseFileName)
|
static long |
getHistoryLogVersion(File historyLogFile)
|
protected XaLogicalLog.LogDeserializer |
getLogDeserializer(ReadableByteChannel byteChannel)
|
LogExtractor |
getLogExtractor(long startTxId,
long endTxIdHint)
|
ReadableByteChannel |
getLogicalLog(long version)
|
ReadableByteChannel |
getLogicalLog(long version,
long position)
|
long |
getLogicalLogLength(long version)
|
ReadableByteChannel |
getLogicalLogOrMyselfCommitted(long version,
long position)
|
long |
getLogicalLogTargetSize()
|
Pair<Integer,Long> |
getMasterForCommittedTransaction(long txId)
|
ReadableByteChannel |
getPreparedTransaction(int identifier)
|
void |
getPreparedTransaction(int identifier,
LogBuffer targetBuffer)
|
boolean |
hasLogicalLog(long version)
|
boolean |
isLogsAutoRotated()
|
boolean |
isLogsKept()
|
void |
prepare(int identifier)
|
long |
rotate()
Rotates this logical log. |
boolean |
scanIsComplete()
|
void |
setAutoRotateLogs(boolean autoRotate)
|
void |
setKeepLogs(boolean keep)
|
void |
setLogicalLogTargetSize(long size)
|
int |
start(Xid xid,
int masterId,
int myId)
|
boolean |
wasNonClean()
|
void |
writeCommand(XaCommand command,
int identifier)
|
void |
writeStartEntry(int identifier)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MASTER_ID_REPRESENTING_NO_MASTER
public static final int MASTER_ID_REPRESENTING_NO_MASTER
- See Also:
- Constant Field Values
scanIsComplete
public boolean scanIsComplete()
start
public int start(Xid xid,
int masterId,
int myId)
throws XAException
- Throws:
XAException
writeStartEntry
public void writeStartEntry(int identifier)
throws XAException
- Throws:
XAException
prepare
public void prepare(int identifier)
throws XAException
- Throws:
XAException
commitOnePhase
public void commitOnePhase(int identifier,
long txId)
throws XAException
- Throws:
XAException
done
public void done(int identifier)
throws XAException
- Throws:
XAException
commitTwoPhase
public void commitTwoPhase(int identifier,
long txId)
throws XAException
- Throws:
XAException
writeCommand
public void writeCommand(XaCommand command,
int identifier)
throws IOException
- Throws:
IOException
close
public void close()
throws IOException
- Throws:
IOException
getCurrentTxIdentifier
public int getCurrentTxIdentifier()
- If the current thread is committing a transaction the identifier of that
XaTransaction
can be obtained invoking this method.
- Returns:
- the identifier of the transaction committing or
-1
if current thread isn't committing any transaction
getLogicalLog
public ReadableByteChannel getLogicalLog(long version)
throws IOException
- Throws:
IOException
getLogicalLog
public ReadableByteChannel getLogicalLog(long version,
long position)
throws IOException
- Throws:
IOException
getPreparedTransaction
public ReadableByteChannel getPreparedTransaction(int identifier)
throws IOException
- Throws:
IOException
getPreparedTransaction
public void getPreparedTransaction(int identifier,
LogBuffer targetBuffer)
throws IOException
- Throws:
IOException
getLogExtractor
public LogExtractor getLogExtractor(long startTxId,
long endTxIdHint)
throws IOException
- Throws:
IOException
getMasterForCommittedTransaction
public Pair<Integer,Long> getMasterForCommittedTransaction(long txId)
throws IOException
- Throws:
IOException
getLogicalLogOrMyselfCommitted
public ReadableByteChannel getLogicalLogOrMyselfCommitted(long version,
long position)
throws IOException
- Specified by:
getLogicalLogOrMyselfCommitted
in interface LogExtractor.LogLoader
- Throws:
IOException
getLogicalLogLength
public long getLogicalLogLength(long version)
hasLogicalLog
public boolean hasLogicalLog(long version)
deleteLogicalLog
public boolean deleteLogicalLog(long version)
getLogDeserializer
protected XaLogicalLog.LogDeserializer getLogDeserializer(ReadableByteChannel byteChannel)
applyTransactionWithoutTxId
public void applyTransactionWithoutTxId(ReadableByteChannel byteChannel,
long nextTxId)
throws IOException
- Throws:
IOException
applyTransaction
public void applyTransaction(ReadableByteChannel byteChannel)
throws IOException
- Throws:
IOException
rotate
public long rotate()
throws IOException
- Rotates this logical log. The pending transactions are moved over to a
new log buffer and the internal structures updated to reflect the new
file offsets. The old log is either renamed or thrown away, depending on
the value of the last call to
setKeepLogs(boolean)
. Additional
side effects include a force() of the store and increment of the log
version.
Outline of how rotation happens:
- The store is flushed - can't have pending changes if there is no log
that contains the commands
- Switch current filename with old and check that new doesn't exist and
the versioned backup isn't there also
- Force the current log buffer
- Create new log file, write header
- Find the position for the first pending transaction. From there start
scanning, transferring the entries of the pending transactions from the
old log to the new, updating the start positions in the in-memory tables
- Keep or delete old log
- Update the log version stored
- Instantiate the new log buffer
- Returns:
- the last tx in the produced log
- Throws:
IOException
- I/O error.
setKeepLogs
public void setKeepLogs(boolean keep)
isLogsKept
public boolean isLogsKept()
setAutoRotateLogs
public void setAutoRotateLogs(boolean autoRotate)
isLogsAutoRotated
public boolean isLogsAutoRotated()
setLogicalLogTargetSize
public void setLogicalLogTargetSize(long size)
getLogicalLogTargetSize
public long getLogicalLogTargetSize()
getFileName
public String getFileName(long version)
getBaseFileName
public String getBaseFileName()
getHistoryFileNamePattern
public Pattern getHistoryFileNamePattern()
getHistoryFileNamePattern
public static Pattern getHistoryFileNamePattern(String baseFileName)
getHistoryLogVersion
public static long getHistoryLogVersion(File historyLogFile)
getHighestHistoryLogVersion
public static long getHighestHistoryLogVersion(File storeDir,
String baseFileName)
wasNonClean
public boolean wasNonClean()
getHighestLogVersion
public long getHighestLogVersion()
- Specified by:
getHighestLogVersion
in interface LogExtractor.LogLoader
Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.