Address comments

This commit is contained in:
Alex Dadgar 2016-04-14 11:41:04 -07:00
parent 066d006868
commit b34ab80c93
2 changed files with 21 additions and 21 deletions

View File

@ -14,7 +14,7 @@ var (
// maxIdsPerReap is the maximum number of evals and allocations to reap in a
// single Raft transaction. This is to ensure that the Raft message does not
// become too large.
maxIdsPerReap = (1024 * 512) / 36 // 0.5 MB of ids.
maxIdsPerReap = (1024 * 256) / 36 // 0.25 MB of ids.
)
// CoreScheduler is a special "scheduler" that is registered
@ -255,7 +255,7 @@ func (c *CoreScheduler) evalReap(evals, allocs []string) error {
// necessary to ensure that the Raft transaction does not become too large.
func (c *CoreScheduler) partitionReap(evals, allocs []string) []*structs.EvalDeleteRequest {
var requests []*structs.EvalDeleteRequest
var submittedEvals, submittedAllocs int
submittedEvals, submittedAllocs := 0, 0
for submittedEvals != len(evals) || submittedAllocs != len(allocs) {
req := &structs.EvalDeleteRequest{
WriteRequest: structs.WriteRequest{
@ -265,29 +265,29 @@ func (c *CoreScheduler) partitionReap(evals, allocs []string) []*structs.EvalDel
requests = append(requests, req)
available := maxIdsPerReap
// Add the evals first
if remaining := len(evals) - submittedEvals; remaining > 0 {
if remaining <= available {
req.Evals = evals[submittedEvals:]
available -= remaining
submittedEvals += remaining
} else {
req.Evals = evals[submittedEvals : submittedEvals+available]
submittedEvals += available
// Exhausted space so skip adding allocs
continue
}
}
// Add the allocs
// Add the allocs first
if remaining := len(allocs) - submittedAllocs; remaining > 0 {
if remaining <= available {
req.Allocs = allocs[submittedAllocs:]
available -= remaining
submittedAllocs += remaining
} else {
req.Allocs = allocs[submittedAllocs : submittedAllocs+available]
submittedAllocs += available
// Exhausted space so skip adding evals
continue
}
}
// Add the evals
if remaining := len(evals) - submittedEvals; remaining > 0 {
if remaining <= available {
req.Evals = evals[submittedEvals:]
submittedEvals += remaining
} else {
req.Evals = evals[submittedEvals : submittedEvals+available]
submittedEvals += available
}
}
}

View File

@ -558,17 +558,17 @@ func TestCoreScheduler_PartitionReap(t *testing.T) {
}
first := requests[0]
if len(first.Evals) != 2 && len(first.Allocs) != 0 {
if len(first.Allocs) != 2 && len(first.Evals) != 0 {
t.Fatalf("Unexpected first request: %v", first)
}
second := requests[1]
if len(second.Evals) != 1 && len(second.Allocs) != 1 {
if len(second.Allocs) != 1 && len(second.Evals) != 1 {
t.Fatalf("Unexpected second request: %v", second)
}
third := requests[2]
if len(third.Evals) != 0 && len(third.Allocs) != 2 {
if len(third.Allocs) != 0 && len(third.Evals) != 2 {
t.Fatalf("Unexpected third request: %v", third)
}
}