Skip to content

Commit

Permalink
Move stepdowns of streams and consumers to not be inline. (#4029)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Apr 6, 2023
2 parents 7547093 + 0d2269b commit f02f379
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions server/jetstream_api.go
Expand Up @@ -1967,18 +1967,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.
Expand Down Expand Up @@ -2073,16 +2079,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.
Expand Down

0 comments on commit f02f379

Please sign in to comment.