Skip to content

Commit 95d08c8

Browse files
authored
Merge pull request #139 from ydb-platform/optout-dont-map-invoke-operation
no wrapping non-success operation results for use Connection as grpc.ClientConnInterface
2 parents 8060252 + c802397 commit 95d08c8

File tree

17 files changed

+586
-233
lines changed

17 files changed

+586
-233
lines changed

.github/workflows/tests.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,46 @@ jobs:
173173
with:
174174
file: ./scripting.txt
175175
flags: scripting,e2e,integration,${{ matrix.os }},${{ matrix.go-version }}
176-
name: scripting
176+
name: scripting
177+
connection:
178+
strategy:
179+
matrix:
180+
go-version: [1.17.x]
181+
os: [ubuntu-latest]
182+
services:
183+
ydb:
184+
image: cr.yandex/yc/yandex-docker-local-ydb:latest
185+
ports:
186+
- 2135:2135
187+
- 8765:8765
188+
volumes:
189+
- /tmp/ydb_certs:/ydb_certs
190+
env:
191+
YDB_LOCAL_SURVIVE_RESTART: true
192+
YDB_USE_IN_MEMORY_PDISKS: true
193+
options: '-h localhost'
194+
env:
195+
OS: ${{ matrix.os }}
196+
GO: ${{ matrix.go-version }}
197+
YDB_CONNECTION_STRING: grpcs://localhost:2135/?database=/local
198+
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
199+
YDB_ANONYMOUS_CREDENTIALS: 1
200+
runs-on: ${{ matrix.os }}
201+
steps:
202+
- name: Install Go
203+
uses: actions/setup-go@v2
204+
with:
205+
go-version: ${{ matrix.go-version }}
206+
- name: Checkout code
207+
uses: actions/checkout@v2
208+
- name: Test
209+
run: go test -race -coverpkg=./... -coverprofile connection.txt -covermode atomic ./test/connection_test.go
210+
- name: Clear report
211+
run: sed -i '/testutil\|trace\|test/d' connection.txt
212+
shell: bash
213+
- name: Upload coverage to Codecov
214+
uses: codecov/codecov-action@v2
215+
with:
216+
file: ./connection.txt
217+
flags: connection,e2e,integration,${{ matrix.os }},${{ matrix.go-version }}
218+
name: connection

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Added removing `conn.Conn` from `conn.Pool` on `conn.Conn.Close()` call
88
* Checked cluster close/empty on keeper goroutine
99
* Fixed `internal.errors.New` wrapping depth
10+
* Added context flag for no wrapping operation results as error
11+
* Refactored `trace.Driver` conn events
1012

1113
## 3.11.7
1214
* Removed internal alias-type `errors.IssuesIterator`

connection.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
discoveryConfig "github.com/ydb-platform/ydb-go-sdk/v3/discovery/config"
1515
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/single"
1616
"github.com/ydb-platform/ydb-go-sdk/v3/internal/closer"
17+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
1718
"github.com/ydb-platform/ydb-go-sdk/v3/internal/db"
1819
"github.com/ydb-platform/ydb-go-sdk/v3/internal/errors"
1920
"github.com/ydb-platform/ydb-go-sdk/v3/internal/lazy"
@@ -136,11 +137,13 @@ func (c *connection) Invoke(
136137
reply interface{},
137138
opts ...grpc.CallOption,
138139
) (err error) {
139-
err = c.db.Invoke(ctx, method, args, reply, opts...)
140-
if err != nil {
141-
err = errors.Errorf(0, "invoke failed: %w", err)
142-
}
143-
return err
140+
return c.db.Invoke(
141+
conn.WithoutWrapping(ctx),
142+
method,
143+
args,
144+
reply,
145+
opts...,
146+
)
144147
}
145148

146149
func (c *connection) NewStream(
@@ -149,7 +152,12 @@ func (c *connection) NewStream(
149152
method string,
150153
opts ...grpc.CallOption,
151154
) (grpc.ClientStream, error) {
152-
return c.db.NewStream(ctx, desc, method, opts...)
155+
return c.db.NewStream(
156+
conn.WithoutWrapping(ctx),
157+
desc,
158+
method,
159+
opts...,
160+
)
153161
}
154162

155163
func (c *connection) Endpoint() string {

internal/balancer/stub/stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func Balancer() (*list.List, balancer.Balancer) {
4444
},
4545
OnPessimize: func(ctx context.Context, x balancer.Element) error {
4646
e := x.(*list.Element)
47-
e.Conn.SetState(ctx, conn.Banned)
47+
e.Conn.SetState(conn.Banned)
4848
return nil
4949
},
5050
OnContains: func(x balancer.Element) bool {

internal/balancer/test/balancer_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package test
22

33
import (
4-
"context"
54
"net"
65
"strconv"
76
"testing"
@@ -469,8 +468,6 @@ var testData = [...]struct {
469468
func TestRoundRobin(t *testing.T) {
470469
for _, test := range testData {
471470
t.Run(test.name, func(t *testing.T) {
472-
ctx, cancel := context.WithCancel(context.Background())
473-
defer cancel()
474471
var (
475472
mconn = map[conn.Conn]string{} // Conn to addr mapping for easy matching.
476473
maddr = map[string]conn.Conn{} // addr to Conn mapping.
@@ -486,10 +483,10 @@ func TestRoundRobin(t *testing.T) {
486483
config.WithEndpoint("test"),
487484
),
488485
)
489-
c.SetState(ctx, conn.Online)
486+
c.SetState(conn.Online)
490487
if test.banned != nil {
491488
if _, ok := test.banned[e.Address()]; ok {
492-
c.SetState(ctx, conn.Banned)
489+
c.SetState(conn.Banned)
493490
}
494491
}
495492
mconn[c] = e.Address()
@@ -529,8 +526,6 @@ func TestRandomChoice(t *testing.T) {
529526
multiplier := 100
530527
for _, test := range testData {
531528
t.Run(test.name, func(t *testing.T) {
532-
ctx, cancel := context.WithCancel(context.Background())
533-
defer cancel()
534529
var (
535530
mconn = map[conn.Conn]string{} // Conn to addr mapping for easy matching.
536531
maddr = map[string]conn.Conn{} // addr to Conn mapping.
@@ -543,9 +538,9 @@ func TestRandomChoice(t *testing.T) {
543538
e,
544539
config.New(),
545540
)
546-
c.SetState(ctx, conn.Online)
541+
c.SetState(conn.Online)
547542
if _, ok := test.banned[e.Address()]; ok {
548-
c.SetState(ctx, conn.Banned)
543+
c.SetState(conn.Banned)
549544
}
550545
mconn[c] = e.Address()
551546
maddr[e.Address()] = c

internal/cluster/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func (c *cluster) Pessimize(ctx context.Context, e endpoint.Endpoint) (err error
385385
if !c.balancer.Contains(entry.Handle) {
386386
return errors.Errorf(0, "cluster: pessimize failed: %w", ErrUnknownBalancerElement)
387387
}
388-
entry.Conn.SetState(ctx, conn.Banned)
388+
entry.Conn.SetState(conn.Banned)
389389
if c.explorer != nil {
390390
// count ratio (banned/all)
391391
online := 0

0 commit comments

Comments
 (0)