Skip to content

Commit

Permalink
Showing 71 changed files with 1,036 additions and 331 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -218,7 +218,6 @@ linters-settings:
linters:
enable-all: true
disable:
- containedctx
- contextcheck
- cyclop
- depguard
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## v3.66.0
* Added experimental package `retry/budget` for limit second and subsequent retry attempts
* Refactored internals for enabling `containedctx` linter
* Fixed the hanging semaphore issue on coordination session reconnect

## v3.65.3
* Fixed data race in `internal/conn.grpcClientStream`

## v3.65.2
* Fixed data race using `log.WithNames`

## v3.65.1
* Updated dependency `ydb-go-genproto`
* Added processing of `Ydb.StatusIds_EXTERNAL_ERROR` in `retry.Retry`
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import (
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
"github.com/ydb-platform/ydb-go-sdk/v3/retry/budget"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)

@@ -157,6 +158,13 @@ func WithTrace(t trace.Driver, opts ...trace.DriverComposeOption) Option { //nol
}
}

// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
func WithRetryBudget(b budget.Budget) Option {
return func(c *Config) {
config.SetRetryBudget(&c.Common, b)
}
}

func WithTraceRetry(t *trace.Retry, opts ...trace.RetryComposeOption) Option {
return func(c *Config) {
config.SetTraceRetry(&c.Common, t, opts...)
2 changes: 0 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
@@ -51,7 +51,6 @@ var _ Connection = (*Driver)(nil)

// Driver type provide access to YDB service clients
type Driver struct {
ctx context.Context // cancel while Driver.Close called.
ctxCancel context.CancelFunc

userInfo *dsn.UserInfo
@@ -311,7 +310,6 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e

d := &Driver{
children: make(map[uint64]*Driver),
ctx: ctx,
ctxCancel: driverCtxCancel,
}

6 changes: 3 additions & 3 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -53,10 +53,10 @@ require (
github.com/yandex-cloud/go-genproto v0.0.0-20220815090733-4c139c0154e2 // indirect
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca // indirect
github.com/ydb-platform/ydb-go-yc-metadata v0.5.4 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9 // indirect
11 changes: 6 additions & 5 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -1270,8 +1270,8 @@ golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -1401,8 +1401,9 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1552,8 +1553,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
4 changes: 2 additions & 2 deletions examples/topic/topicreader/topicreader_trace.go
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ func ExplicitPartitionStartStopHandler(ctx context.Context, db *ydb.Driver) {
) func(
trace.TopicReaderPartitionReadStartResponseDoneInfo,
) {
err := externalSystemLock(info.PartitionContext, info.Topic, info.PartitionID)
err := externalSystemLock(*info.PartitionContext, info.Topic, info.PartitionID)
if err != nil {
stopReader()
}
@@ -105,7 +105,7 @@ func PartitionStartStopHandlerAndOwnReadProgressStorage(ctx context.Context, db
) func(
trace.TopicReaderPartitionReadStartResponseDoneInfo,
) {
err := externalSystemLock(info.PartitionContext, info.Topic, info.PartitionID)
err := externalSystemLock(*info.PartitionContext, info.Topic, info.PartitionID)
if err != nil {
stopReader()
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ require (
github.com/google/uuid v1.3.0
github.com/jonboulle/clockwork v0.3.0
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240316140903-4a47abca1cca
golang.org/x/net v0.17.0
golang.org/x/net v0.23.0
golang.org/x/sync v0.3.0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/grpc v1.57.1
@@ -25,8 +25,8 @@ require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -84,8 +84,8 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -100,12 +100,12 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
2 changes: 1 addition & 1 deletion internal/background/worker.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ var (

// A Worker must not be copied after first use
type Worker struct {
ctx context.Context
ctx context.Context //nolint:containedctx
workers sync.WaitGroup
closeReason error
tasksCompleted empty.Chan
43 changes: 43 additions & 0 deletions internal/backoff/delay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package backoff

import (
"time"
)

type (
delayOptions struct {
fast Backoff
slow Backoff
}
delayOption func(o *delayOptions)
)

func WithFastBackoff(fast Backoff) delayOption {
return func(o *delayOptions) {
o.fast = fast
}
}

func WithSlowBackoff(slow Backoff) delayOption {
return func(o *delayOptions) {
o.slow = slow
}
}

func Delay(t Type, i int, opts ...delayOption) time.Duration {
optionsHolder := delayOptions{
fast: Fast,
slow: Slow,
}
for _, opt := range opts {
opt(&optionsHolder)
}
switch t {
case TypeFast:
return optionsHolder.fast.Delay(i)
case TypeSlow:
return optionsHolder.slow.Delay(i)
default:
return 0
}
}
92 changes: 92 additions & 0 deletions internal/backoff/delay_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package backoff

import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
)

func TestDelay(t *testing.T) {
for _, tt := range []struct {
name string
act time.Duration
exp time.Duration
}{
{
name: xtest.CurrentFileLine(),
act: Delay(TypeNoBackoff, 0),
exp: 0,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeNoBackoff, 1),
exp: 0,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeNoBackoff, 2),
exp: 0,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeFast, 0, WithFastBackoff(New(
WithSlotDuration(fastSlot),
WithCeiling(6),
WithJitterLimit(1),
))),
exp: 5 * time.Millisecond,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeFast, 1, WithFastBackoff(New(
WithSlotDuration(fastSlot),
WithCeiling(6),
WithJitterLimit(1),
))),
exp: 10 * time.Millisecond,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeFast, 3, WithFastBackoff(New(
WithSlotDuration(fastSlot),
WithCeiling(6),
WithJitterLimit(1),
))),
exp: 40 * time.Millisecond,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeSlow, 0, WithSlowBackoff(New(
WithSlotDuration(slowSlot),
WithCeiling(6),
WithJitterLimit(1),
))),
exp: time.Second,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeSlow, 1, WithSlowBackoff(New(
WithSlotDuration(slowSlot),
WithCeiling(6),
WithJitterLimit(1),
))),
exp: 2 * time.Second,
},
{
name: xtest.CurrentFileLine(),
act: Delay(TypeSlow, 3, WithSlowBackoff(New(
WithSlotDuration(slowSlot),
WithCeiling(6),
WithJitterLimit(1),
))),
exp: 8 * time.Second,
},
} {
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.exp, tt.act)
})
}
}
1 change: 1 addition & 0 deletions internal/balancer/balancer.go
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ func (b *Balancer) clusterDiscovery(ctx context.Context) (err error) {
},
retry.WithIdempotent(true),
retry.WithTrace(b.driverConfig.TraceRetry()),
retry.WithBudget(b.driverConfig.RetryBudget()),
)
}

16 changes: 16 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -3,14 +3,18 @@ package config
import (
"time"

"github.com/ydb-platform/ydb-go-sdk/v3/retry/budget"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)

var defaultRetryBudget = budget.Limited(-1)

type Common struct {
operationTimeout time.Duration
operationCancelAfter time.Duration
disableAutoRetry bool
traceRetry trace.Retry
retryBudget budget.Budget

panicCallback func(e interface{})
}
@@ -48,6 +52,14 @@ func (c *Common) TraceRetry() *trace.Retry {
return &c.traceRetry
}

func (c *Common) RetryBudget() budget.Budget {
if c.retryBudget == nil {
return defaultRetryBudget
}

return c.retryBudget
}

// SetOperationTimeout define the maximum amount of time a YDB server will process
// an operation. After timeout exceeds YDB will try to cancel operation and
// regardless of the cancellation appropriate error will be returned to
@@ -81,3 +93,7 @@ func SetAutoRetry(c *Common, autoRetry bool) {
func SetTraceRetry(c *Common, t *trace.Retry, opts ...trace.RetryComposeOption) {
c.traceRetry = *c.traceRetry.Compose(t, opts...)
}

func SetRetryBudget(c *Common, b budget.Budget) {
c.retryBudget = b
}
1 change: 0 additions & 1 deletion internal/conn/conn.go
Original file line number Diff line number Diff line change
@@ -462,7 +462,6 @@ func (c *conn) NewStream(

return &grpcClientStream{
ClientStream: s,
ctx: ctx,
c: c,
wrapping: useWrapping,
traceID: traceID,
Loading

0 comments on commit a056f81

Please sign in to comment.