Package tech.ydb.yoj.repository.db
Interface TxManager
- All Known Implementing Classes:
DelegatingTxManager,StdTxManager
public interface TxManager
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interface -
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.Turn off first level cachedefault TxManagerDisables logging of this transaction's execution.readOnly()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.voidPerforms the specified action inside a transaction.<T> TPerforms the specified action inside a transaction.default TxManagerConfigures brief logging for this transactions's execution.withDryRun(boolean dryRun) Marks the transaction as dry-run.withLogContext(String logContext) 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.Set transaction name used for logging and metrics.default TxManagerShort cut for:withTimeout(Duration timeout) Changes transaction timeout.default TxManagerConfigures verbose logging for this transactions's execution.
-
Method Details
-
withName
Set 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.
- Parameters:
name- used for logging and metrics, notnull
-
withLogContext
- Parameters:
logContext- dynamic context used for logging.
-
separate
TxManager separate()Mark 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
TxManager delayedWrites()Enable pending write queue in transaction and execute write changes right before the transaction is committed. -
immediateWrites
TxManager immediateWrites()Disable pending write queue in transaction and execute write changes immediately. -
noFirstLevelCache
TxManager noFirstLevelCache()Turn off first level cache -
failOnUnknownSeparateTx
TxManager failOnUnknownSeparateTx()Fails 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. -
withName
Short cut for:withName(name).withLogContext(logContext)
-
withMaxRetries
Sets 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.
- Parameters:
maxRetries- maximum number of retries (>= 0)- Throws:
IllegalArgumentException- ifretries < 0
-
withDryRun
Marks 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. -
withVerboseLogging
Configures verbose logging for this transactions's execution. Short representations of DB queries performed and partial results of these queries will be logged.- See Also:
-
withBriefLogging
Configures brief logging for this transactions's execution. Only total time spent in DB session and commit/ rollback timings will be logged.- See Also:
-
noLogging
Disables logging of this transaction's execution. You will still see transaction result messages in the logs, e.g., "runInTx(): Commit/Rollback/...". -
withLogLevel
Changes logging verbosity.- Parameters:
level- minimum accepted log message level, e.g.,DEBUGfor DB queries
-
withLogStatementOnSuccess
Flag for managing logging transaction statement on success. -
withTimeout
Changes transaction timeout. If the timeout elapses before transaction finishes,DeadlineExceededExceptionorQueryCancelledExceptionmight be thrown.- Parameters:
timeout- transaction timeout
-
tx
Performs the specified action inside a transaction. The action must be idempotent, because it might be executed multiple times in case oftransaction lock invalidation.- Parameters:
supplier- action to perform- Returns:
- action result
-
tx
Performs the specified action inside a transaction. The action must be idempotent, because it might be executed multiple times in case oftransaction lock invalidation.- Parameters:
runnable- action to perform
-
readOnly
TxManager.ReadonlyBuilder readOnly()Start 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
TxManager.ScanBuilder scan()Start 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
TxManagerState getState()- Returns:
- information about current transaction settings set for this instance of
TxManager
-