GetCurrent returns the current primary session
()
| 316 | |
| 317 | // GetCurrent returns the current primary session |
| 318 | func (cm *ConnManager) GetCurrent() *Session { |
| 319 | cm.mu.RLock() |
| 320 | defer cm.mu.RUnlock() |
| 321 | |
| 322 | var selectedSession *Session |
| 323 | |
| 324 | // First, look for a healthy primary session |
| 325 | for _, session := range cm.sessions { |
| 326 | if session.IsPrimary() && session.IsHealthy() { |
| 327 | selectedSession = session |
| 328 | break |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // If no healthy primary, look for any healthy secondary (during transition) |
| 333 | if selectedSession == nil { |
| 334 | for _, session := range cm.sessions { |
| 335 | if session.IsSecondary() && session.IsHealthy() { |
| 336 | selectedSession = session |
| 337 | break |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // Last resort: return any healthy session (but not draining) |
| 343 | if selectedSession == nil { |
| 344 | for _, session := range cm.sessions { |
| 345 | if session.IsHealthy() && !session.IsDraining() { |
| 346 | selectedSession = session |
| 347 | break |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | // Only log when no session is found and we have sessions (unusual condition) |
| 353 | if selectedSession == nil && len(cm.sessions) > 0 { |
| 354 | shared.LogNetworkf("GetCurrent: No suitable session found among %d sessions", len(cm.sessions)) |
| 355 | for i, session := range cm.sessions { |
| 356 | shared.LogNetworkf(" Session %d: %s (role: %s, healthy: %v, draining: %v)", |
| 357 | i, session.ID, session.Role, session.IsHealthy(), session.IsDraining()) |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return selectedSession |
| 362 | } |
| 363 | |
| 364 | // GetAllSessions returns all sessions for dashboard display |
| 365 | func (cm *ConnManager) GetAllSessions() []*Session { |
no test coverage detected