@@ -183,24 +183,33 @@ func (vs *volumeSet) releaseVolume(volumeID, taskID string) {
183183//
184184// TODO(dperny): this is messy and has a lot of overhead. it should be reworked
185185// to something more streamlined.
186- func (vs * volumeSet ) freeVolumes (tx store.Tx ) error {
186+ func (vs * volumeSet ) freeVolumes (batch * store.Batch ) error {
187187 for volumeID , info := range vs .volumes {
188- v := store .GetVolume (tx , volumeID )
189- if v == nil {
190- continue
191- }
188+ if err := batch .Update (func (tx store.Tx ) error {
189+ v := store .GetVolume (tx , volumeID )
190+ if v == nil {
191+ return nil
192+ }
192193
193- changed := false
194- for _ , status := range v .PublishStatus {
195- if info .nodes [status .NodeID ] == 0 && status .State == api .VolumePublishStatus_PUBLISHED {
196- status .State = api .VolumePublishStatus_PENDING_NODE_UNPUBLISH
197- changed = true
194+ // when we are freeing a volume, we may update more than one of the
195+ // volume's PublishStatuses. this means we can't simply put the
196+ // Update call inside of the if statement; we need to know if we've
197+ // changed anything once we've checked *all* of the statuses.
198+ changed := false
199+ for _ , status := range v .PublishStatus {
200+ if info .nodes [status .NodeID ] == 0 && status .State == api .VolumePublishStatus_PUBLISHED {
201+ status .State = api .VolumePublishStatus_PENDING_NODE_UNPUBLISH
202+ changed = true
203+ }
198204 }
199- }
200- if changed {
201- if err := store . UpdateVolume ( tx , v ); err != nil {
202- return err
205+ if changed {
206+ if err := store . UpdateVolume ( tx , v ); err != nil {
207+ return err
208+ }
203209 }
210+ return nil
211+ }); err != nil {
212+ return err
204213 }
205214 }
206215 return nil
0 commit comments