Skip to content

Commit

Permalink
Merge pull request #1166 from ydb-platform/default-tx-control
Browse files Browse the repository at this point in the history
* Changed default transaction control to `NoTx` for execute query through query service client
  • Loading branch information
asmyasnikov authored Mar 26, 2024
2 parents 491367d + 9254b79 commit a7527a2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 86 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Changed default transaction control to `NoTx` for execute query through query service client

## v3.61.1
* Renamed `db.Coordination().CreateSession()` to `db.Coordination().Session()` for compatibility with protos

Expand Down
101 changes: 20 additions & 81 deletions internal/query/execute_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
"github.com/ydb-platform/ydb-go-sdk/v3/query"
)

func TestExecute(t *testing.T) {
Expand Down Expand Up @@ -768,6 +769,24 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithoutOptions",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXECUTE,
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Text: "WithoutOptions",
},
},
StatsMode: Ydb_Query.StatsMode_STATS_MODE_NONE,
ConcurrentResultSets: false,
},
},
{
name: "WithTxControl",
opts: []options.ExecuteOption{
options.WithTxControl(query.SerializableReadWriteTxControl(query.CommitTx())),
},
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithTxControl",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXECUTE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
Expand All @@ -781,7 +800,7 @@ func TestExecuteQueryRequest(t *testing.T) {
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Text: "WithoutOptions",
Text: "WithTxControl",
},
},
StatsMode: Ydb_Query.StatsMode_STATS_MODE_NONE,
Expand All @@ -802,16 +821,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithParams",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXECUTE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand Down Expand Up @@ -868,16 +877,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithExplain",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXPLAIN,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand All @@ -896,16 +895,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithValidate",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_VALIDATE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand All @@ -924,16 +913,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithValidate",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_PARSE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand All @@ -952,16 +931,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithStatsFull",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXECUTE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand All @@ -980,16 +949,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithStatsBasic",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXECUTE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand All @@ -1008,16 +967,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithStatsProfile",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXECUTE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand All @@ -1038,16 +987,6 @@ func TestExecuteQueryRequest(t *testing.T) {
request: &Ydb_Query.ExecuteQueryRequest{
SessionId: "WithGrpcCallOptions",
ExecMode: Ydb_Query.ExecMode_EXEC_MODE_EXECUTE,
TxControl: &Ydb_Query.TransactionControl{
TxSelector: &Ydb_Query.TransactionControl_BeginTx{
BeginTx: &Ydb_Query.TransactionSettings{
TxMode: &Ydb_Query.TransactionSettings_SerializableReadWrite{
SerializableReadWrite: &Ydb_Query.SerializableModeSettings{},
},
},
},
CommitTx: true,
},
Query: &Ydb_Query.ExecuteQueryRequest_QueryContent{
QueryContent: &Ydb_Query.QueryContent{
Syntax: Ydb_Query.Syntax_SYNTAX_YQL_V1,
Expand Down
5 changes: 1 addition & 4 deletions internal/query/tx/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ func NoTx() *Control {

// DefaultTxControl returns default transaction control with serializable read-write isolation mode and auto-commit
func DefaultTxControl() *Control {
return NewControl(
BeginTx(WithSerializableReadWrite()),
CommitTx(),
)
return NoTx()
}

// SerializableReadWriteTxControl returns transaction control with serializable read-write isolation mode
Expand Down
2 changes: 1 addition & 1 deletion query/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type (
// Execute executes query.
//
// Execute used by default:
// - DefaultTxControl
// - DefaultTxControl (NoTx)
// - flag WithKeepInCache(true) if params is not empty.
Execute(ctx context.Context, query string, opts ...options.ExecuteOption) (tx Transaction, r Result, err error)

Expand Down

0 comments on commit a7527a2

Please sign in to comment.