autopilot+autopilotrpc: ignore local channels if ignore_local_state set
This commit is contained in:
parent
c7ab6f3603
commit
d4813422c9
@ -270,7 +270,9 @@ func (m *Manager) StopAgent() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// QueryHeuristics queries the available autopilot heuristics for node scores.
|
// QueryHeuristics queries the available autopilot heuristics for node scores.
|
||||||
func (m *Manager) QueryHeuristics(nodes []NodeID) (HeuristicScores, error) {
|
func (m *Manager) QueryHeuristics(nodes []NodeID, localState bool) (
|
||||||
|
HeuristicScores, error) {
|
||||||
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
@ -280,7 +282,7 @@ func (m *Manager) QueryHeuristics(nodes []NodeID) (HeuristicScores, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Querying heuristics for %d nodes", len(n))
|
log.Debugf("Querying heuristics for %d nodes", len(n))
|
||||||
return m.queryHeuristics(n)
|
return m.queryHeuristics(n, localState)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HeuristicScores is an alias for a map that maps heuristic names to a map of
|
// HeuristicScores is an alias for a map that maps heuristic names to a map of
|
||||||
@ -291,17 +293,23 @@ type HeuristicScores map[string]map[NodeID]float64
|
|||||||
// the agent's current active heuristic.
|
// the agent's current active heuristic.
|
||||||
//
|
//
|
||||||
// NOTE: Must be called with the manager's lock.
|
// NOTE: Must be called with the manager's lock.
|
||||||
func (m *Manager) queryHeuristics(nodes map[NodeID]struct{}) (
|
func (m *Manager) queryHeuristics(nodes map[NodeID]struct{}, localState bool) (
|
||||||
HeuristicScores, error) {
|
HeuristicScores, error) {
|
||||||
|
|
||||||
|
// If we want to take the local state into action when querying the
|
||||||
|
// heuristics, we fetch it. If not we'll just pass an emply slice to
|
||||||
|
// the heuristic.
|
||||||
|
var totalChans []Channel
|
||||||
|
var err error
|
||||||
|
if localState {
|
||||||
// Fetch the current set of channels.
|
// Fetch the current set of channels.
|
||||||
totalChans, err := m.cfg.ChannelState()
|
totalChans, err = m.cfg.ChannelState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the agent is active, we can merge the channel state with the
|
// If the agent is active, we can merge the channel state with
|
||||||
// channels pending open.
|
// the channels pending open.
|
||||||
if m.pilot != nil {
|
if m.pilot != nil {
|
||||||
m.pilot.chanStateMtx.Lock()
|
m.pilot.chanStateMtx.Lock()
|
||||||
m.pilot.pendingMtx.Lock()
|
m.pilot.pendingMtx.Lock()
|
||||||
@ -311,6 +319,7 @@ func (m *Manager) queryHeuristics(nodes map[NodeID]struct{}) (
|
|||||||
m.pilot.pendingMtx.Unlock()
|
m.pilot.pendingMtx.Unlock()
|
||||||
m.pilot.chanStateMtx.Unlock()
|
m.pilot.chanStateMtx.Unlock()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// As channel size we'll use the maximum size.
|
// As channel size we'll use the maximum size.
|
||||||
chanSize := m.cfg.PilotCfg.Constraints.MaxChanSize()
|
chanSize := m.cfg.PilotCfg.Constraints.MaxChanSize()
|
||||||
|
@ -180,7 +180,9 @@ func (s *Server) QueryScores(ctx context.Context, in *QueryScoresRequest) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query the heuristics.
|
// Query the heuristics.
|
||||||
heuristicScores, err := s.manager.QueryHeuristics(nodes)
|
heuristicScores, err := s.manager.QueryHeuristics(
|
||||||
|
nodes, !in.IgnoreLocalState,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user