Skip to content

Commit 099461d

Browse files
committed
stability enhancement during overload conditions
Signed-off-by: shenmu.wy <[email protected]>
1 parent 05b8563 commit 099461d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

server/etcdserver/util.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"time"
2020

21+
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
2122
"go.etcd.io/etcd/client/pkg/v3/types"
2223
"go.etcd.io/etcd/server/v3/etcdserver/api/membership"
2324
"go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp"
@@ -42,6 +43,26 @@ func isConnectedFullySince(transport rafthttp.Transporter, since time.Time, self
4243
return numConnectedSince(transport, since, self, members) == len(members)
4344
}
4445

46+
// isTooManyRequest checks whether the gap between applied index and committed
47+
// index is too large. r *pb.InternalRaftRequest should read-only.
48+
func isTooManyRequest(ai, ci uint64, r *pb.InternalRaftRequest) bool {
49+
// Critical request kinds include LeaseRevoke
50+
isCritical := r != nil && r.LeaseRevoke != nil
51+
52+
// If the gap is larger than maxGapBetweenApplyAndCommitIndex, reject all normal request
53+
if !isCritical && ci > ai+maxGapBetweenApplyAndCommitIndex {
54+
return true
55+
}
56+
57+
// Make an extra 10% gap buffer for critical requests, so thay can be applied
58+
// during overload conditions.
59+
if isCritical && ci-ai > maxGapBetweenApplyAndCommitIndex+500 {
60+
return true
61+
}
62+
63+
return false
64+
}
65+
4566
// numConnectedSince counts how many members are connected to the local member
4667
// since the given time.
4768
func numConnectedSince(transport rafthttp.Transporter, since time.Time, self types.ID, members []*membership.Member) int {

server/etcdserver/v3_server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ func (s *EtcdServer) doSerialize(ctx context.Context, chk func(*auth.AuthInfo) e
792792
func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.InternalRaftRequest) (*apply2.Result, error) {
793793
ai := s.getAppliedIndex()
794794
ci := s.getCommittedIndex()
795-
if ci > ai+maxGapBetweenApplyAndCommitIndex {
795+
796+
if isTooManyRequest(ai, ci, &r) {
796797
return nil, errors.ErrTooManyRequests
797798
}
798799

0 commit comments

Comments
 (0)