Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2018-10-06 14:04:14 -07:00
parent 2b0e5b07f4
commit 21ee7ed81a
2 changed files with 14 additions and 12 deletions

View File

@@ -193,9 +193,10 @@ func (s *Server) Connz(opts *ConnzOptions) (*Connz, error) {
case ConnClosed:
c.Total = s.closed.len()
closedClients = s.closed.closedClients()
c.Total = len(closedClients)
case ConnAll:
c.Total = len(s.clients) + s.closed.len()
closedClients = s.closed.closedClients()
c.Total = len(s.clients) + len(closedClients)
}
totalClients := c.Total

View File

@@ -55,21 +55,22 @@ func (rb *closedRingBuffer) totalConns() uint64 {
return rb.total
}
// This will not be sorted. Will return a copy of the list
// which recipient can modify. If the contents of the client
// itself need to be modified, meaning swapping in any optional items,
// a copy should be made. We could introduce a new lock and hold that
// but since we return this list inside monitor which allows programatic
// access, we do not know when it would be done.
// This will return a sorted copy of the list which recipient can
// modify. If the contents of the client itself need to be modified,
// meaning swapping in any optional items, a copy should be made. We
// could introduce a new lock and hold that but since we return this
// list inside monitor which allows programatic access, we do not
// know when it would be done.
func (rb *closedRingBuffer) closedClients() []*closedClient {
dup := make([]*closedClient, rb.len())
if rb.total <= uint64(cap(rb.conns)) {
head := rb.next()
if rb.total <= uint64(cap(rb.conns)) || head == 0 {
copy(dup, rb.conns[:rb.len()])
} else {
first := rb.next()
next := cap(rb.conns) - first
copy(dup, rb.conns[first:])
copy(dup[next:], rb.conns[:next])
fp := rb.conns[head:]
sp := rb.conns[:head]
copy(dup, fp)
copy(dup[len(fp):], sp)
}
return dup
}