4545
4646 leaseBucketName = []byte ("lease" )
4747
48- // maximum number of leases to revoke per second; configurable for tests
49- leaseRevokeRate = 1000
48+ // default number of leases to revoke per second; configurable for tests
49+ defaultLeaseRevokeRate = 1000
5050
5151 // maximum number of lease checkpoints recorded to the consensus log per second; configurable for tests
5252 leaseCheckpointRate = 1000
@@ -173,6 +173,9 @@ type lessor struct {
173173 // requests for shorter TTLs are extended to the minimum TTL.
174174 minLeaseTTL int64
175175
176+ // maximum number of leases to revoke per second
177+ leaseRevokeRate int
178+
176179 expiredC chan []* Lease
177180 // stopC is a channel whose closure indicates that the lessor should be stopped.
178181 stopC chan struct {}
@@ -201,6 +204,8 @@ type LessorConfig struct {
201204 CheckpointInterval time.Duration
202205 ExpiredLeasesRetryInterval time.Duration
203206 CheckpointPersist bool
207+
208+ leaseRevokeRate int
204209}
205210
206211func NewLessor (lg * zap.Logger , b backend.Backend , cluster cluster , cfg LessorConfig ) Lessor {
@@ -210,19 +215,24 @@ func NewLessor(lg *zap.Logger, b backend.Backend, cluster cluster, cfg LessorCon
210215func newLessor (lg * zap.Logger , b backend.Backend , cluster cluster , cfg LessorConfig ) * lessor {
211216 checkpointInterval := cfg .CheckpointInterval
212217 expiredLeaseRetryInterval := cfg .ExpiredLeasesRetryInterval
218+ leaseRevokeRate := cfg .leaseRevokeRate
213219 if checkpointInterval == 0 {
214220 checkpointInterval = defaultLeaseCheckpointInterval
215221 }
216222 if expiredLeaseRetryInterval == 0 {
217223 expiredLeaseRetryInterval = defaultExpiredleaseRetryInterval
218224 }
225+ if leaseRevokeRate == 0 {
226+ leaseRevokeRate = defaultLeaseRevokeRate
227+ }
219228 l := & lessor {
220229 leaseMap : make (map [LeaseID ]* Lease ),
221230 itemMap : make (map [LeaseItem ]LeaseID ),
222231 leaseExpiredNotifier : newLeaseExpiredNotifier (),
223232 leaseCheckpointHeap : make (LeaseQueue , 0 ),
224233 b : b ,
225234 minLeaseTTL : cfg .MinLeaseTTL ,
235+ leaseRevokeRate : leaseRevokeRate ,
226236 checkpointInterval : checkpointInterval ,
227237 expiredLeaseRetryInterval : expiredLeaseRetryInterval ,
228238 checkpointPersist : cfg .CheckpointPersist ,
@@ -475,7 +485,7 @@ func (le *lessor) Promote(extend time.Duration) {
475485 le .scheduleCheckpointIfNeeded (l )
476486 }
477487
478- if len (le .leaseMap ) < leaseRevokeRate {
488+ if len (le .leaseMap ) < le . leaseRevokeRate {
479489 // no possibility of lease pile-up
480490 return
481491 }
@@ -489,7 +499,7 @@ func (le *lessor) Promote(extend time.Duration) {
489499 expires := 0
490500 // have fewer expires than the total revoke rate so piled up leases
491501 // don't consume the entire revoke limit
492- targetExpiresPerSecond := (3 * leaseRevokeRate ) / 4
502+ targetExpiresPerSecond := (3 * le . leaseRevokeRate ) / 4
493503 for _ , l := range leases {
494504 remaining := l .Remaining ()
495505 if remaining > nextWindow {
@@ -628,7 +638,7 @@ func (le *lessor) revokeExpiredLeases() {
628638 var ls []* Lease
629639
630640 // rate limit
631- revokeLimit := leaseRevokeRate / 2
641+ revokeLimit := le . leaseRevokeRate / 2
632642
633643 le .mu .RLock ()
634644 if le .isPrimary () {
0 commit comments