Skip to content

Commit

Permalink
fix(internal/query/conn): badconn rm
Browse files Browse the repository at this point in the history
  • Loading branch information
vladDotH committed Nov 23, 2024
1 parent 2ffc490 commit b7e83f1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
15 changes: 6 additions & 9 deletions internal/query/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/session"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stats"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn/badconn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/tx"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
Expand Down Expand Up @@ -96,9 +95,7 @@ func (c *Conn) beginTx(ctx context.Context, txOptions driver.TxOptions) (tx curr
}()

if c.currentTx != nil {
return nil, badconn.Map(
xerrors.WithStackTrace(xerrors.AlreadyHasTx(c.currentTx.ID())),
)
return nil, xerrors.WithStackTrace(xerrors.AlreadyHasTx(c.currentTx.ID()))
}

tx, err := beginTx(ctx, c, txOptions)
Expand All @@ -121,7 +118,7 @@ func (c *Conn) execContext(
}()

if !c.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}

if c.currentTx != nil {
Expand All @@ -143,7 +140,7 @@ func (c *Conn) execContext(

err = c.session.Exec(ctx, normalizedQuery, options.WithParameters(&params))
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
return nil, xerrors.WithStackTrace(err)
}

return resultNoRows{}, nil
Expand All @@ -157,7 +154,7 @@ func (c *Conn) queryContext(ctx context.Context, queryString string, args []driv
}()

if !c.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}

if c.currentTx != nil {
Expand Down Expand Up @@ -197,7 +194,7 @@ func (c *Conn) queryContextOther(
options.WithParameters(&parameters),
)
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
return nil, xerrors.WithStackTrace(err)
}

return &rows{
Expand All @@ -222,7 +219,7 @@ func (c *Conn) queryContextExplain(
}),
)
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
return nil, xerrors.WithStackTrace(err)
}

return &single{
Expand Down
15 changes: 7 additions & 8 deletions internal/query/conn/driver.impls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn/badconn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
Expand Down Expand Up @@ -44,11 +43,11 @@ func (c *Conn) Ping(ctx context.Context) (finalErr error) {
}()

if !c.isReady() {
return badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return xerrors.WithStackTrace(errNotReadyConn)
}

if !c.session.Core.IsAlive() {
return badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return xerrors.WithStackTrace(errNotReadyConn)
}

err := c.session.Exec(ctx, "select 1")
Expand All @@ -70,7 +69,7 @@ func (c *Conn) PrepareContext(ctx context.Context, query string) (_ driver.Stmt,
}()

if !c.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}

return &stmt{
Expand All @@ -92,7 +91,7 @@ func (c *Conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (driver.

func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
if !c.IsValid() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}

if c.currentTx != nil {
Expand All @@ -104,7 +103,7 @@ func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.Name

func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
if !c.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}
if c.currentTx != nil {
return c.currentTx.QueryContext(ctx, query, args)
Expand All @@ -119,7 +118,7 @@ func (c *Conn) Prepare(query string) (driver.Stmt, error) {

func (c *Conn) Close() (finalErr error) {
if !c.closed.CompareAndSwap(false, true) {
return badconn.Map(xerrors.WithStackTrace(errConnClosedEarly))
return xerrors.WithStackTrace(errConnClosedEarly)
}

defer func() {
Expand All @@ -143,7 +142,7 @@ func (c *Conn) Close() (finalErr error) {
}
err := c.session.Close(xcontext.ValueOnly(ctx))
if err != nil {
return badconn.Map(xerrors.WithStackTrace(err))
return xerrors.WithStackTrace(err)
}

return nil
Expand Down
15 changes: 7 additions & 8 deletions internal/query/conn/rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn/badconn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
)
Expand Down Expand Up @@ -54,7 +53,7 @@ func (r *rows) loadFirstNextSet() {
func (r *rows) Columns() []string {
r.firstNextSet.Do(r.loadFirstNextSet)
if r.columnsFetchError != nil {
panic(badconn.Map(xerrors.WithStackTrace(r.columnsFetchError)))
panic(xerrors.WithStackTrace(r.columnsFetchError))
}

return r.columns
Expand All @@ -63,7 +62,7 @@ func (r *rows) Columns() []string {
func (r *rows) ColumnTypeDatabaseTypeName(index int) string {
r.firstNextSet.Do(r.loadFirstNextSet)
if r.columnsFetchError != nil {
panic(badconn.Map(xerrors.WithStackTrace(r.columnsFetchError)))
panic(xerrors.WithStackTrace(r.columnsFetchError))
}

return r.columnsType[index].String()
Expand All @@ -72,7 +71,7 @@ func (r *rows) ColumnTypeDatabaseTypeName(index int) string {
func (r *rows) ColumnTypeNullable(index int) (nullable, ok bool) {
r.firstNextSet.Do(r.loadFirstNextSet)
if r.columnsFetchError != nil {
panic(badconn.Map(xerrors.WithStackTrace(r.columnsFetchError)))
panic(xerrors.WithStackTrace(r.columnsFetchError))
}
_, castResult := r.nextSet.ColumnTypes()[index].(interface{ IsOptional() })

Expand All @@ -92,7 +91,7 @@ func (r *rows) NextResultSet() (finalErr error) {
}

if r.nextErr != nil {
return badconn.Map(xerrors.WithStackTrace(r.nextErr))
return xerrors.WithStackTrace(r.nextErr)
}

r.columns = r.nextSet.Columns()
Expand All @@ -117,7 +116,7 @@ func (r *rows) Next(dst []driver.Value) error {
return io.EOF
}

return badconn.Map(xerrors.WithStackTrace(r.nextErr))
return xerrors.WithStackTrace(r.nextErr)
}

nextRow, err := r.nextSet.NextRow(ctx)
Expand All @@ -126,7 +125,7 @@ func (r *rows) Next(dst []driver.Value) error {
return io.EOF
}

return badconn.Map(xerrors.WithStackTrace(err))
return xerrors.WithStackTrace(err)
}

ptrs := make([]any, len(dst))
Expand All @@ -135,7 +134,7 @@ func (r *rows) Next(dst []driver.Value) error {
}

if err = nextRow.Scan(ptrs...); err != nil {
return badconn.Map(xerrors.WithStackTrace(err))
return xerrors.WithStackTrace(err)
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions internal/query/conn/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"database/sql/driver"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn/badconn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)
Expand Down Expand Up @@ -35,7 +34,7 @@ func (stmt *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_
onDone(finalErr)
}()
if !stmt.conn.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}

return stmt.processor.QueryContext(ctx, stmt.query, args)
Expand All @@ -50,7 +49,7 @@ func (stmt *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (_
onDone(finalErr)
}()
if !stmt.conn.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}

return stmt.processor.ExecContext(ctx, stmt.query, args)
Expand Down
17 changes: 8 additions & 9 deletions internal/query/conn/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn/isolation"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn/badconn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/tx"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/query"
Expand Down Expand Up @@ -38,7 +37,7 @@ func beginTx(ctx context.Context, c *Conn, txOptions driver.TxOptions) (currentT

nativeTx, err := c.session.Begin(ctx, query.TxSettings(txc))
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
return nil, xerrors.WithStackTrace(err)
}

return &transaction{
Expand Down Expand Up @@ -77,13 +76,13 @@ func (tx *transaction) Commit() (finalErr error) {
onDone(finalErr)
}()
if err := tx.checkTxState(); err != nil {
return badconn.Map(xerrors.WithStackTrace(err))
return xerrors.WithStackTrace(err)
}
defer func() {
tx.conn.currentTx = nil
}()
if err := tx.tx.CommitTx(tx.ctx); err != nil {
return badconn.Map(xerrors.WithStackTrace(err))
return xerrors.WithStackTrace(err)
}

return nil
Expand All @@ -101,14 +100,14 @@ func (tx *transaction) Rollback() (finalErr error) {
onDone(finalErr)
}()
if err := tx.checkTxState(); err != nil {
return badconn.Map(xerrors.WithStackTrace(err))
return xerrors.WithStackTrace(err)
}
defer func() {
tx.conn.currentTx = nil
}()
err := tx.tx.Rollback(tx.ctx)
if err != nil {
return badconn.Map(xerrors.WithStackTrace(err))
return xerrors.WithStackTrace(err)
}

return err
Expand All @@ -133,7 +132,7 @@ func (tx *transaction) QueryContext(ctx context.Context, query string, args []dr
query, options.WithParameters(&parameters),
)
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
return nil, xerrors.WithStackTrace(err)
}

return &rows{
Expand Down Expand Up @@ -161,7 +160,7 @@ func (tx *transaction) ExecContext(ctx context.Context, query string, args []dri
query, options.WithParameters(&parameters),
)
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
return nil, xerrors.WithStackTrace(err)
}

return resultNoRows{}, nil
Expand All @@ -176,7 +175,7 @@ func (tx *transaction) PrepareContext(ctx context.Context, query string) (_ driv
onDone(finalErr)
}()
if !tx.conn.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
return nil, xerrors.WithStackTrace(errNotReadyConn)
}

return &stmt{
Expand Down

0 comments on commit b7e83f1

Please sign in to comment.