Skip to content

Commit df87717

Browse files
committed
* Added ydb.WithDisableServerBalancer() database/sql connector option
1 parent aedbcae commit df87717

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Added `ydb.WithDisableServerBalancer()` database/sql connector option
2+
13
## v3.42.3
24
* Added `credentials.NewStaticCredentials()` static credentials constructor
35
* Changed `internal/credentials.NewStaticCredentials()` signature and behaviour for create grpc connection on each call to auth service

internal/xsql/connector.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ func WithTrace(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) Conn
5151
}
5252
}
5353

54+
func WithDisableServerBalancer() ConnectorOption {
55+
return func(c *Connector) error {
56+
c.disableServerBalancer = true
57+
return nil
58+
}
59+
}
60+
5461
func Open(d Driver, connection connection, opts ...ConnectorOption) (_ *Connector, err error) {
5562
c := &Connector{
5663
driver: d,
@@ -90,10 +97,11 @@ type Connector struct {
9097
driver Driver
9198
connection connection
9299

93-
defaultTxControl *table.TransactionControl
94-
defaultQueryMode QueryMode
95-
defaultDataQueryOpts []options.ExecuteDataQueryOption
96-
defaultScanQueryOpts []options.ExecuteScanQueryOption
100+
defaultTxControl *table.TransactionControl
101+
defaultQueryMode QueryMode
102+
defaultDataQueryOpts []options.ExecuteDataQueryOption
103+
defaultScanQueryOpts []options.ExecuteScanQueryOption
104+
disableServerBalancer bool
97105

98106
trace trace.DatabaseSQL
99107
}
@@ -117,11 +125,10 @@ func (c *Connector) Connect(ctx context.Context) (_ driver.Conn, err error) {
117125
defer func() {
118126
onDone(err)
119127
}()
120-
s, err := c.connection.Table().CreateSession( //nolint:staticcheck // SA1019
121-
meta.WithAllowFeatures(ctx,
122-
metaHeaders.HintSessionBalancer,
123-
),
124-
)
128+
if !c.disableServerBalancer {
129+
ctx = meta.WithAllowFeatures(ctx, metaHeaders.HintSessionBalancer)
130+
}
131+
s, err := c.connection.Table().CreateSession(ctx) //nolint:staticcheck // SA1019
125132
if err != nil {
126133
return nil, xerrors.WithStackTrace(err)
127134
}

sql.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ func WithDatabaseSQLTrace(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeO
117117
return xsql.WithTrace(t, opts...)
118118
}
119119

120+
func WithDisableServerBalancer() ConnectorOption {
121+
return xsql.WithDisableServerBalancer()
122+
}
123+
120124
func Connector(db Connection, opts ...ConnectorOption) (*xsql.Connector, error) {
121125
if c, ok := db.(*connection); ok {
122126
opts = append(opts, c.databaseSQLOptions...)

0 commit comments

Comments
 (0)