classifyServers compares wanted configs against the current server map and returns a diff describing what changed. Acquires and releases m.mu for reading.
(wanted map[string]ServerConfig)
| 584 | // server map and returns a diff describing what changed. |
| 585 | // Acquires and releases m.mu for reading. |
| 586 | func (m *Manager) classifyServers(wanted map[string]ServerConfig) (*serverDiff, error) { |
| 587 | m.mu.RLock() |
| 588 | defer m.mu.RUnlock() |
| 589 | |
| 590 | if m.closed { |
| 591 | return nil, ErrManagerClosed |
| 592 | } |
| 593 | |
| 594 | diff := &serverDiff{ |
| 595 | keep: make(map[string]*serverEntry), |
| 596 | } |
| 597 | |
| 598 | for name, wantCfg := range wanted { |
| 599 | if existing, ok := m.servers[name]; ok { |
| 600 | if reflect.DeepEqual(existing.config, wantCfg) { |
| 601 | diff.keep[name] = existing |
| 602 | } else { |
| 603 | diff.toConnect = append(diff.toConnect, wantCfg) |
| 604 | } |
| 605 | } else { |
| 606 | diff.toConnect = append(diff.toConnect, wantCfg) |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | for name, entry := range m.servers { |
| 611 | if _, ok := wanted[name]; !ok { |
| 612 | diff.toClose = append(diff.toClose, entry) |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | diff.prev = maps.Clone(m.servers) |
| 617 | return diff, nil |
| 618 | } |
| 619 | |
| 620 | // connectAll runs connectServer in parallel for the given configs. |
| 621 | // Failed connects are logged and skipped. |