Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Apr 14, 2016
1 parent b25ceee commit fdb619e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
30 changes: 15 additions & 15 deletions nomad/core_sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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 {
// Add the allocs first
if remaining := len(allocs) - submittedAllocs; remaining > 0 {
if remaining <= available {
req.Evals = evals[submittedEvals:]
req.Allocs = allocs[submittedAllocs:]
available -= remaining
submittedEvals += remaining
submittedAllocs += remaining
} else {
req.Evals = evals[submittedEvals : submittedEvals+available]
submittedEvals += available
req.Allocs = allocs[submittedAllocs : submittedAllocs+available]
submittedAllocs += available

// Exhausted space so skip adding allocs
// Exhausted space so skip adding evals
continue
}
}

// Add the allocs
if remaining := len(allocs) - submittedAllocs; remaining > 0 {
// Add the evals
if remaining := len(evals) - submittedEvals; remaining > 0 {
if remaining <= available {
req.Allocs = allocs[submittedAllocs:]
submittedAllocs += remaining
req.Evals = evals[submittedEvals:]
submittedEvals += remaining
} else {
req.Allocs = allocs[submittedAllocs : submittedAllocs+available]
submittedAllocs += available
req.Evals = evals[submittedEvals : submittedEvals+available]
submittedEvals += available
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions nomad/core_sched_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit fdb619e

Please sign in to comment.