Skip to content

Commit 7b429f9

Browse files
authored
Merge pull request #18677 from serathius/context-remove-3
Remove context from appliers
2 parents 620a00b + 08d54bc commit 7b429f9

File tree

5 files changed

+43
-59
lines changed

5 files changed

+43
-59
lines changed

server/etcdserver/apply/apply.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ type applierV3 interface {
7070
// delegates the actual execution to the applyFunc method.
7171
Apply(r *pb.InternalRaftRequest, applyFunc applyFunc) *Result
7272

73-
Put(ctx context.Context, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error)
74-
Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error)
75-
DeleteRange(ctx context.Context, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error)
76-
Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error)
73+
Put(p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error)
74+
Range(r *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error)
75+
DeleteRange(dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error)
76+
Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error)
7777
Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, *traceutil.Trace, error)
7878

7979
LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error)
@@ -150,20 +150,20 @@ func (a *applierV3backend) Apply(r *pb.InternalRaftRequest, applyFunc applyFunc)
150150
return applyFunc(r)
151151
}
152152

153-
func (a *applierV3backend) Put(ctx context.Context, p *pb.PutRequest) (resp *pb.PutResponse, trace *traceutil.Trace, err error) {
154-
return mvcctxn.Put(ctx, a.lg, a.lessor, a.kv, p)
153+
func (a *applierV3backend) Put(p *pb.PutRequest) (resp *pb.PutResponse, trace *traceutil.Trace, err error) {
154+
return mvcctxn.Put(context.TODO(), a.lg, a.lessor, a.kv, p)
155155
}
156156

157-
func (a *applierV3backend) DeleteRange(ctx context.Context, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error) {
158-
return mvcctxn.DeleteRange(ctx, a.lg, a.kv, dr)
157+
func (a *applierV3backend) DeleteRange(dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error) {
158+
return mvcctxn.DeleteRange(context.TODO(), a.lg, a.kv, dr)
159159
}
160160

161-
func (a *applierV3backend) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error) {
162-
return mvcctxn.Range(ctx, a.lg, a.kv, r)
161+
func (a *applierV3backend) Range(r *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error) {
162+
return mvcctxn.Range(context.TODO(), a.lg, a.kv, r)
163163
}
164164

165-
func (a *applierV3backend) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
166-
return mvcctxn.Txn(ctx, a.lg, rt, a.txnModeWriteWithSharedBuffer, a.kv, a.lessor)
165+
func (a *applierV3backend) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
166+
return mvcctxn.Txn(context.TODO(), a.lg, rt, a.txnModeWriteWithSharedBuffer, a.kv, a.lessor)
167167
}
168168

169169
func (a *applierV3backend) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, *traceutil.Trace, error) {
@@ -248,15 +248,15 @@ type applierV3Capped struct {
248248
// with Puts so that the number of keys in the store is capped.
249249
func newApplierV3Capped(base applierV3) applierV3 { return &applierV3Capped{applierV3: base} }
250250

251-
func (a *applierV3Capped) Put(_ context.Context, _ *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
251+
func (a *applierV3Capped) Put(_ *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
252252
return nil, nil, errors.ErrNoSpace
253253
}
254254

255-
func (a *applierV3Capped) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
255+
func (a *applierV3Capped) Txn(r *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
256256
if a.q.Cost(r) > 0 {
257257
return nil, nil, errors.ErrNoSpace
258258
}
259-
return a.applierV3.Txn(ctx, r)
259+
return a.applierV3.Txn(r)
260260
}
261261

262262
func (a *applierV3Capped) LeaseGrant(_ *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) {
@@ -454,18 +454,18 @@ func newQuotaApplierV3(lg *zap.Logger, quotaBackendBytesCfg int64, be backend.Ba
454454
return &quotaApplierV3{app, serverstorage.NewBackendQuota(lg, quotaBackendBytesCfg, be, "v3-applier")}
455455
}
456456

457-
func (a *quotaApplierV3) Put(ctx context.Context, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
457+
func (a *quotaApplierV3) Put(p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
458458
ok := a.q.Available(p)
459-
resp, trace, err := a.applierV3.Put(ctx, p)
459+
resp, trace, err := a.applierV3.Put(p)
460460
if err == nil && !ok {
461461
err = errors.ErrNoSpace
462462
}
463463
return resp, trace, err
464464
}
465465

466-
func (a *quotaApplierV3) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
466+
func (a *quotaApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
467467
ok := a.q.Available(rt)
468-
resp, trace, err := a.applierV3.Txn(ctx, rt)
468+
resp, trace, err := a.applierV3.Txn(rt)
469469
if err == nil && !ok {
470470
err = errors.ErrNoSpace
471471
}

server/etcdserver/apply/apply_auth.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package apply
1616

1717
import (
18-
"context"
1918
"sync"
2019

2120
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
@@ -63,7 +62,7 @@ func (aa *authApplierV3) Apply(r *pb.InternalRaftRequest, applyFunc applyFunc) *
6362
return ret
6463
}
6564

66-
func (aa *authApplierV3) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
65+
func (aa *authApplierV3) Put(r *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
6766
if err := aa.as.IsPutPermitted(&aa.authInfo, r.Key); err != nil {
6867
return nil, nil, err
6968
}
@@ -82,17 +81,17 @@ func (aa *authApplierV3) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResp
8281
return nil, nil, err
8382
}
8483
}
85-
return aa.applierV3.Put(ctx, r)
84+
return aa.applierV3.Put(r)
8685
}
8786

88-
func (aa *authApplierV3) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error) {
87+
func (aa *authApplierV3) Range(r *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error) {
8988
if err := aa.as.IsRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil {
9089
return nil, nil, err
9190
}
92-
return aa.applierV3.Range(ctx, r)
91+
return aa.applierV3.Range(r)
9392
}
9493

95-
func (aa *authApplierV3) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error) {
94+
func (aa *authApplierV3) DeleteRange(r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error) {
9695
if err := aa.as.IsDeleteRangePermitted(&aa.authInfo, r.Key, r.RangeEnd); err != nil {
9796
return nil, nil, err
9897
}
@@ -103,14 +102,14 @@ func (aa *authApplierV3) DeleteRange(ctx context.Context, r *pb.DeleteRangeReque
103102
}
104103
}
105104

106-
return aa.applierV3.DeleteRange(ctx, r)
105+
return aa.applierV3.DeleteRange(r)
107106
}
108107

109-
func (aa *authApplierV3) Txn(ctx context.Context, rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
108+
func (aa *authApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
110109
if err := txn.CheckTxnAuth(aa.as, &aa.authInfo, rt); err != nil {
111110
return nil, nil, err
112111
}
113-
return aa.applierV3.Txn(ctx, rt)
112+
return aa.applierV3.Txn(rt)
114113
}
115114

116115
func (aa *authApplierV3) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) {

server/etcdserver/apply/apply_auth_test.go

+8-19
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package apply
1616

1717
import (
18-
"context"
1918
"errors"
2019
"testing"
2120
"time"
@@ -437,12 +436,10 @@ func TestAuthApplierV3_Put(t *testing.T) {
437436

438437
authApplier := defaultAuthApplierV3(t)
439438
mustCreateRolesAndEnableAuth(t, authApplier)
440-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
441-
defer cancel()
442439
for _, tc := range tcs {
443440
t.Run(tc.name, func(t *testing.T) {
444441
setAuthInfo(authApplier, tc.userName)
445-
_, _, err := authApplier.Put(ctx, tc.request)
442+
_, _, err := authApplier.Put(tc.request)
446443
require.Equalf(t, tc.expectError, err, "Put returned unexpected error (or lack thereof), expected: %v, got: %v", tc.expectError, err)
447444
})
448445
}
@@ -452,8 +449,6 @@ func TestAuthApplierV3_Put(t *testing.T) {
452449
func TestAuthApplierV3_LeasePut(t *testing.T) {
453450
authApplier := defaultAuthApplierV3(t)
454451
mustCreateRolesAndEnableAuth(t, authApplier)
455-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
456-
defer cancel()
457452

458453
_, err := authApplier.LeaseGrant(&pb.LeaseGrantRequest{
459454
TTL: lease.MaxLeaseTTL,
@@ -463,7 +458,7 @@ func TestAuthApplierV3_LeasePut(t *testing.T) {
463458

464459
// The user should be able to put the key
465460
setAuthInfo(authApplier, userWriteOnly)
466-
_, _, err = authApplier.Put(ctx, &pb.PutRequest{
461+
_, _, err = authApplier.Put(&pb.PutRequest{
467462
Key: []byte(key),
468463
Value: []byte("1"),
469464
Lease: leaseID,
@@ -472,7 +467,7 @@ func TestAuthApplierV3_LeasePut(t *testing.T) {
472467

473468
// Put a key under the lease outside user's key range
474469
setAuthInfo(authApplier, userRoot)
475-
_, _, err = authApplier.Put(ctx, &pb.PutRequest{
470+
_, _, err = authApplier.Put(&pb.PutRequest{
476471
Key: []byte(keyOutsideRange),
477472
Value: []byte("1"),
478473
Lease: leaseID,
@@ -481,7 +476,7 @@ func TestAuthApplierV3_LeasePut(t *testing.T) {
481476

482477
// The user should not be able to put the key anymore
483478
setAuthInfo(authApplier, userWriteOnly)
484-
_, _, err = authApplier.Put(ctx, &pb.PutRequest{
479+
_, _, err = authApplier.Put(&pb.PutRequest{
485480
Key: []byte(key),
486481
Value: []byte("1"),
487482
Lease: leaseID,
@@ -524,12 +519,10 @@ func TestAuthApplierV3_Range(t *testing.T) {
524519

525520
authApplier := defaultAuthApplierV3(t)
526521
mustCreateRolesAndEnableAuth(t, authApplier)
527-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
528-
defer cancel()
529522
for _, tc := range tcs {
530523
t.Run(tc.name, func(t *testing.T) {
531524
setAuthInfo(authApplier, tc.userName)
532-
_, _, err := authApplier.Range(ctx, tc.request)
525+
_, _, err := authApplier.Range(tc.request)
533526
require.Equalf(t, tc.expectError, err, "Range returned unexpected error (or lack thereof), expected: %v, got: %v", tc.expectError, err)
534527
})
535528
}
@@ -593,7 +586,7 @@ func TestAuthApplierV3_DeleteRange(t *testing.T) {
593586
for _, tc := range tcs {
594587
t.Run(tc.name, func(t *testing.T) {
595588
setAuthInfo(authApplier, tc.userName)
596-
_, _, err := authApplier.DeleteRange(context.Background(), tc.request)
589+
_, _, err := authApplier.DeleteRange(tc.request)
597590
require.Equalf(t, tc.expectError, err, "Range returned unexpected error (or lack thereof), expected: %v, got: %v", tc.expectError, err)
598591
})
599592
}
@@ -660,12 +653,10 @@ func TestAuthApplierV3_Txn(t *testing.T) {
660653

661654
authApplier := defaultAuthApplierV3(t)
662655
mustCreateRolesAndEnableAuth(t, authApplier)
663-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
664-
defer cancel()
665656
for _, tc := range tcs {
666657
t.Run(tc.name, func(t *testing.T) {
667658
setAuthInfo(authApplier, tc.userName)
668-
_, _, err := authApplier.Txn(ctx, tc.request)
659+
_, _, err := authApplier.Txn(tc.request)
669660
require.Equalf(t, tc.expectError, err, "Range returned unexpected error (or lack thereof), expected: %v, got: %v", tc.expectError, err)
670661
})
671662
}
@@ -676,8 +667,6 @@ func TestAuthApplierV3_Txn(t *testing.T) {
676667
func TestAuthApplierV3_LeaseRevoke(t *testing.T) {
677668
authApplier := defaultAuthApplierV3(t)
678669
mustCreateRolesAndEnableAuth(t, authApplier)
679-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
680-
defer cancel()
681670

682671
_, err := authApplier.LeaseGrant(&pb.LeaseGrantRequest{
683672
TTL: lease.MaxLeaseTTL,
@@ -700,7 +689,7 @@ func TestAuthApplierV3_LeaseRevoke(t *testing.T) {
700689

701690
// Put a key under the lease outside user's key range
702691
setAuthInfo(authApplier, userRoot)
703-
_, _, err = authApplier.Put(ctx, &pb.PutRequest{
692+
_, _, err = authApplier.Put(&pb.PutRequest{
704693
Key: []byte(keyOutsideRange),
705694
Value: []byte("1"),
706695
Lease: leaseID,

server/etcdserver/apply/corrupt.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package apply
1616

1717
import (
18-
"context"
19-
2018
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
2119
"go.etcd.io/etcd/pkg/v3/traceutil"
2220
"go.etcd.io/etcd/server/v3/etcdserver/errors"
@@ -28,19 +26,19 @@ type applierV3Corrupt struct {
2826

2927
func newApplierV3Corrupt(a applierV3) *applierV3Corrupt { return &applierV3Corrupt{a} }
3028

31-
func (a *applierV3Corrupt) Put(_ context.Context, _ *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
29+
func (a *applierV3Corrupt) Put(_ *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
3230
return nil, nil, errors.ErrCorrupt
3331
}
3432

35-
func (a *applierV3Corrupt) Range(_ context.Context, _ *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error) {
33+
func (a *applierV3Corrupt) Range(_ *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error) {
3634
return nil, nil, errors.ErrCorrupt
3735
}
3836

39-
func (a *applierV3Corrupt) DeleteRange(_ context.Context, _ *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error) {
37+
func (a *applierV3Corrupt) DeleteRange(_ *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error) {
4038
return nil, nil, errors.ErrCorrupt
4139
}
4240

43-
func (a *applierV3Corrupt) Txn(_ context.Context, _ *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
41+
func (a *applierV3Corrupt) Txn(_ *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) {
4442
return nil, nil, errors.ErrCorrupt
4543
}
4644

server/etcdserver/apply/uber_applier.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package apply
1616

1717
import (
18-
"context"
1918
"errors"
2019
"time"
2120

@@ -121,7 +120,6 @@ func (a *uberApplier) Apply(r *pb.InternalRaftRequest) *Result {
121120
// dispatch translates the request (r) into appropriate call (like Put) on
122121
// the underlying applyV3 object.
123122
func (a *uberApplier) dispatch(r *pb.InternalRaftRequest) *Result {
124-
ctx := context.TODO()
125123
op := "unknown"
126124
ar := &Result{}
127125
defer func(start time.Time) {
@@ -136,16 +134,16 @@ func (a *uberApplier) dispatch(r *pb.InternalRaftRequest) *Result {
136134
switch {
137135
case r.Range != nil:
138136
op = "Range"
139-
ar.Resp, ar.Trace, ar.Err = a.applyV3.Range(ctx, r.Range)
137+
ar.Resp, ar.Trace, ar.Err = a.applyV3.Range(r.Range)
140138
case r.Put != nil:
141139
op = "Put"
142-
ar.Resp, ar.Trace, ar.Err = a.applyV3.Put(ctx, r.Put)
140+
ar.Resp, ar.Trace, ar.Err = a.applyV3.Put(r.Put)
143141
case r.DeleteRange != nil:
144142
op = "DeleteRange"
145-
ar.Resp, ar.Trace, ar.Err = a.applyV3.DeleteRange(ctx, r.DeleteRange)
143+
ar.Resp, ar.Trace, ar.Err = a.applyV3.DeleteRange(r.DeleteRange)
146144
case r.Txn != nil:
147145
op = "Txn"
148-
ar.Resp, ar.Trace, ar.Err = a.applyV3.Txn(ctx, r.Txn)
146+
ar.Resp, ar.Trace, ar.Err = a.applyV3.Txn(r.Txn)
149147
case r.Compaction != nil:
150148
op = "Compaction"
151149
ar.Resp, ar.Physc, ar.Trace, ar.Err = a.applyV3.Compaction(r.Compaction)

0 commit comments

Comments
 (0)