Skip to content

Commit

Permalink
csi: remove PastAllocs from state_store
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Feb 14, 2020
1 parent 5ba637c commit 6b219bd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 35 deletions.
10 changes: 5 additions & 5 deletions nomad/core_sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,10 @@ func (c *CoreScheduler) volumeClaimReap(jobs []*structs.Job, leaderACL string) e

collectFunc := func(allocs map[string]*structs.Allocation) {
for _, alloc := range allocs {
// we call denormalize on the volume above to make sure the Allocation
// pointer in PastAllocs isn't nil. But the alloc might have been
// garbage collected concurrently, so if the alloc is still nil we can
// safely skip it.
// we call denormalize on the volume above to populate
// Allocation pointers. But the alloc might have been
// garbage collected concurrently, so if the alloc is
// still nil we can safely skip it.
if alloc == nil {
continue
}
Expand All @@ -796,7 +796,7 @@ func (c *CoreScheduler) volumeClaimReap(jobs []*structs.Job, leaderACL string) e
req := &structs.CSIVolumeClaimRequest{
VolumeID: volID,
Allocation: nil, // unpublish never uses this field
Claim: structs.CSIVolumeClaimGC,
Claim: structs.CSIVolumeClaimRelease,
WriteRequest: structs.WriteRequest{
Region: job.Region,
Namespace: job.Namespace,
Expand Down
8 changes: 0 additions & 8 deletions nomad/state/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1929,14 +1929,6 @@ func (s *StateStore) CSIVolumeDenormalize(ws memdb.WatchSet, vol *structs.CSIVol
vol.WriteAllocs[id] = a
}

for id := range vol.PastAllocs {
a, err := s.AllocByID(ws, id)
if err != nil {
return nil, err
}
vol.PastAllocs[id] = a
}

return vol, nil
}

Expand Down
22 changes: 0 additions & 22 deletions nomad/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ type CSIVolume struct {
// Allocations, tracking claim status
ReadAllocs map[string]*Allocation
WriteAllocs map[string]*Allocation
PastAllocs map[string]*Allocation

// Healthy is true if all the denormalized plugin health fields are true, and the
// volume has not been marked for garbage collection
Expand Down Expand Up @@ -203,7 +202,6 @@ func (v *CSIVolume) newStructs() {

v.ReadAllocs = map[string]*Allocation{}
v.WriteAllocs = map[string]*Allocation{}
v.PastAllocs = map[string]*Allocation{}
}

func (v *CSIVolume) Stub() *CSIVolListStub {
Expand Down Expand Up @@ -265,10 +263,6 @@ func (v *CSIVolume) Copy() *CSIVolume {
out.WriteAllocs[k] = v
}

for k, v := range v.PastAllocs {
out.PastAllocs[k] = v
}

return out
}

Expand All @@ -281,8 +275,6 @@ func (v *CSIVolume) Claim(claim CSIVolumeClaimMode, alloc *Allocation) bool {
return v.ClaimWrite(alloc)
case CSIVolumeClaimRelease:
return v.ClaimRelease(alloc)
case CSIVolumeClaimGC:
return v.ClaimGC(alloc)
}
return false
}
Expand All @@ -296,7 +288,6 @@ func (v *CSIVolume) ClaimRead(alloc *Allocation) bool {
// pointer. We'll get it from the db in denormalize.
v.ReadAllocs[alloc.ID] = nil
delete(v.WriteAllocs, alloc.ID)
delete(v.PastAllocs, alloc.ID)
return true
}

Expand All @@ -309,25 +300,13 @@ func (v *CSIVolume) ClaimWrite(alloc *Allocation) bool {
// pointer. We'll get it from the db in denormalize.
v.WriteAllocs[alloc.ID] = nil
delete(v.ReadAllocs, alloc.ID)
delete(v.PastAllocs, alloc.ID)
return true
}

// ClaimRelease is called when the allocation has terminated and already stopped using the volume
func (v *CSIVolume) ClaimRelease(alloc *Allocation) bool {
delete(v.ReadAllocs, alloc.ID)
delete(v.WriteAllocs, alloc.ID)
// Allocations are copy on write, so we want to keep the id but don't need the
// pointer. We'll get it from the db in denormalize.
v.PastAllocs[alloc.ID] = nil
return true
}

// ClaimGC is called on Allocation gc, by following the alloc's pointer back to the volume
func (v *CSIVolume) ClaimGC(alloc *Allocation) bool {
delete(v.ReadAllocs, alloc.ID)
delete(v.WriteAllocs, alloc.ID)
delete(v.PastAllocs, alloc.ID)
return true
}

Expand Down Expand Up @@ -426,7 +405,6 @@ const (
CSIVolumeClaimRead CSIVolumeClaimMode = iota
CSIVolumeClaimWrite
CSIVolumeClaimRelease
CSIVolumeClaimGC
)

type CSIVolumeClaimRequest struct {
Expand Down

0 comments on commit 6b219bd

Please sign in to comment.