Skip to content

Commit cfbe693

Browse files
committed
Fixed CHANGELOG.md + refactored retry.Retry
1 parent 69185dd commit cfbe693

File tree

12 files changed

+62
-55
lines changed

12 files changed

+62
-55
lines changed

CHANGELOG.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
## 3.10.0
2-
* Added `trace.Discovery`
3-
* Added `trace.Scripting` stub (will be implements in the future)
4-
* Added `trace.Scheme` stub (will be implements in the future)
5-
* Added `trace.Coordination` stub (will be implements in the future)
6-
* Added `trace.Ratelimiter` stub (will be implements in the future)
2+
* Extended `trace.Details` constants for support per-service events
3+
* Added `trace.Discovery` struct for traces discovery events
4+
* Added `trace.Ratelimiter`, `trace.Coordination`, `trace.Scripting`, `trace.Scheme` stubs (will be implements in the future)
5+
* Added `ratelimiter/config`, `coordination/config`, `scripting/config`, `scheme/config`, `discovery/config` packages for specify per-service configs
76
* Removed `trace.Driver.OnDiscovery` callback (moved to `trace.Discovery`)
8-
* Added `discovery/config` package for specify discovery config
9-
* Added `scheme/config` package for specify scheme config
10-
* Added `scripting/config` package for specify scripting config
11-
* Added `coordination/config` package for specify coordination config
12-
* Added `ratelimiter/config` package for specify ratelimiter config
137
* Refactored initialization step (firstly makes discovery client)
14-
* Refactored dns-balancing logic for grpc-go 1.43
8+
* Removed `internal/lazy.Discovery` (discovery client always initialized)
9+
* Fixed `trace.Table` event structs
10+
* Refactored grpc options for define dns-balancing configuration
11+
* Refactored `retry.Retry` signature (added `retry.WithID`, `retry.WithTrace` and `retry.WithIdempotent` opt-in args, required param `isIdempotentOperation` removed)
1512

1613
## 3.9.4
1714
* Fixed data race on closing session pool

internal/lazy/coordiantion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ func Coordination(db db.Connection, options []config.Option) coordination.Client
2828

2929
func (c *lazyCoordination) CreateNode(ctx context.Context, path string, config coordination.NodeConfig) (err error) {
3030
c.init()
31-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
31+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
3232
return c.client.CreateNode(ctx, path, config)
3333
})
3434
}
3535

3636
func (c *lazyCoordination) AlterNode(ctx context.Context, path string, config coordination.NodeConfig) (err error) {
3737
c.init()
38-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
38+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
3939
return c.client.AlterNode(ctx, path, config)
4040
})
4141
}
4242

4343
func (c *lazyCoordination) DropNode(ctx context.Context, path string) (err error) {
4444
c.init()
45-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
45+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
4646
return c.client.DropNode(ctx, path)
4747
})
4848
}
@@ -56,7 +56,7 @@ func (c *lazyCoordination) DescribeNode(
5656
err error,
5757
) {
5858
c.init()
59-
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
59+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
6060
entry, config, err = c.client.DescribeNode(ctx, path)
6161
return err
6262
})

internal/lazy/ratelimiter.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (r *lazyRatelimiter) CreateResource(
4343
resource ratelimiter.Resource,
4444
) (err error) {
4545
r.init()
46-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
46+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
4747
return r.client.CreateResource(ctx, coordinationNodePath, resource)
4848
})
4949
}
@@ -54,7 +54,7 @@ func (r *lazyRatelimiter) AlterResource(
5454
resource ratelimiter.Resource,
5555
) (err error) {
5656
r.init()
57-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
57+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
5858
return r.client.AlterResource(ctx, coordinationNodePath, resource)
5959
})
6060
}
@@ -65,7 +65,7 @@ func (r *lazyRatelimiter) DropResource(
6565
resourcePath string,
6666
) (err error) {
6767
r.init()
68-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
68+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
6969
return r.client.DropResource(ctx, coordinationNodePath, resourcePath)
7070
})
7171
}
@@ -77,7 +77,7 @@ func (r *lazyRatelimiter) ListResource(
7777
recursive bool,
7878
) (paths []string, err error) {
7979
r.init()
80-
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
80+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
8181
paths, err = r.client.ListResource(ctx, coordinationNodePath, resourcePath, recursive)
8282
return err
8383
})
@@ -90,7 +90,7 @@ func (r *lazyRatelimiter) DescribeResource(
9090
resourcePath string,
9191
) (resource *ratelimiter.Resource, err error) {
9292
r.init()
93-
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
93+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
9494
resource, err = r.client.DescribeResource(ctx, coordinationNodePath, resourcePath)
9595
return err
9696
})
@@ -105,7 +105,7 @@ func (r *lazyRatelimiter) AcquireResource(
105105
isUsedAmount bool,
106106
) (err error) {
107107
r.init()
108-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
108+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
109109
return r.client.AcquireResource(ctx, coordinationNodePath, resourcePath, amount, isUsedAmount)
110110
})
111111
}

internal/lazy/scheme.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (s *lazyScheme) ModifyPermissions(
3131
opts ...scheme.PermissionsOption,
3232
) (err error) {
3333
s.init()
34-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
34+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
3535
return s.client.ModifyPermissions(ctx, path, opts...)
3636
})
3737
}
@@ -58,32 +58,32 @@ func (s *lazyScheme) init() {
5858

5959
func (s *lazyScheme) DescribePath(ctx context.Context, path string) (e scheme.Entry, err error) {
6060
s.init()
61-
err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
61+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
6262
e, err = s.client.DescribePath(ctx, path)
6363
return err
64-
})
64+
}, retry.WithIdempotent())
6565
return e, err
6666
}
6767

6868
func (s *lazyScheme) MakeDirectory(ctx context.Context, path string) (err error) {
6969
s.init()
70-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
70+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
7171
return s.client.MakeDirectory(ctx, path)
7272
})
7373
}
7474

7575
func (s *lazyScheme) ListDirectory(ctx context.Context, path string) (d scheme.Directory, err error) {
7676
s.init()
77-
err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
77+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
7878
d, err = s.client.ListDirectory(ctx, path)
7979
return err
80-
})
80+
}, retry.WithIdempotent())
8181
return d, err
8282
}
8383

8484
func (s *lazyScheme) RemoveDirectory(ctx context.Context, path string) (err error) {
8585
s.init()
86-
return retry.Retry(ctx, false, func(ctx context.Context) (err error) {
86+
return retry.Retry(ctx, func(ctx context.Context) (err error) {
8787
return s.client.RemoveDirectory(ctx, path)
8888
})
8989
}

internal/lazy/scripting.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (s *lazyScripting) Execute(
2626
params *table.QueryParameters,
2727
) (res result.Result, err error) {
2828
s.init()
29-
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
29+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
3030
res, err = s.client.Execute(ctx, query, params)
3131
return err
3232
})
@@ -39,7 +39,7 @@ func (s *lazyScripting) Explain(
3939
mode scripting.ExplainMode,
4040
) (e table.ScriptingYQLExplanation, err error) {
4141
s.init()
42-
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
42+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
4343
e, err = s.client.Explain(ctx, query, mode)
4444
return err
4545
})
@@ -52,7 +52,7 @@ func (s *lazyScripting) StreamExecute(
5252
params *table.QueryParameters,
5353
) (res result.StreamResult, err error) {
5454
s.init()
55-
err = retry.Retry(ctx, false, func(ctx context.Context) (err error) {
55+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
5656
res, err = s.client.StreamExecute(ctx, query, params)
5757
return err
5858
})

internal/lazy/table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func Table(db db.Connection, options []config.Option) table.Client {
2727

2828
func (t *lazyTable) CreateSession(ctx context.Context) (s table.ClosableSession, err error) {
2929
t.init(ctx)
30-
err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
30+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
3131
s, err = t.client.CreateSession(ctx)
3232
return err
33-
})
33+
}, retry.WithIdempotent())
3434
return s, err
3535
}
3636

log/table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func Table(log Logger, details trace.Details) (t trace.Table) {
266266
t.OnSessionQueryStreamExecute = func(
267267
info trace.SessionQueryStreamExecuteStartInfo,
268268
) func(
269-
intermediateInfo trace.SessionQueryStreamExecuteIntermediateInfo,
269+
trace.SessionQueryStreamExecuteIntermediateInfo,
270270
) func(
271271
trace.SessionQueryStreamExecuteDoneInfo,
272272
) {

retry/retry.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ func RetryableError(err error, opts ...retryableErrorOption) error {
6262
}
6363

6464
type retryOptionsHolder struct {
65-
id string
66-
trace trace.Retry
65+
id string
66+
trace trace.Retry
67+
idempotent bool
6768
}
6869

6970
type retryOption func(h *retryOptionsHolder)
@@ -81,13 +82,20 @@ func WithTrace(trace trace.Retry) retryOption {
8182
}
8283
}
8384

85+
// WithIdempotent returns discovery trace option
86+
func WithIdempotent() retryOption {
87+
return func(h *retryOptionsHolder) {
88+
h.idempotent = true
89+
}
90+
}
91+
8492
// Retry provide the best effort fo retrying operation
8593
// Retry implements internal busy loop until one of the following conditions is met:
8694
// - deadline was canceled or deadlined
8795
// - retry operation returned nil as error
8896
// Warning: if deadline without deadline or cancellation func Retry will be worked infinite
89-
// If you need to retry your op func on some logic errors - you must returns from op func RetryableError()
90-
func Retry(ctx context.Context, isIdempotentOperation bool, op retryOperation, opts ...retryOption) (err error) {
97+
// If you need to retry your op func on some logic errors - you must return RetryableError() from retryOperation
98+
func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err error) {
9199
h := &retryOptionsHolder{
92100
trace: trace.ContextRetry(ctx),
93101
}
@@ -100,7 +108,7 @@ func Retry(ctx context.Context, isIdempotentOperation bool, op retryOperation, o
100108
attempts int
101109

102110
code = int32(0)
103-
onIntermediate = trace.RetryOnRetry(h.trace, ctx, h.id)
111+
onIntermediate = trace.RetryOnRetry(h.trace, ctx, h.id, h.idempotent)
104112
onDone func(attempts int, _ error)
105113
)
106114
defer func() {
@@ -126,7 +134,7 @@ func Retry(ctx context.Context, isIdempotentOperation bool, op retryOperation, o
126134
if m.StatusCode() != code {
127135
i = 0
128136
}
129-
if !m.MustRetry(isIdempotentOperation) {
137+
if !m.MustRetry(h.idempotent) {
130138
return
131139
}
132140
if e := Wait(ctx, FastBackoff, SlowBackoff, m, i); e != nil {

sugar/sugar.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ func RemoveRecursive(ctx context.Context, db ydb.Connection, pathToRemove string
6969
list = func(i int, p string) error {
7070
var dir scheme.Directory
7171
var err error
72-
err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
72+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
7373
dir, err = db.Scheme().ListDirectory(ctx, p)
7474
return err
75-
})
75+
}, retry.WithIdempotent())
7676
var opErr *errors.OpError
7777
if errors.As(err, &opErr) && opErr.Reason == errors.StatusSchemeError {
7878
return nil
@@ -91,9 +91,9 @@ func RemoveRecursive(ctx context.Context, db ydb.Connection, pathToRemove string
9191
if err = list(i+1, pt); err != nil {
9292
return err
9393
}
94-
err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
94+
err = retry.Retry(ctx, func(ctx context.Context) (err error) {
9595
return db.Scheme().RemoveDirectory(ctx, pt)
96-
})
96+
}, retry.WithIdempotent())
9797
if err != nil {
9898
return err
9999
}

test/scripting_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestScripting(t *testing.T) {
5555
}
5656
}()
5757
// Execute
58-
if err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
58+
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
5959
res, err := db.Scripting().Execute(
6060
ctx,
6161
"SELECT 1+1",
@@ -87,11 +87,11 @@ func TestScripting(t *testing.T) {
8787
return fmt.Errorf("unexpected sum: %v", sum)
8888
}
8989
return res.Err()
90-
}); err != nil {
90+
}, retry.WithIdempotent()); err != nil {
9191
t.Fatalf("Execute failed: %v", err)
9292
}
9393
// StreamExecute
94-
if err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
94+
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
9595
res, err := db.Scripting().StreamExecute(
9696
ctx,
9797
"SELECT 1+1",
@@ -124,11 +124,11 @@ func TestScripting(t *testing.T) {
124124
return fmt.Errorf("unexpected sum: %v", sum)
125125
}
126126
return res.Err()
127-
}); err != nil {
127+
}, retry.WithIdempotent()); err != nil {
128128
t.Fatalf("StreamExecute failed: %v", err)
129129
}
130130
// ExplainPlan
131-
if err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
131+
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
132132
res, err := db.Scripting().Explain(
133133
ctx,
134134
"SELECT 1+1",
@@ -141,11 +141,11 @@ func TestScripting(t *testing.T) {
141141
return fmt.Errorf("empty plan")
142142
}
143143
return nil
144-
}); err != nil {
144+
}, retry.WithIdempotent()); err != nil {
145145
t.Fatalf("Explain failed: %v", err)
146146
}
147147
// ExplainValidate
148-
if err = retry.Retry(ctx, true, func(ctx context.Context) (err error) {
148+
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
149149
res, err := db.Scripting().Explain(
150150
ctx,
151151
"SELECT 1+1",
@@ -158,7 +158,7 @@ func TestScripting(t *testing.T) {
158158
return fmt.Errorf("unexpected parameter types")
159159
}
160160
return nil
161-
}); err != nil {
161+
}, retry.WithIdempotent()); err != nil {
162162
t.Fatalf("Explain failed: %v", err)
163163
}
164164
}

0 commit comments

Comments
 (0)