com.sleepycat.je.txn
Class Txn

java.lang.Object
  extended by com.sleepycat.je.txn.Locker
      extended by com.sleepycat.je.txn.Txn
All Implemented Interfaces:
Loggable
Direct Known Subclasses:
MasterTxn, PreparedTxn, ReadonlyTxn, ReplayTxn

public class Txn
extends Locker
implements Loggable

A Txn is the internal representation of a transaction created by a call to Environment.txnBegin. This class must support multi-threaded use.


Field Summary
(package private)  long abortLsn
           
static int ACCUMULATED_LIMIT
           
protected  long commitLsn
           
protected  Set<com.sleepycat.je.txn.Txn.DatabaseCleanupInfo> deletedDatabases
           
protected  long firstLoggedLsn
           
protected  long lastLoggedLsn
           
protected  Set<Database> openedDatabaseHandles
           
protected  ReplicationContext repContext
           
protected  Map<DatabaseId,DatabaseImpl> undoDatabases
           
 
Fields inherited from class com.sleepycat.je.txn.Locker
defaultNoWait, deleteInfo, envImpl, id, lockManager, readUncommittedDefault, thread
 
Constructor Summary
  Txn()
          Constructor for reading from log.
protected Txn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext)
           
protected Txn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext, long mandatedId)
          A non-zero mandatedId is specified only by subtypes which arbitrarily impose a transaction id value onto the transaction.
 
Method Summary
 void abort()
          Abort this transaction.
 long abort(boolean forceFlush)
          Abort this transaction.
 void abort(Xid xid)
           
(package private)  void addBuddy(BuddyLocker buddy)
          By default the set of buddy lockers is not maintained.
protected  void addLock(Long lsn, LockType type, LockGrantType grantStatus)
          Add lock to the appropriate queue.
 void addLogInfo(long lastLsn)
          Called by the recovery manager when logging a transaction aware object.
 void addOpenedDatabase(Database dbHandle)
          Called at the end of a database open operation to add the database handle to a user txn.
 void checkPreempted(Locker allowPreemptedLocker)
          Checks for preemption in this locker and all its child buddies.
 void checkState(boolean calledByAbort)
          Throw an exception if the transaction is not open.
protected  void cleanupDatabaseImpls(boolean isCommit)
          Cleanup leftover databaseImpls that are a by-product of database operations like removeDatabase(), truncateDatabase().
protected  void clearWriteLocks(Set<Long> retainedNodes)
          Release any write locks that are not in the retainedNodes set.
protected  void close(boolean isCommit)
          Close and unregister this txn.
 StatGroup collectStats()
          stats
 long commit()
          Call commit() with the default sync configuration property.
 long commit(Durability durability)
          Commit this transaction; it involves the following logical steps: 1.
 void commit(Xid xid)
           
(package private) static Txn createAutoTxn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext)
           
 boolean createdNode(long lsn)
           
static Txn createLocalAutoTxn(EnvironmentImpl envImpl, TransactionConfig config)
           
static Txn createLocalTxn(EnvironmentImpl envImpl, TransactionConfig config)
           
(package private) static Txn createUserTxn(EnvironmentImpl envImpl, TransactionConfig config)
           
 void dumpLog(StringBuilder sb, boolean verbose)
          Write the object into the string buffer for log dumping.
protected  long generateId(TxnManager txnManager, long ignore)
          UserTxns get a new unique id for each instance.
(package private)  int getBudgetedMemorySize()
          Returns the amount of memory currently budgeted for this transaction.
 Durability getCommitDurability()
          Returns the durability used for the commit operation.
 CommitToken getCommitToken()
          Returns the CommitToken associated with a successful replicated commit.
 Durability getDefaultDurability()
          Returns the durability associated the transaction at the time it's first created.
 EnvironmentImpl getEnvironmentImpl()
           
 boolean getExplicitDurabilityConfigured()
           
 boolean getExplicitSyncConfigured()
           
 long getFirstActiveLsn()
          [#16861] The firstLoggedLsn field is volatile to avoid making getFirstActiveLsn synchronized, which causes a deadlock in HA.
 boolean getImportunate()
          Get the state of a transaction's IMPORTUNATE bit.
 long getLastLsn()
          Access to last LSN.
 int getLogSize()
           
 boolean getPrepared()
           
 Set<Long> getReadLockIds()
           
protected  int getReplicatorNodeId()
           
 Transaction.State getState()
           
 Transaction getTransaction()
          Returns a Transaction is the locker is transctional, or null otherwise.
 long getTransactionId()
           
 Set<DatabaseImpl> getTriggerDbs()
          Returns the set of databases for which transaction commit/abort triggers must be run.
 Txn getTxnLocker()
          This is a transactional locker.
 Set<Long> getWriteLockIds()
           
 WriteLockInfo getWriteLockInfo(long lsn)
           
 boolean isAutoTxn()
          Determines whether this is an auto transaction.
 boolean isClosed()
           
 boolean isOnlyAbortable()
           
 boolean isReadCommittedIsolation()
          Is read-committed isolation if so configured.
 boolean isRolledBack()
           
 boolean isSerializableIsolation()
          Is serializable isolation if so configured.
 boolean isSuspended()
           
 boolean isTransactional()
          Is always transactional.
 boolean isValid()
          Used to determine whether the locker is usable.
 boolean lockingRequired()
          Returns true if locking is required for this Locker.
protected  LockResult lockInternal(long lsn, LockType lockType, boolean noWait, boolean jumpAheadOfWaiters, DatabaseImpl database)
          Gets a lock on this LSN and, if it is a write lock, saves an abort LSN.
 boolean logicalEquals(Loggable other)
           
 void markDeleteAtTxnEnd(DatabaseImpl dbImpl, boolean deleteAtCommit)
          Database operations like remove and truncate leave behind residual DatabaseImpls that must be purged at transaction commit or abort.
(package private)  void moveWriteToReadLock(long lsn, Lock lock)
          A lock is being demoted.
 Locker newNonTxnLocker()
          Returns 'this', since this locker holds no non-transactional locks.
 void nonTxnOperationEnd()
          Created transactions do nothing at the end of the operation.
 void noteTriggerDb(DatabaseImpl dbImpl)
          Accumulates the set of databases for which transaction commit/abort triggers must be run.
 void operationEnd(boolean operationOK)
          Different types of transactions do different things when the operation ends.
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.
 void preLogWithoutLock(DatabaseImpl database)
          If logging succeeds but locking fails, we need the database for undo.
 int prepare(Xid xid)
           
protected  boolean propagatePostCommitException(DatabaseException postCommitException)
          Identifies exceptions that may be propagated back to the caller during the postCommit phase of a transaction commit.
 void readFromLog(ByteBuffer logBuffer, int entryVersion)
          Initialize this object from the data in itemBuf.
 void registerCursor(CursorImpl cursor)
          Increase the counter if a new Cursor is opened under this transaction.
 void releaseNonTxnLocks()
          This locker holds no non-transactional locks.
protected  void releaseWriteLocks()
          Releases all write locks, nulls the lock collection.
(package private)  void removeBuddy(BuddyLocker buddy)
          By default the set of buddy lockers is not maintained.
(package private)  void removeLock(long lsn)
          Remove the lock from the set owned by this transaction.
protected  void setDeletedDatabaseState(boolean isCommit)
           
 void setImportunate(boolean importunate)
          Set the state of a transaction's IMPORTUNATE bit.
 void setOnlyAbortable(OperationFailureException cause)
          Set the state of a transaction to abort-only.
 void setPrepared(boolean prepared)
           
protected  void setRollback()
           
 void setSuspended(boolean suspended)
           
 void setTransaction(Transaction transaction)
           
protected  void txnBeginHook(TransactionConfig config)
          A replicated environment introduces some new considerations when entering a transaction scope via an Environment.transactionBegin() operation.
protected  void undo()
          Undo write operations and release all resources held by the transaction.
 void unRegisterCursor(CursorImpl cursor)
          Decrease the counter if a Cursor is closed under this transaction.
protected  boolean updateLoggedForTxn()
           
 void writeToLog(ByteBuffer logBuffer)
          Serialize this object into the buffer.
 
Methods inherited from class com.sleepycat.je.txn.Locker
addDeleteInfo, allowReleaseLockAfterLsnChange, close, demoteLock, disallowReplicaWrite, dumpLockTable, getDefaultNoWait, getEnvironment, getId, getInitialLockTimeout, getLockTimeout, getPreemptable, getTxnStartMillis, getTxnTimeout, getWaitingFor, isPreempted, isReadUncommittedDefault, isReplicationDefined, isTimedOut, lock, lockAfterLsnChange, nonBlockingLock, openCursorHook, operationEnd, operationEnd, releaseLock, setAllowMultithreadedAccess, setClosingLocker, setLockTimeout, setPreemptable, setPreempted, setTxnTimeout, setWaitingFor, sharesLocksWith, throwIfPreempted, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

deletedDatabases

protected Set<com.sleepycat.je.txn.Txn.DatabaseCleanupInfo> deletedDatabases

undoDatabases

protected Map<DatabaseId,DatabaseImpl> undoDatabases

openedDatabaseHandles

protected Set<Database> openedDatabaseHandles
See Also:
addOpenedDatabase(com.sleepycat.je.Database), HandleLocker

firstLoggedLsn

protected volatile long firstLoggedLsn

lastLoggedLsn

protected long lastLoggedLsn

commitLsn

protected long commitLsn

abortLsn

long abortLsn

ACCUMULATED_LIMIT

public static int ACCUMULATED_LIMIT

repContext

protected ReplicationContext repContext
Constructor Detail

Txn

public Txn()
Constructor for reading from log.


Txn

protected Txn(EnvironmentImpl envImpl,
              TransactionConfig config,
              ReplicationContext repContext)

Txn

protected Txn(EnvironmentImpl envImpl,
              TransactionConfig config,
              ReplicationContext repContext,
              long mandatedId)
       throws DatabaseException
A non-zero mandatedId is specified only by subtypes which arbitrarily impose a transaction id value onto the transaction. This is done by implementing a version of Locker.generateId() which uses the proposed id.

Throws:
DatabaseException
Method Detail

createLocalTxn

public static Txn createLocalTxn(EnvironmentImpl envImpl,
                                 TransactionConfig config)

createLocalAutoTxn

public static Txn createLocalAutoTxn(EnvironmentImpl envImpl,
                                     TransactionConfig config)

createUserTxn

static Txn createUserTxn(EnvironmentImpl envImpl,
                         TransactionConfig config)

createAutoTxn

static Txn createAutoTxn(EnvironmentImpl envImpl,
                         TransactionConfig config,
                         ReplicationContext repContext)
                  throws DatabaseException
Throws:
DatabaseException

addBuddy

void addBuddy(BuddyLocker buddy)
Description copied from class: Locker
By default the set of buddy lockers is not maintained. This is overridden by Txn.

Overrides:
addBuddy in class Locker

removeBuddy

void removeBuddy(BuddyLocker buddy)
Description copied from class: Locker
By default the set of buddy lockers is not maintained. This is overridden by Txn.

Overrides:
removeBuddy in class Locker

generateId

protected long generateId(TxnManager txnManager,
                          long ignore)
UserTxns get a new unique id for each instance.

Specified by:
generateId in class Locker

getLastLsn

public long getLastLsn()
Access to last LSN.


getCommitDurability

public Durability getCommitDurability()
Returns the durability used for the commit operation. It's only available after a commit operation has been initiated.

Returns:
the durability associated with the commit, or null if the commit has not yet been initiated.

getDefaultDurability

public Durability getDefaultDurability()
Returns the durability associated the transaction at the time it's first created.

Returns:
the durability associated with the transaction at creation.

getPrepared

public boolean getPrepared()

setPrepared

public void setPrepared(boolean prepared)

setSuspended

public void setSuspended(boolean suspended)

isSuspended

public boolean isSuspended()

setRollback

protected void setRollback()

isRolledBack

public boolean isRolledBack()
Overrides:
isRolledBack in class Locker
Returns:
if this transaction has ever executed a rollback. A Rollback is an undo of the transaction that can return either to the original pre-txn state, or to an intermediate intra-txn state. An abort always returns the txn to the pre-txn state.

lockInternal

protected LockResult lockInternal(long lsn,
                                  LockType lockType,
                                  boolean noWait,
                                  boolean jumpAheadOfWaiters,
                                  DatabaseImpl database)
                           throws DatabaseException
Gets a lock on this LSN and, if it is a write lock, saves an abort LSN. Caller will set the abortLsn later, after the write lock has been obtained.

Specified by:
lockInternal in class Locker
Parameters:
lsn - is the node to lock.
lockType - is the type of lock to request.
noWait - is true to override the defaultNoWait setting. If true, or if defaultNoWait is true, throws LockNotAvailableException if the lock cannot be granted without waiting.
jumpAheadOfWaiters - grant the lock before other waiters, if any.
database - is the database containing lsn.
Throws:
IllegalStateException - via API read/write methods if the txn is closed, in theory. However, this should not occur from a user API call, because the API methods first call Transaction.getLocker, which will throw IllegalStateException if the txn is closed. It might occur, however, if the transaction ends in the window between the call to getLocker and the lock attempt.
OperationFailureException - via API read/write methods if an OperationFailureException occurred earlier and set the txn to abort-only.
LockConflictException - if a blocking lock could not be acquired.
DatabaseException
See Also:
Locker.lockInternal(long, com.sleepycat.je.txn.LockType, boolean, boolean, com.sleepycat.je.dbi.DatabaseImpl)

preLogWithoutLock

public void preLogWithoutLock(DatabaseImpl database)
If logging succeeds but locking fails, we need the database for undo.

Specified by:
preLogWithoutLock in class Locker

prepare

public int prepare(Xid xid)
            throws DatabaseException
Throws:
IllegalStateException - via XAResource
DatabaseException

commit

public void commit(Xid xid)
            throws DatabaseException
Throws:
DatabaseException

abort

public void abort(Xid xid)
           throws DatabaseException
Throws:
DatabaseException

commit

public long commit()
            throws DatabaseException
Call commit() with the default sync configuration property.

Throws:
DatabaseException

commit

public long commit(Durability durability)
            throws DatabaseException
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. In addition, if the environment is made invalid in another thread, or the transaction is closed by another thread, then we propagate the exception and we do not attempt to abort. This special handling is prior to the pre-commit stage. 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.

Throws:
IllegalStateException - via Transaction.commit if cursors are open.
OperationFailureException - via Transaction.commit if an OperationFailureException occurred earlier and set the txn to abort-only. Note that IllegalStateException should never be thrown by Transaction.commit because of a closed txn, since Transaction.commit and abort set the Transaction.txn to null and disallow subsequent method calls (other than abort). So in a sense the call to checkState(true) in this method is unnecessary, although perhaps a good safeguard.
DatabaseException

releaseWriteLocks

protected void releaseWriteLocks()
                          throws DatabaseException
Releases all write locks, nulls the lock collection.

Throws:
DatabaseException

abort

public void abort()
           throws DatabaseException
Abort this transaction. This flavor does not return an LSN, nor does it require the logging of a durable abort record.

Throws:
DatabaseException

abort

public long abort(boolean forceFlush)
           throws DatabaseException
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.

Throws:
DatabaseException

undo

protected void undo()
             throws DatabaseException
Undo write operations and release all resources held by the transaction.

Throws:
DatabaseException

clearWriteLocks

protected void clearWriteLocks(Set<Long> retainedNodes)
                        throws DatabaseException
Release any write locks that are not in the retainedNodes set.

Throws:
DatabaseException

addLogInfo

public void addLogInfo(long lastLsn)
Called by the recovery manager when logging a transaction aware object. This method is synchronized by the caller, by being called within the log latch. Record the last LSN for this transaction, to create the transaction chain, and also record the LSN in the write info for abort logic.


getFirstActiveLsn

public long getFirstActiveLsn()
[#16861] The firstLoggedLsn field is volatile to avoid making getFirstActiveLsn synchronized, which causes a deadlock in HA.

Returns:
first logged LSN, to aid recovery undo

updateLoggedForTxn

protected boolean updateLoggedForTxn()
Returns:
true if this txn has logged any log entries.

markDeleteAtTxnEnd

public void markDeleteAtTxnEnd(DatabaseImpl dbImpl,
                               boolean deleteAtCommit)
Description copied from class: Locker
Database operations like remove and truncate leave behind residual DatabaseImpls that must be purged at transaction commit or abort.

Specified by:
markDeleteAtTxnEnd in class Locker
Parameters:
dbImpl - databaseImpl to remove
deleteAtCommit - true if this databaseImpl should be cleaned on commit, false if it should be cleaned on abort.

setDeletedDatabaseState

protected void setDeletedDatabaseState(boolean isCommit)

cleanupDatabaseImpls

protected void cleanupDatabaseImpls(boolean isCommit)
                             throws DatabaseException
Cleanup leftover databaseImpls that are a by-product of database operations like removeDatabase(), truncateDatabase(). This method must be called outside the synchronization on this txn, because it calls finishDeleteProcessing, which gets the TxnManager's allTxns latch. The checkpointer also gets the allTxns latch, and within that latch, needs to synchronize on individual txns, so we must avoid a latching hiearchy conflict. [#16861] FUTURE: Perhaps this special handling is no longer needed, now that firstLoggedLsn is volatile and getFirstActiveLsn is not synchronized.

Throws:
DatabaseException

addLock

protected void addLock(Long lsn,
                       LockType type,
                       LockGrantType grantStatus)
Add lock to the appropriate queue.

Specified by:
addLock in class Locker

removeLock

void removeLock(long lsn)
Remove the lock from the set owned by this transaction. If specified to LockManager.release, the lock manager will call this when its releasing a lock. Usually done because the transaction doesn't need to really keep the lock, i.e for a deleted record.

Specified by:
removeLock in class Locker

moveWriteToReadLock

void moveWriteToReadLock(long lsn,
                         Lock lock)
A lock is being demoted. Move it from the write collection into the read collection.

Specified by:
moveWriteToReadLock in class Locker

getBudgetedMemorySize

int getBudgetedMemorySize()
Returns the amount of memory currently budgeted for this transaction.


createdNode

public boolean createdNode(long lsn)
Specified by:
createdNode in class Locker
Returns:
true if this transaction created this node. We know that this is true if the node is write locked and has a null abort LSN.

getWriteLockInfo

public WriteLockInfo getWriteLockInfo(long lsn)
Specified by:
getWriteLockInfo in class Locker
Returns:
the WriteLockInfo for this node.

isTransactional

public boolean isTransactional()
Is always transactional.

Specified by:
isTransactional in class Locker

isAutoTxn

public boolean isAutoTxn()
Determines whether this is an auto transaction.


isSerializableIsolation

public boolean isSerializableIsolation()
Is serializable isolation if so configured.

Specified by:
isSerializableIsolation in class Locker

isReadCommittedIsolation

public boolean isReadCommittedIsolation()
Is read-committed isolation if so configured.

Specified by:
isReadCommittedIsolation in class Locker

getExplicitSyncConfigured

public boolean getExplicitSyncConfigured()

getExplicitDurabilityConfigured

public boolean getExplicitDurabilityConfigured()

getTxnLocker

public Txn getTxnLocker()
This is a transactional locker.

Specified by:
getTxnLocker in class Locker

newNonTxnLocker

public Locker newNonTxnLocker()
Returns 'this', since this locker holds no non-transactional locks. Since this is returned, sharing of locks is obviously supported.

Specified by:
newNonTxnLocker in class Locker

releaseNonTxnLocks

public void releaseNonTxnLocks()
This locker holds no non-transactional locks.

Specified by:
releaseNonTxnLocks in class Locker

nonTxnOperationEnd

public void nonTxnOperationEnd()
Created transactions do nothing at the end of the operation.

Specified by:
nonTxnOperationEnd in class Locker

operationEnd

public void operationEnd(boolean operationOK)
                  throws DatabaseException
Description copied from class: Locker
Different types of transactions do different things when the operation ends. Txn does nothing, auto Txn commits or aborts, and BasicLocker (and its subclasses) just releases locks.

Specified by:
operationEnd in class Locker
Parameters:
operationOK - is whether the operation succeeded, since that may impact ending behavior. (i.e for an auto Txn)
Throws:
DatabaseException

addOpenedDatabase

public void addOpenedDatabase(Database dbHandle)
Called at the end of a database open operation to add the database handle to a user txn. When a user txn aborts, handles opened using that txn are invalidated. A non-txnal locker or auto-commit txn does not retain the handle, because the open database operation will succeed or fail atomically and no database invalidation is needed at a later time.

Overrides:
addOpenedDatabase in class Locker
See Also:
HandleLocker

registerCursor

public void registerCursor(CursorImpl cursor)
Increase the counter if a new Cursor is opened under this transaction.

Specified by:
registerCursor in class Locker

unRegisterCursor

public void unRegisterCursor(CursorImpl cursor)
Decrease the counter if a Cursor is closed under this transaction.

Specified by:
unRegisterCursor in class Locker

lockingRequired

public boolean lockingRequired()
Description copied from class: Locker
Returns true if locking is required for this Locker. All Txnal lockers require it; most BasicLockers do not, but BasicLockers on internal dbs do.

Specified by:
lockingRequired in class Locker

collectStats

public StatGroup collectStats()
stats

Specified by:
collectStats in class Locker

setOnlyAbortable

public void setOnlyAbortable(OperationFailureException cause)
Set the state of a transaction to abort-only. Should ONLY be called by OperationFailureException.

Overrides:
setOnlyAbortable in class Locker

setImportunate

public void setImportunate(boolean importunate)
Set the state of a transaction's IMPORTUNATE bit.

Overrides:
setImportunate in class Locker

getImportunate

public boolean getImportunate()
Get the state of a transaction's IMPORTUNATE bit.

Overrides:
getImportunate in class Locker

checkPreempted

public void checkPreempted(Locker allowPreemptedLocker)
                    throws OperationFailureException
Checks for preemption in this locker and all its child buddies. Does NOT call checkPreempted on its child buddies, since this would cause an infinite recursion.

Overrides:
checkPreempted in class Locker
Parameters:
allowPreemptedLocker - is a locker that is being closed as the result of a cursor move operation. If the operation is successful then allowPreemptedLocker will be closed, and the fact that a lock has been stolen from allowPreemptedLocker can be ignored.
Throws:
OperationFailureException

checkState

public void checkState(boolean calledByAbort)
                throws DatabaseException
Throw an exception if the transaction is not open. If calledByAbort is true, it means we're being called from abort(). But once closed, a Transaction never calls abort(). See comment at the top of abortInternal. Caller must invoke with "this" synchronized.

Specified by:
checkState in class Locker
Throws:
DatabaseException

close

protected void close(boolean isCommit)
Close and unregister this txn.


getState

public Transaction.State getState()

isValid

public boolean isValid()
Description copied from class: Locker
Used to determine whether the locker is usable. FUTURE: Note that this method is overridden by Txn, and Txn.abort sets the state to closed when it begins rather than when it ends, but calls close() (the method above) when it ends. This is not ideal and deserves attention in the future.

Overrides:
isValid in class Locker

isClosed

public boolean isClosed()

isOnlyAbortable

public boolean isOnlyAbortable()

getReplicatorNodeId

protected int getReplicatorNodeId()

getLogSize

public int getLogSize()
Specified by:
getLogSize in interface Loggable
Returns:
number of bytes used to store this object.
See Also:
Loggable.getLogSize()

writeToLog

public void writeToLog(ByteBuffer logBuffer)
Description copied from interface: Loggable
Serialize this object into the buffer.

Specified by:
writeToLog in interface Loggable
Parameters:
logBuffer - is the destination buffer
See Also:
It's ok for FindBugs to whine about id not being synchronized.

readFromLog

public void readFromLog(ByteBuffer logBuffer,
                        int entryVersion)
Description copied from interface: Loggable
Initialize this object from the data in itemBuf.

Specified by:
readFromLog in interface Loggable
See Also:
It's ok for FindBugs to whine about id not being synchronized.

dumpLog

public void dumpLog(StringBuilder sb,
                    boolean verbose)
Description copied from interface: Loggable
Write the object into the string buffer for log dumping. Each object should be dumped without indentation or new lines and should be valid XML.

Specified by:
dumpLog in interface Loggable
Parameters:
sb - destination string buffer
verbose - if true, dump the full, verbose version
See Also:
Loggable.dumpLog(java.lang.StringBuilder, boolean)

getTransactionId

public long getTransactionId()
Specified by:
getTransactionId in interface Loggable
Returns:
the transaction id embedded within this loggable object. Objects that have no transaction id should return 0.
See Also:
Loggable.getTransactionId()

logicalEquals

public boolean logicalEquals(Loggable other)
Specified by:
logicalEquals in interface Loggable
Returns:
true if these two loggable items are logically the same. Used for replication testing.
See Also:
Loggable.logicalEquals(com.sleepycat.je.log.Loggable)

txnBeginHook

protected void txnBeginHook(TransactionConfig config)
                     throws DatabaseException
A replicated environment introduces some new considerations when entering a transaction scope via an Environment.transactionBegin() operation. On a Replica, the transactionBegin() operation must wait until the Replica has synched up to where it satisfies the ConsistencyPolicy that is in effect. On a Master, the transactionBegin() must wait until the Feeder has sufficient connections to ensure that it can satisfy the ReplicaAckPolicy, since if it does not, it will fail at commit() and the work done in the transaction will need to be undone. This hook provides the mechanism for implementing the above support for replicated transactions. It ignores all non-replicated transactions. The hook throws ReplicaStateException, if a Master switches to a Replica state while waiting for its Replicas connections. Changes from a Replica to a Master are handled transparently to the application. Exceptions manifest themselves as DatabaseException at the interface to minimize use of Replication based exceptions in core JE.

Parameters:
config - the transaction config that applies to the txn
Throws:
DatabaseException - if there is a failure

preLogCommitHook

protected void preLogCommitHook()
                         throws DatabaseException
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.

Parameters:
txn - the transaction being committed
Throws:
DatabaseException - if there was a problem and that the transaction should be aborted.

postLogCommitHook

protected void postLogCommitHook(LogItem commitItem)
                          throws DatabaseException
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.

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
Throws:
DatabaseException

postLogCommitAbortHook

protected void postLogCommitAbortHook()
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.


postLogAbortHook

protected void postLogAbortHook()

getCommitToken

public CommitToken getCommitToken()
Returns the CommitToken associated with a successful replicated commit.

See Also:
Transaction.getCommitToken()

propagatePostCommitException

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

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.

noteTriggerDb

public void noteTriggerDb(DatabaseImpl dbImpl)
Accumulates the set of databases for which transaction commit/abort triggers must be run.

Parameters:
dbImpl - the database that associated with the trigger

getTriggerDbs

public Set<DatabaseImpl> getTriggerDbs()
Returns the set of databases for which transaction commit/abort triggers must be run. Returns Null if no triggers need to be run.


getWriteLockIds

public Set<Long> getWriteLockIds()

getReadLockIds

public Set<Long> getReadLockIds()

getEnvironmentImpl

public EnvironmentImpl getEnvironmentImpl()

setTransaction

public void setTransaction(Transaction transaction)

getTransaction

public Transaction getTransaction()
Description copied from class: Locker
Returns a Transaction is the locker is transctional, or null otherwise.

Overrides:
getTransaction in class Locker


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