Class StdTxManager
- All Implemented Interfaces:
TxManager,TxManagerState
transaction manager interface, which logs transaction statements and
results, and reports transaction execution metrics: rollback and commit counts; attempt duration, total duration
and retry count histograms.
If you need a transaction manager, this is the right choice: just construct an instance of StdTxManager
and use it.
If you need to decorate transaction execution logic with e.g. additional logging, tracing, rate limiting etc.,
extend DelegatingTxManager, and override one or both of DelegatingTxManager.doRunTx(Supplier)
and wrapTxBody() methods.
- 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
ConstructorsConstructorDescriptionStdTxManager(Repository repository) StdTxManager(Repository repository, int maxAttemptCount, String name, Integer logLine, String logContext, TxOptions options) Deprecated.Low-level constructor, kept for compatibility with existing code. -
Method Summary
Modifier and TypeMethodDescriptionEnable pending write queue in transaction and execute write changes right before the transaction is committed.Fails if you try to create a separate transaction inside other transaction.getState()Disable pending write queue in transaction and execute write changes immediately.booleanbooleanbooleanisScan()Turn off first level cachereadOnly()Start a transaction-like session of read-only statements.scan()Start a transaction-like session of scan queries.separate()Mark transaction as explicitly separate from current transaction.toString()voidPerforms the specified action inside a transaction.<T> TPerforms the specified action inside a transaction.withDryRun(boolean dryRun) Marks the transaction as dry-run.withLogLevel(TransactionLog.Level level) Changes logging verbosity.withLogStatementOnSuccess(boolean logStatementOnSuccess) Flag for managing logging transaction statement on success.withMaxRetries(int maxRetries) Sets maximum number of retries for eachtx() call:RetryableExceptions will cause the call to be retried at most(1 + maxRetries)times.withTimeout(Duration timeout) Changes transaction timeout.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface tech.ydb.yoj.repository.db.TxManager
noLogging, withBriefLogging, withLogContext, withName, withName, withVerboseLoggingMethods inherited from interface tech.ydb.yoj.repository.db.TxManagerState
getLogContext, getRepository
-
Field Details
-
useNewTxNameGeneration
public static volatile boolean useNewTxNameGeneration
-
-
Constructor Details
-
StdTxManager
-
StdTxManager
@Deprecated public StdTxManager(Repository repository, int maxAttemptCount, String name, Integer logLine, String logContext, TxOptions options) Deprecated.Low-level constructor, kept for compatibility with existing code. Not recommended.
-
-
Method Details
-
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
-
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
-
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
-
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. -
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. -
getState
-
isFirstLevelCache
public boolean isFirstLevelCache()- Specified by:
isFirstLevelCachein interfaceTxManagerState
-
getIsolationLevel
- Specified by:
getIsolationLevelin interfaceTxManagerState
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnlyin interfaceTxManagerState
-
isScan
public boolean isScan()- Specified by:
isScanin interfaceTxManagerState
-
toString
-