Skip to content

Commit 64337c2

Browse files
committed
## 3.13.0
* Refactored `Connection` interface * Removed `CustomOption` and taking client with custom options * Removed `proxy` package * Improved `db.With()` helper for create child connections
1 parent d2a873e commit 64337c2

File tree

17 files changed

+199
-670
lines changed

17 files changed

+199
-670
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 3.13.0
2+
* Refactored `Connection` interface
3+
* Removed `CustomOption` and taking client with custom options
4+
* Removed `proxy` package
5+
* Improved `db.With()` helper for create child connections
6+
17
## 3.12.1
28
* Added `trace.Driver.OnConnPark` event
39
* Added `trace.Driver.OnConnClose` event

connection.go

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
2020
"github.com/ydb-platform/ydb-go-sdk/v3/internal/lazy"
2121
"github.com/ydb-platform/ydb-go-sdk/v3/internal/logger"
22-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/proxy"
2322
"github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter"
2423
ratelimiterConfig "github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter/config"
2524
"github.com/ydb-platform/ydb-go-sdk/v3/scheme"
@@ -38,42 +37,32 @@ type Connection interface {
3837
db.ConnectionInfo
3938
grpc.ClientConnInterface
4039

41-
// Table returns table client with options from Connection instance.
42-
// Options provide options replacement for requested table client
43-
// such as database and access token
44-
Table(opts ...CustomOption) table.Client
40+
// Table returns table client
41+
Table() table.Client
4542

46-
// Scheme returns scheme client with options from Connection instance.
47-
// Options provide options replacement for requested scheme client
48-
// such as database and access token
49-
Scheme(opts ...CustomOption) scheme.Client
43+
// Scheme returns scheme client
44+
Scheme() scheme.Client
5045

51-
// Coordination returns coordination client with options from Connection instance.
52-
// Options provide options replacement for requested coordination client
53-
// such as database and access token
54-
Coordination(opts ...CustomOption) coordination.Client
46+
// Coordination returns coordination client
47+
Coordination() coordination.Client
5548

56-
// Ratelimiter returns rate limiter client with options from Connection instance.
57-
// Options provide options replacement for requested rate limiter client
58-
// such as database and access token
59-
Ratelimiter(opts ...CustomOption) ratelimiter.Client
49+
// Ratelimiter returns rate limiter client
50+
Ratelimiter() ratelimiter.Client
6051

61-
// Discovery returns discovery client with options from Connection instance.
62-
// Options provide options replacement for requested discovery client
63-
// such as database and access token
64-
Discovery(opts ...CustomOption) discovery.Client
52+
// Discovery returns discovery client
53+
Discovery() discovery.Client
6554

66-
// Scripting returns scripting client with options from Connection instance.
67-
// Options provide options replacement for requested scripting client
68-
// such as database and access token
69-
Scripting(opts ...CustomOption) scripting.Client
55+
// Scripting returns scripting client
56+
Scripting() scripting.Client
7057

7158
// With returns Connection specified with custom options
7259
// Options provide options replacement for all clients taked from new Connection
73-
With(opts ...CustomOption) Connection
60+
With(ctx context.Context, opts ...Option) (Connection, error)
7461
}
7562

7663
type connection struct {
64+
opts []Option
65+
7766
config config.Config
7867
options []config.Option
7968

@@ -96,37 +85,65 @@ type connection struct {
9685

9786
mtx sync.Mutex
9887
db db.Connection
99-
}
10088

101-
func (c *connection) With(opts ...CustomOption) Connection {
102-
return newProxy(c, newMeta(c.config.Meta(), opts...))
89+
children map[uint64]Connection
90+
childrenMtx sync.Mutex
91+
onClose []func(c *connection)
10392
}
10493

10594
func (c *connection) Close(ctx context.Context) error {
10695
c.mtx.Lock()
10796
defer c.mtx.Unlock()
108-
var issues []error
97+
98+
var (
99+
issues []error
100+
children = make([]Connection, 0, len(c.children))
101+
)
102+
103+
c.childrenMtx.Lock()
104+
for _, child := range c.children {
105+
children = append(children, child)
106+
}
107+
c.childrenMtx.Unlock()
108+
109+
for _, child := range children {
110+
if err := child.Close(ctx); err != nil {
111+
issues = append(issues, err)
112+
}
113+
}
114+
109115
if err := c.ratelimiter.Close(ctx); err != nil {
110116
issues = append(issues, err)
111117
}
118+
112119
if err := c.coordination.Close(ctx); err != nil {
113120
issues = append(issues, err)
114121
}
122+
115123
if err := c.scheme.Close(ctx); err != nil {
116124
issues = append(issues, err)
117125
}
126+
118127
if err := c.table.Close(ctx); err != nil {
119128
issues = append(issues, err)
120129
}
130+
121131
if err := c.scripting.Close(ctx); err != nil {
122132
issues = append(issues, err)
123133
}
134+
124135
if err := c.db.Close(ctx); err != nil {
125136
issues = append(issues, err)
126137
}
138+
127139
if len(issues) > 0 {
128140
return errors.NewWithIssues("close failed", issues...)
129141
}
142+
143+
for _, f := range c.onClose {
144+
f(c)
145+
}
146+
130147
return nil
131148
}
132149

@@ -172,51 +189,36 @@ func (c *connection) Secure() bool {
172189
return c.config.Secure()
173190
}
174191

175-
func (c *connection) Table(opts ...CustomOption) table.Client {
176-
if len(opts) == 0 {
177-
return c.table
178-
}
179-
return proxy.Table(c.table, newMeta(c.config.Meta(), opts...))
192+
func (c *connection) Table() table.Client {
193+
return c.table
180194
}
181195

182-
func (c *connection) Scheme(opts ...CustomOption) scheme.Client {
183-
if len(opts) == 0 {
184-
return c.scheme
185-
}
186-
return proxy.Scheme(c.scheme, newMeta(c.config.Meta(), opts...))
196+
func (c *connection) Scheme() scheme.Client {
197+
return c.scheme
187198
}
188199

189-
func (c *connection) Coordination(opts ...CustomOption) coordination.Client {
190-
if len(opts) == 0 {
191-
return c.coordination
192-
}
193-
return proxy.Coordination(c.coordination, newMeta(c.config.Meta(), opts...))
200+
func (c *connection) Coordination() coordination.Client {
201+
return c.coordination
194202
}
195203

196-
func (c *connection) Ratelimiter(opts ...CustomOption) ratelimiter.Client {
197-
if len(opts) == 0 {
198-
return c.ratelimiter
199-
}
200-
return proxy.Ratelimiter(c.ratelimiter, newMeta(c.config.Meta(), opts...))
204+
func (c *connection) Ratelimiter() ratelimiter.Client {
205+
return c.ratelimiter
201206
}
202207

203-
func (c *connection) Discovery(opts ...CustomOption) discovery.Client {
204-
if len(opts) == 0 {
205-
return c.db.Discovery()
206-
}
207-
return proxy.Discovery(c.db.Discovery(), newMeta(c.config.Meta(), opts...))
208+
func (c *connection) Discovery() discovery.Client {
209+
return c.db.Discovery()
208210
}
209211

210-
func (c *connection) Scripting(opts ...CustomOption) scripting.Client {
211-
if len(opts) == 0 {
212-
return c.scripting
213-
}
214-
return proxy.Scripting(c.scripting, newMeta(c.config.Meta(), opts...))
212+
func (c *connection) Scripting() scripting.Client {
213+
return c.scripting
215214
}
216215

217216
// New connects to name and return name runtime holder
218217
func New(ctx context.Context, opts ...Option) (_ Connection, err error) {
219-
c := &connection{}
218+
c := &connection{
219+
opts: opts,
220+
children: make(map[uint64]Connection),
221+
}
220222
if caFile, has := os.LookupEnv("YDB_SSL_ROOT_CERTIFICATES_FILE"); has {
221223
opts = append([]Option{WithCertificatesFromFile(caFile)}, opts...)
222224
}

custom_options.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

internal/balancer/single/single.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type single struct {
1515
}
1616

1717
func (b *single) Create() balancer.Balancer {
18-
return &single{conn: b.conn}
18+
return &single{}
1919
}
2020

2121
func (b *single) Next() conn.Conn {

internal/meta/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package meta
22

33
const (
4-
Version = "ydb-go-sdk/3.12.1"
4+
Version = "ydb-go-sdk/3.13.0"
55
)

internal/proxy/coordiantion.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

internal/proxy/discovery.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)