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, openedDatabaseHandles, repContext, undoDatabases
 
Fields inherited from class com.sleepycat.je.txn.Locker
defaultNoWait, deleteInfo, envImpl, 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.
 boolean lockOnce()
          Determines whether we should lock the block-latch lock.
 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()
           
protected  void postLogCommitAbortHook()
          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 preLogAbortHook()
           
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.
 boolean unlockOnce()
          Determines whether we should unlock the block-latch lock.
 
Methods inherited from class com.sleepycat.je.txn.Txn
abort, abort, abort, addLock, addLogInfo, addOpenedDatabase, checkPreempted, checkState, cleanupDatabaseImpls, clearWriteLocks, close, collectStats, commit, commit, commit, createdNode, createLocalAutoTxn, createLocalTxn, dumpLog, getCommitDurability, getDefaultDurability, getEnvironmentImpl, getExplicitDurabilityConfigured, getExplicitSyncConfigured, getFirstActiveLsn, getImportunate, getLastLsn, getLogSize, getPrepared, getReadLockIds, getState, getTransaction, getTransactionId, getTriggerDbs, getTxnLocker, getWriteLockIds, getWriteLockInfo, isAutoTxn, isClosed, isOnlyAbortable, isReadCommittedIsolation, isRolledBack, isSerializableIsolation, isSuspended, isTransactional, isValid, lockingRequired, lockInternal, logicalEquals, markDeleteAtTxnEnd, newNonTxnLocker, nonTxnOperationEnd, noteTriggerDb, operationEnd, preLogWithoutLock, prepare, readFromLog, registerCursor, releaseNonTxnLocks, releaseWriteLocks, setDeletedDatabaseState, setImportunate, setOnlyAbortable, setPrepared, setRollback, setSuspended, setTransaction, undo, unRegisterCursor, updateLoggedForTxn, writeToLog
 
Methods inherited from class com.sleepycat.je.txn.Locker
addDeleteInfo, allowReleaseLockAfterLsnChange, demoteLock, disallowReplicaWrite, dumpLockTable, getDefaultNoWait, getEnvironment, getId, getInitialLockTimeout, getLockTimeout, getPreemptable, getTxnTimeout, isReadUncommittedDefault, isTimedOut, lock, lockAfterLsnChange, nonBlockingLock, openCursorHook, operationEnd, operationEnd, releaseLock, setClosingLocker, setLockTimeout, setPreemptable, setPreempted, setTxnTimeout, sharesLocksWith, toString
 
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.

preLogAbortHook

protected void preLogAbortHook()
                        throws DatabaseException
Overrides:
preLogAbortHook in class Txn
Throws:
DatabaseException

postLogCommitAbortHook

protected void postLogCommitAbortHook()
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:
postLogCommitAbortHook in class Txn

postLogAbortHook

protected void postLogAbortHook()
Overrides:
postLogAbortHook in class Txn

lockOnce

public boolean lockOnce()
Determines whether we should lock the block-latch lock.

We acquire the lock during pre-log hook, and release it during post-log hook. Specifically, there are the following cases:

  1. For a normal commit, we acquire it in preLogCommitHook() and release it in postLogCommitHook()
  2. For a normal abort (invoked by the application on the Txn.abort() API), we acquire the lock in preLogAbortHook() and release it in postLogAbortHook().
  3. When a commit fails in such a way as to call Txn.throwPreCommitException(), we go through the abort path as well. In this case:
    • we will of course already have called preLogCommitHook();
    • the abort path calls preLogAbortHook() and postLogAbortHook() as always;
    • finally we call postLogCommitAbortHook()
    Fortunately we can avoid the complexity of dealing with a second (recursive) lock acquisition here, because by the time either post-hook is called we've done any writing of VLSNs. Thus, when we want to take the lock, we take it if it hasn't already been taken, and do nothing if it has; when releasing, we release it if we have it, and do nothing if we don't.

See additional javadoc at RepImpl.blockLatchLock


unlockOnce

public boolean unlockOnce()
Determines whether we should unlock the block-latch lock.

See Also:
lockOnce()

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-2012 Oracle. All rights reserved.