github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/state/allcollections.go (about) 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 // This collection is basically a standard SQL intersection table; it 187 // references the global records of the users allowed access to a 188 // given operation. 189 permissionsC: { 190 global: true, 191 }, 192 193 // This collection holds information cached by autocert certificate 194 // acquisition. 195 autocertCacheC: { 196 global: true, 197 rawAccess: true, 198 }, 199 200 // This collection holds the last time the model user connected 201 // to the model. 202 modelUserLastConnectionC: { 203 rawAccess: true, 204 }, 205 206 // ----------------- 207 208 // Local collections 209 // ================= 210 211 // This collection holds users related to a model and will be used as one 212 // of the intersection axis of permissionsC 213 modelUsersC: {}, 214 215 // This collection contains governors that prevent certain kinds of 216 // changes from being accepted. 217 blocksC: {}, 218 219 // This collection is used for internal bookkeeping; certain complex 220 // or tedious state changes are deferred by recording a cleanup doc 221 // for later handling. 222 cleanupsC: {}, 223 224 // This collection contains incrementing integers, subdivided by name, 225 // to ensure various IDs aren't reused. 226 sequenceC: {}, 227 228 // This collection holds lease data. It's currently only used to 229 // implement application leadership, but is namespaced and available 230 // for use by other clients in future. 231 leasesC: { 232 indexes: []mgo.Index{{ 233 Key: []string{"model-uuid", "type"}, 234 }, { 235 Key: []string{"model-uuid", "namespace"}, 236 }}, 237 }, 238 239 // ----- 240 241 // These collections hold information associated with applications. 242 charmsC: {}, 243 applicationsC: {}, 244 unitsC: { 245 indexes: []mgo.Index{{ 246 Key: []string{"model-uuid", "application"}, 247 }, { 248 Key: []string{"model-uuid", "principal"}, 249 }, { 250 Key: []string{"model-uuid", "machineid"}, 251 }}, 252 }, 253 minUnitsC: {}, 254 255 // This collection holds documents that indicate units which are queued 256 // to be assigned to machines. It is used exclusively by the 257 // AssignUnitWorker. 258 assignUnitC: {}, 259 260 // meterStatusC is the collection used to store meter status information. 261 meterStatusC: {}, 262 refcountsC: {}, 263 relationsC: { 264 indexes: []mgo.Index{{ 265 Key: []string{"model-uuid", "endpoints.relationname"}, 266 }, { 267 Key: []string{"model-uuid", "endpoints.applicationname"}, 268 }}, 269 }, 270 relationScopesC: {}, 271 272 // ----- 273 274 // These collections hold information associated with machines. 275 containerRefsC: {}, 276 instanceDataC: {}, 277 machinesC: {}, 278 rebootC: {}, 279 sshHostKeysC: {}, 280 281 // This collection contains information from removed machines 282 // that needs to be cleaned up in the provider. 283 machineRemovalsC: {}, 284 285 // ----- 286 287 // These collections hold information associated with storage. 288 blockDevicesC: { 289 indexes: []mgo.Index{{ 290 Key: []string{"model-uuid", "machineid"}, 291 }}, 292 }, 293 filesystemsC: { 294 indexes: []mgo.Index{{ 295 Key: []string{"model-uuid", "storageid"}, 296 }}, 297 }, 298 filesystemAttachmentsC: {}, 299 storageInstancesC: { 300 indexes: []mgo.Index{{ 301 Key: []string{"model-uuid", "owner"}, 302 }}, 303 }, 304 storageAttachmentsC: { 305 indexes: []mgo.Index{{ 306 Key: []string{"model-uuid", "storageid"}, 307 }, { 308 Key: []string{"model-uuid", "unitid"}, 309 }}, 310 }, 311 volumesC: { 312 indexes: []mgo.Index{{ 313 Key: []string{"model-uuid", "storageid"}, 314 }}, 315 }, 316 volumeAttachmentsC: {}, 317 318 // ----- 319 320 providerIDsC: {}, 321 spacesC: {}, 322 subnetsC: {}, 323 linkLayerDevicesC: {}, 324 linkLayerDevicesRefsC: {}, 325 ipAddressesC: {}, 326 endpointBindingsC: {}, 327 openedPortsC: {}, 328 329 // ----- 330 331 // These collections hold information associated with actions. 332 actionsC: { 333 indexes: []mgo.Index{{ 334 Key: []string{"model-uuid", "name"}, 335 }}, 336 }, 337 actionNotificationsC: {}, 338 339 // ----- 340 341 // This collection holds information associated with charm payloads. 342 payloadsC: { 343 indexes: []mgo.Index{{ 344 Key: []string{"model-uuid", "unitid"}, 345 }, { 346 Key: []string{"model-uuid", "name"}, 347 }}, 348 }, 349 350 // This collection holds information associated with charm resources. 351 // See resource/persistence/mongo.go, where it should never have 352 // been put in the first place. 353 "resources": {}, 354 355 // ----- 356 357 // The remaining non-global collections share the property of being 358 // relevant to multiple other kinds of entities, and are thus generally 359 // indexed by globalKey(). This is unhelpfully named in this context -- 360 // it's meant to imply "global within an model", because it was 361 // named before multi-env support. 362 363 // This collection holds user annotations for various entities. They 364 // shouldn't be written or interpreted by juju. 365 annotationsC: {}, 366 367 // This collection in particular holds an astounding number of 368 // different sorts of data: application config settings by charm version, 369 // unit relation settings, model config, etc etc etc. 370 settingsC: {}, 371 372 constraintsC: {}, 373 storageConstraintsC: {}, 374 statusesC: {}, 375 statusesHistoryC: { 376 rawAccess: true, 377 indexes: []mgo.Index{{ 378 Key: []string{"model-uuid", "globalkey", "updated"}, 379 }}, 380 }, 381 382 // This collection holds information about cloud image metadata. 383 cloudimagemetadataC: { 384 global: true, 385 }, 386 387 // ---------------------- 388 389 // Raw-access collections 390 // ====================== 391 392 // metrics; status-history; logs; ..? 393 394 auditingC: { 395 global: true, 396 rawAccess: true, 397 }, 398 } 399 } 400 401 // These constants are used to avoid sprinkling the package with any more 402 // magic strings. If a collection deserves documentation, please document 403 // it in allCollections, above; and please keep this list sorted for easy 404 // inspection. 405 const ( 406 actionNotificationsC = "actionnotifications" 407 actionresultsC = "actionresults" 408 actionsC = "actions" 409 annotationsC = "annotations" 410 autocertCacheC = "autocertCache" 411 assignUnitC = "assignUnits" 412 auditingC = "audit.log" 413 bakeryStorageItemsC = "bakeryStorageItems" 414 blockDevicesC = "blockdevices" 415 blocksC = "blocks" 416 charmsC = "charms" 417 cleanupsC = "cleanups" 418 cloudimagemetadataC = "cloudimagemetadata" 419 cloudsC = "clouds" 420 cloudCredentialsC = "cloudCredentials" 421 constraintsC = "constraints" 422 containerRefsC = "containerRefs" 423 controllersC = "controllers" 424 controllerUsersC = "controllerusers" 425 filesystemAttachmentsC = "filesystemAttachments" 426 filesystemsC = "filesystems" 427 globalSettingsC = "globalSettings" 428 guimetadataC = "guimetadata" 429 guisettingsC = "guisettings" 430 instanceDataC = "instanceData" 431 leasesC = "leases" 432 machinesC = "machines" 433 machineRemovalsC = "machineremovals" 434 meterStatusC = "meterStatus" 435 metricsC = "metrics" 436 metricsManagerC = "metricsmanager" 437 minUnitsC = "minunits" 438 migrationsActiveC = "migrations.active" 439 migrationsC = "migrations" 440 migrationsMinionSyncC = "migrations.minionsync" 441 migrationsStatusC = "migrations.status" 442 modelUserLastConnectionC = "modelUserLastConnection" 443 modelUsersC = "modelusers" 444 modelsC = "models" 445 modelEntityRefsC = "modelEntityRefs" 446 openedPortsC = "openedPorts" 447 payloadsC = "payloads" 448 permissionsC = "permissions" 449 providerIDsC = "providerIDs" 450 rebootC = "reboot" 451 relationScopesC = "relationscopes" 452 relationsC = "relations" 453 restoreInfoC = "restoreInfo" 454 sequenceC = "sequence" 455 applicationsC = "applications" 456 endpointBindingsC = "endpointbindings" 457 settingsC = "settings" 458 refcountsC = "refcounts" 459 sshHostKeysC = "sshhostkeys" 460 spacesC = "spaces" 461 statusesC = "statuses" 462 statusesHistoryC = "statuseshistory" 463 storageAttachmentsC = "storageattachments" 464 storageConstraintsC = "storageconstraints" 465 storageInstancesC = "storageinstances" 466 subnetsC = "subnets" 467 linkLayerDevicesC = "linklayerdevices" 468 linkLayerDevicesRefsC = "linklayerdevicesrefs" 469 ipAddressesC = "ip.addresses" 470 toolsmetadataC = "toolsmetadata" 471 txnLogC = "txns.log" 472 txnsC = "txns" 473 unitsC = "units" 474 upgradeInfoC = "upgradeInfo" 475 userLastLoginC = "userLastLogin" 476 usermodelnameC = "usermodelname" 477 usersC = "users" 478 volumeAttachmentsC = "volumeattachments" 479 volumesC = "volumes" 480 // "resources" (see resource/persistence/mongo.go) 481 )