Skip to content

Commit f8925e5

Browse files
authored
Merge branch 'master' into remove-check-node-id
2 parents 249700d + f2e5b7b commit f8925e5

File tree

15 files changed

+54
-5
lines changed

15 files changed

+54
-5
lines changed

.golangci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ linters:
226226
- exhaustivestruct
227227
- exhaustruct
228228
- forbidigo
229-
- funlen
230229
- gochecknoglobals
231230
- gocognit
232231
- godot
@@ -304,7 +303,10 @@ issues:
304303
- path: examples
305304
linters:
306305
- gomnd
307-
306+
- funlen
307+
- path: tests
308+
linters:
309+
- funlen
308310
# Allow underscore and capital camel case for readability
309311
# Examples: Type_PRIMITIVE_TYPE_ID_UNSPECIFIED, Ydb_Discovery_V1, _voidValue
310312
- linters:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* Removed check the node is available for query and table service sessions
2+
* Refactored the `balancers.PreferLocations()' function - it is a clean/pure function
23

34
## v3.74.2
45
* Added description to scan errors with use query service client scanner

balancers/balancers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
88
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
9+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xslices"
910
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring"
1011
)
1112

@@ -91,6 +92,10 @@ func PreferLocations(balancer *balancerConfig.Config, locations ...string) *bala
9192
if len(locations) == 0 {
9293
panic("empty list of locations")
9394
}
95+
96+
// Prevent modify source locations
97+
locations = xslices.Clone(locations)
98+
9499
for i := range locations {
95100
locations[i] = strings.ToUpper(locations[i])
96101
}

driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func New(ctx context.Context, opts ...Option) (_ *Driver, err error) { //nolint:
306306
return d, nil
307307
}
308308

309-
//nolint:cyclop, nonamedreturns
309+
//nolint:cyclop, nonamedreturns, funlen
310310
func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, err error) {
311311
ctx, driverCtxCancel := xcontext.WithCancel(xcontext.ValueOnly(ctx))
312312
defer func() {

dsn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func UnregisterDsnParser(registrationID int) {
4343
dsnParsers[registrationID] = nil
4444
}
4545

46+
//nolint:funlen
4647
func parseConnectionString(dataSourceName string) (opts []Option, _ error) {
4748
info, err := dsn.Parse(dataSourceName)
4849
if err != nil {

internal/table/session.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,8 @@ func (s *session) ExecuteSchemeQuery(
922922
}
923923

924924
// DescribeTableOptions describes supported table options.
925+
//
926+
//nolint:funlen
925927
func (s *session) DescribeTableOptions(ctx context.Context) (
926928
desc options.TableOptionsDescription,
927929
err error,
@@ -1059,6 +1061,8 @@ func (s *session) DescribeTableOptions(ctx context.Context) (
10591061
// Note that given ctx controls the lifetime of the whole read, not only this
10601062
// StreamReadTable() call; that is, the time until returned result is closed
10611063
// via Close() call or fully drained by sequential NextResultSet() calls.
1064+
//
1065+
//nolint:funlen
10621066
func (s *session) StreamReadTable(
10631067
ctx context.Context,
10641068
path string,
@@ -1174,6 +1178,8 @@ func (s *session) ReadRows(
11741178
// Note that given ctx controls the lifetime of the whole read, not only this
11751179
// StreamExecuteScanQuery() call; that is, the time until returned result is closed
11761180
// via Close() call or fully drained by sequential NextResultSet() calls.
1181+
//
1182+
//nolint:funlen
11771183
func (s *session) StreamExecuteScanQuery(
11781184
ctx context.Context,
11791185
query string,

internal/value/value.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ func FloatValue(v float32) *floatValue {
788788

789789
type int8Value int8
790790

791+
//nolint:funlen
791792
func (v int8Value) castTo(dst interface{}) error {
792793
switch vv := dst.(type) {
793794
case *string:
@@ -964,6 +965,7 @@ func Int16Value(v int16) int16Value {
964965

965966
type int32Value int32
966967

968+
//nolint:funlen
967969
func (v int32Value) castTo(dst interface{}) error {
968970
switch vv := dst.(type) {
969971
case *string:

internal/xslices/clone.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build go1.21
2+
// +build go1.21
3+
4+
package xslices
5+
6+
import "slices"
7+
8+
// Clone returns a copy of the slice.
9+
// The elements are copied using assignment, so this is a shallow clone.
10+
func Clone[S ~[]E, E any](s S) S {
11+
return slices.Clone(s)
12+
}

internal/xslices/clone_1.20.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build !go1.21
2+
// +build !go1.21
3+
4+
package xslices
5+
6+
// Clone returns a copy of the slice.
7+
// The elements are copied using assignment, so this is a shallow clone.
8+
func Clone[S ~[]E, E any](s S) S {
9+
// Preserve nil in case it matters.
10+
if s == nil {
11+
return nil
12+
}
13+
return append(S([]E{}), s...)
14+
}

metrics/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
// driver makes driver with New publishing
12+
//
13+
//nolint:funlen
1214
func driver(config Config) (t trace.Driver) {
1315
config = config.WithSystem("driver")
1416
endpoints := config.WithSystem("balancer").GaugeVec("endpoints", "az")

0 commit comments

Comments
 (0)