Skip to content

Commit 0f98551

Browse files
committed
add internal retryer's to lazy ratelimiter client
1 parent 55ed91d commit 0f98551

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

internal/lazy/ratelimiter.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/ydb-platform/ydb-go-sdk/v3/internal/db"
88
builder "github.com/ydb-platform/ydb-go-sdk/v3/internal/ratelimiter"
99
"github.com/ydb-platform/ydb-go-sdk/v3/ratelimiter"
10+
"github.com/ydb-platform/ydb-go-sdk/v3/retry"
1011
)
1112

1213
type lazyRatelimiter struct {
@@ -39,7 +40,9 @@ func (r *lazyRatelimiter) CreateResource(
3940
resource ratelimiter.Resource,
4041
) (err error) {
4142
r.init()
42-
return r.client.CreateResource(ctx, coordinationNodePath, resource)
43+
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
44+
return r.client.CreateResource(ctx, coordinationNodePath, resource)
45+
})
4346
}
4447

4548
func (r *lazyRatelimiter) AlterResource(
@@ -48,7 +51,9 @@ func (r *lazyRatelimiter) AlterResource(
4851
resource ratelimiter.Resource,
4952
) (err error) {
5053
r.init()
51-
return r.client.AlterResource(ctx, coordinationNodePath, resource)
54+
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
55+
return r.client.AlterResource(ctx, coordinationNodePath, resource)
56+
})
5257
}
5358

5459
func (r *lazyRatelimiter) DropResource(
@@ -57,26 +62,36 @@ func (r *lazyRatelimiter) DropResource(
5762
resourcePath string,
5863
) (err error) {
5964
r.init()
60-
return r.client.DropResource(ctx, coordinationNodePath, resourcePath)
65+
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
66+
return r.client.DropResource(ctx, coordinationNodePath, resourcePath)
67+
})
6168
}
6269

6370
func (r *lazyRatelimiter) ListResource(
6471
ctx context.Context,
6572
coordinationNodePath string,
6673
resourcePath string,
6774
recursive bool,
68-
) (_ []string, err error) {
75+
) (paths []string, err error) {
6976
r.init()
70-
return r.client.ListResource(ctx, coordinationNodePath, resourcePath, recursive)
77+
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
78+
paths, err = r.client.ListResource(ctx, coordinationNodePath, resourcePath, recursive)
79+
return err
80+
})
81+
return paths, err
7182
}
7283

7384
func (r *lazyRatelimiter) DescribeResource(
7485
ctx context.Context,
7586
coordinationNodePath string,
7687
resourcePath string,
77-
) (_ *ratelimiter.Resource, err error) {
88+
) (resource *ratelimiter.Resource, err error) {
7889
r.init()
79-
return r.client.DescribeResource(ctx, coordinationNodePath, resourcePath)
90+
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
91+
resource, err = r.client.DescribeResource(ctx, coordinationNodePath, resourcePath)
92+
return err
93+
})
94+
return resource, err
8095
}
8196

8297
func (r *lazyRatelimiter) AcquireResource(
@@ -87,7 +102,9 @@ func (r *lazyRatelimiter) AcquireResource(
87102
isUsedAmount bool,
88103
) (err error) {
89104
r.init()
90-
return r.client.AcquireResource(ctx, coordinationNodePath, resourcePath, amount, isUsedAmount)
105+
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
106+
return r.client.AcquireResource(ctx, coordinationNodePath, resourcePath, amount, isUsedAmount)
107+
})
91108
}
92109

93110
func (r *lazyRatelimiter) init() {

0 commit comments

Comments
 (0)