~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/relation.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
200
200
                        hasLastRef := bson.D{{"life", Dying}, {"unitcount", 0}, {"relationcount", 1}}
201
201
                        removable := append(bson.D{{"_id", ep.ApplicationName}}, hasLastRef...)
202
202
                        if err := applications.Find(removable).One(&svc.doc); err == nil {
203
 
                                ops = append(ops, svc.removeOps(hasLastRef)...)
 
203
                                appRemoveOps, err := svc.removeOps(hasLastRef)
 
204
                                if err != nil {
 
205
                                        return nil, errors.Trace(err)
 
206
                                }
 
207
                                ops = append(ops, appRemoveOps...)
204
208
                                continue
205
209
                        } else if err != mgo.ErrNotFound {
206
210
                                return nil, err
220
224
                        Update: bson.D{{"$inc", bson.D{{"relationcount", -1}}}},
221
225
                })
222
226
        }
223
 
        cleanupOp := r.st.newCleanupOp(cleanupRelationSettings, fmt.Sprintf("r#%d#", r.Id()))
 
227
        cleanupOp := newCleanupOp(cleanupRelationSettings, fmt.Sprintf("r#%d#", r.Id()))
224
228
        return append(ops, cleanupOp), nil
225
229
}
226
230
 
291
295
                scope:    strings.Join(scope, "#"),
292
296
        }, nil
293
297
}
 
298
 
 
299
// relationSettingsCleanupChange removes the settings doc.
 
300
type relationSettingsCleanupChange struct {
 
301
        Prefix string
 
302
}
 
303
 
 
304
// Prepare is part of the Change interface.
 
305
func (change relationSettingsCleanupChange) Prepare(db Database) ([]txn.Op, error) {
 
306
        settings, closer := db.GetCollection(settingsC)
 
307
        defer closer()
 
308
        sel := bson.D{{"_id", bson.D{{"$regex", "^" + change.Prefix}}}}
 
309
        var docs []struct {
 
310
                DocID string `bson:"_id"`
 
311
        }
 
312
        err := settings.Find(sel).Select(bson.D{{"_id", 1}}).All(&docs)
 
313
        if err != nil {
 
314
                return nil, errors.Trace(err)
 
315
        }
 
316
        if len(docs) == 0 {
 
317
                return nil, ErrChangeComplete
 
318
        }
 
319
 
 
320
        ops := make([]txn.Op, len(docs))
 
321
        for i, doc := range docs {
 
322
                ops[i] = txn.Op{
 
323
                        C:      settingsC,
 
324
                        Id:     doc.DocID,
 
325
                        Remove: true,
 
326
                }
 
327
        }
 
328
        return ops, nil
 
329
 
 
330
}