Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switching to perfect use case of sync.Map and remove the locks #2976

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions dgraph/cmd/zero/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Server struct {
closer *y.Closer // Used to tell stream to close.
connectLock sync.Mutex // Used to serialize connect requests from servers.

blockCommitsOn map[string]struct{}
blockCommitsOn *sync.Map
}

func (s *Server) Init() {
Expand All @@ -78,7 +78,7 @@ func (s *Server) Init() {
s.nextGroup = 1
s.leaderChangeCh = make(chan struct{}, 1)
s.closer = y.NewCloser(2) // grpc and http
s.blockCommitsOn = make(map[string]struct{})
s.blockCommitsOn = new(sync.Map)
go s.rebalanceTablets()
}

Expand Down Expand Up @@ -285,20 +285,14 @@ func (s *Server) ServingTablet(tablet string) *pb.Tablet {
}

func (s *Server) blockTablet(pred string) func() {
s.Lock()
s.blockCommitsOn[pred] = struct{}{}
s.Unlock()
s.blockCommitsOn.Store(pred, struct{}{})
return func() {
s.Lock()
delete(s.blockCommitsOn, pred)
s.Unlock()
s.blockCommitsOn.Delete(pred)
}
}

func (s *Server) isBlocked(pred string) bool {
s.RLock()
defer s.RUnlock()
_, blocked := s.blockCommitsOn[pred]
_, blocked := s.blockCommitsOn.Load(pred)
return blocked
}

Expand Down