Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
registry: remove units sorting since we already reclaim sorted keys f…
Browse files Browse the repository at this point in the history
…rom etcd

We are already reclaiming sorted Job units from etcd, so remove the
sorting logic and an extra loop while we are it.
  • Loading branch information
Djalal Harouni committed Mar 22, 2016
1 parent 66959a7 commit 66d31fd
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions registry/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (r *EtcdRegistry) Schedule() ([]job.ScheduledUnit, error) {
func (r *EtcdRegistry) Units() ([]job.Unit, error) {
key := r.prefixed(jobPrefix)
opts := &etcd.GetOptions{
// We need Job Units to be sorted
Sort: true,
Recursive: true,
}
Expand Down Expand Up @@ -117,8 +118,9 @@ func (r *EtcdRegistry) Units() ([]job.Unit, error) {
return unit
}

var sortable sort.StringSlice
uMap := make(map[string]*job.Unit)
// make it at least size of Nodes
uMap := make(map[string]bool, len(res.Node.Nodes))
units := make([]job.Unit, 0)
for _, dir := range res.Node.Nodes {
u, err := r.dirToUnit(dir, unitHashLookupFunc)
if err != nil {
Expand All @@ -134,15 +136,8 @@ func (r *EtcdRegistry) Units() ([]job.Unit, error) {
continue
}

uMap[u.Name] = u
sortable = append(sortable, u.Name)
}

sortable.Sort()

units := make([]job.Unit, len(sortable))
for i, name := range sortable {
units[i] = *uMap[name]
uMap[u.Name] = true
units = append(units, *u)
}

return units, nil
Expand Down

0 comments on commit 66d31fd

Please sign in to comment.