snapshot returns up to limit most-recent errors, newest first (limit <= 0 returns all retained).
(limit int)
| 62 | // snapshot returns up to limit most-recent errors, newest first (limit <= 0 |
| 63 | // returns all retained). |
| 64 | func (r *recentErrorRing) snapshot(limit int) []RecentError { |
| 65 | if r == nil { |
| 66 | return nil |
| 67 | } |
| 68 | r.mu.Lock() |
| 69 | defer r.mu.Unlock() |
| 70 | count := r.n |
| 71 | if limit > 0 && limit < count { |
| 72 | count = limit |
| 73 | } |
| 74 | out := make([]RecentError, 0, count) |
| 75 | idx := (r.next - 1 + len(r.buf)) % len(r.buf) |
| 76 | for i := 0; i < count; i++ { |
| 77 | out = append(out, r.buf[idx]) |
| 78 | idx = (idx - 1 + len(r.buf)) % len(r.buf) |
| 79 | } |
| 80 | return out |
| 81 | } |
| 82 | |
| 83 | // recordRecentError adds a redacted error to the server's ring (nil-safe). |
| 84 | func (s *Server) recordRecentError(e RecentError) { |
no outgoing calls