Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distinct_property constraint #2418

Merged
merged 8 commits into from
Mar 10, 2017
Merged

distinct_property constraint #2418

merged 8 commits into from
Mar 10, 2017

Conversation

dadgar
Copy link
Contributor

@dadgar dadgar commented Mar 9, 2017

This PR introduces a distinct property constraint. This allows constraints such as:

constraint {
  distinct_property = "${meta.rack}"
}

Which causes each placement to be on a node with a distinct value of ${meta.rack}.

Fixes #1387

// Hot-path if the option is nil or there are no distinct_hosts or
// distinct_property constraints.
hosts := iter.jobDistinctHosts || iter.tgDistinctHosts
properties := iter.distinctProperties.HasDistinctPropertyConstraints()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call HasDistinctPropertyConstraints() in SetJob and then just check for a nil distinctProperties here? Seems more efficient that way, avoids some allocations.

}

// Check if the property constraints are satisfied
if properties {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should just be a new iterator? Seem's odd to create a split code path like this, instead of just having another iterator type.

@dadgar dadgar force-pushed the f-distinct-property branch 2 times, most recently from 81fc49c to d688a7f Compare March 9, 2017 23:23
@dadgar dadgar force-pushed the f-distinct-property branch 2 times, most recently from 5432abc to e03bb92 Compare March 10, 2017 00:16
Copy link
Member

@armon armon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor feedback, way more understandable!

iter.jobPropertySets = append(iter.jobPropertySets, pset)
}

for _, tg := range job.TaskGroups {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do this inside SetTaskGroup?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realizes SetTFConstraint populates, so doing this as lazily as possible seems preferable.

}

// Check if the constraints are met
for _, ps := range iter.jobPropertySets {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably just have a helper method for satisfiesProperties() which takes a list, and call it once for jobPropertySets and groupPropertySets to DRY

both := make([]*structs.Allocation, 0, len(stopping)+len(proposed))
both = append(both, stopping...)
both = append(both, proposed...)
nodes, err := p.buildNodeMap(both)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a helper that takes []*Allocation and map[string]struct{} and does both the node map building, and property setting. It seems that pattern exists a few times here.

continue
}

return false, fmt.Sprintf("distinct_property: %s=%s already used", p.constraint.LTarget, nValue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if including the value which may be distinct could case an explosion of annotations for AllocMetrics e.g. if I have high cardinality. Might be not worth considering at this point.

Copy link
Member

@schmichael schmichael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of your tests is failing, otherwise looks good to my untrained eye.

--- FAIL: TestServiceSched_JobModify_DistinctProperty (0.00s)
	generic_sched_test.go:1649: bad: []*structs.Allocation{(*structs.Allocation)(0xc420443400), (*structs.Allocation)(0xc420442100), (*structs.Allocation)(0xc420442600), (*structs.Allocation)(0xc420442b00), (*structs.Allocation)(0xc420442f00), (*structs.Allocation)(0xc420443200)}

@dadgar
Copy link
Contributor Author

dadgar commented Mar 10, 2017

@schmichael Thanks! Its fixed in the most recent commit!

@dadgar dadgar merged commit d0d3663 into master Mar 10, 2017
@dadgar dadgar deleted the f-distinct-property branch March 10, 2017 06:15
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants