~nskaggs/+junk/xenial-test

« back to all changes in this revision

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

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012-2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package state
 
5
 
 
6
import (
 
7
        "gopkg.in/mgo.v2"
 
8
 
 
9
        "github.com/juju/juju/state/bakerystorage"
 
10
)
 
11
 
 
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.
 
15
var (
 
16
        txnLogSize      = 10000000
 
17
        txnLogSizeTests = 1000000
 
18
)
 
19
 
 
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:
 
22
//
 
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.
 
26
//
 
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.
 
30
//
 
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.
 
37
//
 
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.
 
42
//
 
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{
 
48
 
 
49
                // Infrastructure collections
 
50
                // ==========================
 
51
 
 
52
                txnsC: {
 
53
                        // This collection is used exclusively by mgo/txn to record transactions.
 
54
                        global:         true,
 
55
                        rawAccess:      true,
 
56
                        explicitCreate: &mgo.CollectionInfo{},
 
57
                },
 
58
                txnLogC: {
 
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.
 
63
                        global:    true,
 
64
                        rawAccess: true,
 
65
                        explicitCreate: &mgo.CollectionInfo{
 
66
                                Capped:   true,
 
67
                                MaxBytes: txnLogSize,
 
68
                        },
 
69
                },
 
70
 
 
71
                // ------------------
 
72
 
 
73
                // Global collections
 
74
                // ==================
 
75
 
 
76
                // This collection holds the details of the controllers hosting, well,
 
77
                // everything in state.
 
78
                controllersC: {global: true},
 
79
 
 
80
                // This collection is used to track progress when restoring a
 
81
                // controller from backup.
 
82
                restoreInfoC: {global: true},
 
83
 
 
84
                // This collection is used by the controllers to coordinate binary
 
85
                // upgrades and schema migrations.
 
86
                upgradeInfoC: {global: true},
 
87
 
 
88
                // This collection holds a convenient representation of the content of
 
89
                // the simplestreams data source pointing to binaries required by juju.
 
90
                //
 
91
                // Tools metadata is per-model, to allow multiple revisions of tools to
 
92
                // be uploaded to different models without affecting other models.
 
93
                toolsmetadataC: {},
 
94
 
 
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},
 
98
 
 
99
                // This collection holds Juju GUI current version and other settings.
 
100
                guisettingsC: {global: true},
 
101
 
 
102
                // This collection holds model information; in particular its
 
103
                // Life and its UUID.
 
104
                modelsC: {global: true},
 
105
 
 
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},
 
110
 
 
111
                // This collection is holds the parameters for model migrations.
 
112
                migrationsC: {
 
113
                        global: true,
 
114
                        indexes: []mgo.Index{{
 
115
                                Key: []string{"model-uuid"},
 
116
                        }},
 
117
                },
 
118
 
 
119
                // This collection tracks the progress of model migrations.
 
120
                migrationsStatusC: {global: true},
 
121
 
 
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},
 
126
 
 
127
                // This collection tracks migration progress reports from the
 
128
                // migration minions.
 
129
                migrationsMinionSyncC: {global: true},
 
130
 
 
131
                // This collection holds user information that's not specific to any
 
132
                // one model.
 
133
                usersC: {
 
134
                        global: true,
 
135
                },
 
136
 
 
137
                // This collection holds users that are relative to controllers.
 
138
                controllerUsersC: {
 
139
                        global: true,
 
140
                },
 
141
 
 
142
                // This collection holds the last time the user connected to the API server.
 
143
                userLastLoginC: {
 
144
                        global:    true,
 
145
                        rawAccess: true,
 
146
                },
 
147
 
 
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},
 
153
 
 
154
                // This collection holds cloud definitions.
 
155
                cloudsC: {global: true},
 
156
 
 
157
                // This collection holds users' cloud credentials.
 
158
                cloudCredentialsC: {
 
159
                        global: true,
 
160
                        indexes: []mgo.Index{{
 
161
                                Key: []string{"owner", "cloud"},
 
162
                        }},
 
163
                },
 
164
 
 
165
                // This collection holds settings from various sources which
 
166
                // are inherited and then forked by new models.
 
167
                globalSettingsC: {global: true},
 
168
 
 
169
                // This collection holds workload metrics reported by certain charms
 
170
                // for passing onward to other tools.
 
171
                metricsC: {global: true},
 
172
 
 
173
                // This collection holds persistent state for the metrics manager.
 
174
                metricsManagerC: {global: true},
 
175
 
 
176
                // This collection was deprecated before multi-model support
 
177
                // was implemented.
 
178
                actionresultsC: {global: true},
 
179
 
 
180
                // This collection holds storage items for a macaroon bakery.
 
181
                bakeryStorageItemsC: {
 
182
                        global:  true,
 
183
                        indexes: bakerystorage.MongoIndexes(),
 
184
                },
 
185
 
 
186
                // -----------------
 
187
 
 
188
                // Local collections
 
189
                // =================
 
190
 
 
191
                // This collection holds users related to a model and will be usde as one
 
192
                // of the intersection axis of permissionsC
 
193
                modelUsersC: {},
 
194
 
 
195
                // This collection is basically a standard SQL intersection table; it
 
196
                // references the global records of the users allowed access to a
 
197
                // given operation.
 
198
                permissionsC: {},
 
199
 
 
200
                // This collection holds the last time the model user connected
 
201
                // to the model.
 
202
                modelUserLastConnectionC: {
 
203
                        rawAccess: true,
 
204
                },
 
205
 
 
206
                // This collection contains governors that prevent certain kinds of
 
207
                // changes from being accepted.
 
208
                blocksC: {},
 
209
 
 
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.
 
213
                cleanupsC: {},
 
214
 
 
215
                // This collection contains incrementing integers, subdivided by name,
 
216
                // to ensure various IDs aren't reused.
 
217
                sequenceC: {},
 
218
 
 
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.
 
222
                leasesC: {
 
223
                        indexes: []mgo.Index{{
 
224
                                Key: []string{"model-uuid", "type"},
 
225
                        }, {
 
226
                                Key: []string{"model-uuid", "namespace"},
 
227
                        }},
 
228
                },
 
229
 
 
230
                // -----
 
231
 
 
232
                // These collections hold information associated with applications.
 
233
                charmsC:       {},
 
234
                applicationsC: {},
 
235
                unitsC: {
 
236
                        indexes: []mgo.Index{{
 
237
                                Key: []string{"model-uuid", "application"},
 
238
                        }, {
 
239
                                Key: []string{"model-uuid", "principal"},
 
240
                        }, {
 
241
                                Key: []string{"model-uuid", "machineid"},
 
242
                        }},
 
243
                },
 
244
                minUnitsC: {},
 
245
 
 
246
                // This collection holds documents that indicate units which are queued
 
247
                // to be assigned to machines. It is used exclusively by the
 
248
                // AssignUnitWorker.
 
249
                assignUnitC: {},
 
250
 
 
251
                // meterStatusC is the collection used to store meter status information.
 
252
                meterStatusC:  {},
 
253
                settingsrefsC: {},
 
254
                relationsC: {
 
255
                        indexes: []mgo.Index{{
 
256
                                Key: []string{"model-uuid", "endpoints.relationname"},
 
257
                        }, {
 
258
                                Key: []string{"model-uuid", "endpoints.applicationname"},
 
259
                        }},
 
260
                },
 
261
                relationScopesC: {},
 
262
 
 
263
                // -----
 
264
 
 
265
                // These collections hold information associated with machines.
 
266
                containerRefsC: {},
 
267
                instanceDataC:  {},
 
268
                machinesC:      {},
 
269
                rebootC:        {},
 
270
                sshHostKeysC:   {},
 
271
 
 
272
                // This collection contains information from removed machines
 
273
                // that needs to be cleaned up in the provider.
 
274
                machineRemovalsC: {},
 
275
 
 
276
                // -----
 
277
 
 
278
                // These collections hold information associated with storage.
 
279
                blockDevicesC: {
 
280
                        indexes: []mgo.Index{{
 
281
                                Key: []string{"model-uuid", "machineid"},
 
282
                        }},
 
283
                },
 
284
                filesystemsC: {
 
285
                        indexes: []mgo.Index{{
 
286
                                Key: []string{"model-uuid", "storageid"},
 
287
                        }},
 
288
                },
 
289
                filesystemAttachmentsC: {},
 
290
                storageInstancesC: {
 
291
                        indexes: []mgo.Index{{
 
292
                                Key: []string{"model-uuid", "owner"},
 
293
                        }},
 
294
                },
 
295
                storageAttachmentsC: {
 
296
                        indexes: []mgo.Index{{
 
297
                                Key: []string{"model-uuid", "storageid"},
 
298
                        }, {
 
299
                                Key: []string{"model-uuid", "unitid"},
 
300
                        }},
 
301
                },
 
302
                volumesC: {
 
303
                        indexes: []mgo.Index{{
 
304
                                Key: []string{"model-uuid", "storageid"},
 
305
                        }},
 
306
                },
 
307
                volumeAttachmentsC: {},
 
308
 
 
309
                // -----
 
310
 
 
311
                providerIDsC:          {},
 
312
                spacesC:               {},
 
313
                subnetsC:              {},
 
314
                linkLayerDevicesC:     {},
 
315
                linkLayerDevicesRefsC: {},
 
316
                ipAddressesC:          {},
 
317
                endpointBindingsC:     {},
 
318
                openedPortsC:          {},
 
319
 
 
320
                // -----
 
321
 
 
322
                // These collections hold information associated with actions.
 
323
                actionsC: {
 
324
                        indexes: []mgo.Index{{
 
325
                                Key: []string{"model-uuid", "name"},
 
326
                        }},
 
327
                },
 
328
                actionNotificationsC: {},
 
329
 
 
330
                // -----
 
331
 
 
332
                // This collection holds information associated with charm payloads.
 
333
                payloadsC: {
 
334
                        indexes: []mgo.Index{{
 
335
                                Key: []string{"model-uuid", "unitid"},
 
336
                        }, {
 
337
                                Key: []string{"model-uuid", "name"},
 
338
                        }},
 
339
                },
 
340
 
 
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.
 
344
                "resources": {},
 
345
 
 
346
                // -----
 
347
 
 
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.
 
353
 
 
354
                // This collection holds user annotations for various entities. They
 
355
                // shouldn't be written or interpreted by juju.
 
356
                annotationsC: {},
 
357
 
 
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.
 
361
                settingsC: {},
 
362
 
 
363
                constraintsC:        {},
 
364
                storageConstraintsC: {},
 
365
                statusesC:           {},
 
366
                statusesHistoryC: {
 
367
                        rawAccess: true,
 
368
                        indexes: []mgo.Index{{
 
369
                                Key: []string{"model-uuid", "globalkey", "updated"},
 
370
                        }},
 
371
                },
 
372
 
 
373
                // This collection holds information about cloud image metadata.
 
374
                cloudimagemetadataC: {},
 
375
 
 
376
                // ----------------------
 
377
 
 
378
                // Raw-access collections
 
379
                // ======================
 
380
 
 
381
                // metrics; status-history; logs; ..?
 
382
 
 
383
                auditingC: {
 
384
                        global:    true,
 
385
                        rawAccess: true,
 
386
                },
 
387
        }
 
388
}
 
389
 
 
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
 
393
// inspection.
 
394
const (
 
395
        actionNotificationsC     = "actionnotifications"
 
396
        actionresultsC           = "actionresults"
 
397
        actionsC                 = "actions"
 
398
        annotationsC             = "annotations"
 
399
        assignUnitC              = "assignUnits"
 
400
        auditingC                = "audit.log"
 
401
        bakeryStorageItemsC      = "bakeryStorageItems"
 
402
        blockDevicesC            = "blockdevices"
 
403
        blocksC                  = "blocks"
 
404
        charmsC                  = "charms"
 
405
        cleanupsC                = "cleanups"
 
406
        cloudimagemetadataC      = "cloudimagemetadata"
 
407
        cloudsC                  = "clouds"
 
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"
 
419
        leasesC                  = "leases"
 
420
        machinesC                = "machines"
 
421
        machineRemovalsC         = "machineremovals"
 
422
        meterStatusC             = "meterStatus"
 
423
        metricsC                 = "metrics"
 
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"
 
432
        modelsC                  = "models"
 
433
        modelEntityRefsC         = "modelEntityRefs"
 
434
        openedPortsC             = "openedPorts"
 
435
        payloadsC                = "payloads"
 
436
        permissionsC             = "permissions"
 
437
        providerIDsC             = "providerIDs"
 
438
        rebootC                  = "reboot"
 
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"
 
448
        spacesC                  = "spaces"
 
449
        statusesC                = "statuses"
 
450
        statusesHistoryC         = "statuseshistory"
 
451
        storageAttachmentsC      = "storageattachments"
 
452
        storageConstraintsC      = "storageconstraints"
 
453
        storageInstancesC        = "storageinstances"
 
454
        subnetsC                 = "subnets"
 
455
        linkLayerDevicesC        = "linklayerdevices"
 
456
        linkLayerDevicesRefsC    = "linklayerdevicesrefs"
 
457
        ipAddressesC             = "ip.addresses"
 
458
        toolsmetadataC           = "toolsmetadata"
 
459
        txnLogC                  = "txns.log"
 
460
        txnsC                    = "txns"
 
461
        unitsC                   = "units"
 
462
        upgradeInfoC             = "upgradeInfo"
 
463
        userLastLoginC           = "userLastLogin"
 
464
        usermodelnameC           = "usermodelname"
 
465
        usersC                   = "users"
 
466
        volumeAttachmentsC       = "volumeattachments"
 
467
        volumesC                 = "volumes"
 
468
        // "resources" (see resource/persistence/mongo.go)
 
469
)