|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sleepycat.je.txn.Locker
com.sleepycat.je.txn.Txn
public class Txn
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Set<com.sleepycat.je.txn.Txn.DatabaseCleanupInfo> deletedDatabases
protected Map<DatabaseId,DatabaseImpl> undoDatabases
protected Set<Database> openedDatabaseHandles
addOpenedDatabase(com.sleepycat.je.Database)
,
HandleLocker
protected volatile long firstLoggedLsn
protected long lastLoggedLsn
protected long commitLsn
long abortLsn
public static int ACCUMULATED_LIMIT
protected ReplicationContext repContext
Constructor Detail |
---|
public Txn()
protected Txn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext)
protected Txn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext, long mandatedId) throws DatabaseException
DatabaseException
Method Detail |
---|
public static Txn createLocalTxn(EnvironmentImpl envImpl, TransactionConfig config)
public static Txn createLocalAutoTxn(EnvironmentImpl envImpl, TransactionConfig config)
static Txn createUserTxn(EnvironmentImpl envImpl, TransactionConfig config)
static Txn createAutoTxn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext) throws DatabaseException
DatabaseException
void addBuddy(BuddyLocker buddy)
Locker
addBuddy
in class Locker
void removeBuddy(BuddyLocker buddy)
Locker
removeBuddy
in class Locker
protected long generateId(TxnManager txnManager, long ignore)
generateId
in class Locker
public long getLastLsn()
public Durability getCommitDurability()
public Durability getDefaultDurability()
public boolean getPrepared()
public void setPrepared(boolean prepared)
public void setSuspended(boolean suspended)
public boolean isSuspended()
protected void setRollback()
public boolean isRolledBack()
isRolledBack
in class Locker
protected LockResult lockInternal(long lsn, LockType lockType, boolean noWait, boolean jumpAheadOfWaiters, DatabaseImpl database) throws DatabaseException
lockInternal
in class Locker
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.
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
Locker.lockInternal(long, com.sleepycat.je.txn.LockType, boolean, boolean, com.sleepycat.je.dbi.DatabaseImpl)
public void preLogWithoutLock(DatabaseImpl database)
preLogWithoutLock
in class Locker
public int prepare(Xid xid) throws DatabaseException
IllegalStateException
- via XAResource
DatabaseException
public void commit(Xid xid) throws DatabaseException
DatabaseException
public void abort(Xid xid) throws DatabaseException
DatabaseException
public long commit() throws DatabaseException
DatabaseException
public long commit(Durability durability) throws DatabaseException
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
protected void releaseWriteLocks() throws DatabaseException
DatabaseException
public void abort() throws DatabaseException
DatabaseException
public long abort(boolean forceFlush) throws DatabaseException
DatabaseException
protected void undo() throws DatabaseException
DatabaseException
protected void clearWriteLocks(Set<Long> retainedNodes) throws DatabaseException
DatabaseException
public void addLogInfo(long lastLsn)
public long getFirstActiveLsn()
protected boolean updateLoggedForTxn()
public void markDeleteAtTxnEnd(DatabaseImpl dbImpl, boolean deleteAtCommit)
Locker
markDeleteAtTxnEnd
in class Locker
dbImpl
- databaseImpl to removedeleteAtCommit
- true if this databaseImpl should be cleaned on
commit, false if it should be cleaned on abort.protected void setDeletedDatabaseState(boolean isCommit)
protected void cleanupDatabaseImpls(boolean isCommit) throws DatabaseException
DatabaseException
protected void addLock(Long lsn, LockType type, LockGrantType grantStatus)
addLock
in class Locker
void removeLock(long lsn)
removeLock
in class Locker
void moveWriteToReadLock(long lsn, Lock lock)
moveWriteToReadLock
in class Locker
int getBudgetedMemorySize()
public boolean createdNode(long lsn)
createdNode
in class Locker
public WriteLockInfo getWriteLockInfo(long lsn)
getWriteLockInfo
in class Locker
public boolean isTransactional()
isTransactional
in class Locker
public boolean isAutoTxn()
public boolean isSerializableIsolation()
isSerializableIsolation
in class Locker
public boolean isReadCommittedIsolation()
isReadCommittedIsolation
in class Locker
public boolean getExplicitSyncConfigured()
public boolean getExplicitDurabilityConfigured()
public Txn getTxnLocker()
getTxnLocker
in class Locker
public Locker newNonTxnLocker()
newNonTxnLocker
in class Locker
public void releaseNonTxnLocks()
releaseNonTxnLocks
in class Locker
public void nonTxnOperationEnd()
nonTxnOperationEnd
in class Locker
public void operationEnd(boolean operationOK) throws DatabaseException
Locker
operationEnd
in class Locker
operationOK
- is whether the operation succeeded, since
that may impact ending behavior. (i.e for an auto Txn)
DatabaseException
public void addOpenedDatabase(Database dbHandle)
addOpenedDatabase
in class Locker
HandleLocker
public void registerCursor(CursorImpl cursor)
registerCursor
in class Locker
public void unRegisterCursor(CursorImpl cursor)
unRegisterCursor
in class Locker
public boolean lockingRequired()
Locker
lockingRequired
in class Locker
public StatGroup collectStats()
collectStats
in class Locker
public void setOnlyAbortable(OperationFailureException cause)
setOnlyAbortable
in class Locker
public void setImportunate(boolean importunate)
setImportunate
in class Locker
public boolean getImportunate()
getImportunate
in class Locker
public void checkPreempted(Locker allowPreemptedLocker) throws OperationFailureException
checkPreempted
in class Locker
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.
OperationFailureException
public void checkState(boolean calledByAbort) throws DatabaseException
checkState
in class Locker
DatabaseException
protected void close(boolean isCommit)
public Transaction.State getState()
public boolean isValid()
Locker
isValid
in class Locker
public boolean isClosed()
public boolean isOnlyAbortable()
protected int getReplicatorNodeId()
public int getLogSize()
getLogSize
in interface Loggable
Loggable.getLogSize()
public void writeToLog(ByteBuffer logBuffer)
Loggable
writeToLog
in interface Loggable
logBuffer
- is the destination bufferIt's ok for FindBugs to whine about id not being synchronized.
public void readFromLog(ByteBuffer logBuffer, int entryVersion)
Loggable
readFromLog
in interface Loggable
It's ok for FindBugs to whine about id not being synchronized.
public void dumpLog(StringBuilder sb, boolean verbose)
Loggable
dumpLog
in interface Loggable
sb
- destination string bufferverbose
- if true, dump the full, verbose versionLoggable.dumpLog(java.lang.StringBuilder, boolean)
public long getTransactionId()
getTransactionId
in interface Loggable
Loggable.getTransactionId()
public boolean logicalEquals(Loggable other)
logicalEquals
in interface Loggable
Loggable.logicalEquals(com.sleepycat.je.log.Loggable)
protected void txnBeginHook(TransactionConfig config) throws DatabaseException
config
- the transaction config that applies to the txn
DatabaseException
- if there is a failureprotected void preLogCommitHook() throws DatabaseException
txn
- the transaction being committed
DatabaseException
- if there was a problem and that the
transaction should be aborted.protected void postLogCommitHook(LogItem commitItem) throws DatabaseException
commitItem
- the commit item that was just logged
DatabaseException
- to indicate that there was a replication
related problem that needs to be communicated back to the application.protected void preLogAbortHook() throws DatabaseException
DatabaseException
protected void postLogCommitAbortHook()
protected void postLogAbortHook()
public CommitToken getCommitToken()
Transaction.getCommitToken()
protected boolean propagatePostCommitException(DatabaseException postCommitException)
postCommitException
- the exception being evaluated
public void noteTriggerDb(DatabaseImpl dbImpl)
dbImpl
- the database that associated with the triggerpublic Set<DatabaseImpl> getTriggerDbs()
public Set<Long> getWriteLockIds()
public Set<Long> getReadLockIds()
public EnvironmentImpl getEnvironmentImpl()
public void setTransaction(Transaction transaction)
public Transaction getTransaction()
Locker
getTransaction
in class Locker
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |