com.sleepycat.je.rep.txn
Class MasterTxn

java.lang.Object
  extended by com.sleepycat.je.txn.Locker
      extended by com.sleepycat.je.txn.Txn
          extended by com.sleepycat.je.rep.txn.MasterTxn
All Implemented Interfaces:
Loggable

public class MasterTxn
extends Txn

A MasterTxn represents a user initiated Txn executed on the Master node. This class uses the hooks defined by Txn to support the durability requirements of a replicated transaction on the Master.


Nested Class Summary
static interface MasterTxn.MasterTxnFactory
           
 
Field Summary
 
Fields inherited from class com.sleepycat.je.txn.Txn
ACCUMULATED_LIMIT, commitLsn, deletedDatabases, firstLoggedLsn, lastLoggedLsn, repContext, undoDatabases
 
Fields inherited from class com.sleepycat.je.txn.Locker
defaultNoWait, deleteInfo, envImpl, handleLockToHandleMap, handleToHandleLockMap, id, lockManager, readUncommittedDefault, thread
 
Constructor Summary
MasterTxn(EnvironmentImpl envImpl, TransactionConfig config, NameIdPair nameIdPair)
           
 
Method Summary
static MasterTxn create(EnvironmentImpl envImpl, TransactionConfig config, NameIdPair nameIdPair)
           
protected  long generateId(TxnManager txnManager, long ignore)
          MasterTxns use txn ids from a reserved negative space.
 CommitToken getCommitToken()
          Returns the transaction commit token used to identify the transaction.
 VLSN getCommitVLSN()
           
 int getCurrentRequiredAckCount()
           
protected  int getReplicatorNodeId()
          A masterTxn always writes its own id into the commit or abort.
 int getRequiredAckCount()
           
 long getStartMs()
           
 boolean isReplicationDefined()
          Used for debugging checks to ensure that replication-defined lockers are used for accessing replicated databases.
 long messageTransferMs()
          Returns the amount of time it took to copy the commit record from the log buffer to the rep stream.
protected  void postLogAbortHook()
          Invoked if the transaction associated with the preLogCommitHook was subsequently aborted, for example due to a lack of disk space.
protected  void postLogCommitHook(LogItem commitItem)
          This hook is invoked after the commit record has been written to the log, but before write locks have been released, so that other application cannot see the changes made by the transaction.
protected  void preLogCommitHook()
          This hook is invoked before the commit of a transaction that made changes to a replicated environment.
protected  boolean propagatePostCommitException(DatabaseException postCommitException)
          Identifies exceptions that may be propagated back to the caller during the postCommit phase of a transaction commit.
 void resetRequiredAckCount()
           
static void setFactory(MasterTxn.MasterTxnFactory factory)
          Method used for unit testing.
 void stampRepWriteTime()
           
protected  void txnBeginHook(TransactionConfig config)
          Causes the transaction to wait until we have sufficient replicas to acknowledge the commit.
 
Methods inherited from class com.sleepycat.je.txn.Txn
abort, abort, abort, addLock, addLogInfo, checkState, cleanupDatabaseImpls, clearWriteLocks, close, collectStats, commit, commit, commit, createdNode, createLocalAutoTxn, createLocalTxn, dumpLog, getAbortLsn, getCommitDurability, getDefaultDurability, getExplicitDurabilityConfigured, getExplicitSyncConfigured, getFirstActiveLsn, getImportunate, getLastLsn, getLogSize, getPrepared, getReadLockIds, getTransactionId, getTxnLocker, getWriteLockIds, getWriteLockInfo, isAutoTxn, isClosed, isHandleLockTransferrable, isOnlyAbortable, isReadCommittedIsolation, isRolledBack, isSerializableIsolation, isSuspended, isTransactional, isValid, lockingRequired, lockInternal, logicalEquals, markDeleteAtTxnEnd, newNonTxnLocker, nonTxnOperationEnd, operationEnd, prepare, readFromLog, registerCursor, releaseNonTxnLocks, releaseWriteLocks, setDeletedDatabaseState, setHandleLockOwner, setImportunate, setOnlyAbortable, setPrepared, setRollback, setSuspended, undo, unRegisterCursor, updateLoggedForTxn, writeToLog
 
Methods inherited from class com.sleepycat.je.txn.Locker
addDeleteInfo, addToHandleMaps, demoteLock, dumpLockTable, getDefaultNoWait, getId, getInitialLockTimeout, getLockTimeout, getPreemptable, getTxnTimeout, isReadUncommittedDefault, isTimedOut, lock, nonBlockingLock, openCursorHook, operationEnd, operationEnd, releaseLock, setClosingLocker, setLockTimeout, setPreemptable, setPreempted, setTxnTimeout, sharesLocksWith, toString, transferHandleLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MasterTxn

public MasterTxn(EnvironmentImpl envImpl,
                 TransactionConfig config,
                 NameIdPair nameIdPair)
          throws DatabaseException
Throws:
DatabaseException
Method Detail

getCommitToken

public CommitToken getCommitToken()
Returns the transaction commit token used to identify the transaction.

Overrides:
getCommitToken in class Txn
See Also:
Txn.getCommitToken()

getCommitVLSN

public VLSN getCommitVLSN()

generateId

protected long generateId(TxnManager txnManager,
                          long ignore)
MasterTxns use txn ids from a reserved negative space. So override the default generation of ids.

Overrides:
generateId in class Txn

txnBeginHook

protected void txnBeginHook(TransactionConfig config)
                     throws DatabaseException
Causes the transaction to wait until we have sufficient replicas to acknowledge the commit.

Overrides:
txnBeginHook in class Txn
Parameters:
config - the transaction config that applies to the txn
Throws:
DatabaseException - if there is a failure

preLogCommitHook

protected void preLogCommitHook()
                         throws DatabaseException
Description copied from class: Txn
This hook is invoked before the commit of a transaction that made changes to a replicated environment. It's invoked for transactions executed on the master or replica, but is only relevant to transactions being done on the master. When invoked for a transaction on a replica the implementation just returns. The hook is invoked at a very specific point in the normal commit sequence: immediately before the commit log entry is written to the log. It represents the last chance to abort the transaction and provides an opportunity to make some final checks before allowing the commit can go ahead. Note that it should be possible to abort the transaction at the time the hook is invoked. After invocation of the "pre" hook one of the "post" hooks: postLogCommitHook or postLogAbortHook must always be invoked. Exceptions thrown by this hook result in the transaction being aborted and the exception being propagated back to the application.

Overrides:
preLogCommitHook in class Txn
Throws:
DatabaseException - if there was a problem and that the transaction should be aborted.

postLogCommitHook

protected void postLogCommitHook(LogItem commitItem)
                          throws DatabaseException
Description copied from class: Txn
This hook is invoked after the commit record has been written to the log, but before write locks have been released, so that other application cannot see the changes made by the transaction. At this point the transaction has been committed by the Master. Exceptions thrown by this hook result in the transaction being completed on the Master, that is, locks are released, etc. and the exception is propagated back to the application.

Overrides:
postLogCommitHook in class Txn
Parameters:
commitItem - the commit item that was just logged
Throws:
DatabaseException - to indicate that there was a replication related problem that needs to be communicated back to the application.

postLogAbortHook

protected void postLogAbortHook()
Description copied from class: Txn
Invoked if the transaction associated with the preLogCommitHook was subsequently aborted, for example due to a lack of disk space. This method is responsible for any cleanup that may need to be done as a result of the abort. Note that only one of the "post" hooks (commit or abort) is invoked following the invocation of the "pre" hook.

Overrides:
postLogAbortHook in class Txn

getRequiredAckCount

public int getRequiredAckCount()

getCurrentRequiredAckCount

public int getCurrentRequiredAckCount()

resetRequiredAckCount

public void resetRequiredAckCount()

getReplicatorNodeId

protected int getReplicatorNodeId()
A masterTxn always writes its own id into the commit or abort.

Overrides:
getReplicatorNodeId in class Txn

getStartMs

public long getStartMs()

stampRepWriteTime

public void stampRepWriteTime()

messageTransferMs

public long messageTransferMs()
Returns the amount of time it took to copy the commit record from the log buffer to the rep stream. It's measured as the time interval starting with the time the preCommit hook completed, to the time the message write to the replication stream was initiated.


propagatePostCommitException

protected boolean propagatePostCommitException(DatabaseException postCommitException)
Description copied from class: Txn
Identifies exceptions that may be propagated back to the caller during the postCommit phase of a transaction commit.

Overrides:
propagatePostCommitException in class Txn
Parameters:
postCommitException - the exception being evaluated
Returns:
true if the exception must be propagated back to the caller, false if the exception indicates there is a serious problem with the commit operation and the environment should be invalidated.

create

public static MasterTxn create(EnvironmentImpl envImpl,
                               TransactionConfig config,
                               NameIdPair nameIdPair)

setFactory

public static void setFactory(MasterTxn.MasterTxnFactory factory)
Method used for unit testing. Sets the factory to the one supplied. If the argument is null it restores the factory to the original default value.


isReplicationDefined

public boolean isReplicationDefined()
Description copied from class: Locker
Used for debugging checks to ensure that replication-defined lockers are used for accessing replicated databases. Overridden by replicated-defined lockers to return true.

Overrides:
isReplicationDefined in class Locker


Copyright (c) 2004-2010 Oracle. All rights reserved.