Package tech.ydb.yoj.repository.db
Class DelegatingTxManager
java.lang.Object
tech.ydb.yoj.repository.db.DelegatingTxManager
- All Implemented Interfaces:
TxManager
Abstract base class for decorating
TxManagers:
- Enable additional tracing and logging, collect more metrics etc.:
wrapTxBody() - Transform transaction results and accept/reject transactions (e.g. rate limiting):
doRunTx()
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface tech.ydb.yoj.repository.db.TxManager
TxManager.ReadonlyBuilder, TxManager.ScanBuilder -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final Objectclone()protected abstract TxManagercreateTxManager(TxManager delegate) Creates an instance of this class that wraps the specifiedTxManager.Enable pending write queue in transaction and execute write changes right before the transaction is committed.protected <T> TStarts running the specified transaction manager logic in the desired environment (e.g.final booleanfinal TxManagerFails if you try to create a separate transaction inside other transaction.final TxManagerStategetState()final inthashCode()final TxManagerDisable pending write queue in transaction and execute write changes immediately.final TxManagerTurn off first level cachefinal TxManagerDisables logging of this transaction's execution.readOnly()Start a transaction-like session of read-only statements.final TxManager.ScanBuilderscan()Start a transaction-like session of scan queries.final TxManagerseparate()Mark transaction as explicitly separate from current transaction.final StringtoString()final voidPerforms the specified action inside a transaction.final <T> TPerforms the specified action inside a transaction.final TxManagerConfigures brief logging for this transactions's execution.final TxManagerwithDryRun(boolean dryRun) Marks the transaction as dry-run.final TxManagerwithLogContext(String logContext) final TxManagerwithLogLevel(TransactionLog.Level level) Changes logging verbosity.withLogStatementOnSuccess(boolean logStatementOnSuccess) Flag for managing logging transaction statement on success.final TxManagerwithMaxRetries(int maxRetries) Sets maximum number of retries for eachtx() call:RetryableExceptions will cause the call to be retried at most(1 + maxRetries)times.final TxManagerSet transaction name used for logging and metrics.final TxManagerShort cut for:final TxManagerwithTimeout(Duration timeout) Changes transaction timeout.final TxManagerConfigures verbose logging for this transactions's execution.protected <T> Supplier<T>wrapTxBody(Supplier<T> supplier) Wraps the transaction body logic, e.g.
-
Field Details
-
delegate
-
-
Constructor Details
-
DelegatingTxManager
-
-
Method Details
-
doRunTx
Starts running the specified transaction manager logic in the desired environment (e.g. starts running the logic only if rate limit is not exceeded), postprocesses the run results and returns them to the user.Default implementation just returns the result of
supplier.get().- Type Parameters:
T- transaction result type- Parameters:
supplier- some logic that calls thedelegatetransaction manager, e.g., a call todelegate.tx(...)).- Returns:
- results returned by
supplier, possibly post-processed by thisdoRun()method
-
wrapTxBody
Wraps the transaction body logic, e.g. establishes a tracing context for the specific transaction, runs the transaction body and closes the tracing context.Default implementation just returns the original
supplier.- Type Parameters:
T- transaction result type- Parameters:
supplier- logic that is run inside the transaction- Returns:
- transaction body logic to execute
-
createTxManager
Creates an instance of this class that wraps the specifiedTxManager.- Parameters:
delegate- transaction manager to delegate to- Returns:
- wrapped
delegate
-
tx
Description copied from interface:TxManagerPerforms the specified action inside a transaction. The action must be idempotent, because it might be executed multiple times in case oftransaction lock invalidation. -
tx
Description copied from interface:TxManagerPerforms the specified action inside a transaction. The action must be idempotent, because it might be executed multiple times in case oftransaction lock invalidation. -
withName
Description copied from interface:TxManagerShort cut for:withName(name).withLogContext(logContext)
-
withName
Description copied from interface:TxManagerSet transaction name used for logging and metrics.Since name is used as metric label, there should be limited numbers of names used for transactions. Normally one per code occurrence.
-
withLogContext
- Specified by:
withLogContextin interfaceTxManager- Parameters:
logContext- dynamic context used for logging.
-
separate
Description copied from interface:TxManagerMark transaction as explicitly separate from current transaction. Otherwise, you will be failed or WARNed about initiating a new transaction while already being in a transaction -
delayedWrites
Description copied from interface:TxManagerEnable pending write queue in transaction and execute write changes right before the transaction is committed.- Specified by:
delayedWritesin interfaceTxManager
-
immediateWrites
Description copied from interface:TxManagerDisable pending write queue in transaction and execute write changes immediately.- Specified by:
immediateWritesin interfaceTxManager
-
noFirstLevelCache
Description copied from interface:TxManagerTurn off first level cache- Specified by:
noFirstLevelCachein interfaceTxManager
-
failOnUnknownSeparateTx
Description copied from interface:TxManagerFails if you try to create a separate transaction inside other transaction. TxManager with this setting is good to use in tests. Call separate() before start transaction if you really need to create a one transaction inside other transaction.- Specified by:
failOnUnknownSeparateTxin interfaceTxManager
-
withMaxRetries
Description copied from interface:TxManagerSets maximum number of retries for eachtx() call:RetryableExceptions will cause the call to be retried at most(1 + maxRetries)times. Last retryable exception will berethrown as fatalif retries fail.- Fatal exceptions (not subclasses of
RetryableException) will not be retried; they are thrown immediately.
- Specified by:
withMaxRetriesin interfaceTxManager- Parameters:
maxRetries- maximum number of retries (>= 0)
-
withDryRun
Description copied from interface:TxManagerMarks the transaction as dry-run. If transaction is marked as dry-run, its changes will be rolled back but no exception will be thrown and transaction result will be returned.- Specified by:
withDryRunin interfaceTxManager
-
withLogLevel
Description copied from interface:TxManagerChanges logging verbosity.- Specified by:
withLogLevelin interfaceTxManager- Parameters:
level- minimum accepted log message level, e.g.,DEBUGfor DB queries
-
withLogStatementOnSuccess
Description copied from interface:TxManagerFlag for managing logging transaction statement on success.- Specified by:
withLogStatementOnSuccessin interfaceTxManager
-
withTimeout
Description copied from interface:TxManagerChanges transaction timeout. If the timeout elapses before transaction finishes,DeadlineExceededExceptionorQueryCancelledExceptionmight be thrown.- Specified by:
withTimeoutin interfaceTxManager- Parameters:
timeout- transaction timeout
-
withVerboseLogging
Description copied from interface:TxManagerConfigures verbose logging for this transactions's execution. Short representations of DB queries performed and partial results of these queries will be logged.- Specified by:
withVerboseLoggingin interfaceTxManager- See Also:
-
withBriefLogging
Description copied from interface:TxManagerConfigures brief logging for this transactions's execution. Only total time spent in DB session and commit/ rollback timings will be logged.- Specified by:
withBriefLoggingin interfaceTxManager- See Also:
-
noLogging
Description copied from interface:TxManagerDisables logging of this transaction's execution. You will still see transaction result messages in the logs, e.g., "runInTx(): Commit/Rollback/...". -
readOnly
Description copied from interface:TxManagerStart a transaction-like session of read-only statements. Each statement will be executed separately, with the specified isolation level (online consistent read-only, by default).YDB doesn't currently support multi-statement read-only transactions. If you perform more than one read, be ready to handle potential inconsistencies between the reads.
You can also use
readOnly().run(() -> [table].readTable(...));to efficiently read data from the table without interfering with OLTP transactions. In this case, data consistency is similar to snapshot isolation. If perform more than onereadTable(), be ready to handle potential inconsistencies between the reads. -
scan
Description copied from interface:TxManagerStart a transaction-like session of scan queries. Each query will be executed separately. Scan query consistency is similar to snapshot isolation, and these queries efficiently read data from the snapshot without interfering with OLTP transactions. Be ready to handle potential inconsistencies between the reads if you perform more than one scan query. -
getState
-
toString
-
equals
-
hashCode
public final int hashCode() -
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-