|
@@ -34,8 +34,7 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
|
- warnApplyDuration = 100 * time.Millisecond
|
|
|
|
|
- rangeTraceThreshold = 100 * time.Millisecond
|
|
|
|
|
|
|
+ warnApplyDuration = 100 * time.Millisecond
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type applyResult struct {
|
|
type applyResult struct {
|
|
@@ -45,13 +44,14 @@ type applyResult struct {
|
|
|
// to being logically reflected by the node. Currently only used for
|
|
// to being logically reflected by the node. Currently only used for
|
|
|
// Compaction requests.
|
|
// Compaction requests.
|
|
|
physc <-chan struct{}
|
|
physc <-chan struct{}
|
|
|
|
|
+ trace *traceutil.Trace
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// applierV3 is the interface for processing V3 raft messages
|
|
// applierV3 is the interface for processing V3 raft messages
|
|
|
type applierV3 interface {
|
|
type applierV3 interface {
|
|
|
Apply(r *pb.InternalRaftRequest) *applyResult
|
|
Apply(r *pb.InternalRaftRequest) *applyResult
|
|
|
|
|
|
|
|
- Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error)
|
|
|
|
|
|
|
+ Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error)
|
|
|
Range(ctx context.Context, txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error)
|
|
Range(ctx context.Context, txn mvcc.TxnRead, r *pb.RangeRequest) (*pb.RangeResponse, error)
|
|
|
DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error)
|
|
DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error)
|
|
|
Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error)
|
|
Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error)
|
|
@@ -123,7 +123,7 @@ func (a *applierV3backend) Apply(r *pb.InternalRaftRequest) *applyResult {
|
|
|
case r.Range != nil:
|
|
case r.Range != nil:
|
|
|
ar.resp, ar.err = a.s.applyV3.Range(context.TODO(), nil, r.Range)
|
|
ar.resp, ar.err = a.s.applyV3.Range(context.TODO(), nil, r.Range)
|
|
|
case r.Put != nil:
|
|
case r.Put != nil:
|
|
|
- ar.resp, ar.err = a.s.applyV3.Put(nil, r.Put)
|
|
|
|
|
|
|
+ ar.resp, ar.trace, ar.err = a.s.applyV3.Put(nil, r.Put)
|
|
|
case r.DeleteRange != nil:
|
|
case r.DeleteRange != nil:
|
|
|
ar.resp, ar.err = a.s.applyV3.DeleteRange(nil, r.DeleteRange)
|
|
ar.resp, ar.err = a.s.applyV3.DeleteRange(nil, r.DeleteRange)
|
|
|
case r.Txn != nil:
|
|
case r.Txn != nil:
|
|
@@ -176,22 +176,19 @@ func (a *applierV3backend) Apply(r *pb.InternalRaftRequest) *applyResult {
|
|
|
return ar
|
|
return ar
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (a *applierV3backend) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (resp *pb.PutResponse, err error) {
|
|
|
|
|
|
|
+func (a *applierV3backend) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (resp *pb.PutResponse, trace *traceutil.Trace, err error) {
|
|
|
resp = &pb.PutResponse{}
|
|
resp = &pb.PutResponse{}
|
|
|
resp.Header = &pb.ResponseHeader{}
|
|
resp.Header = &pb.ResponseHeader{}
|
|
|
- trace := traceutil.New("put",
|
|
|
|
|
|
|
+ trace = traceutil.New("put",
|
|
|
a.s.getLogger(),
|
|
a.s.getLogger(),
|
|
|
traceutil.Field{Key: "key", Value: string(p.Key)},
|
|
traceutil.Field{Key: "key", Value: string(p.Key)},
|
|
|
traceutil.Field{Key: "value", Value: string(p.Value)},
|
|
traceutil.Field{Key: "value", Value: string(p.Value)},
|
|
|
)
|
|
)
|
|
|
- defer func() {
|
|
|
|
|
- trace.LogIfLong(warnApplyDuration)
|
|
|
|
|
- }()
|
|
|
|
|
val, leaseID := p.Value, lease.LeaseID(p.Lease)
|
|
val, leaseID := p.Value, lease.LeaseID(p.Lease)
|
|
|
if txn == nil {
|
|
if txn == nil {
|
|
|
if leaseID != lease.NoLease {
|
|
if leaseID != lease.NoLease {
|
|
|
if l := a.s.lessor.Lookup(leaseID); l == nil {
|
|
if l := a.s.lessor.Lookup(leaseID); l == nil {
|
|
|
- return nil, lease.ErrLeaseNotFound
|
|
|
|
|
|
|
+ return nil, nil, lease.ErrLeaseNotFound
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
txn = a.s.KV().Write(trace)
|
|
txn = a.s.KV().Write(trace)
|
|
@@ -203,14 +200,14 @@ func (a *applierV3backend) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (resp *pb.Pu
|
|
|
trace.StepBegin()
|
|
trace.StepBegin()
|
|
|
rr, err = txn.Range(p.Key, nil, mvcc.RangeOptions{})
|
|
rr, err = txn.Range(p.Key, nil, mvcc.RangeOptions{})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, err
|
|
|
|
|
|
|
+ return nil, nil, err
|
|
|
}
|
|
}
|
|
|
trace.StepEnd("get previous kv pair")
|
|
trace.StepEnd("get previous kv pair")
|
|
|
}
|
|
}
|
|
|
if p.IgnoreValue || p.IgnoreLease {
|
|
if p.IgnoreValue || p.IgnoreLease {
|
|
|
if rr == nil || len(rr.KVs) == 0 {
|
|
if rr == nil || len(rr.KVs) == 0 {
|
|
|
// ignore_{lease,value} flag expects previous key-value pair
|
|
// ignore_{lease,value} flag expects previous key-value pair
|
|
|
- return nil, ErrKeyNotFound
|
|
|
|
|
|
|
+ return nil, nil, ErrKeyNotFound
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if p.IgnoreValue {
|
|
if p.IgnoreValue {
|
|
@@ -226,7 +223,7 @@ func (a *applierV3backend) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (resp *pb.Pu
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
resp.Header.Revision = txn.Put(p.Key, val, leaseID)
|
|
resp.Header.Revision = txn.Put(p.Key, val, leaseID)
|
|
|
- return resp, nil
|
|
|
|
|
|
|
+ return resp, trace, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (a *applierV3backend) DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) {
|
|
func (a *applierV3backend) DeleteRange(txn mvcc.TxnWrite, dr *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) {
|
|
@@ -540,7 +537,7 @@ func (a *applierV3backend) applyTxn(txn mvcc.TxnWrite, rt *pb.TxnRequest, txnPat
|
|
|
}
|
|
}
|
|
|
respi.(*pb.ResponseOp_ResponseRange).ResponseRange = resp
|
|
respi.(*pb.ResponseOp_ResponseRange).ResponseRange = resp
|
|
|
case *pb.RequestOp_RequestPut:
|
|
case *pb.RequestOp_RequestPut:
|
|
|
- resp, err := a.Put(txn, tv.RequestPut)
|
|
|
|
|
|
|
+ resp, _, err := a.Put(txn, tv.RequestPut)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
if lg != nil {
|
|
if lg != nil {
|
|
|
lg.Panic("unexpected error during txn", zap.Error(err))
|
|
lg.Panic("unexpected error during txn", zap.Error(err))
|
|
@@ -688,8 +685,8 @@ type applierV3Capped struct {
|
|
|
// with Puts so that the number of keys in the store is capped.
|
|
// with Puts so that the number of keys in the store is capped.
|
|
|
func newApplierV3Capped(base applierV3) applierV3 { return &applierV3Capped{applierV3: base} }
|
|
func newApplierV3Capped(base applierV3) applierV3 { return &applierV3Capped{applierV3: base} }
|
|
|
|
|
|
|
|
-func (a *applierV3Capped) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) {
|
|
|
|
|
- return nil, ErrNoSpace
|
|
|
|
|
|
|
+func (a *applierV3Capped) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
|
|
|
|
|
+ return nil, nil, ErrNoSpace
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (a *applierV3Capped) Txn(r *pb.TxnRequest) (*pb.TxnResponse, error) {
|
|
func (a *applierV3Capped) Txn(r *pb.TxnRequest) (*pb.TxnResponse, error) {
|
|
@@ -838,13 +835,13 @@ func newQuotaApplierV3(s *EtcdServer, app applierV3) applierV3 {
|
|
|
return "aApplierV3{app, NewBackendQuota(s, "v3-applier")}
|
|
return "aApplierV3{app, NewBackendQuota(s, "v3-applier")}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (a *quotaApplierV3) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, error) {
|
|
|
|
|
|
|
+func (a *quotaApplierV3) Put(txn mvcc.TxnWrite, p *pb.PutRequest) (*pb.PutResponse, *traceutil.Trace, error) {
|
|
|
ok := a.q.Available(p)
|
|
ok := a.q.Available(p)
|
|
|
- resp, err := a.applierV3.Put(txn, p)
|
|
|
|
|
|
|
+ resp, trace, err := a.applierV3.Put(txn, p)
|
|
|
if err == nil && !ok {
|
|
if err == nil && !ok {
|
|
|
err = ErrNoSpace
|
|
err = ErrNoSpace
|
|
|
}
|
|
}
|
|
|
- return resp, err
|
|
|
|
|
|
|
+ return resp, trace, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (a *quotaApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) {
|
|
func (a *quotaApplierV3) Txn(rt *pb.TxnRequest) (*pb.TxnResponse, error) {
|