public class Txn extends Locker implements VersionedWriteLoggable
| Modifier and Type | Field and Description |
|---|---|
static int |
ACCUMULATED_LIMIT |
protected long |
commitLsn |
protected Set<DbCleanup> |
dbCleanupSet |
protected long |
firstLoggedLsn |
protected long |
lastLoggedLsn |
protected Set<Database> |
openedDatabaseHandles |
protected ReplicationContext |
repContext |
protected Map<DatabaseId,DatabaseImpl> |
undoDatabases |
afterWaiterHook, envImpl, id, lockManager, thread| Modifier | Constructor and Description |
|---|---|
|
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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Abort this transaction.
|
long |
abort(boolean forceFlush)
Abort this transaction.
|
void |
abort(Xid xid) |
void |
addDbCleanup(DbCleanup cleanup)
Database operations like remove, truncate and rename require that
DatabaseImpls are deleted or updated at transaction commit or abort.
|
protected void |
addLock(Long lsn,
LockType type,
LockGrantType grantStatus)
Add lock to the appropriate queue.
|
void |
addLogInfo(long lastLsn)
Called by LNLogEntry.postLogWork() via the LogManager (while still under
the LWL) after a transactional LN is logged.
|
void |
addOpenedDatabase(Database dbHandle)
Called at the end of a database open operation to add the database
handle to a user txn.
|
protected void |
checkIfFrozen(boolean isCommit)
Txn freezing is used to prevent changes to transaction lock contents.
|
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 and renameDatabase.
|
protected int |
clearReadLocks() |
protected void |
clearWriteLocks(Set<Long> retainedNodes)
Release any write locks that are not in the retainedNodes set.
|
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) |
static Txn |
createAutoTxn(EnvironmentImpl envImpl,
TransactionConfig config,
ReplicationContext repContext) |
static Txn |
createLocalAutoTxn(EnvironmentImpl envImpl,
TransactionConfig config) |
static Txn |
createLocalTxn(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.
|
Durability |
getCommitDurability()
Returns the durability used for the commit operation.
|
CommitToken |
getCommitToken()
Returns the CommitToken associated with a successful replicated commit.
|
Set<DbCleanup> |
getDbCleanupSet() |
Durability |
getDefaultDurability()
Returns the durability associated the transaction at the time it's first
created.
|
protected long |
getDTVLSN()
This method is overridden by replication txn subclasses and returns the
DTVLSN associated with the Txn.
|
Collection<VersionedWriteLoggable> |
getEmbeddedLoggables() |
EnvironmentImpl |
getEnvironmentImpl() |
boolean |
getExplicitDurabilityConfigured()
Returns true if the durability api was used for configuration.
|
boolean |
getExplicitSyncConfigured()
Returns true if the sync api was used for configuration
|
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.
|
int |
getLastFormatChange()
Returns the log version of the most recent format change for this
loggable item.
|
long |
getLastLsn()
Access to last LSN.
|
int |
getLogSize() |
int |
getLogSize(int logVersion,
boolean forReplication)
Returns the number of bytes needed to store this object in the format
for the specified log version.
|
boolean |
getPrepared() |
Set<Long> |
getReadLockIds() |
protected int |
getReplicatorNodeId()
This method is overridden by HA txn subclasses and returns the node id
of the master node that committed or aborted the txn.
|
Transaction.State |
getState() |
Transaction |
getTransaction()
Returns a Transaction if 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.
|
Map<DatabaseId,DatabaseImpl> |
getUndoDatabases() |
Set<Long> |
getWriteLockIds()
Get the set of lock ids owned by this transaction
|
WriteLockInfo |
getWriteLockInfo(long lsn) |
boolean |
hasReplicationFormat()
Returns whether this format has a variant that is optimized for
replication.
|
boolean |
isAutoTxn()
Determines whether this is an auto transaction.
|
boolean |
isClosed() |
boolean |
isMasterTxn() |
boolean |
isOnlyAbortable() |
boolean |
isReadCommittedIsolation()
Is read-committed isolation if so configured.
|
boolean |
isReadOnly()
Returns whether writes are prohibited using this locker.
|
boolean |
isReplicationFormatWorthwhile(ByteBuffer logBuffer,
int srcVersion,
int destVersion)
Returns whether it is worthwhile to materialize and then re-serialize a
log entry in a format optimized for replication.
|
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) |
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)
Prepare to undo in the (very unlikely) event that logging succeeds but
locking fails.
|
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)
It's ok for FindBugs to whine about id not being synchronized.
|
void |
registerCursor(CursorImpl cursor)
Increase the counter if a new Cursor is opened under this transaction.
|
protected boolean |
registerImmediately()
True if this transaction should be registered with the transaction
manager immediately at startup.
|
void |
releaseNonTxnLocks()
This locker holds no non-transactional locks.
|
protected void |
releaseWriteLocks()
Releases all write locks, nulls the lock collection.
|
protected void |
removeLock(long lsn)
Remove the lock from the set owned by this transaction.
|
protected void |
setDbCleanupState(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.
|
void |
writeToLog(ByteBuffer logBuffer,
int logVersion,
boolean forReplication)
It's ok for FindBugs to whine about id not being synchronized.
|
addDeleteInfo, allowReleaseLockAfterLsnChange, demoteLock, disallowReplicaWrite, dumpLockTable, getDefaultNoWait, getEnvironment, getId, getInitialLockTimeout, getLockTimeout, getPreemptable, getTxnTimeout, isLocalWrite, isReadUncommittedDefault, isReplicated, isTimedOut, lock, lockAfterLsnChange, nonBlockingLock, openCursorHook, operationEnd, operationEnd, releaseLock, setClosingLocker, setDefaultNoWait, setLockTimeout, setPreemptable, setPreempted, setTxnTimeout, sharesLocksWith, toStringprotected Map<DatabaseId,DatabaseImpl> undoDatabases
protected volatile long firstLoggedLsn
protected long lastLoggedLsn
protected long commitLsn
public static int ACCUMULATED_LIMIT
protected ReplicationContext repContext
public Txn()
protected Txn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext)
protected Txn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext, long mandatedId) throws DatabaseException
DatabaseExceptionpublic static Txn createLocalTxn(EnvironmentImpl envImpl, TransactionConfig config)
public static Txn createLocalAutoTxn(EnvironmentImpl envImpl, TransactionConfig config)
public static Txn createAutoTxn(EnvironmentImpl envImpl, TransactionConfig config, ReplicationContext repContext) throws DatabaseException
DatabaseExceptionprotected boolean registerImmediately()
protected long generateId(TxnManager txnManager, long ignore)
generateId in class Lockerpublic 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 Lockerprotected LockResult lockInternal(long lsn, LockType lockType, boolean noWait, boolean jumpAheadOfWaiters, DatabaseImpl database) throws DatabaseException
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.DatabaseExceptionLocker.lockInternal(long, com.sleepycat.je.txn.LockType, boolean, boolean, com.sleepycat.je.dbi.DatabaseImpl)public void preLogWithoutLock(DatabaseImpl database)
preLogWithoutLock in class Lockerpublic int prepare(Xid xid) throws DatabaseException
IllegalStateException - via XAResourceDatabaseExceptionpublic void commit(Xid xid) throws DatabaseException
DatabaseExceptionpublic void abort(Xid xid) throws DatabaseException
DatabaseExceptionpublic long commit()
throws DatabaseException
DatabaseExceptionpublic 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.DatabaseExceptionprotected void releaseWriteLocks()
throws DatabaseException
DatabaseExceptionpublic void abort()
throws DatabaseException
DatabaseExceptionpublic long abort(boolean forceFlush)
throws DatabaseException
DatabaseExceptionprotected void undo()
throws DatabaseException
DatabaseExceptionprotected void clearWriteLocks(Set<Long> retainedNodes) throws DatabaseException
DatabaseExceptionprotected int clearReadLocks()
throws DatabaseException
DatabaseExceptionpublic void addLogInfo(long lastLsn)
public long getFirstActiveLsn()
protected boolean updateLoggedForTxn()
public void addDbCleanup(DbCleanup cleanup)
LockeraddDbCleanup in class Lockerprotected void setDbCleanupState(boolean isCommit)
protected void cleanupDatabaseImpls(boolean isCommit)
throws DatabaseException
DatabaseExceptionprotected void addLock(Long lsn, LockType type, LockGrantType grantStatus)
protected void removeLock(long lsn)
public WriteLockInfo getWriteLockInfo(long lsn)
getWriteLockInfo in class Lockerpublic boolean isTransactional()
isTransactional in class Lockerpublic boolean isAutoTxn()
public boolean isReadOnly()
LockerisReadOnly in class Lockerpublic boolean isSerializableIsolation()
isSerializableIsolation in class Lockerpublic boolean isReadCommittedIsolation()
isReadCommittedIsolation in class Lockerpublic boolean getExplicitSyncConfigured()
public boolean getExplicitDurabilityConfigured()
public Txn getTxnLocker()
getTxnLocker in class Lockerpublic Locker newNonTxnLocker()
newNonTxnLocker in class Lockerpublic void releaseNonTxnLocks()
releaseNonTxnLocks in class Lockerpublic void nonTxnOperationEnd()
nonTxnOperationEnd in class Lockerpublic void operationEnd(boolean operationOK)
throws DatabaseException
LockeroperationEnd in class LockeroperationOK - is whether the operation succeeded, since
that may impact ending behavior. (i.e for an auto Txn)DatabaseExceptionpublic void addOpenedDatabase(Database dbHandle)
addOpenedDatabase in class LockerHandleLockerpublic void registerCursor(CursorImpl cursor)
registerCursor in class Lockerpublic void unRegisterCursor(CursorImpl cursor)
unRegisterCursor in class Lockerpublic boolean lockingRequired()
LockerlockingRequired in class Lockerpublic StatGroup collectStats()
collectStats in class Lockerpublic void setOnlyAbortable(OperationFailureException cause)
setOnlyAbortable in class Lockerpublic void setImportunate(boolean importunate)
setImportunate in class Lockerpublic boolean getImportunate()
getImportunate in class Lockerpublic void checkPreempted(Locker allowPreemptedLocker) throws OperationFailureException
checkPreempted in class LockerallowPreemptedLocker - 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.OperationFailureExceptionpublic void checkState(boolean calledByAbort)
throws DatabaseException
checkState in class LockerDatabaseExceptionpublic void close(boolean isCommit)
public Transaction.State getState()
public boolean isValid()
Lockerpublic boolean isClosed()
public boolean isOnlyAbortable()
protected int getReplicatorNodeId()
protected long getDTVLSN()
public int getLastFormatChange()
VersionedWriteLoggablegetLastFormatChange in interface VersionedWriteLoggableReplicableLogEntry.getLastFormatChange()public Collection<VersionedWriteLoggable> getEmbeddedLoggables()
getEmbeddedLoggables in interface VersionedWriteLoggableReplicableLogEntry.getEmbeddedLoggables()public int getLogSize()
getLogSize in interface Loggablepublic void writeToLog(ByteBuffer logBuffer)
LoggablewriteToLog in interface LoggablelogBuffer - is the destination bufferpublic int getLogSize(int logVersion,
boolean forReplication)
VersionedWriteLoggableLogEntryType.LOG_VERSION_REPLICATE_OLDER or greater.getLogSize in interface VersionedWriteLoggablelogVersion - the log versionforReplication - whether the entry will be sent over the wire,
and not written to the log.public void writeToLog(ByteBuffer logBuffer, int logVersion, boolean forReplication)
writeToLog in interface VersionedWriteLoggablelogBuffer - the destination bufferlogVersion - the log versionforReplication - whether the entry will be sent over the wire,
and not written to the log.public void readFromLog(ByteBuffer logBuffer, int entryVersion)
readFromLog in interface LoggablelogBuffer - the source bufferentryVersion - the log version of the datapublic boolean hasReplicationFormat()
VersionedWriteLoggablehasReplicationFormat in interface VersionedWriteLoggablepublic boolean isReplicationFormatWorthwhile(ByteBuffer logBuffer, int srcVersion, int destVersion)
VersionedWriteLoggableWARNING: The logBuffer position must not be changed by this method.
WARNING: The shared LogEntry object is used for calling this method, and this method must not change any of the fields in the object.
isReplicationFormatWorthwhile in interface VersionedWriteLoggablelogBuffer - contains the entry that would be re-serialized.srcVersion - the log version of entry in logBuffer.destVersion - the version that would be used for re-serialization.public void dumpLog(StringBuilder sb, boolean verbose)
Loggablepublic long getTransactionId()
getTransactionId in interface Loggablepublic boolean logicalEquals(Loggable other)
logicalEquals in interface Loggableprotected void txnBeginHook(TransactionConfig config) throws DatabaseException
config - the transaction config that applies to the txnDatabaseException - if there is a failureprotected void preLogCommitHook()
throws DatabaseException
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 loggedDatabaseException - to indicate that there was a replication
related problem that needs to be communicated back to the application.protected void preLogAbortHook()
throws DatabaseException
DatabaseExceptionprotected void postLogCommitAbortHook()
protected void postLogAbortHook()
public CommitToken getCommitToken()
Transaction.getCommitToken()protected boolean propagatePostCommitException(DatabaseException postCommitException)
postCommitException - the exception being evaluatedpublic void noteTriggerDb(DatabaseImpl dbImpl)
dbImpl - the database that associated with the triggerpublic Set<DatabaseImpl> getTriggerDbs()
public Set<Long> getWriteLockIds()
public EnvironmentImpl getEnvironmentImpl()
public void setTransaction(Transaction transaction)
public Transaction getTransaction()
LockergetTransaction in class Lockerpublic Map<DatabaseId,DatabaseImpl> getUndoDatabases()
protected void checkIfFrozen(boolean isCommit)
throws DatabaseException
isCommit - true if called by commit.DatabaseExceptionpublic boolean isMasterTxn()
Copyright © 2024. All rights reserved.