ydb-platform / ydb-go-sdk

Pure Go native and database/sql driver for YDB
https://ydb.tech
Apache License 2.0
132 stars 69 forks source link

bug: something is wrong with `DoTx` + `query.WithOnlineReadOnly()` #1295

Open pelageech opened 2 weeks ago

pelageech commented 2 weeks ago

Bug Report

YDB GO SDK version: 3.74.3

Environment MacOS Sonoma 14.2.1 AMD64

Current behavior:

2024/06/18 13:06:47 queryconnError{node_id:1,address:'localhost:2136'}: operation/NOT_FOUND (code = 400140, address = localhost:2136, issues = [{#2015 'Transaction not found: '}]) at `github.com/ydb-platform/ydb-go-sdk/v3/internal/conn.(*grpcClientStream).RecvMsg(grpc_client_stream.go:178)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/query.nextPart(result.go:143)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/query.newResult(result.go:101)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/query.execute(execute_query.go:74)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/query.transaction.Execute(transaction.go:83)`

Expected behavior: No error, 42 in stdout.

Steps to reproduce: Run the code.

Related code:

package main

import (
    "context"
    "errors"
    "fmt"
    "io"
    "log"
    "time"

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

func main() {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()

    driver, err := ydb.Open(ctx, "grpc://localhost:2136/local")
    if err != nil {
        log.Fatal("open", err)
    }
    defer driver.Close(ctx)

    err = driver.Query().DoTx(ctx, func(ctx context.Context, s query.TxActor) error {
        res, err := s.Execute(ctx, `SELECT CAST(42 AS Uint32);`)
        if err != nil {
            log.Fatal("query", err)
        }

        var a uint32
        for set, err := res.NextResultSet(ctx); !errors.Is(err, io.EOF); set, err = res.NextResultSet(ctx) {
            if err != nil {
                return err
            }
            for row, err := set.NextRow(ctx); !errors.Is(err, io.EOF); row, err = set.NextRow(ctx) {
                if err != nil {
                    return err
                }

                err = row.Scan(&a)
                if err != nil {
                    return err
                }

                fmt.Println(a)
            }
        }
        return res.Err()
    }, query.WithIdempotent(), query.WithTxSettings(query.TxSettings(query.WithOnlineReadOnly())))

    if err != nil {
        log.Fatal(err)
    }
}

Other information: There's no error if I remove query.WithTxSettings(query.TxSettings(query.WithOnlineReadOnly())).

neyguvj commented 2 weeks ago
Ydb_Query.BeginTransactionResponse=status:BAD_REQUEST issues:{message:"Failed to begin transaction: open transactions not supported for transaction mode OnlineReadOnly, use tx_control field in ExecuteDataQueryRequest to begin transaction with this mode.
neyguvj commented 2 weeks ago

Currently only two transaction modes are supported for interactive transactions: