jobqueue: do not sort dependencies
While dependencies are purely internal, sorting and pruning them is a reasonable optimization. However, we wish to expose them in follow-up commits and then we want them to remain unchanged from the input. Nothing in the internal logic seems to rely on the fact the dependencies were sorted. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
f355bdd426
commit
e72b14bdd1
3 changed files with 2 additions and 88 deletions
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -108,7 +107,7 @@ func (q *fsJobQueue) Enqueue(jobType string, args interface{}, dependencies []uu
|
||||||
var j = job{
|
var j = job{
|
||||||
Id: uuid.New(),
|
Id: uuid.New(),
|
||||||
Type: jobType,
|
Type: jobType,
|
||||||
Dependencies: uniqueUUIDList(dependencies),
|
Dependencies: dependencies,
|
||||||
QueuedAt: time.Now(),
|
QueuedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,30 +335,6 @@ func (q *fsJobQueue) maybeEnqueue(j *job, updateDependants bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sorts and removes duplicates from `ids`.
|
|
||||||
func uniqueUUIDList(ids []uuid.UUID) []uuid.UUID {
|
|
||||||
s := map[uuid.UUID]bool{}
|
|
||||||
for _, id := range ids {
|
|
||||||
s[id] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
l := []uuid.UUID{}
|
|
||||||
for id := range s {
|
|
||||||
l = append(l, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(l, func(i, j int) bool {
|
|
||||||
for b := 0; b < 16; b++ {
|
|
||||||
if l[i][b] < l[j][b] {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select on a list of `chan uuid.UUID`s. Returns an error if one of the
|
// Select on a list of `chan uuid.UUID`s. Returns an error if one of the
|
||||||
// channels is closed.
|
// channels is closed.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
package fsjobqueue
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func uuidList(t *testing.T, strs ...string) []uuid.UUID {
|
|
||||||
var err error
|
|
||||||
ids := make([]uuid.UUID, len(strs))
|
|
||||||
for i, s := range strs {
|
|
||||||
ids[i], err = uuid.Parse(s)
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
return ids
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUniqueUUIDList(t *testing.T) {
|
|
||||||
l := uniqueUUIDList([]uuid.UUID{})
|
|
||||||
require.Empty(t, l)
|
|
||||||
|
|
||||||
s := uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "a0ad7428-b813-4efb-a156-da2b524f4868", "36e5817c-f29d-4043-8d7d-95ffaa77ff88")
|
|
||||||
l = uniqueUUIDList(s)
|
|
||||||
require.ElementsMatch(t, s, l)
|
|
||||||
|
|
||||||
s = uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2")
|
|
||||||
l = uniqueUUIDList(s)
|
|
||||||
require.ElementsMatch(t, uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2"), l)
|
|
||||||
|
|
||||||
s = uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "a0ad7428-b813-4efb-a156-da2b524f4868", "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2")
|
|
||||||
l = uniqueUUIDList(s)
|
|
||||||
require.ElementsMatch(t, uuidList(t, "8ad6bbcd-55f9-4cd8-be45-d0370ff079d2", "a0ad7428-b813-4efb-a156-da2b524f4868"), l)
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
@ -48,7 +47,7 @@ func (q *testJobQueue) Enqueue(jobType string, args interface{}, dependencies []
|
||||||
var j = job{
|
var j = job{
|
||||||
Id: uuid.New(),
|
Id: uuid.New(),
|
||||||
Type: jobType,
|
Type: jobType,
|
||||||
Dependencies: uniqueUUIDList(dependencies),
|
Dependencies: dependencies,
|
||||||
QueuedAt: time.Now(),
|
QueuedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,28 +178,3 @@ func (q *testJobQueue) countFinishedJobs(ids []uuid.UUID) (int, error) {
|
||||||
|
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sorts and removes duplicates from `ids`.
|
|
||||||
// Copied from fsjobqueue, which also contains a test.
|
|
||||||
func uniqueUUIDList(ids []uuid.UUID) []uuid.UUID {
|
|
||||||
s := map[uuid.UUID]bool{}
|
|
||||||
for _, id := range ids {
|
|
||||||
s[id] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
l := []uuid.UUID{}
|
|
||||||
for id := range s {
|
|
||||||
l = append(l, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(l, func(i, j int) bool {
|
|
||||||
for b := 0; b < 16; b++ {
|
|
||||||
if l[i][b] < l[j][b] {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue