Skip to content

Commit

Permalink
fix(lease): don't do rate limiting when not limit is not specified (#…
Browse files Browse the repository at this point in the history
…7787)

(cherry picked from commit e98009b)
  • Loading branch information
NamanJain8 authored and ahsanbarkati committed May 27, 2021
1 parent 9476647 commit f172024
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 3 additions & 0 deletions dgraph/cmd/zero/assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ func (s *Server) AssignIds(ctx context.Context, num *pb.Num) (*pb.AssignedIds, e
defer span.End()

rateLimit := func() error {
if s.rateLimiter == nil {
return nil
}
if num.GetType() != pb.Num_UID {
// We only rate limit lease of UIDs.
return nil
Expand Down
5 changes: 0 additions & 5 deletions dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"crypto/tls"
"fmt"
"log"
"math"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -238,10 +237,6 @@ func run() {
UidLeaseLimit: limit.GetUint64("uid-lease"),
RefillAfter: limit.GetDuration("refill-interval"),
}
if limitConf.UidLeaseLimit == 0 {
// Setting it to 0 removes the limit.
limitConf.UidLeaseLimit = math.MaxInt64
}
opts = options{
telemetry: telemetry,
raft: raft,
Expand Down
7 changes: 5 additions & 2 deletions dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ func (s *Server) Init() {
s.blockCommitsOn = new(sync.Map)
s.moveOngoing = make(chan struct{}, 1)
s.checkpointPerGroup = make(map[uint32]uint64)
s.rateLimiter = x.NewRateLimiter(int64(opts.limiterConfig.UidLeaseLimit),
opts.limiterConfig.RefillAfter, s.closer)
if opts.limiterConfig.UidLeaseLimit > 0 {
// rate limiting is not enabled when lease limit is set to zero.
s.rateLimiter = x.NewRateLimiter(int64(opts.limiterConfig.UidLeaseLimit),
opts.limiterConfig.RefillAfter, s.closer)
}

go s.rebalanceTablets()
}
Expand Down

0 comments on commit f172024

Please sign in to comment.