Skip to content

Commit

Permalink
optimize query observer
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-sun-star committed Sep 19, 2023
1 parent fa001cc commit df2a477
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/oceanbase/operation/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ import (
)

func (m *OceanbaseOperationManager) GetServer(s *model.ServerInfo) (*model.OBServer, error) {
observers, err := m.ListServers()
observers := make([]model.OBServer, 0)
err := m.QueryList(&observers, sql.GetServer, s.Ip, s.Port)
if err != nil {
return nil, err
}
for _, observer := range observers {
if s.Ip == observer.Ip && s.Port == observer.Port {
return &observer, nil
}
if len(observers) == 0 {
m.Logger.Info("observer not found", "server identity", s)
return nil, nil
}
m.Logger.Info("observer not found", "identity", s)
return nil, nil
return &observers[0], nil
}

func (m *OceanbaseOperationManager) ListServers() ([]model.OBServer, error) {
Expand Down

0 comments on commit df2a477

Please sign in to comment.