diff --git a/server/etcdserver/apply/apply.go b/server/etcdserver/apply/apply.go index 849e0ddc4..3014520b0 100644 --- a/server/etcdserver/apply/apply.go +++ b/server/etcdserver/apply/apply.go @@ -52,7 +52,7 @@ type RaftStatusGetter interface { Term() uint64 } -type ApplyResult struct { +type Result struct { Resp proto.Message Err error // Physc signals the physical effect of the request has completed in addition @@ -62,12 +62,13 @@ type ApplyResult struct { Trace *traceutil.Trace } -type ApplyFunc func(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *ApplyResult +type applyFunc func(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *Result // applierV3 is the interface for processing V3 raft messages type applierV3 interface { - WrapApply(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3, applyFunc ApplyFunc) *ApplyResult - //Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *ApplyResult + // Apply executes the generic portion of application logic for the current applier, but + // delegates the actual execution to the applyFunc method. + Apply(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3, applyFunc applyFunc) *Result Put(ctx context.Context, txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) Range(ctx context.Context, txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) @@ -151,7 +152,7 @@ func newApplierV3Backend( txnModeWriteWithSharedBuffer: txnModeWriteWithSharedBuffer} } -func (a *applierV3backend) WrapApply(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3, applyFunc ApplyFunc) *ApplyResult { +func (a *applierV3backend) Apply(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3, applyFunc applyFunc) *Result { return applyFunc(ctx, r, shouldApplyV3) } diff --git a/server/etcdserver/apply/apply_auth.go b/server/etcdserver/apply/apply_auth.go index 947d82840..fc94e88b3 100644 --- a/server/etcdserver/apply/apply_auth.go +++ b/server/etcdserver/apply/apply_auth.go @@ -43,7 +43,7 @@ func newAuthApplierV3(as auth.AuthStore, base applierV3, lessor lease.Lessor) *a return &authApplierV3{applierV3: base, as: as, lessor: lessor} } -func (aa *authApplierV3) WrapApply(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3, applyFunc ApplyFunc) *ApplyResult { +func (aa *authApplierV3) Apply(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3, applyFunc applyFunc) *Result { aa.mu.Lock() defer aa.mu.Unlock() if r.Header != nil { @@ -56,10 +56,10 @@ func (aa *authApplierV3) WrapApply(ctx context.Context, r *pb.InternalRaftReques if err := aa.as.IsAdminPermitted(&aa.authInfo); err != nil { aa.authInfo.Username = "" aa.authInfo.Revision = 0 - return &ApplyResult{Err: err} + return &Result{Err: err} } } - ret := aa.applierV3.WrapApply(ctx, r, shouldApplyV3, applyFunc) + ret := aa.applierV3.Apply(ctx, r, shouldApplyV3, applyFunc) aa.authInfo.Username = "" aa.authInfo.Revision = 0 return ret diff --git a/server/etcdserver/apply/uber_applier.go b/server/etcdserver/apply/uber_applier.go index 25a2f1801..50f8ba4b1 100644 --- a/server/etcdserver/apply/uber_applier.go +++ b/server/etcdserver/apply/uber_applier.go @@ -31,7 +31,7 @@ import ( ) type UberApplier interface { - Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *ApplyResult + Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *Result } type uberApplier struct { @@ -107,20 +107,20 @@ func (a *uberApplier) restoreAlarms() { } } -func (a *uberApplier) Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *ApplyResult { - // We first execute chain of WrapApply() calls down the hierarchy: +func (a *uberApplier) Apply(r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *Result { + // We first execute chain of Apply() calls down the hierarchy: // (i.e. CorruptApplier -> CappedApplier -> Auth -> Quota -> Backend), // then dispatch() unpacks the request to a specific method (like Put), // that gets executed down the hierarchy again: // i.e. CorruptApplier.Put(CappedApplier.Put(...(BackendApplier.Put(...)))). - return a.applyV3.WrapApply(context.TODO(), r, shouldApplyV3, a.dispatch) + return a.applyV3.Apply(context.TODO(), r, shouldApplyV3, a.dispatch) } // dispatch translates the request (r) into appropriate call (like Put) on // the underlying applyV3 object. -func (a *uberApplier) dispatch(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *ApplyResult { +func (a *uberApplier) dispatch(ctx context.Context, r *pb.InternalRaftRequest, shouldApplyV3 membership.ShouldApplyV3) *Result { op := "unknown" - ar := &ApplyResult{} + ar := &Result{} defer func(start time.Time) { success := ar.Err == nil || ar.Err == mvcc.ErrCompacted txn.ApplySecObserve(v3Version, op, success, time.Since(start)) diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index 71e499be5..a64939e34 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -1829,7 +1829,7 @@ func (s *EtcdServer) apply( func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) { shouldApplyV3 := membership.ApplyV2storeOnly applyV3Performed := false - var ar *apply.ApplyResult + var ar *apply.Result index := s.consistIndex.ConsistentIndex() if e.Index > index { // set the consistent index of current executing entry diff --git a/server/etcdserver/server_test.go b/server/etcdserver/server_test.go index cb86eb4a8..f60f73f4d 100644 --- a/server/etcdserver/server_test.go +++ b/server/etcdserver/server_test.go @@ -1479,7 +1479,7 @@ func TestPublishV3(t *testing.T) { n := newNodeRecorder() ch := make(chan interface{}, 1) // simulate that request has gone through consensus - ch <- &apply2.ApplyResult{} + ch <- &apply2.Result{} w := wait.NewWithResponse(ch) ctx, cancel := context.WithCancel(context.Background()) lg := zaptest.NewLogger(t) diff --git a/server/etcdserver/v3_server.go b/server/etcdserver/v3_server.go index e5c267279..63a190e6e 100644 --- a/server/etcdserver/v3_server.go +++ b/server/etcdserver/v3_server.go @@ -656,7 +656,7 @@ func (s *EtcdServer) doSerialize(ctx context.Context, chk func(*auth.AuthInfo) e return nil } -func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (*apply2.ApplyResult, error) { +func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (*apply2.Result, error) { ai := s.getAppliedIndex() ci := s.getCommittedIndex() if ci > ai+maxGapBetweenApplyAndCommitIndex { @@ -709,7 +709,7 @@ func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.In select { case x := <-ch: - return x.(*apply2.ApplyResult), nil + return x.(*apply2.Result), nil case <-cctx.Done(): proposalsFailed.Inc() s.w.Trigger(id, nil) // GC wait