Skip to content

Commit

Permalink
fixed linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Oct 31, 2024
1 parent 5eeebb7 commit 5212602
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 47 deletions.
2 changes: 1 addition & 1 deletion internal/query/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type (
Rollback() error
}
conn struct {
ctx context.Context
ctx context.Context //nolint:containedctx
parent Parent
trace *trace.DatabaseSQL
traceRetry *trace.Retry
Expand Down
4 changes: 1 addition & 3 deletions internal/query/conn/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ package conn

import "errors"

var (
errConnClosedEarly = errors.New("conn closed early")
)
var errConnClosedEarly = errors.New("conn closed early")
13 changes: 6 additions & 7 deletions internal/table/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var (
)

func New(ctx context.Context, parent Parent, opts ...Option) (*conn, error) {
s, err := parent.Table().CreateSession(ctx)
s, err := parent.Table().CreateSession(ctx) //nolint:staticcheck
if err != nil {
return nil, xerrors.WithStackTrace(err)
}
Expand Down Expand Up @@ -471,12 +471,11 @@ func (c *conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (_ drive
}()

if c.currentTx != nil {
return nil, xerrors.WithStackTrace(
xerrors.Retryable(
&ConnAlreadyHaveTxError{
currentTx: c.currentTx.ID(),
},
xerrors.InvalidObject(),
return nil, badconn.Map(
xerrors.WithStackTrace(
fmt.Errorf("broken conn state: conn=%q already have current tx=%q",
c.ID(), c.currentTx.ID(),
),
),
)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/table/conn/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ var (
errNotReadyConn = xerrors.Retryable(errors.New("conn not ready"), xerrors.InvalidObject())
)

type ConnAlreadyHaveTxError struct {
type AlreadyHaveTxError struct {
currentTx string
}

func (err *ConnAlreadyHaveTxError) Error() string {
func (err *AlreadyHaveTxError) Error() string {
return "conn already have an open currentTx: " + err.currentTx
}

func (err *ConnAlreadyHaveTxError) As(target interface{}) bool {
func (err *AlreadyHaveTxError) As(target interface{}) bool {
switch t := target.(type) {
case *ConnAlreadyHaveTxError:
case *AlreadyHaveTxError:
t.currentTx = err.currentTx

return true
Expand Down
12 changes: 1 addition & 11 deletions internal/table/conn/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ var (
)

func beginTx(ctx context.Context, c *conn, txOptions driver.TxOptions) (currentTx, error) {
if c.currentTx != nil {
return nil, badconn.Map(
xerrors.WithStackTrace(
fmt.Errorf("broken conn state: conn=%q already have current tx=%q",
c.ID(), c.currentTx.ID(),
),
),
)
}
txc, err := isolation.ToYDB(txOptions)
if err != nil {
return nil, xerrors.WithStackTrace(err)
Expand All @@ -47,14 +38,13 @@ func beginTx(ctx context.Context, c *conn, txOptions driver.TxOptions) (currentT
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
}

return &transaction{
Identifier: tx.ID(nativeTx.ID()),
conn: c,
ctx: ctx,
tx: nativeTx,
}, nil

return c.currentTx, nil
}

func (tx *transaction) checkTxState() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/table/conn/tx_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
_ tx.Identifier = &txFake{}
)

func beginTxFake(ctx context.Context, c *conn, txOptions driver.TxOptions) (currentTx, error) {
func beginTxFake(ctx context.Context, c *conn, _ driver.TxOptions) (currentTx, error) {
return &txFake{
Identifier: tx.ID("FAKE"),
conn: c,
Expand Down
2 changes: 1 addition & 1 deletion internal/xsql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (c *connWrapper) IsColumnExists(ctx context.Context, tableName, columnName

func (c *connWrapper) IsTableExists(ctx context.Context, tableName string) (tableExists bool, finalErr error) {
tableName = c.normalizePath(tableName)
onDone := trace.DatabaseSQLOnConnIsTableExists(c.connector.traceSql, &ctx,
onDone := trace.DatabaseSQLOnConnIsTableExists(c.connector.trace, &ctx,
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.(*connWrapper).IsTableExists"),
tableName,
)
Expand Down
17 changes: 8 additions & 9 deletions internal/xsql/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type (
idleThreshold time.Duration
conns xsync.Map[uuid.UUID, *connWrapper]
done chan struct{}
traceSql *trace.DatabaseSQL
trace *trace.DatabaseSQL
traceRetry *trace.Retry
retryBudget budget.Budget
}
Expand Down Expand Up @@ -80,18 +80,17 @@ func (c *Connector) Scheme() scheme.Client {
}

const (
queryProcessor_QueryService = iota + 1
queryProcessor_TableService
QUERY_SERVICE = iota + 1 //nolint:revive,stylecheck
TABLE_SERVICE //nolint:revive,stylecheck
)

func (c *Connector) Open(name string) (driver.Conn, error) {
//TODO implement me
panic("implement me")
return nil, xerrors.WithStackTrace(driver.ErrSkip)
}

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error) {
switch c.queryProcessor {
case queryProcessor_QueryService:
case QUERY_SERVICE:
id := uuid.New()
cc, err := querySql.New(ctx, c, append(
c.queryOpts,
Expand All @@ -114,7 +113,7 @@ func (c *Connector) Connect(ctx context.Context) (driver.Conn, error) {

return conn, nil

case queryProcessor_TableService:
case TABLE_SERVICE:
id := uuid.New()
cc, err := tableSql.New(ctx, c, append(
c.tableOpts,
Expand Down Expand Up @@ -168,10 +167,10 @@ func Open(parent ydbDriver, balancer grpc.ClientConnInterface, opts ...Option) (
c := &Connector{
parent: parent,
balancer: balancer,
queryProcessor: queryProcessor_TableService,
queryProcessor: TABLE_SERVICE,
clock: clockwork.NewRealClock(),
done: make(chan struct{}),
traceSql: &trace.DatabaseSQL{},
trace: &trace.DatabaseSQL{},
traceRetry: &trace.Retry{},
}

Expand Down
1 change: 0 additions & 1 deletion internal/xsql/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

var (
ErrUnsupported = driver.ErrSkip
errDeprecated = driver.ErrSkip
errAlreadyClosed = errors.New("already closed")
errWrongQueryProcessor = errors.New("wrong query processor")
)
12 changes: 6 additions & 6 deletions internal/xsql/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type (
tableOps []tableSql.Option
queryOpts []querySql.Option
}
traceDatabaseSqlOption struct {
traceDatabaseSQLOption struct {
t *trace.DatabaseSQL
opts []trace.DatabaseSQLComposeOption
}
Expand Down Expand Up @@ -81,8 +81,8 @@ func (disableServerBalancerOption) Apply(c *Connector) error {
return nil
}

func (opt traceDatabaseSqlOption) Apply(c *Connector) error {
c.traceSql = c.traceSql.Compose(opt.t, opt.opts...)
func (opt traceDatabaseSQLOption) Apply(c *Connector) error {
c.trace = c.trace.Compose(opt.t, opt.opts...)
c.tableOpts = append(c.tableOpts, tableSql.WithTrace(opt.t, opt.opts...))
c.queryOpts = append(c.queryOpts, querySql.WithTrace(opt.t, opt.opts...))

Expand All @@ -100,7 +100,7 @@ func WithTrace(
t *trace.DatabaseSQL, //nolint:gocritic
opts ...trace.DatabaseSQLComposeOption,
) Option {
return traceDatabaseSqlOption{
return traceDatabaseSQLOption{
t: t,
opts: opts,
}
Expand Down Expand Up @@ -173,9 +173,9 @@ func WithQueryOptions(opts ...querySql.Option) Option {
}

func OverQueryService() Option {
return queryProcessorOption(queryProcessor_QueryService)
return queryProcessorOption(QUERY_SERVICE)
}

func OverTableService() Option {
return queryProcessorOption(queryProcessor_TableService)
return queryProcessorOption(TABLE_SERVICE)
}
5 changes: 4 additions & 1 deletion sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ func WithDefaultScanQueryOptions(opts ...options.ExecuteScanQueryOption) Connect
return xsql.WithTableOptions(tableSql.WithScanOpts(opts...))
}

func overQueryService() ConnectorOption {
// overQueryService is an option for switch database/sql driver implementation from default to over query service
//
// TODO: Make public when ready
func overQueryService() ConnectorOption { //nolint:unused
return xsql.OverQueryService()
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ydb-platform/ydb-go-sdk/v3"
sql2 "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn"
tableSql "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
"github.com/ydb-platform/ydb-go-sdk/v3/table"
"github.com/ydb-platform/ydb-go-sdk/v3/table/result/indexed"
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestNoEffectsIfForgetCommitTx(t *testing.T) {
// check row for NO write
var (
value string
connAlreadyHaveTxError *sql2.ConnAlreadyHaveTxError
connAlreadyHaveTxError *tableSql.AlreadyHaveTxError
)
err = db.QueryRowContext(ctx, `SELECT val FROM table WHERE id = $1`, id).Scan(&value)
require.ErrorIs(t, err, sql.ErrNoRows)
Expand Down

0 comments on commit 5212602

Please sign in to comment.