Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 authored and ti-chi-bot committed Jun 5, 2024
1 parent 8da5859 commit bceed84
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/core/storelimit/store_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ func (l *StoreRateLimit) Reset(rate float64, typ Type) {

// limit the operators of a store
type limit struct {
syncutil.RWMutex
limiter *ratelimit.RateLimiter
ratePerSec float64
limiter *ratelimit.RateLimiter
ratePerSecMutex syncutil.RWMutex
ratePerSec float64
}

// Reset resets the rate limit.
func (l *limit) Reset(ratePerSec float64) {
l.Lock()
defer l.Unlock()
l.ratePerSecMutex.Lock()
defer l.ratePerSecMutex.Unlock()
if l.ratePerSec == ratePerSec {
return
}
Expand All @@ -159,8 +159,8 @@ func (l *limit) Reset(ratePerSec float64) {
// Available returns the number of available tokens
// It returns true if the rate per second is zero.
func (l *limit) Available(n int64) bool {
l.RLock()
defer l.RUnlock()
l.ratePerSecMutex.RLock()
defer l.ratePerSecMutex.RUnlock()
if l.ratePerSec == 0 {
return true
}
Expand All @@ -170,16 +170,16 @@ func (l *limit) Available(n int64) bool {

// Take takes count tokens from the bucket without blocking.
func (l *limit) Take(count int64) bool {
l.RLock()
defer l.RUnlock()
l.ratePerSecMutex.RLock()
defer l.ratePerSecMutex.RUnlock()
if l.ratePerSec == 0 {
return true
}
return l.limiter.AllowN(int(count))
}

func (l *limit) GetRatePerSec() float64 {
l.RLock()
defer l.RUnlock()
l.ratePerSecMutex.RLock()
defer l.ratePerSecMutex.RUnlock()
return l.ratePerSec
}

0 comments on commit bceed84

Please sign in to comment.