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

[membership] Replace Ringop with PeerProvider interface #4653

Merged
Prev Previous commit
Next Next commit
Allow only single subscription to ringpop per service
  • Loading branch information
mantas-sidlauskas committed Nov 23, 2021
commit ac9ea4e78f4944da52a42a1b508b7faf990ae30d
5 changes: 3 additions & 2 deletions common/membership/hashring.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ type ring struct {

sync.Mutex
keys map[string]struct{} // for de-duping change notifications

}

subscribers struct {
Expand Down Expand Up @@ -120,7 +119,9 @@ func (r *ring) Start() {
) {
return
}
r.peerProvider.Subscribe(r.service, r.refreshChan)
if err := r.peerProvider.Subscribe(r.service, r.refreshChan); err != nil {
r.logger.Fatal("subscribing to peer provider", tag.Error(err))
}

if err := r.refreshLocked(); err != nil {
r.logger.Fatal("failed to start service resolver", tag.Error(err))
Expand Down
5 changes: 5 additions & 0 deletions common/peerprovider/ringpopprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ func (r *Provider) Subscribe(name string, notifyChannel chan<- *membership.Chang
r.smu.RLock()
defer r.smu.RUnlock()

_, ok := r.subscribers[name]
if ok {
return fmt.Errorf("%q already subscribed to ringpop provider", name)
}

r.subscribers[name] = notifyChannel
return nil
}