Skip to content

Added Isolation concept #1739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Added Isolation concept #1739

wants to merge 1 commit into from

Conversation

asmyasnikov
Copy link
Member

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

@asmyasnikov asmyasnikov added the tx label Apr 24, 2025
@asmyasnikov asmyasnikov self-assigned this Apr 24, 2025
Copy link

github-actions bot commented Apr 24, 2025

github.com/ydb-platform/ydb-go-sdk/v3/query

compatible changes

Isolation: added
OnlineRO: added
OnlineROWithInconsistentReads: added
SerializableRW: added
SnapshotRO: added
StaleRO: added

github.com/ydb-platform/ydb-go-sdk/v3/table

incompatible changes

Options.TxSettings: changed from *TransactionSettings to *TransactionSettings
Session.BeginTransaction: changed from func(context.Context, *TransactionSettings) (Transaction, error) to func(context.Context, *TransactionSettings) (Transaction, error)
TransactionSettings: changed from github.com/ydb-platform/ydb-go-sdk/v3/internal/tx.Settings to github.com/ydb-platform/ydb-go-sdk/v3/internal/tx.Options
TxSettings: changed from func(...TxOption) *TransactionSettings to func(...TxOption) *TransactionSettings
WithTxSettings: changed from func(*TransactionSettings) txSettingsOption to func(*TransactionSettings) txSettingsOption

summary

Base version: v3.108.1 (master)
Cannot suggest a release version.
Incompatible changes were detected.

@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2025

Codecov Report

Attention: Patch coverage is 22.58065% with 48 lines in your changes missing coverage. Please review.

Project coverage is 70.96%. Comparing base (4b3e883) to head (263da45).

Files with missing lines Patch % Lines
internal/tx/isolation.go 0.00% 38 Missing ⚠️
internal/tx/settings.go 52.38% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1739      +/-   ##
==========================================
- Coverage   71.02%   70.96%   -0.06%     
==========================================
  Files         383      384       +1     
  Lines       39152    39206      +54     
==========================================
+ Hits        27807    27823      +16     
- Misses      10205    10247      +42     
+ Partials     1140     1136       -4     
Flag Coverage Δ
experiment 70.51% <22.58%> (-0.09%) ⬇️
go-1.21.x 70.83% <22.58%> (-0.14%) ⬇️
go-1.24.x 70.95% <22.58%> (-0.01%) ⬇️
integration 53.50% <22.58%> (-0.41%) ⬇️
macOS 38.22% <3.22%> (-0.06%) ⬇️
ubuntu 70.96% <22.58%> (-0.06%) ⬇️
unit 38.22% <3.22%> (-0.07%) ⬇️
windows 38.21% <3.22%> (-0.06%) ⬇️
ydb-24.1 51.33% <22.58%> (+0.08%) ⬆️
ydb-24.2 51.28% <22.58%> (-0.37%) ⬇️
ydb-24.3 51.79% <22.58%> (+0.03%) ⬆️
ydb-24.4 51.75% <22.58%> (-0.01%) ⬇️
ydb-25.1 53.39% <22.58%> (-0.05%) ⬇️
ydb-nightly 70.51% <22.58%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces the Isolation concept and refactors transaction settings by replacing the former Settings type with the new Options type, thereby standardizing how transaction settings are created and applied.

  • Renames TransactionSettings alias from tx.Settings to tx.Options in table.go.
  • Introduces a new Isolation type with corresponding methods and constants in internal/tx/isolation.go.
  • Refactors functions and method receivers in internal/tx/settings.go and updates transaction control usage in query/transaction.go and internal/query/transaction.go.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
table/table.go Updates the alias for TransactionSettings to use tx.Options instead of tx.Settings.
query/transaction.go Adjusts method calls to use the new ToQuerySettings conversion and transaction control.
internal/tx/settings.go Refactors from Settings to Options, updating function receivers and related helpers.
internal/tx/isolation.go Adds a new Isolation type with methods to convert to table/query settings.
internal/query/transaction.go Updates usage of transaction settings in Begin and txControl functions.
Comments suppressed due to low confidence (1)

internal/query/transaction.go:188

  • Verify that passing tx.txSettings directly (instead of using the variadic expansion with '...') is compatible with NewControl's expected parameter type to avoid any behavioral changes.
tx.txSettings,

@@ -177,7 +177,7 @@ type Session interface {
}

type (
TransactionSettings = tx.Settings
TransactionSettings = tx.Options
// Transaction control options
Copy link
Preview

Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that any related documentation or inline comments are updated to reflect the change from tx.Settings to tx.Options.

Suggested change
// Transaction control options
// TransactionSettings is an alias for tx.Options (previously tx.Settings) used for transaction control options.

Copilot uses AI. Check for mistakes.

Comment on lines 181 to +182
// NewSettings returns transaction settings
func NewSettings(opts ...SettingsOption) Settings {
func NewSettings(opts ...SettingsOption) Options {
Copy link
Preview

Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider renaming NewSettings to NewOptions to better align with the new Options type, or update documentation to clarify the transition from Settings to Options.

Copilot uses AI. Check for mistakes.

Comment on lines +32 to +62
func (iso Isolation) tableTxSelector() *Ydb_Table.TransactionControl_BeginTx {
switch iso {
case SerializableRW:
return tableSerializableReadWriteTxSelector
case SnapshotRO:
return tableSnapshotReadOnlyTxSelector
case OnlineRO:
return tableOnlineReadOnlyForbidInconsistentReadsTxSelector
case OnlineROWithInconsistentReads:
return tableOnlineReadOnlyAllowInconsistentReadsTxSelector
case StaleRO:
return tableStaleReadOnlyTxSelector
default:
panic(fmt.Sprintf("unknown isolation: %d", iso))
}
}

func (iso Isolation) queryTxSelector() *Ydb_Query.TransactionControl_BeginTx {
switch iso {
case SerializableRW:
return querySerializableReadWriteTxSelector
case SnapshotRO:
return querySnapshotReadOnlyTxSelector
case OnlineRO:
return queryOnlineReadOnlyForbidInconsistentReadsTxSelector
case OnlineROWithInconsistentReads:
return queryOnlineReadOnlyAllowInconsistentReadsTxSelector
case StaleRO:
return queryStaleReadOnlyTxSelector
default:
panic(fmt.Sprintf("unknown isolation: %d", iso))
Copy link
Preview

Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider handling unexpected isolation values more gracefully instead of panicking, such as by returning an error, to improve robustness in production environments.

Suggested change
func (iso Isolation) tableTxSelector() *Ydb_Table.TransactionControl_BeginTx {
switch iso {
case SerializableRW:
return tableSerializableReadWriteTxSelector
case SnapshotRO:
return tableSnapshotReadOnlyTxSelector
case OnlineRO:
return tableOnlineReadOnlyForbidInconsistentReadsTxSelector
case OnlineROWithInconsistentReads:
return tableOnlineReadOnlyAllowInconsistentReadsTxSelector
case StaleRO:
return tableStaleReadOnlyTxSelector
default:
panic(fmt.Sprintf("unknown isolation: %d", iso))
}
}
func (iso Isolation) queryTxSelector() *Ydb_Query.TransactionControl_BeginTx {
switch iso {
case SerializableRW:
return querySerializableReadWriteTxSelector
case SnapshotRO:
return querySnapshotReadOnlyTxSelector
case OnlineRO:
return queryOnlineReadOnlyForbidInconsistentReadsTxSelector
case OnlineROWithInconsistentReads:
return queryOnlineReadOnlyAllowInconsistentReadsTxSelector
case StaleRO:
return queryStaleReadOnlyTxSelector
default:
panic(fmt.Sprintf("unknown isolation: %d", iso))
func (iso Isolation) tableTxSelector() (*Ydb_Table.TransactionControl_BeginTx, error) {
switch iso {
case SerializableRW:
return tableSerializableReadWriteTxSelector, nil
case SnapshotRO:
return tableSnapshotReadOnlyTxSelector, nil
case OnlineRO:
return tableOnlineReadOnlyForbidInconsistentReadsTxSelector, nil
case OnlineROWithInconsistentReads:
return tableOnlineReadOnlyAllowInconsistentReadsTxSelector, nil
case StaleRO:
return tableStaleReadOnlyTxSelector, nil
default:
return nil, fmt.Errorf("unknown isolation: %d", iso)
}
}
func (iso Isolation) queryTxSelector() (*Ydb_Query.TransactionControl_BeginTx, error) {
switch iso {
case SerializableRW:
return querySerializableReadWriteTxSelector, nil
case SnapshotRO:
return querySnapshotReadOnlyTxSelector, nil
case OnlineRO:
return queryOnlineReadOnlyForbidInconsistentReadsTxSelector, nil
case OnlineROWithInconsistentReads:
return queryOnlineReadOnlyAllowInconsistentReadsTxSelector, nil
case StaleRO:
return queryStaleReadOnlyTxSelector, nil
default:
return nil, fmt.Errorf("unknown isolation: %d", iso)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants