From 11bf77ace57304e7d2906071414ee3f64045e03a Mon Sep 17 00:00:00 2001 From: Alessio Attilio Date: Wed, 4 Mar 2026 23:07:24 +0100 Subject: [PATCH] fix(txn): Ensure range requests in transactions are executed only on the requester member Signed-off-by: Alessio Attilio --- api/etcdserverpb/raft_internal.pb.go | 175 ++++++++++++++---------- api/etcdserverpb/raft_internal.proto | 1 + server/etcdserver/apply/apply.go | 21 --- server/etcdserver/apply/auth.go | 4 +- server/etcdserver/apply/auth_test.go | 2 +- server/etcdserver/apply/backend.go | 14 +- server/etcdserver/apply/capped.go | 4 +- server/etcdserver/apply/corrupt.go | 2 +- server/etcdserver/apply/interface.go | 2 +- server/etcdserver/apply/quota.go | 4 +- server/etcdserver/apply/uber_applier.go | 2 +- server/etcdserver/txn/range.go | 23 +++- server/etcdserver/txn/txn.go | 14 +- server/etcdserver/txn/txn_test.go | 6 +- server/etcdserver/v3_server.go | 5 +- 15 files changed, 161 insertions(+), 118 deletions(-) diff --git a/api/etcdserverpb/raft_internal.pb.go b/api/etcdserverpb/raft_internal.pb.go index 3c7d28d9e1fd..64ea8de704d9 100644 --- a/api/etcdserverpb/raft_internal.pb.go +++ b/api/etcdserverpb/raft_internal.pb.go @@ -31,6 +31,7 @@ type RequestHeader struct { Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"` // auth_revision is a revision number of auth.authStore. It is not related to mvcc AuthRevision uint64 `protobuf:"varint,3,opt,name=auth_revision,json=authRevision,proto3" json:"auth_revision,omitempty"` + RequesterMemberId uint64 `protobuf:"varint,4,opt,name=requester_member_id,json=requesterMemberId,proto3" json:"requester_member_id,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -90,6 +91,13 @@ func (m *RequestHeader) GetAuthRevision() uint64 { return 0 } +func (m *RequestHeader) GetRequesterMemberId() uint64 { + if m != nil { + return m.RequesterMemberId + } + return 0 +} + // An InternalRaftRequest is the union of all requests which can be // sent via raft. type InternalRaftRequest struct { @@ -503,75 +511,77 @@ func init() { func init() { proto.RegisterFile("raft_internal.proto", fileDescriptor_b4c9a9be0cfca103) } var fileDescriptor_b4c9a9be0cfca103 = []byte{ - // 1077 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x56, 0x4d, 0x73, 0x1b, 0x45, - 0x10, 0x45, 0xb6, 0x63, 0x5b, 0x23, 0xdb, 0x71, 0xc6, 0x26, 0x19, 0xec, 0x2a, 0xe3, 0x38, 0x10, - 0x0c, 0x04, 0x39, 0xd8, 0x84, 0x03, 0x17, 0x50, 0x2c, 0x97, 0xe3, 0x54, 0x92, 0x72, 0x6d, 0x0c, - 0x95, 0x82, 0xa2, 0x96, 0xd1, 0x6e, 0x5b, 0xda, 0x78, 0xb5, 0xbb, 0xcc, 0x8c, 0x1c, 0xe7, 0xca, - 0x91, 0x33, 0x50, 0xf9, 0x11, 0x1c, 0xf8, 0xfc, 0x0f, 0x1c, 0xf8, 0x08, 0xf0, 0x07, 0x28, 0x73, - 0xe1, 0x0e, 0xdc, 0x53, 0xf3, 0xb1, 0xb3, 0x5a, 0x69, 0xe4, 0x9b, 0xb6, 0xfb, 0xf5, 0x7b, 0x6f, - 0x66, 0xbb, 0x57, 0x8d, 0x16, 0x18, 0x3d, 0x14, 0x7e, 0x94, 0x08, 0x60, 0x09, 0x8d, 0xeb, 0x19, - 0x4b, 0x45, 0x8a, 0x67, 0x40, 0x04, 0x21, 0x07, 0x76, 0x0c, 0x2c, 0x6b, 0x2d, 0x55, 0x59, 0x16, - 0xe8, 0xc4, 0xd2, 0xaa, 0x4c, 0x6c, 0xd0, 0x2c, 0xda, 0x38, 0x06, 0xc6, 0xa3, 0x34, 0xc9, 0x5a, - 0xf9, 0x2f, 0x83, 0xb8, 0x6a, 0x11, 0x5d, 0xe8, 0xb6, 0x80, 0xf1, 0x4e, 0x94, 0x65, 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b, - 0x59, 0xef, 0x44, 0x5c, 0x94, 0xfa, 0x28, 0x0f, 0x5a, 0x26, 0x69, 0x4d, 0x33, 0xfd, 0x39, 0x92, - 0x49, 0x4a, 0x0f, 0x31, 0xe5, 0x41, 0xfb, 0xea, 0x15, 0x93, 0xec, 0xc8, 0x6f, 0xaa, 0xa3, 0x5e, - 0xbd, 0xac, 0x19, 0xec, 0x48, 0x13, 0xb3, 0x1d, 0xa9, 0x68, 0x4c, 0x47, 0x7e, 0x5b, 0x1d, 0xd5, - 0x91, 0xb2, 0xca, 0xd1, 0x91, 0x45, 0xb8, 0x6c, 0x4b, 0x76, 0xe4, 0x77, 0x67, 0xda, 0x1a, 0xec, - 0x48, 0x13, 0xc3, 0x0f, 0xd1, 0x52, 0x1f, 0x8d, 0x6a, 0x94, 0x0c, 0x58, 0x37, 0xe2, 0xea, 0x8f, - 0xf5, 0x7b, 0xcd, 0x79, 0x6d, 0x04, 0xa7, 0x84, 0xef, 0x5b, 0x74, 0xce, 0x7f, 0x89, 0xba, 0xf3, - 0xb8, 0x8b, 0x96, 0x0b, 0x2d, 0xd3, 0x3a, 0x7d, 0x62, 0x3f, 0x68, 0xb1, 0x37, 0xdc, 0x62, 0xba, - 0x4b, 0x86, 0xd5, 0x08, 0x1d, 0x01, 0xc0, 0x9f, 0xa0, 0x85, 0x20, 0xee, 0x71, 0x01, 0xcc, 0x37, - 0x4b, 0x8a, 0xcf, 0x41, 0x90, 0x2f, 0x90, 0x19, 0x81, 0xfe, 0x0d, 0xa5, 0xbe, 0xad, 0x91, 0x1f, - 0x68, 0xe0, 0x7d, 0x10, 0x43, 0x5f, 0xbd, 0x0b, 0xc1, 0x20, 0x04, 0x3f, 0x44, 0x97, 0x72, 0x05, - 0x4d, 0xe6, 0x53, 0x21, 0x98, 0x52, 0xf9, 0x12, 0x99, 0xef, 0xa0, 0x4b, 0xe5, 0xae, 0x8a, 0x35, - 0x84, 0x60, 0x2e, 0xa1, 0xc5, 0xc0, 0x81, 0x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0xff, 0x7f, 0x47, 0x30, - 0xbe, 0x52, 0x0b, 0x00, 0x00, + // 1105 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x56, 0xcd, 0x72, 0x1b, 0x45, + 0x10, 0x46, 0xb6, 0x63, 0x5b, 0x23, 0xdb, 0xb1, 0xc7, 0x26, 0x19, 0xec, 0x2a, 0xe3, 0x38, 0x10, + 0x0c, 0x04, 0x39, 0xd8, 0x84, 0x54, 0x71, 0x01, 0xc5, 0x72, 0x39, 0x4e, 0x25, 0x29, 0xd7, 0xc6, + 0x50, 0x29, 0x28, 0x6a, 0x19, 0xed, 0xb6, 0xa5, 0x8d, 0x57, 0xbb, 0xcb, 0xec, 0x48, 0x71, 0xae, + 0x1c, 0x39, 0x03, 0x95, 0x77, 0x80, 0x03, 0xbf, 0xef, 0xc0, 0x81, 0x9f, 0x00, 0x2f, 0x40, 0x99, + 0x0b, 0x77, 0xe0, 0x4e, 0xcd, 0xcf, 0xce, 0xee, 0x4a, 0x23, 0xdf, 0xb4, 0xdd, 0x5f, 0x7f, 0x5f, + 0xf7, 0x4c, 0xf7, 0xa8, 0xd1, 0x22, 0xa3, 0x47, 0xdc, 0x0d, 0x22, 0x0e, 0x2c, 0xa2, 0x61, 0x3d, + 0x61, 0x31, 0x8f, 0xf1, 0x0c, 0x70, 0xcf, 0x4f, 0x81, 0xf5, 0x81, 0x25, 0xad, 0xe5, 0x2a, 0x4b, + 0x3c, 0xe5, 0x58, 0x5e, 0x13, 0x8e, 0x4d, 0x9a, 0x04, 0x9b, 0x7d, 0x60, 0x69, 0x10, 0x47, 0x49, + 0x2b, 0xfb, 0xa5, 0x11, 0x57, 0x0c, 0xa2, 0x0b, 0xdd, 0x16, 0xb0, 0xb4, 0x13, 0x24, 0x49, 0xab, + 0xf0, 0xa1, 0x70, 0xeb, 0x5f, 0x56, 0xd0, 0xac, 0x03, 0x1f, 0xf7,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, 0xde, 0xde, 0x2c, 0x1e, 0x48, 0x6b, 0x52, + 0xae, 0xc4, 0xdb, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x61, 0xb3, 0xae, 0xea, 0x8c, 0x0b, 0x00, + 0x00, } func (m *RequestHeader) Marshal() (dAtA []byte, err error) { @@ -598,6 +608,11 @@ func (m *RequestHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } + if m.RequesterMemberId != 0 { + i = encodeVarintRaftInternal(dAtA, i, uint64(m.RequesterMemberId)) + i-- + dAtA[i] = 0x20 + } if m.AuthRevision != 0 { i = encodeVarintRaftInternal(dAtA, i, uint64(m.AuthRevision)) i-- @@ -1170,6 +1185,9 @@ func (m *RequestHeader) Size() (n int) { if m.AuthRevision != 0 { n += 1 + sovRaftInternal(uint64(m.AuthRevision)) } + if m.RequesterMemberId != 0 { + n += 1 + sovRaftInternal(uint64(m.RequesterMemberId)) + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -1456,6 +1474,25 @@ func (m *RequestHeader) Unmarshal(dAtA []byte) error { break } } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RequesterMemberId", wireType) + } + m.RequesterMemberId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRaftInternal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RequesterMemberId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipRaftInternal(dAtA[iNdEx:]) diff --git a/api/etcdserverpb/raft_internal.proto b/api/etcdserverpb/raft_internal.proto index 51767ea9ecab..baa51151a837 100644 --- a/api/etcdserverpb/raft_internal.proto +++ b/api/etcdserverpb/raft_internal.proto @@ -15,6 +15,7 @@ message RequestHeader { string username = 2; // auth_revision is a revision number of auth.authStore. It is not related to mvcc uint64 auth_revision = 3 [(versionpb.etcd_version_field) = "3.1"]; + uint64 requester_member_id = 4 [(versionpb.etcd_version_field) = "3.7"]; } // An InternalRaftRequest is the union of all requests which can be diff --git a/server/etcdserver/apply/apply.go b/server/etcdserver/apply/apply.go index 8730260499c7..b5932cb2add3 100644 --- a/server/etcdserver/apply/apply.go +++ b/server/etcdserver/apply/apply.go @@ -39,9 +39,6 @@ func Apply(lg *zap.Logger, e *raftpb.Entry, uberApply UberApplier, w wait.Wait, needResult := w.IsRegistered(id) if needResult || !noSideEffect(&raftReq) { - if !needResult && raftReq.Txn != nil { - removeNeedlessRangeReqs(raftReq.Txn) - } return uberApply.Apply(&raftReq, shouldApplyV3), id } return nil, id @@ -50,21 +47,3 @@ func Apply(lg *zap.Logger, e *raftpb.Entry, uberApply UberApplier, w wait.Wait, func noSideEffect(r *pb.InternalRaftRequest) bool { return r.Range != nil || r.AuthUserGet != nil || r.AuthRoleGet != nil || r.AuthStatus != nil } - -func removeNeedlessRangeReqs(txn *pb.TxnRequest) { - f := func(ops []*pb.RequestOp) []*pb.RequestOp { - j := 0 - for i := 0; i < len(ops); i++ { - if _, ok := ops[i].Request.(*pb.RequestOp_RequestRange); ok { - continue - } - ops[j] = ops[i] - j++ - } - - return ops[:j] - } - - txn.Success = f(txn.Success) - txn.Failure = f(txn.Failure) -} diff --git a/server/etcdserver/apply/auth.go b/server/etcdserver/apply/auth.go index edb1fe447a1f..a9fc10820556 100644 --- a/server/etcdserver/apply/auth.go +++ b/server/etcdserver/apply/auth.go @@ -106,11 +106,11 @@ func (aa *authApplierV3) DeleteRange(r *pb.DeleteRangeRequest) (*pb.DeleteRangeR return aa.applierV3.DeleteRange(r) } -func (aa *authApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { +func (aa *authApplierV3) Txn(rt *pb.TxnRequest, header *pb.RequestHeader) (*pb.TxnResponse, *traceutil.Trace, error) { if err := txn.CheckTxnAuth(aa.as, &aa.authInfo, rt); err != nil { return nil, nil, err } - return aa.applierV3.Txn(rt) + return aa.applierV3.Txn(rt, header) } func (aa *authApplierV3) LeaseRevoke(lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { diff --git a/server/etcdserver/apply/auth_test.go b/server/etcdserver/apply/auth_test.go index 7a079f82d239..4495777b030d 100644 --- a/server/etcdserver/apply/auth_test.go +++ b/server/etcdserver/apply/auth_test.go @@ -652,7 +652,7 @@ func TestAuthApplierV3_Txn(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { setAuthInfo(authApplier, tc.userName) - _, _, err := authApplier.Txn(tc.request) + _, _, err := authApplier.Txn(tc.request, nil) require.Equalf(t, tc.expectError, err, "Range returned unexpected error (or lack thereof), expected: %v, got: %v", tc.expectError, err) }) } diff --git a/server/etcdserver/apply/backend.go b/server/etcdserver/apply/backend.go index ef2f23f76f32..a0f2c84c7e36 100644 --- a/server/etcdserver/apply/backend.go +++ b/server/etcdserver/apply/backend.go @@ -34,12 +34,18 @@ import ( ) type applierV3backend struct { - options ApplierOptions + options ApplierOptions + memberID uint64 } func newApplierV3Backend(opts ApplierOptions) applierV3 { + memberID := uint64(0) + if opts.RaftStatus != nil { + memberID = uint64(opts.RaftStatus.MemberID()) + } return &applierV3backend{ - options: opts, + options: opts, + memberID: memberID, } } @@ -59,8 +65,8 @@ func (a *applierV3backend) Range(r *pb.RangeRequest) (*pb.RangeResponse, *traceu return mvcctxn.Range(context.TODO(), a.options.Logger, a.options.KV, r) } -func (a *applierV3backend) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { - return mvcctxn.Txn(context.TODO(), a.options.Logger, rt, a.options.TxnModeWriteWithSharedBuffer, a.options.KV, a.options.Lessor) +func (a *applierV3backend) Txn(rt *pb.TxnRequest, header *pb.RequestHeader) (*pb.TxnResponse, *traceutil.Trace, error) { + return mvcctxn.Txn(context.TODO(), a.options.Logger, rt, a.options.TxnModeWriteWithSharedBuffer, a.options.KV, a.options.Lessor, header, a.memberID) } func (a *applierV3backend) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, *traceutil.Trace, error) { diff --git a/server/etcdserver/apply/capped.go b/server/etcdserver/apply/capped.go index 312eeb52c904..89f76b5074ac 100644 --- a/server/etcdserver/apply/capped.go +++ b/server/etcdserver/apply/capped.go @@ -34,11 +34,11 @@ func (a *applierV3Capped) Put(_ *pb.PutRequest) (*pb.PutResponse, *traceutil.Tra return nil, nil, errors.ErrNoSpace } -func (a *applierV3Capped) Txn(r *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { +func (a *applierV3Capped) Txn(r *pb.TxnRequest, header *pb.RequestHeader) (*pb.TxnResponse, *traceutil.Trace, error) { if a.q.Cost(r) > 0 { return nil, nil, errors.ErrNoSpace } - return a.applierV3.Txn(r) + return a.applierV3.Txn(r, header) } func (a *applierV3Capped) LeaseGrant(_ *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) { diff --git a/server/etcdserver/apply/corrupt.go b/server/etcdserver/apply/corrupt.go index c198119510aa..0fc6da7100cf 100644 --- a/server/etcdserver/apply/corrupt.go +++ b/server/etcdserver/apply/corrupt.go @@ -38,7 +38,7 @@ func (a *applierV3Corrupt) DeleteRange(_ *pb.DeleteRangeRequest) (*pb.DeleteRang return nil, nil, errors.ErrCorrupt } -func (a *applierV3Corrupt) Txn(_ *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { +func (a *applierV3Corrupt) Txn(_ *pb.TxnRequest, _ *pb.RequestHeader) (*pb.TxnResponse, *traceutil.Trace, error) { return nil, nil, errors.ErrCorrupt } diff --git a/server/etcdserver/apply/interface.go b/server/etcdserver/apply/interface.go index 85bfb6109d57..0cc4370d06ec 100644 --- a/server/etcdserver/apply/interface.go +++ b/server/etcdserver/apply/interface.go @@ -42,7 +42,7 @@ type applierV3 interface { Put(p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) Range(r *pb.RangeRequest) (*pb.RangeResponse, *traceutil.Trace, error) DeleteRange(dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, *traceutil.Trace, error) - Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) + Txn(rt *pb.TxnRequest, header *pb.RequestHeader) (*pb.TxnResponse, *traceutil.Trace, error) Compaction(compaction *pb.CompactionRequest) (*pb.CompactionResponse, <-chan struct{}, *traceutil.Trace, error) LeaseGrant(lc *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) diff --git a/server/etcdserver/apply/quota.go b/server/etcdserver/apply/quota.go index e1cef6016fb7..195b8949919f 100644 --- a/server/etcdserver/apply/quota.go +++ b/server/etcdserver/apply/quota.go @@ -42,9 +42,9 @@ func (a *quotaApplierV3) Put(p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trac return resp, trace, err } -func (a *quotaApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, *traceutil.Trace, error) { +func (a *quotaApplierV3) Txn(rt *pb.TxnRequest, header *pb.RequestHeader) (*pb.TxnResponse, *traceutil.Trace, error) { ok := a.q.Available(rt) - resp, trace, err := a.applierV3.Txn(rt) + resp, trace, err := a.applierV3.Txn(rt, header) if err == nil && !ok { err = errors.ErrNoSpace } diff --git a/server/etcdserver/apply/uber_applier.go b/server/etcdserver/apply/uber_applier.go index 0eb76e3d4209..f14262d66a82 100644 --- a/server/etcdserver/apply/uber_applier.go +++ b/server/etcdserver/apply/uber_applier.go @@ -139,7 +139,7 @@ func (a *uberApplier) dispatch(r *pb.InternalRaftRequest, shouldApplyV3 membersh ar.Resp, ar.Trace, ar.Err = a.applyV3.DeleteRange(r.DeleteRange) case r.Txn != nil: op = "Txn" - ar.Resp, ar.Trace, ar.Err = a.applyV3.Txn(r.Txn) + ar.Resp, ar.Trace, ar.Err = a.applyV3.Txn(r.Txn, r.Header) case r.Compaction != nil: op = "Compaction" ar.Resp, ar.Physc, ar.Trace, ar.Err = a.applyV3.Compaction(r.Compaction) diff --git a/server/etcdserver/txn/range.go b/server/etcdserver/txn/range.go index 2ffc920e20e9..170a14a0d5c7 100644 --- a/server/etcdserver/txn/range.go +++ b/server/etcdserver/txn/range.go @@ -36,13 +36,32 @@ func Range(ctx context.Context, lg *zap.Logger, kv mvcc.KV, r *pb.RangeRequest) }(time.Now()) txnRead := kv.Read(mvcc.ConcurrentReadTxMode, trace) defer txnRead.End() - resp, err = executeRange(ctx, lg, txnRead, r) + resp, err = executeRange(ctx, lg, txnRead, r, nil, 0) return resp, trace, err } -func executeRange(ctx context.Context, lg *zap.Logger, txnRead mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error) { +func executeRange(ctx context.Context, lg *zap.Logger, txnRead mvcc.TxnRead, r *pb.RangeRequest, header *pb.RequestHeader, thisMemberId uint64) (*pb.RangeResponse, error) { trace := traceutil.Get(ctx) + // Skip range execution on non-requester members only if: + // 1. Request comes from raft (header != nil) + // 2. Requester member is known (RequesterMemberId != 0) + // 3. This member has a valid ID (thisMemberId != 0) + // 4. Range specifies a revision (Revision != 0) + // + // This optimization avoids executing expensive range queries on + // members that didn't receive the request, while ensuring all members + // validate via checkRange() for consistency. + if header != nil && header.RequesterMemberId != 0 && thisMemberId != 0 && + r.Revision != 0 && thisMemberId != header.RequesterMemberId { + // Non-requester member, skip range execution + return &pb.RangeResponse{ + Header: &pb.ResponseHeader{Revision: txnRead.Rev()}, + Kvs: nil, + Count: 0, + }, nil + } + limit := rangeLimit(r) ro := mvcc.RangeOptions{ Limit: limit, diff --git a/server/etcdserver/txn/txn.go b/server/etcdserver/txn/txn.go index 3917fbb886de..8e615d00af78 100644 --- a/server/etcdserver/txn/txn.go +++ b/server/etcdserver/txn/txn.go @@ -29,7 +29,7 @@ import ( "go.etcd.io/etcd/server/v3/storage/mvcc" ) -func Txn(ctx context.Context, lg *zap.Logger, rt *pb.TxnRequest, txnModeWriteWithSharedBuffer bool, kv mvcc.KV, lessor lease.Lessor) (txnResp *pb.TxnResponse, trace *traceutil.Trace, err error) { +func Txn(ctx context.Context, lg *zap.Logger, rt *pb.TxnRequest, txnModeWriteWithSharedBuffer bool, kv mvcc.KV, lessor lease.Lessor, header *pb.RequestHeader, thisMemberId uint64) (txnResp *pb.TxnResponse, trace *traceutil.Trace, err error) { ctx, trace = traceutil.EnsureTrace(ctx, lg, "transaction") isWrite := !IsTxnReadonly(rt) // When the transaction contains write operations, we use ReadTx instead of @@ -68,7 +68,7 @@ func Txn(ctx context.Context, lg *zap.Logger, rt *pb.TxnRequest, txnModeWriteWit } else { txnWrite = mvcc.NewReadOnlyTxnWrite(txnRead) } - txnResp, err = txn(ctx, lg, txnWrite, rt, isWrite, txnPath) + txnResp, err = txn(ctx, lg, txnWrite, rt, isWrite, txnPath, header, thisMemberId) txnWrite.End() trace.AddField( @@ -78,9 +78,9 @@ func Txn(ctx context.Context, lg *zap.Logger, rt *pb.TxnRequest, txnModeWriteWit return txnResp, trace, err } -func txn(ctx context.Context, lg *zap.Logger, txnWrite mvcc.TxnWrite, rt *pb.TxnRequest, isWrite bool, txnPath []bool) (*pb.TxnResponse, error) { +func txn(ctx context.Context, lg *zap.Logger, txnWrite mvcc.TxnWrite, rt *pb.TxnRequest, isWrite bool, txnPath []bool, header *pb.RequestHeader, thisMemberId uint64) (*pb.TxnResponse, error) { txnResp, _ := newTxnResp(rt, txnPath) - _, err := executeTxn(ctx, lg, txnWrite, rt, txnPath, txnResp) + _, err := executeTxn(ctx, lg, txnWrite, rt, txnPath, txnResp, header, thisMemberId) if err != nil { if isWrite { // CAUTION: When a txn performing write operations starts, we always expect it to be successful. @@ -132,7 +132,7 @@ func newTxnResp(rt *pb.TxnRequest, txnPath []bool) (txnResp *pb.TxnResponse, txn return txnResp, txnCount } -func executeTxn(ctx context.Context, lg *zap.Logger, txnWrite mvcc.TxnWrite, rt *pb.TxnRequest, txnPath []bool, tresp *pb.TxnResponse) (txns int, err error) { +func executeTxn(ctx context.Context, lg *zap.Logger, txnWrite mvcc.TxnWrite, rt *pb.TxnRequest, txnPath []bool, tresp *pb.TxnResponse, header *pb.RequestHeader, thisMemberId uint64) (txns int, err error) { trace := traceutil.Get(ctx) reqs := rt.Success if !txnPath[0] { @@ -147,7 +147,7 @@ func executeTxn(ctx context.Context, lg *zap.Logger, txnWrite mvcc.TxnWrite, rt traceutil.Field{Key: "req_type", Value: "range"}, traceutil.Field{Key: "range_begin", Value: string(tv.RequestRange.Key)}, traceutil.Field{Key: "range_end", Value: string(tv.RequestRange.RangeEnd)}) - resp, err := executeRange(ctx, lg, txnWrite, tv.RequestRange) + resp, err := executeRange(ctx, lg, txnWrite, tv.RequestRange, header, thisMemberId) if err != nil { return 0, fmt.Errorf("applyTxn: failed Range: %w", err) } @@ -173,7 +173,7 @@ func executeTxn(ctx context.Context, lg *zap.Logger, txnWrite mvcc.TxnWrite, rt respi.(*pb.ResponseOp_ResponseDeleteRange).ResponseDeleteRange = resp case *pb.RequestOp_RequestTxn: resp := respi.(*pb.ResponseOp_ResponseTxn).ResponseTxn - applyTxns, err := executeTxn(ctx, lg, txnWrite, tv.RequestTxn, txnPath[1:], resp) + applyTxns, err := executeTxn(ctx, lg, txnWrite, tv.RequestTxn, txnPath[1:], resp, header, thisMemberId) if err != nil { // don't wrap the error. It's a recursive call and err should be already wrapped return 0, err diff --git a/server/etcdserver/txn/txn_test.go b/server/etcdserver/txn/txn_test.go index 7aa0c08aea46..50731d711bbb 100644 --- a/server/etcdserver/txn/txn_test.go +++ b/server/etcdserver/txn/txn_test.go @@ -228,7 +228,7 @@ func TestCheckTxn(t *testing.T) { ctx, cancel := context.WithCancel(t.Context()) defer cancel() - _, _, err := Txn(ctx, zaptest.NewLogger(t), tc.txn, false, s, lessor) + _, _, err := Txn(ctx, zaptest.NewLogger(t), tc.txn, false, s, lessor, nil, 0) gotErr := "" if err != nil { @@ -333,7 +333,7 @@ func TestReadonlyTxnError(t *testing.T) { }, } - _, _, err := Txn(ctx, zaptest.NewLogger(t), txn, false, s, &lease.FakeLessor{}) + _, _, err := Txn(ctx, zaptest.NewLogger(t), txn, false, s, &lease.FakeLessor{}, nil, 0) if err == nil || !strings.Contains(err.Error(), "applyTxn: failed Range: rangeKeys: context cancelled: context canceled") { t.Fatalf("Expected context canceled error, got %v", err) } @@ -376,7 +376,7 @@ func TestWriteTxnPanicWithoutApply(t *testing.T) { // we verify the following properties below: // 1. server panics after a write txn aply fails (invariant: server should never try to move on from a failed write) // 2. no writes from the txn are applied to the backend (invariant: failed write should have no side-effect on DB state besides panic) - assert.Panicsf(t, func() { Txn(ctx, zaptest.NewLogger(t), txn, false, s, &lease.FakeLessor{}) }, "Expected panic in Txn with writes") + assert.Panicsf(t, func() { Txn(ctx, zaptest.NewLogger(t), txn, false, s, &lease.FakeLessor{}, nil, 0) }, "Expected panic in Txn with writes") dbHashAfter, err := computeFileHash(bePath) require.NoErrorf(t, err, "failed to compute DB file hash after txn") require.Equalf(t, dbHashBefore, dbHashAfter, "mismatch in DB hash before and after failed write txn") diff --git a/server/etcdserver/v3_server.go b/server/etcdserver/v3_server.go index e45524289e13..fc43f7bac410 100644 --- a/server/etcdserver/v3_server.go +++ b/server/etcdserver/v3_server.go @@ -225,7 +225,7 @@ func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse }(time.Now()) get := func() { - resp, _, err = txn.Txn(ctx, s.Logger(), r, s.Cfg.ServerFeatureGate.Enabled(features.TxnModeWriteWithSharedBuffer), s.KV(), s.lessor) + resp, _, err = txn.Txn(ctx, s.Logger(), r, s.Cfg.ServerFeatureGate.Enabled(features.TxnModeWriteWithSharedBuffer), s.KV(), s.lessor, nil, 0) } if serr := s.doSerialize(ctx, chk, get); serr != nil { return nil, serr @@ -832,7 +832,8 @@ func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.In } r.Header = &pb.RequestHeader{ - ID: s.reqIDGen.Next(), + ID: s.reqIDGen.Next(), + RequesterMemberId: uint64(s.memberID), } // check authinfo if it is not InternalAuthenticateRequest