Merge branch 'main' into dev

This commit is contained in:
Derek Collison
2023-04-07 05:32:05 -07:00
7 changed files with 111 additions and 67 deletions

View File

@@ -894,10 +894,17 @@ func (s *Server) sendAPIErrResponse(ci *ClientInfo, acc *Account, subject, reply
const errRespDelay = 500 * time.Millisecond
func (s *Server) sendDelayedAPIErrResponse(ci *ClientInfo, acc *Account, subject, reply, request, response string, rg *raftGroup) {
js := s.getJetStream()
if js == nil {
return
}
var quitCh <-chan struct{}
js.mu.RLock()
if rg != nil && rg.node != nil {
quitCh = rg.node.QuitC()
}
js.mu.RUnlock()
s.startGoRoutine(func() {
defer s.grWG.Done()
select {
@@ -1971,18 +1978,24 @@ func (s *Server) jsStreamLeaderStepDownRequest(sub *subscription, c *client, _ *
return
}
// Call actual stepdown.
if mset != nil {
if mset == nil {
resp.Success = true
s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp))
return
}
// Call actual stepdown. Do this in a Go routine.
go func() {
if node := mset.raftNode(); node != nil {
mset.setLeader(false)
// TODO (mh) eventually make sure all go routines exited and all channels are cleared
time.Sleep(250 * time.Millisecond)
node.StepDown()
}
}
resp.Success = true
s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp))
resp.Success = true
s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp))
}()
}
// Request to have a consumer leader stepdown.
@@ -2077,16 +2090,23 @@ func (s *Server) jsConsumerLeaderStepDownRequest(sub *subscription, c *client, _
return
}
// Call actual stepdown.
if n := o.raftNode(); n != nil {
n := o.raftNode()
if n == nil {
resp.Success = true
s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp))
return
}
// Call actual stepdown. Do this in a Go routine.
go func() {
o.setLeader(false)
// TODO (mh) eventually make sure all go routines exited and all channels are cleared
time.Sleep(250 * time.Millisecond)
n.StepDown()
}
resp.Success = true
s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp))
resp.Success = true
s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp))
}()
}
// Request to remove a peer from a clustered stream.