1
// Copyright 2012-2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/juju/state/bakerystorage"
12
// The capped collection used for transaction logs defaults to 10MB.
13
// It's tweaked in export_test.go to 1MB to avoid the overhead of
14
// creating and deleting the large file repeatedly in tests.
17
txnLogSizeTests = 1000000
20
// allCollections should be the single source of truth for information about
21
// any collection we use. It's broken up into 4 main sections:
23
// * infrastructure: we really don't have any business touching these once
24
// we've created them. They should have the rawAccess attribute set, so that
25
// multiModelRunner will consider them forbidden.
27
// * global: these hold information external to models. They may include
28
// model metadata, or references; but they're generally not relevant
29
// from the perspective of a given model.
31
// * local (in opposition to global; and for want of a better term): these
32
// hold information relevant *within* specific models (machines,
33
// applications, relations, settings, bookkeeping, etc) and should generally be
34
// read via an modelStateCollection, and written via a multiModelRunner. This is
35
// the most common form of collection, and the above access should usually
36
// be automatic via Database.Collection and Database.Runner.
38
// * raw-access: there's certainly data that's a poor fit for mgo/txn. Most
39
// forms of logs, for example, will benefit both from the speedy insert and
40
// worry-free bulk deletion; so raw-access collections are fine. Just don't
41
// try to run transactions that reference them.
43
// Please do not use collections not referenced here; and when adding new
44
// collections, please document them, and make an effort to put them in an
45
// appropriate section.
46
func allCollections() collectionSchema {
47
return collectionSchema{
49
// Infrastructure collections
50
// ==========================
53
// This collection is used exclusively by mgo/txn to record transactions.
56
explicitCreate: &mgo.CollectionInfo{},
59
// This collection is used by mgo/txn to record the set of documents
60
// affected by each successful transaction; and by state/watcher to
61
// generate a stream of document-resolution events that are delivered
62
// to, and interpreted by, both state and state/multiwatcher.
65
explicitCreate: &mgo.CollectionInfo{
76
// This collection holds the details of the controllers hosting, well,
77
// everything in state.
78
controllersC: {global: true},
80
// This collection is used to track progress when restoring a
81
// controller from backup.
82
restoreInfoC: {global: true},
84
// This collection is used by the controllers to coordinate binary
85
// upgrades and schema migrations.
86
upgradeInfoC: {global: true},
88
// This collection holds a convenient representation of the content of
89
// the simplestreams data source pointing to binaries required by juju.
91
// Tools metadata is per-model, to allow multiple revisions of tools to
92
// be uploaded to different models without affecting other models.
95
// This collection holds a convenient representation of the content of
96
// the simplestreams data source pointing to Juju GUI archives.
97
guimetadataC: {global: true},
99
// This collection holds Juju GUI current version and other settings.
100
guisettingsC: {global: true},
102
// This collection holds model information; in particular its
103
// Life and its UUID.
104
modelsC: {global: true},
106
// This collection holds references to entities owned by a
107
// model. We use this to determine whether or not we can safely
108
// destroy empty models.
109
modelEntityRefsC: {global: true},
111
// This collection is holds the parameters for model migrations.
114
indexes: []mgo.Index{{
115
Key: []string{"model-uuid"},
119
// This collection tracks the progress of model migrations.
120
migrationsStatusC: {global: true},
122
// This collection records the model migrations which
123
// are currently in progress. It is used to ensure that only
124
// one model migration document exists per model.
125
migrationsActiveC: {global: true},
127
// This collection tracks migration progress reports from the
128
// migration minions.
129
migrationsMinionSyncC: {global: true},
131
// This collection holds user information that's not specific to any
137
// This collection holds users that are relative to controllers.
142
// This collection holds the last time the user connected to the API server.
148
// This collection is used as a unique key restraint. The _id field is
149
// a concatenation of multiple fields that form a compound index,
150
// allowing us to ensure users cannot have the same name for two
151
// different models at a time.
152
usermodelnameC: {global: true},
154
// This collection holds cloud definitions.
155
cloudsC: {global: true},
157
// This collection holds users' cloud credentials.
160
indexes: []mgo.Index{{
161
Key: []string{"owner", "cloud"},
165
// This collection holds settings from various sources which
166
// are inherited and then forked by new models.
167
globalSettingsC: {global: true},
169
// This collection holds workload metrics reported by certain charms
170
// for passing onward to other tools.
171
metricsC: {global: true},
173
// This collection holds persistent state for the metrics manager.
174
metricsManagerC: {global: true},
176
// This collection was deprecated before multi-model support
178
actionresultsC: {global: true},
180
// This collection holds storage items for a macaroon bakery.
181
bakeryStorageItemsC: {
183
indexes: bakerystorage.MongoIndexes(),
191
// This collection holds users related to a model and will be usde as one
192
// of the intersection axis of permissionsC
195
// This collection is basically a standard SQL intersection table; it
196
// references the global records of the users allowed access to a
200
// This collection holds the last time the model user connected
202
modelUserLastConnectionC: {
206
// This collection contains governors that prevent certain kinds of
207
// changes from being accepted.
210
// This collection is used for internal bookkeeping; certain complex
211
// or tedious state changes are deferred by recording a cleanup doc
212
// for later handling.
215
// This collection contains incrementing integers, subdivided by name,
216
// to ensure various IDs aren't reused.
219
// This collection holds lease data. It's currently only used to
220
// implement application leadership, but is namespaced and available
221
// for use by other clients in future.
223
indexes: []mgo.Index{{
224
Key: []string{"model-uuid", "type"},
226
Key: []string{"model-uuid", "namespace"},
232
// These collections hold information associated with applications.
236
indexes: []mgo.Index{{
237
Key: []string{"model-uuid", "application"},
239
Key: []string{"model-uuid", "principal"},
241
Key: []string{"model-uuid", "machineid"},
246
// This collection holds documents that indicate units which are queued
247
// to be assigned to machines. It is used exclusively by the
251
// meterStatusC is the collection used to store meter status information.
255
indexes: []mgo.Index{{
256
Key: []string{"model-uuid", "endpoints.relationname"},
258
Key: []string{"model-uuid", "endpoints.applicationname"},
265
// These collections hold information associated with machines.
272
// This collection contains information from removed machines
273
// that needs to be cleaned up in the provider.
274
machineRemovalsC: {},
278
// These collections hold information associated with storage.
280
indexes: []mgo.Index{{
281
Key: []string{"model-uuid", "machineid"},
285
indexes: []mgo.Index{{
286
Key: []string{"model-uuid", "storageid"},
289
filesystemAttachmentsC: {},
291
indexes: []mgo.Index{{
292
Key: []string{"model-uuid", "owner"},
295
storageAttachmentsC: {
296
indexes: []mgo.Index{{
297
Key: []string{"model-uuid", "storageid"},
299
Key: []string{"model-uuid", "unitid"},
303
indexes: []mgo.Index{{
304
Key: []string{"model-uuid", "storageid"},
307
volumeAttachmentsC: {},
314
linkLayerDevicesC: {},
315
linkLayerDevicesRefsC: {},
317
endpointBindingsC: {},
322
// These collections hold information associated with actions.
324
indexes: []mgo.Index{{
325
Key: []string{"model-uuid", "name"},
328
actionNotificationsC: {},
332
// This collection holds information associated with charm payloads.
334
indexes: []mgo.Index{{
335
Key: []string{"model-uuid", "unitid"},
337
Key: []string{"model-uuid", "name"},
341
// This collection holds information associated with charm resources.
342
// See resource/persistence/mongo.go, where it should never have
343
// been put in the first place.
348
// The remaining non-global collections share the property of being
349
// relevant to multiple other kinds of entities, and are thus generally
350
// indexed by globalKey(). This is unhelpfully named in this context --
351
// it's meant to imply "global within an model", because it was
352
// named before multi-env support.
354
// This collection holds user annotations for various entities. They
355
// shouldn't be written or interpreted by juju.
358
// This collection in particular holds an astounding number of
359
// different sorts of data: application config settings by charm version,
360
// unit relation settings, model config, etc etc etc.
364
storageConstraintsC: {},
368
indexes: []mgo.Index{{
369
Key: []string{"model-uuid", "globalkey", "updated"},
373
// This collection holds information about cloud image metadata.
374
cloudimagemetadataC: {},
376
// ----------------------
378
// Raw-access collections
379
// ======================
381
// metrics; status-history; logs; ..?
390
// These constants are used to avoid sprinkling the package with any more
391
// magic strings. If a collection deserves documentation, please document
392
// it in allCollections, above; and please keep this list sorted for easy
395
actionNotificationsC = "actionnotifications"
396
actionresultsC = "actionresults"
398
annotationsC = "annotations"
399
assignUnitC = "assignUnits"
400
auditingC = "audit.log"
401
bakeryStorageItemsC = "bakeryStorageItems"
402
blockDevicesC = "blockdevices"
405
cleanupsC = "cleanups"
406
cloudimagemetadataC = "cloudimagemetadata"
408
cloudCredentialsC = "cloudCredentials"
409
constraintsC = "constraints"
410
containerRefsC = "containerRefs"
411
controllersC = "controllers"
412
controllerUsersC = "controllerusers"
413
filesystemAttachmentsC = "filesystemAttachments"
414
filesystemsC = "filesystems"
415
globalSettingsC = "globalSettings"
416
guimetadataC = "guimetadata"
417
guisettingsC = "guisettings"
418
instanceDataC = "instanceData"
420
machinesC = "machines"
421
machineRemovalsC = "machineremovals"
422
meterStatusC = "meterStatus"
424
metricsManagerC = "metricsmanager"
425
minUnitsC = "minunits"
426
migrationsActiveC = "migrations.active"
427
migrationsC = "migrations"
428
migrationsMinionSyncC = "migrations.minionsync"
429
migrationsStatusC = "migrations.status"
430
modelUserLastConnectionC = "modelUserLastConnection"
431
modelUsersC = "modelusers"
433
modelEntityRefsC = "modelEntityRefs"
434
openedPortsC = "openedPorts"
435
payloadsC = "payloads"
436
permissionsC = "permissions"
437
providerIDsC = "providerIDs"
439
relationScopesC = "relationscopes"
440
relationsC = "relations"
441
restoreInfoC = "restoreInfo"
442
sequenceC = "sequence"
443
applicationsC = "applications"
444
endpointBindingsC = "endpointbindings"
445
settingsC = "settings"
446
settingsrefsC = "settingsrefs"
447
sshHostKeysC = "sshhostkeys"
449
statusesC = "statuses"
450
statusesHistoryC = "statuseshistory"
451
storageAttachmentsC = "storageattachments"
452
storageConstraintsC = "storageconstraints"
453
storageInstancesC = "storageinstances"
455
linkLayerDevicesC = "linklayerdevices"
456
linkLayerDevicesRefsC = "linklayerdevicesrefs"
457
ipAddressesC = "ip.addresses"
458
toolsmetadataC = "toolsmetadata"
462
upgradeInfoC = "upgradeInfo"
463
userLastLoginC = "userLastLogin"
464
usermodelnameC = "usermodelname"
466
volumeAttachmentsC = "volumeattachments"
468
// "resources" (see resource/persistence/mongo.go)