Skip to content

Commit

Permalink
resolve comments from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed May 20, 2020
1 parent a012a56 commit 54bde4d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 5 additions & 3 deletions nomad/csi_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nomad

import (
log "github.com/hashicorp/go-hclog"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/nomad/nomad/structs"
)

Expand Down Expand Up @@ -30,7 +31,7 @@ func newCSIBatchRelease(srv *Server, logger log.Logger, max int) *csiBatchReleas

// add the volume ID + namespace to the deduplicated batches
func (c *csiBatchRelease) add(vol, namespace string) {
id := vol + namespace
id := vol + "\x00" + namespace

// ignore duplicates
_, seen := c.seen[id]
Expand Down Expand Up @@ -60,14 +61,15 @@ func (c *csiBatchRelease) add(vol, namespace string) {

// apply flushes the batches to raft
func (c *csiBatchRelease) apply() error {
var result *multierror.Error
for _, batch := range c.batches {
if len(batch.Claims) > 0 {
_, _, err := c.srv.raftApply(structs.CSIVolumeClaimBatchRequestType, batch)
if err != nil {
c.logger.Error("csi raft apply failed", "error", err, "method", "claim")
return err
result = multierror.Append(result, err)
}
}
}
return nil
return result.ErrorOrNil()
}
11 changes: 8 additions & 3 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,11 @@ func (j *Job) Deregister(args *structs.JobDeregisterRequest, reply *structs.JobD
reply.JobModifyIndex = index

// Make a raft apply to release the CSI volume claims of terminal allocs.
volumesToGC.apply()
var result *multierror.Error
err = volumesToGC.apply()
if err != nil {
result = multierror.Append(result, err)
}

// If the job is periodic or parameterized, we don't create an eval.
if job != nil && (job.IsPeriodic() || job.IsParameterized()) {
Expand Down Expand Up @@ -762,15 +766,16 @@ func (j *Job) Deregister(args *structs.JobDeregisterRequest, reply *structs.JobD
// Commit this evaluation via Raft
_, evalIndex, err := j.srv.raftApply(structs.EvalUpdateRequestType, update)
if err != nil {
result = multierror.Append(result, err)
j.logger.Error("eval create failed", "error", err, "method", "deregister")
return err
return result.ErrorOrNil()
}

// Populate the reply with eval information
reply.EvalID = eval.ID
reply.EvalCreateIndex = evalIndex
reply.Index = evalIndex
return nil
return result.ErrorOrNil()
}

// BatchDeregister is used to remove a set of jobs from the cluster.
Expand Down
11 changes: 8 additions & 3 deletions nomad/node_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,11 @@ func (n *Node) UpdateAlloc(args *structs.AllocUpdateRequest, reply *structs.Gene
}

// Make a raft apply to release the CSI volume claims of terminal allocs.
volumesToGC.apply()
var result *multierror.Error
err := volumesToGC.apply()
if err != nil {
result = multierror.Append(result, err)
}

// Add this to the batch
n.updatesLock.Lock()
Expand Down Expand Up @@ -1171,12 +1175,13 @@ func (n *Node) UpdateAlloc(args *structs.AllocUpdateRequest, reply *structs.Gene

// Wait for the future
if err := future.Wait(); err != nil {
return err
result = multierror.Append(result, err)
return result.ErrorOrNil()
}

// Setup the response
reply.Index = future.Index()
return nil
return result.ErrorOrNil()
}

// batchUpdate is used to update all the allocations
Expand Down

0 comments on commit 54bde4d

Please sign in to comment.