scheduler: check node status before evicting

This commit is contained in:
Armon Dadgar
2015-08-11 14:04:04 -07:00
parent b92d49a09f
commit 9c17cceaa3
2 changed files with 20 additions and 0 deletions

View File

@@ -57,6 +57,9 @@ type State interface {
// AllocsByJob returns the allocations by JobID
AllocsByJob(jobID string) ([]*structs.Allocation, error)
// GetNodeByID is used to lookup a node by ID
GetNodeByID(nodeID string) (*structs.Node, error)
}
// Planner interface is used to submit a task allocation plan.

View File

@@ -52,6 +52,23 @@ func (s *ServiceScheduler) handleJobRegister(eval *structs.Evaluation) error {
// handleJobDeregister is used to handle a job being deregistered
func (s *ServiceScheduler) handleJobDeregister(eval *structs.Evaluation) error {
START:
// Lookup the node ID
node, err := s.state.GetNodeByID(eval.NodeID)
if err != nil {
return fmt.Errorf("failed to get node '%s': %v",
eval.NodeID, err)
}
// Could be a potential race, and the node is actually fine
if node != nil {
switch node.Status {
case structs.NodeStatusInit, structs.NodeStatusReady, structs.NodeStatusMaint:
s.logger.Printf("[DEBUG] sched: (eval %s) not evicting node %s allocs, status %s",
eval.ID, eval.NodeID, node.Status)
return nil
}
}
// Lookup the allocations by JobID
allocs, err := s.state.AllocsByJob(eval.JobID)
if err != nil {