fix: Add EmptySessionWatcher to prevent panic in IndexNodeBinding mode (#45911)

Related to #45910

When IndexNodeBinding mode is enabled, DataCoord skips session watching
for datanodes but the dnSessionWatcher field remains nil. This causes a
panic when other code attempts to access the watcher.

This fix introduces an EmptySessionWatcher as a placeholder for the
IndexNodeBinding mode scenario. The empty watcher implements the
SessionWatcher interface with no-op methods, preventing nil pointer
dereferences while maintaining the expected interface contract.

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2025-11-28 19:07:08 +08:00 committed by GitHub
parent d2e4278b18
commit ea4bbbda3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -528,6 +528,7 @@ func (s *Server) initServiceDiscovery() error {
log.Warn("DataCoord failed to add datanode", zap.Error(err)) log.Warn("DataCoord failed to add datanode", zap.Error(err))
return err return err
} }
s.dnSessionWatcher = sessionutil.EmptySessionWatcher()
} else { } else {
err := s.rewatchDataNodes(sessions) err := s.rewatchDataNodes(sessions)
if err != nil { if err != nil {

View File

@ -806,6 +806,20 @@ func (w *sessionWatcher) Stop() {
w.wg.Wait() w.wg.Wait()
} }
// EmptySessionWatcher returns a place holder for IndexNodeBinding mode datacoord
func EmptySessionWatcher() SessionWatcher {
return emptySessionWatcher{}
}
// emptySessionWatcher is a place holder for IndexNodeBinding mode datacoord
type emptySessionWatcher struct{}
func (emptySessionWatcher) EventChannel() <-chan *SessionEvent {
return nil
}
func (emptySessionWatcher) Stop() {}
// WatchServices watches the service's up and down in etcd, and sends event to // WatchServices watches the service's up and down in etcd, and sends event to
// eventChannel. // eventChannel.
// prefix is a parameter to know which service to watch and can be obtained in // prefix is a parameter to know which service to watch and can be obtained in