com.sleepycat.je.rep.txn
Class ReplayTxn

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

public final class ReplayTxn
extends Txn

Used for replaying replicated operations at replica nodes.


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
ReplayTxn(EnvironmentImpl envImpl, TransactionConfig config, long txnId, Logger logger)
          Used when creating ReplayTxns at recovery.
ReplayTxn(EnvironmentImpl envImpl, TransactionConfig config, long txnId, Map<Long,ReplayTxn> activeTxns, Logger logger)
          Used when creating ReplayTxns for Replay.
 
Method Summary
 void abort()
          Abort this transaction.
 long abort(boolean forceFlush)
          Abort this transaction.
 long abort(ReplicationContext clientRepContext, int abortMasterNodeId)
           
 void cleanup()
          Invoked when a ReplayTxn is being abandoned on shutdown.
protected  void close(boolean isCommit)
          Unregister this txn.
 long commit()
          Call commit() with the default sync configuration property.
 long commit(Durability.SyncPolicy syncPolicy, ReplicationContext clientRepContext, int commitMasterNodeId)
          Commits the txn being replayed.
 long commit(Durability durability)
          Commit this transaction; it involves the following logical steps: 1.
 long elapsedTime()
          Returns the elapsed time associated with this transaction.
protected  long generateId(TxnManager txnManager, long mandatedId)
          Replay transactions always use the txn id that is included in its replicated operation.
protected  long getInitialLockTimeout()
          Don't let the ReplayTxn have a timeout of 0.
 boolean getRepGroupDbChange()
           
protected  int getReplicatorNodeId()
           
 boolean isReplicationDefined()
          Used for debugging checks to ensure that replication-defined lockers are used for accessing replicated databases.
 void noteRepGroupDbChange()
           
 void registerWithActiveTxns(Map<Long,ReplayTxn> newActiveTxns)
           
 Collection<Long> rollback(long matchpointLsn)
          Rollback all write operations that are logged with an LSN > the matchpointLsn parameter.
 void setLastAppliedVLSN(VLSN justApplied)
           
 void setRepContext(ReplicationContext repContext)
          ReplicatedTxns set it when the txn commit or abort arrives.
 String toString()
           
 
Methods inherited from class com.sleepycat.je.txn.Txn
abort, addLock, addLogInfo, checkState, cleanupDatabaseImpls, clearWriteLocks, collectStats, commit, createdNode, createLocalAutoTxn, createLocalTxn, dumpLog, getAbortLsn, getCommitDurability, getCommitToken, 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, postLogAbortHook, postLogCommitHook, preLogCommitHook, prepare, propagatePostCommitException, readFromLog, registerCursor, releaseNonTxnLocks, releaseWriteLocks, setDeletedDatabaseState, setHandleLockOwner, setImportunate, setOnlyAbortable, setPrepared, setRollback, setSuspended, txnBeginHook, undo, unRegisterCursor, updateLoggedForTxn, writeToLog
 
Methods inherited from class com.sleepycat.je.txn.Locker
addDeleteInfo, addToHandleMaps, demoteLock, dumpLockTable, getDefaultNoWait, getId, getLockTimeout, getPreemptable, getTxnTimeout, isReadUncommittedDefault, isTimedOut, lock, nonBlockingLock, openCursorHook, operationEnd, operationEnd, releaseLock, setClosingLocker, setLockTimeout, setPreemptable, setPreempted, setTxnTimeout, sharesLocksWith, transferHandleLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReplayTxn

public ReplayTxn(EnvironmentImpl envImpl,
                 TransactionConfig config,
                 long txnId,
                 Map<Long,ReplayTxn> activeTxns,
                 Logger logger)
          throws DatabaseException
Used when creating ReplayTxns for Replay. The ReplayTxn adds itself to the activeTxns map.

Throws:
DatabaseException

ReplayTxn

public ReplayTxn(EnvironmentImpl envImpl,
                 TransactionConfig config,
                 long txnId,
                 Logger logger)
          throws DatabaseException
Used when creating ReplayTxns at recovery. No ActiveTxns map is available.

Throws:
DatabaseException
Method Detail

getInitialLockTimeout

protected long getInitialLockTimeout()
Don't let the ReplayTxn have a timeout of 0. If it did, it could be deadlocked against a reader txn. As long as there is a non zero timeout, any conflicts will be adjugated by the LockManager in its favor.

Overrides:
getInitialLockTimeout in class Locker

getRepGroupDbChange

public boolean getRepGroupDbChange()

noteRepGroupDbChange

public void noteRepGroupDbChange()

registerWithActiveTxns

public void registerWithActiveTxns(Map<Long,ReplayTxn> newActiveTxns)

generateId

protected long generateId(TxnManager txnManager,
                          long mandatedId)
Replay transactions always use the txn id that is included in its replicated operation.

Overrides:
generateId in class Txn

getReplicatorNodeId

protected int getReplicatorNodeId()
Overrides:
getReplicatorNodeId in class Txn

commit

public long commit(Durability.SyncPolicy syncPolicy,
                   ReplicationContext clientRepContext,
                   int commitMasterNodeId)
            throws DatabaseException
Commits the txn being replayed.

Parameters:
syncPolicy - to be used for the commit.
clientRepContext - the replication context it encapsulates the VLSN associated with the txn.
Returns:
the commit LSN
Throws:
DatabaseException

commit

public long commit()
Description copied from class: Txn
Call commit() with the default sync configuration property.

Overrides:
commit in class Txn

commit

public long commit(Durability durability)
Description copied from class: Txn
Commit this transaction; it involves the following logical steps: 1. Run pre-commit hook. 2. Release read locks. 3. Log a txn commit record and flush the log as indicated by the durability policy. 4. Run the post-commit hook. 5. Add deleted LN info to IN compressor queue. 6. Release all write locks If this transaction has not made any changes to the database, that is, it is a read-only transaction, no entry is made to the log. Otherwise, a concerted effort is made to log a commit entry, or an abort entry, but NOT both. If exceptions are encountered and neither entry can be logged, a EnvironmentFailureException is thrown. Error conditions (in contrast to Exceptions) always result in the environment being invalidated and the Error being propagated back to the application. From an exception handling viewpoint the commit goes through two stages: a pre-commit stage spanning steps 1-3, and a post-commit stage spanning steps 4-5 The post-commit stage is entered only after a commit entry has been successfully logged. Any exceptions detected during the pre-commit stage results in an attempt to log an abort entry. A NULL commitLsn (and abortLsn) indicates that we are in the pre-commit stage. Note in particular, that if the log of the commit entry (step 3) fails due to an IOException, then the lower levels are responsible for wrapping it in a EnvironmentFailureException which is propagated directly to the application. Exceptions thrown in the post-commit stage are examined to see if they are expected and must be propagated back to the caller after completing any pending cleanup; some replication exceptions fall into this category. If the exception was unexpected, the environment is invalidated and a EnvironmentFailureException is thrown instead. The current implementation only allows propagation of exceptions from the post-commit hook, since we do not expect exceptions from any of the other post-commit operations. When there are multiple failures in commit(), we want the caller to receive the first exception, to make the problem manifest. So an effort is made to preserve that primary exception and propagate it instead of any following, secondary exceptions. The secondary exception is always logged in such a circumstance.

Overrides:
commit in class Txn

abort

public void abort()
Description copied from class: Txn
Abort this transaction. This flavor does not return an LSN, nor does it require the logging of a durable abort record.

Overrides:
abort in class Txn

abort

public long abort(boolean forceFlush)
Description copied from class: Txn
Abort this transaction. Steps are: 1. Release LN read locks. 2. Write a txn abort entry to the log. This is used for log file cleaning optimization and replication, and there's no need to guarantee a flush to disk. 3. Find the last LN log entry written for this txn, and use that to traverse the log looking for nodes to undo. For each node, use the same undo logic as recovery to undo the transaction. Note that we walk the log in order to undo in reverse order of the actual operations. For example, suppose the txn did this: delete K1/D1 (in LN 10) create K1/D1 (in LN 20) If we process LN10 before LN 20, we'd inadvertently create a duplicate tree of "K1", which would be fatal for the mapping tree. 4. Release the write lock for this LN. An abort differs from a rollback in that the former always undoes every operation, and returns it to the pre-txn state. A rollback may return the txn to an intermediate state, or to the pre-txn state.

Overrides:
abort in class Txn

abort

public long abort(ReplicationContext clientRepContext,
                  int abortMasterNodeId)
           throws DatabaseException
Throws:
DatabaseException

close

protected void close(boolean isCommit)
              throws DatabaseException
Description copied from class: Txn
Unregister this txn.

Overrides:
close in class Txn
Throws:
DatabaseException

cleanup

public void cleanup()
             throws DatabaseException
Invoked when a ReplayTxn is being abandoned on shutdown.

Throws:
DatabaseException

rollback

public Collection<Long> rollback(long matchpointLsn)
                          throws DatabaseException
Rollback all write operations that are logged with an LSN > the matchpointLsn parameter. This is logically a truncation of the log entries written by this transaction. Any log entries created by this transaction are marked obsolete. Note that this is by no means a complete implementation of what would be needed to support user visible savepoints. This method only rolls back write operations and doesn't handle other types of state, like read locks and open cursors. There are several key assumptions: - the transaction does not hold read locks. - the transaction will either be resumed, and any rolled back operations will be repeated, or the transaction will be aborted in its entirety. If all operations in the transaction are rolled back, this transaction is also unregistered and closed. Rolling back a log entry through rollback is akin to truncating the transactional log. The on-disk entries should not be referred to by anything in the in-memory tree or the transaction chain. JE's append only storage and the fact that the transactional log entries are intertwined through the physical log prohibits any log truncation. To mimic log truncation, any rolled back log entry is marked as obsolete. Since only the last version of any data record is alive, any future uses of this transaction must use the obsoleteDupsAllowed option (see Txn.countObsoleteExact) to prevent asserts about duplicate obsolete offsets. For example, suppose the transaction logs this: 100 LNa (version1) 200 LNa (version2) 300 LNa (version3) At this point in time, LSN 100 and 200 are obsolete. Now, suppose we roll back to LSN 100. LSNs 200 and 300 are marked obsolete by the rollback.(although LSN 200 was already obsolete). It is true that for an instance in time LSN 100 is incorrectly marked as obsolete, when it's really alive. But this transaction is going to either abort or resume exactly as it was before, so LSN 100 is going to be obsolete again. Suppose txn.abort() is called. The abort() logic will mark LSN 100 as obsolete, since it is the latest version of the record in the transaction. Using the obsoleteDupsAllowed option avoids an assertion on the double recording of LSN 100. Alternatively, suppose LNa (version2) is retransmitted and logged as LSN 400. Normal execution of LN.log() marks LSN 100 as obsolete, which would trigger the assertion were it not for obsoleteDupsAllowed.

Returns:
list of LSNs that were rolled back
Throws:
DatabaseException

elapsedTime

public long elapsedTime()
Returns the elapsed time associated with this transaction. If the transaction is in progress, it returns the running elapsed time.

Returns:
the elapsed time as above.

setLastAppliedVLSN

public void setLastAppliedVLSN(VLSN justApplied)

setRepContext

public void setRepContext(ReplicationContext repContext)
ReplicatedTxns set it when the txn commit or abort arrives.


toString

public String toString()
Overrides:
toString in class Locker

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.