Skip to content

Commit 5f83b53

Browse files
committed
Merge branch 'master' into param-builder-optional
2 parents a55bb2f + 9cd2f73 commit 5f83b53

File tree

110 files changed

+5106
-4522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+5106
-4522
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
go-version: "1.23.x"
6969
- name: Install utilities
7070
run: |
71-
go install mvdan.cc/gofumpt@v0.3.1
71+
go install mvdan.cc/gofumpt@v0.7.0
7272
go install github.com/daixiang0/[email protected]
7373
- name: format all files with auto-formatter
7474
run: bash ./.github/scripts/format-all-go-code.sh "$PWD"

.github/workflows/slo.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ jobs:
7373
workload_build_context4: ../..
7474
workload_build_options4: -f Dockerfile --build-arg SRC_PATH=native/query --build-arg JOB_NAME=workload-native-query
7575

76-
language_id5: 'native-query-with-pool'
77-
workload_path5: 'tests/slo'
78-
language5: 'Native ydb-go-sdk/v3 over query-service with session pool'
79-
workload_build_context5: ../..
80-
workload_build_options5: -f Dockerfile --build-arg SRC_PATH=native/query/with/pool --build-arg JOB_NAME=workload-native-query-with-pool
81-
8276
- uses: actions/upload-artifact@v4
8377
if: always()
8478
with:

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666
YDB_LOCAL_SURVIVE_RESTART: true
6767
YDB_USE_IN_MEMORY_PDISKS: true
6868
YDB_TABLE_ENABLE_PREPARED_DDL: true
69+
YDB_ENABLE_COLUMN_TABLES: true
6970
options: '-h localhost'
7071
env:
7172
OS: ubuntu-latest
@@ -119,6 +120,7 @@ jobs:
119120
YDB_USE_IN_MEMORY_PDISKS: true
120121
YDB_TABLE_ENABLE_PREPARED_DDL: true
121122
YDB_FEATURE_FLAGS: enable_topic_service_tx
123+
YDB_ENABLE_COLUMN_TABLES: true
122124
options: '-h localhost'
123125
env:
124126
OS: ubuntu-latest

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
## v3.80.8
2+
* Added `ydb.WithLazyTx(bool)` option for create lazy transactions on `query.Session.Begin` call
3+
* Added initial experimental topic and cdc-helpers, see examples in [tests/integration/topic_helpers_test.go](https://github.com/ydb-platform/ydb-go-sdk/blob/master/tests/integration/topic_helpers_test.go)
4+
* Added experimental `sugar.UnmarshalRows` for user unmarshaller structs in own code in go 1.23, change example for use the iterator.
5+
* Added `ydb_go_sdk_ydb_query_pool_size_index` metrics
6+
7+
## v3.80.7
8+
* Fixed bug with doesn't rollback the transaction on the operation error in table service
9+
10+
## v3.80.6
11+
* Fixed concurrent map writes in metrics
12+
* Renamed method at experimental API `reader.PopBatchTx` to `reader.PopMessagesBatchTx`
13+
14+
## v3.80.5
15+
* Fixed connections pool leak on failed `ydb.Open` call
16+
17+
## v3.80.4
18+
* Fixed panic on usage metrics package from prometheus adapter on `trace.Driver.OnNewStream` callback
19+
20+
## v3.80.3
21+
* Added option `ydb.WithSessionPoolSessionIdleTimeToLive` for restrict idle time of query sessions
22+
* Fixed bug with leak of query transactions
23+
* Changed `ydb_go_sdk_ydb_driver_conn_requests` metrics splitted to `ydb_go_sdk_ydb_driver_conn_request_statuses` and `ydb_go_sdk_ydb_driver_conn_request_methods`
24+
* Fixed metadata for operation service connection
25+
* Fixed composing query traces in call `db.Query.Do[Tx]` using option `query.WithTrace`
26+
27+
## v3.80.2
28+
* Added `balancers.PreferNearestDC[WithFallback]` balancers
29+
* Marked as deprecated `balancers.PreferLocalDC[WithFallback]` balancers because `local` word is ambiguous for balancer idea
30+
31+
## v3.80.1
32+
* Added `lastErr` from previous attempt in `retry.RetryWithResult`
33+
34+
## v3.80.0
35+
* Replaced internal table client pool entities to `internal/pool`
36+
37+
## v3.79.2
38+
* Enabled by default usage of `internal/pool` in `internal/query.Client`
39+
40+
## v3.79.1
41+
* Changed `trace.Table` and `trace.Query` traces
42+
* Implemented `internal/pool` the same as table client pool from `internal/table.Client`
43+
144
## v3.79.0
245
* Added commit messages for topic listener
346
* EOF error in RecvMsg is no longer logged

README.md

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,7 @@ if err != nil {
4242
log.Fatal(err)
4343
}
4444
```
45-
* execute `SELECT` query over `Table` service client
46-
```go
47-
// Do retry operation on errors with best effort
48-
err := db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
49-
_, res, err := s.Execute(ctx, table.DefaultTxControl(),
50-
`SELECT 42 as id, "myStr" as myStr;`,
51-
nil, // empty parameters
52-
)
53-
if err != nil {
54-
return err
55-
}
56-
defer res.Close()
57-
if err = res.NextResultSetErr(ctx); err != nil {
58-
return err
59-
}
60-
for res.NextRow() {
61-
var id int32
62-
var myStr string
63-
err = res.ScanNamed(named.Required("id", &id),named.OptionalWithDefault("myStr", &myStr))
64-
if err != nil {
65-
log.Fatal(err)
66-
}
67-
log.Printf("id=%v, myStr='%s'\n", id, myStr)
68-
}
69-
return res.Err() // for driver retry if not nil
70-
})
71-
if err != nil {
72-
log.Fatal(err)
73-
}
74-
```
75-
* execute `SELECT` query over `Query` service client
45+
* execute `SELECT` query with `Query` service client
7646
```go
7747
// Do retry operation on errors with best effort
7848
err := db.Query().Do( // Do retry operation on errors with best effort
@@ -149,6 +119,7 @@ Driver implements several ways for making credentials for `YDB`:
149119
- `ydb.WithAnonymousCredentials()` (enabled by default unless otherwise specified)
150120
- `ydb.WithAccessTokenCredentials("token")`
151121
- `ydb.WithStaticCredentials("user", "password")`,
122+
- `ydb.WithOauth2TokenExchangeCredentials()` and `ydb,WithOauth2TokenExchangeCredentialsFile(configFilePath)`
152123
- as part of connection string, like as `grpcs://user:password@endpoint/database`
153124

154125
Another variants of `credentials.Credentials` object provides with external packages:

balancers/balancers.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,41 @@ func (filterLocalDC) String() string {
3737
return "LocalDC"
3838
}
3939

40-
// PreferLocalDC creates balancer which use endpoints only in location such as initial endpoint location
41-
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
42-
// PreferLocalDC balancer try to autodetect local DC from client side.
40+
// Deprecated: use PreferNearestDC instead
41+
// Will be removed after March 2025.
42+
// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
4343
func PreferLocalDC(balancer *balancerConfig.Config) *balancerConfig.Config {
4444
balancer.Filter = filterLocalDC{}
45-
balancer.DetectLocalDC = true
45+
balancer.DetectNearestDC = true
4646

4747
return balancer
4848
}
4949

50-
// PreferLocalDCWithFallBack creates balancer which use endpoints only in location such as initial endpoint location
50+
// PreferNearestDC creates balancer which use endpoints only in location such as initial endpoint location
5151
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
52-
// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
52+
// PreferNearestDC balancer try to autodetect local DC from client side.
53+
func PreferNearestDC(balancer *balancerConfig.Config) *balancerConfig.Config {
54+
balancer.Filter = filterLocalDC{}
55+
balancer.DetectNearestDC = true
56+
57+
return balancer
58+
}
59+
60+
// Deprecated: use PreferNearestDCWithFallBack instead
61+
// Will be removed after March 2025.
62+
// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
5363
func PreferLocalDCWithFallBack(balancer *balancerConfig.Config) *balancerConfig.Config {
54-
balancer = PreferLocalDC(balancer)
64+
balancer = PreferNearestDC(balancer)
65+
balancer.AllowFallback = true
66+
67+
return balancer
68+
}
69+
70+
// PreferNearestDCWithFallBack creates balancer which use endpoints only in location such as initial endpoint location
71+
// Balancer "balancer" defines balancing algorithm between endpoints selected with filter by location
72+
// If filter returned zero endpoints from all discovery endpoints list - used all endpoint instead
73+
func PreferNearestDCWithFallBack(balancer *balancerConfig.Config) *balancerConfig.Config {
74+
balancer = PreferNearestDC(balancer)
5575
balancer.AllowFallback = true
5676

5777
return balancer

balancers/balancers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestPreferLocalDC(t *testing.T) {
1717
&mock.Conn{AddrField: "2", State: conn.Online, LocationField: "2"},
1818
&mock.Conn{AddrField: "3", State: conn.Online, LocationField: "2"},
1919
}
20-
rr := PreferLocalDC(RandomChoice())
20+
rr := PreferNearestDC(RandomChoice())
2121
require.False(t, rr.AllowFallback)
2222
require.Equal(t, []conn.Conn{conns[1], conns[2]}, applyPreferFilter(balancerConfig.Info{SelfLocation: "2"}, rr, conns))
2323
}
@@ -28,7 +28,7 @@ func TestPreferLocalDCWithFallBack(t *testing.T) {
2828
&mock.Conn{AddrField: "2", State: conn.Online, LocationField: "2"},
2929
&mock.Conn{AddrField: "3", State: conn.Online, LocationField: "2"},
3030
}
31-
rr := PreferLocalDCWithFallBack(RandomChoice())
31+
rr := PreferNearestDCWithFallBack(RandomChoice())
3232
require.True(t, rr.AllowFallback)
3333
require.Equal(t, []conn.Conn{conns[1], conns[2]}, applyPreferFilter(balancerConfig.Info{SelfLocation: "2"}, rr, conns))
3434
}

balancers/config.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ const (
2020
type preferType string
2121

2222
const (
23-
preferTypeLocalDC = preferType("local_dc")
23+
preferTypeNearestDC = preferType("nearest_dc")
2424
preferTypeLocations = preferType("locations")
25+
26+
// Deprecated
27+
// Will be removed after March 2025.
28+
// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
29+
preferTypeLocalDC = preferType("local_dc")
2530
)
2631

2732
type balancersConfig struct {
@@ -90,10 +95,16 @@ func CreateFromConfig(s string) (*balancerConfig.Config, error) {
9095
switch c.Prefer {
9196
case preferTypeLocalDC:
9297
if c.Fallback {
93-
return PreferLocalDCWithFallBack(b), nil
98+
return PreferNearestDCWithFallBack(b), nil
99+
}
100+
101+
return PreferNearestDC(b), nil
102+
case preferTypeNearestDC:
103+
if c.Fallback {
104+
return PreferNearestDCWithFallBack(b), nil
94105
}
95106

96-
return PreferLocalDC(b), nil
107+
return PreferNearestDC(b), nil
97108
case preferTypeLocations:
98109
if len(c.Locations) == 0 {
99110
return nil, xerrors.WithStackTrace(fmt.Errorf("empty locations list in balancer '%s' config", c.Type))

balancers/config_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,21 @@ func TestFromConfig(t *testing.T) {
7070
"prefer": "local_dc"
7171
}`,
7272
res: balancerConfig.Config{
73-
DetectLocalDC: true,
73+
DetectNearestDC: true,
74+
Filter: filterFunc(func(info balancerConfig.Info, e endpoint.Info) bool {
75+
// some non nil func
76+
return false
77+
}),
78+
},
79+
},
80+
{
81+
name: "prefer_nearest_dc",
82+
config: `{
83+
"type": "random_choice",
84+
"prefer": "nearest_dc"
85+
}`,
86+
res: balancerConfig.Config{
87+
DetectNearestDC: true,
7488
Filter: filterFunc(func(info balancerConfig.Info, e endpoint.Info) bool {
7589
// some non nil func
7690
return false
@@ -93,8 +107,24 @@ func TestFromConfig(t *testing.T) {
93107
"fallback": true
94108
}`,
95109
res: balancerConfig.Config{
96-
AllowFallback: true,
97-
DetectLocalDC: true,
110+
AllowFallback: true,
111+
DetectNearestDC: true,
112+
Filter: filterFunc(func(info balancerConfig.Info, e endpoint.Info) bool {
113+
// some non nil func
114+
return false
115+
}),
116+
},
117+
},
118+
{
119+
name: "prefer_nearest_dc_with_fallback",
120+
config: `{
121+
"type": "random_choice",
122+
"prefer": "nearest_dc",
123+
"fallback": true
124+
}`,
125+
res: balancerConfig.Config{
126+
AllowFallback: true,
127+
DetectNearestDC: true,
98128
Filter: filterFunc(func(info balancerConfig.Info, e endpoint.Info) bool {
99129
// some non nil func
100130
return false

driver.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ func Open(ctx context.Context, dsn string, opts ...Option) (_ *Driver, _ error)
274274
}()
275275

276276
if err = d.connect(ctx); err != nil {
277+
_ = d.pool.Release(ctx)
278+
277279
return nil, xerrors.WithStackTrace(err)
278280
}
279281

@@ -519,7 +521,7 @@ func (d *Driver) connect(ctx context.Context) (err error) {
519521

520522
d.operation = xsync.OnceValue(func() (*operation.Client, error) {
521523
return operation.New(xcontext.ValueOnly(ctx),
522-
d.pool.Get(endpoint.New(d.config.Endpoint())),
524+
d.balancer,
523525
), nil
524526
})
525527

0 commit comments

Comments
 (0)