mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
better error when peer selection fails (#3342)
* better error when peer selection fails
It is pretty hard to diagnose what went wrong when not enough peers for
an operation where found. This change now returns counts of reasons why
peers where discarded.
Changed the error to JSClusterNoPeers as it seems more appropriate
of an error for that operation. Not having enough resources is one of
the conditions for a peer not being considered. But so is having a non
matching tag. Which is why JSClusterNoPeers seems more appropriate
In addition, JSClusterNoPeers was already used as error after one call
to selectPeerGroup already.
example:
no suitable peers for placement: peer selection cluster 'C' with 3 peers
offline: 0
excludeTag: 1
noTagMatch: 2
noSpace: 0
uniqueTag: 0
misc: 0
Examle for mqtt:
mid:12 - "mqtt" - unable to connect: create sessions stream for account "$G":
no suitable peers for placement: peer selection cluster 'MQTT' with 3 peers
offline: 0
excludeTag: 0
noTagMatch: 0
noSpace: 0
uniqueTag: 0
misc: 0
(10005)
Signed-off-by: Matthias Hanel <mh@synadia.com>
* review comment
Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
@@ -2357,7 +2357,7 @@ func (s *Server) jsLeaderServerStreamMoveRequest(sub *subscription, c *client, _
|
||||
cfg.Placement.Tags = append(cfg.Placement.Tags, req.Tags...)
|
||||
}
|
||||
|
||||
peers := cc.selectPeerGroup(cfg.Replicas+1, currCluster, &cfg, currPeers, 1)
|
||||
peers, e := cc.selectPeerGroup(cfg.Replicas+1, currCluster, &cfg, currPeers, 1)
|
||||
if len(peers) <= cfg.Replicas {
|
||||
// since expanding in the same cluster did not yield a result, try in different cluster
|
||||
peers = nil
|
||||
@@ -2369,16 +2369,18 @@ func (s *Server) jsLeaderServerStreamMoveRequest(sub *subscription, c *client, _
|
||||
}
|
||||
return true
|
||||
})
|
||||
errs := selectPeerErrors{e}
|
||||
for cluster := range clusters {
|
||||
newPeers := cc.selectPeerGroup(cfg.Replicas, cluster, &cfg, nil, 0)
|
||||
newPeers, _ := cc.selectPeerGroup(cfg.Replicas, cluster, &cfg, nil, 0)
|
||||
if len(newPeers) >= cfg.Replicas {
|
||||
peers = append([]string{}, currPeers...)
|
||||
peers = append(peers, newPeers[:cfg.Replicas]...)
|
||||
break
|
||||
}
|
||||
errs = append(errs, e)
|
||||
}
|
||||
if peers == nil {
|
||||
resp.Error = NewJSClusterNoPeersError()
|
||||
resp.Error = NewJSClusterNoPeersError(&errs)
|
||||
s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp))
|
||||
return
|
||||
}
|
||||
@@ -2619,7 +2621,7 @@ func (s *Server) jsLeaderStepDownRequest(sub *subscription, c *client, _ *Accoun
|
||||
}
|
||||
}
|
||||
if len(peers) == 0 {
|
||||
resp.Error = NewJSClusterNoPeersError()
|
||||
resp.Error = NewJSClusterNoPeersError(fmt.Errorf("no replacement peer connected"))
|
||||
s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user