Skip to content

Commit c69ae61

Browse files
authored
Merge pull request #174 from ydb-platform/revert-meta
* Rollback moving `meta.Meta` call to conn exclusively from `internal…
2 parents 5e09ccd + 59ddca9 commit c69ae61

File tree

8 files changed

+44
-23
lines changed

8 files changed

+44
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Rollback moving `meta.Meta` call to conn exclusively from `internal/db` and `internal/discovery`
2+
* Added `WithMeta()` discovery config option
3+
14
## v3.16.5
25
* Added `config.SharedPool()` setting and `config.WithSharedPool()` option
36
* Added management of shared pool flag on change dial timeout and credentials

connection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ func New(ctx context.Context, opts ...Option) (_ Connection, err error) {
282282
discoveryConfig.WithEndpoint(c.Endpoint()),
283283
discoveryConfig.WithDatabase(c.Name()),
284284
discoveryConfig.WithSecure(c.Secure()),
285+
discoveryConfig.WithMeta(c.config.Meta()),
285286
discoveryConfig.WithOperationTimeout(c.config.OperationTimeout()),
286287
discoveryConfig.WithOperationCancelAfter(c.config.OperationCancelAfter()),
287288
},

discovery/config/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"time"
55

6+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
67
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
78
)
89

@@ -41,12 +42,16 @@ type Config interface {
4142
// If Interval is zero then the DefaultInterval is used.
4243
// If Interval is negative, then no background discovery prepared.
4344
Interval() time.Duration
45+
46+
// Meta is an option which contains meta information about database connection
47+
Meta() meta.Meta
4448
}
4549

4650
type config struct {
4751
endpoint string
4852
database string
4953
secure bool
54+
meta meta.Meta
5055

5156
operationTimeout time.Duration
5257
operationCancelAfter time.Duration
@@ -55,6 +60,10 @@ type config struct {
5560
trace trace.Discovery
5661
}
5762

63+
func (c *config) Meta() meta.Meta {
64+
return c.meta
65+
}
66+
5867
func (c *config) OperationTimeout() time.Duration {
5968
return c.operationTimeout
6069
}
@@ -103,6 +112,12 @@ func WithSecure(ssl bool) Option {
103112
}
104113
}
105114

115+
func WithMeta(meta meta.Meta) Option {
116+
return func(c *config) {
117+
c.meta = meta
118+
}
119+
}
120+
106121
func WithTrace(trace trace.Discovery) Option {
107122
return func(c *config) {
108123
c.trace = c.trace.Compose(trace)

internal/conn/config.go

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

66
"google.golang.org/grpc"
77

8-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
98
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
109
)
1110

@@ -14,6 +13,5 @@ type Config interface {
1413
Trace() trace.Driver
1514
ConnectionTTL() time.Duration
1615
GrpcDialOptions() []grpc.DialOption
17-
Meta() meta.Meta
1816
UseDNSResolver() bool
1917
}

internal/conn/conn.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,6 @@ func (c *conn) invoke(
339339
)
340340
}
341341

342-
ctx, err = c.config.Meta().Meta(ctx)
343-
if err != nil {
344-
return errors.NewGrpcError(
345-
errors.WithStatus(grpcStatus.New(codes.Unavailable, "ydb driver conn apply meta failed")),
346-
errors.WithErr(err),
347-
)
348-
}
349-
350342
c.changeUsages(1)
351343
defer c.changeUsages(-1)
352344

@@ -356,6 +348,7 @@ func (c *conn) invoke(
356348
if s, ok := grpcStatus.FromError(err); ok {
357349
return errors.NewGrpcError(
358350
errors.WithStatus(s),
351+
errors.WithErr(errors.WithStackTrace(err)),
359352
)
360353
}
361354
return errors.WithStackTrace(err)
@@ -436,14 +429,6 @@ func (c *conn) newStream(
436429
)
437430
}
438431

439-
ctx, err = c.config.Meta().Meta(ctx)
440-
if err != nil {
441-
return nil, errors.NewGrpcError(
442-
errors.WithStatus(grpcStatus.New(codes.Unavailable, "ydb driver conn apply meta failed")),
443-
errors.WithErr(err),
444-
)
445-
}
446-
447432
c.changeStreamUsages(1)
448433
defer c.changeStreamUsages(-1)
449434

@@ -454,6 +439,7 @@ func (c *conn) newStream(
454439
if s, ok := grpcStatus.FromError(err); ok {
455440
return nil, errors.NewGrpcError(
456441
errors.WithStatus(s),
442+
errors.WithErr(errors.WithStackTrace(err)),
457443
)
458444
}
459445
return nil, errors.WithStackTrace(err)

internal/db/database.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func (db *database) Invoke(
120120
}
121121
}()
122122

123+
ctx, err = db.config.Meta().Meta(ctx)
124+
if err != nil {
125+
return errors.WithStackTrace(err)
126+
}
127+
123128
err = cc.Invoke(ctx, method, args, reply, opts...)
124129
if err != nil {
125130
return errors.WithStackTrace(err)
@@ -145,6 +150,11 @@ func (db *database) NewStream(
145150
}
146151
}()
147152

153+
ctx, err = db.config.Meta().Meta(ctx)
154+
if err != nil {
155+
return nil, errors.WithStackTrace(err)
156+
}
157+
148158
var client grpc.ClientStream
149159
client, err = cc.NewStream(ctx, desc, method, opts...)
150160
if err != nil {

internal/discovery/discovery.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ func (c *client) Discover(ctx context.Context) (endpoints []endpoint.Endpoint, e
137137
onDone(location, nodes, err)
138138
}()
139139

140+
ctx, err = c.config.Meta().Meta(ctx)
141+
if err != nil {
142+
return nil, errors.WithStackTrace(err)
143+
}
144+
140145
response, err = c.service.ListEndpoints(ctx, &request)
141146
if err != nil {
142147
return nil, errors.WithStackTrace(err)
@@ -180,6 +185,11 @@ func (c *client) WhoAmI(ctx context.Context) (whoAmI *discovery.WhoAmI, err erro
180185
}
181186
}()
182187

188+
ctx, err = c.config.Meta().Meta(ctx)
189+
if err != nil {
190+
return nil, errors.WithStackTrace(err)
191+
}
192+
183193
response, err = c.service.WhoAmI(ctx, &request)
184194
if err != nil {
185195
return nil, errors.WithStackTrace(err)

internal/errors/grpc.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package errors
22

33
import (
4-
"fmt"
5-
64
"google.golang.org/grpc/status"
75
)
86

@@ -14,11 +12,11 @@ type grpcError struct {
1412

1513
func (e *grpcError) isYdbError() {}
1614

17-
func (e *grpcError) Error() string {
15+
func (e *grpcError) Error() (s string) {
1816
if e.err != nil {
19-
return fmt.Sprintf("%s: %v", e.err, e.status.String())
17+
s += e.err.Error() + ": "
2018
}
21-
return e.status.String()
19+
return s + e.status.String()
2220
}
2321

2422
func (e *grpcError) Unwrap() error {

0 commit comments

Comments
 (0)