github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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 // services, 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 environment. 125 migrationsActiveC: {global: true}, 126 127 // This collection holds user information that's not specific to any 128 // one model. 129 usersC: { 130 global: true, 131 indexes: []mgo.Index{{ 132 // TODO(thumper): schema change to remove this index. 133 Key: []string{"name"}, 134 }}, 135 }, 136 137 // This collection holds the last time the user connected to the API server. 138 userLastLoginC: { 139 global: true, 140 rawAccess: true, 141 }, 142 143 // This collection is used as a unique key restraint. The _id field is 144 // a concatenation of multiple fields that form a compound index, 145 // allowing us to ensure users cannot have the same name for two 146 // different models at a time. 147 usermodelnameC: {global: true}, 148 149 // This collection holds workload metrics reported by certain charms 150 // for passing onward to other tools. 151 metricsC: {global: true}, 152 153 // This collection holds persistent state for the metrics manager. 154 metricsManagerC: {global: true}, 155 156 // This collection holds lease data, which is per-model, but is 157 // not itself multi-model-aware; happily it will imminently be 158 // deprecated in favour of the non-global leasesC below. 159 // TODO(fwereade): drop leaseC entirely so can't use wrong const. 160 leaseC: {global: true}, 161 162 // This collection was deprecated before multi-model support 163 // was implemented. 164 actionresultsC: {global: true}, 165 166 // This collection holds storage items for a macaroon bakery. 167 bakeryStorageItemsC: { 168 global: true, 169 indexes: bakerystorage.MongoIndexes(), 170 }, 171 172 // ----------------- 173 174 // Local collections 175 // ================= 176 177 // This collection is basically a standard SQL intersection table; it 178 // references the global records of the users allowed access to a 179 // given collection. 180 modelUsersC: {}, 181 182 // This collection holds the last time the model user connected 183 // to the model. 184 modelUserLastConnectionC: { 185 rawAccess: true, 186 }, 187 188 // This collection contains governors that prevent certain kinds of 189 // changes from being accepted. 190 blocksC: {}, 191 192 // This collection is used for internal bookkeeping; certain complex 193 // or tedious state changes are deferred by recording a cleanup doc 194 // for later handling. 195 cleanupsC: {}, 196 197 // This collection contains incrementing integers, subdivided by name, 198 // to ensure various IDs aren't reused. 199 sequenceC: {}, 200 201 // This collection holds lease data. It's currently only used to 202 // implement service leadership, but is namespaced and available 203 // for use by other clients in future. 204 leasesC: { 205 indexes: []mgo.Index{{ 206 Key: []string{"model-uuid", "type"}, 207 }, { 208 Key: []string{"model-uuid", "namespace"}, 209 }}, 210 }, 211 212 // ----- 213 214 // These collections hold information associated with services. 215 charmsC: {}, 216 servicesC: {}, 217 unitsC: { 218 indexes: []mgo.Index{{ 219 Key: []string{"model-uuid", "service"}, 220 }, { 221 Key: []string{"model-uuid", "principal"}, 222 }, { 223 Key: []string{"model-uuid", "machineid"}, 224 }}, 225 }, 226 minUnitsC: {}, 227 228 // This collection holds documents that indicate units which are queued 229 // to be assigned to machines. It is used exclusively by the 230 // AssignUnitWorker. 231 assignUnitC: {}, 232 233 // meterStatusC is the collection used to store meter status information. 234 meterStatusC: {}, 235 settingsrefsC: {}, 236 relationsC: { 237 indexes: []mgo.Index{{ 238 Key: []string{"model-uuid", "endpoints.relationname"}, 239 }, { 240 Key: []string{"model-uuid", "endpoints.servicename"}, 241 }}, 242 }, 243 relationScopesC: {}, 244 245 // ----- 246 247 // These collections hold information associated with machines. 248 containerRefsC: {}, 249 instanceDataC: {}, 250 machinesC: {}, 251 rebootC: {}, 252 sshHostKeysC: {}, 253 254 // ----- 255 256 // These collections hold information associated with storage. 257 blockDevicesC: { 258 indexes: []mgo.Index{{ 259 Key: []string{"model-uuid", "machineid"}, 260 }}, 261 }, 262 filesystemsC: { 263 indexes: []mgo.Index{{ 264 Key: []string{"model-uuid", "storageid"}, 265 }}, 266 }, 267 filesystemAttachmentsC: {}, 268 storageInstancesC: { 269 indexes: []mgo.Index{{ 270 Key: []string{"model-uuid", "owner"}, 271 }}, 272 }, 273 storageAttachmentsC: { 274 indexes: []mgo.Index{{ 275 Key: []string{"model-uuid", "storageid"}, 276 }, { 277 Key: []string{"model-uuid", "unitid"}, 278 }}, 279 }, 280 volumesC: { 281 indexes: []mgo.Index{{ 282 Key: []string{"model-uuid", "storageid"}, 283 }}, 284 }, 285 volumeAttachmentsC: {}, 286 287 // ----- 288 289 // These collections hold information associated with networking. 290 // TODO(dimitern): Remove the obsolete collections below once possible. 291 legacyipaddressesC: { 292 indexes: []mgo.Index{{ 293 Key: []string{"uuid"}, 294 }, { 295 Key: []string{"model-uuid", "state"}, 296 }, { 297 Key: []string{"model-uuid", "subnetid"}, 298 }}, 299 }, 300 // TODO(dimitern): End of obsolete networking collections. 301 spacesC: { 302 indexes: []mgo.Index{{ 303 Key: []string{"providerid"}, 304 Unique: true, 305 Sparse: true, 306 }}, 307 }, 308 subnetsC: { 309 indexes: []mgo.Index{{ 310 Key: []string{"providerid"}, 311 Unique: true, 312 Sparse: true, 313 }}, 314 }, 315 linkLayerDevicesC: { 316 indexes: []mgo.Index{{ 317 Key: []string{"providerid"}, 318 Unique: true, 319 Sparse: true, 320 }}, 321 }, 322 linkLayerDevicesRefsC: {}, 323 ipAddressesC: { 324 indexes: []mgo.Index{{ 325 Key: []string{"providerid"}, 326 Unique: true, 327 Sparse: true, 328 }}, 329 }, 330 endpointBindingsC: {}, 331 openedPortsC: {}, 332 333 // ----- 334 335 // These collections hold information associated with actions. 336 actionsC: { 337 indexes: []mgo.Index{{ 338 Key: []string{"model-uuid", "name"}, 339 }}, 340 }, 341 actionNotificationsC: {}, 342 343 // ----- 344 345 // TODO(ericsnow) Use a component-oriented registration mechanism... 346 347 // This collection holds information associated with charm payloads. 348 // See payload/persistence/mongo.go. 349 "payloads": {}, 350 351 // This collection holds information associated with charm resources. 352 // See resource/persistence/mongo.go. 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: service 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 indexes: []mgo.Index{{ 377 Key: []string{"model-uuid", "globalkey"}, 378 }}, 379 }, 380 381 // This collection holds information about cloud image metadata. 382 cloudimagemetadataC: {}, 383 384 // ---------------------- 385 386 // Raw-access collections 387 // ====================== 388 389 // metrics; status-history; logs; ..? 390 } 391 } 392 393 // These constants are used to avoid sprinkling the package with any more 394 // magic strings. If a collection deserves documentation, please document 395 // it in allCollections, above; and please keep this list sorted for easy 396 // inspection. 397 const ( 398 actionNotificationsC = "actionnotifications" 399 actionresultsC = "actionresults" 400 actionsC = "actions" 401 annotationsC = "annotations" 402 assignUnitC = "assignUnits" 403 bakeryStorageItemsC = "bakeryStorageItems" 404 blockDevicesC = "blockdevices" 405 blocksC = "blocks" 406 charmsC = "charms" 407 cleanupsC = "cleanups" 408 cloudimagemetadataC = "cloudimagemetadata" 409 constraintsC = "constraints" 410 containerRefsC = "containerRefs" 411 controllersC = "controllers" 412 filesystemAttachmentsC = "filesystemAttachments" 413 filesystemsC = "filesystems" 414 guimetadataC = "guimetadata" 415 guisettingsC = "guisettings" 416 instanceDataC = "instanceData" 417 legacyipaddressesC = "ipaddresses" 418 leaseC = "lease" 419 leasesC = "leases" 420 machinesC = "machines" 421 meterStatusC = "meterStatus" 422 metricsC = "metrics" 423 metricsManagerC = "metricsmanager" 424 minUnitsC = "minunits" 425 migrationsStatusC = "migrations.status" 426 migrationsActiveC = "migrations.active" 427 migrationsC = "migrations" 428 modelUserLastConnectionC = "modelUserLastConnection" 429 modelUsersC = "modelusers" 430 modelsC = "models" 431 modelEntityRefsC = "modelEntityRefs" 432 openedPortsC = "openedPorts" 433 rebootC = "reboot" 434 relationScopesC = "relationscopes" 435 relationsC = "relations" 436 restoreInfoC = "restoreInfo" 437 sequenceC = "sequence" 438 servicesC = "services" 439 endpointBindingsC = "endpointbindings" 440 settingsC = "settings" 441 settingsrefsC = "settingsrefs" 442 sshHostKeysC = "sshhostkeys" 443 spacesC = "spaces" 444 statusesC = "statuses" 445 statusesHistoryC = "statuseshistory" 446 storageAttachmentsC = "storageattachments" 447 storageConstraintsC = "storageconstraints" 448 storageInstancesC = "storageinstances" 449 subnetsC = "subnets" 450 linkLayerDevicesC = "linklayerdevices" 451 linkLayerDevicesRefsC = "linklayerdevicesrefs" 452 ipAddressesC = "ip.addresses" 453 toolsmetadataC = "toolsmetadata" 454 txnLogC = "txns.log" 455 txnsC = "txns" 456 unitsC = "units" 457 upgradeInfoC = "upgradeInfo" 458 userLastLoginC = "userLastLogin" 459 usermodelnameC = "usermodelname" 460 usersC = "users" 461 volumeAttachmentsC = "volumeattachments" 462 volumesC = "volumes" 463 // "payloads" (see payload/persistence/mongo.go) 464 // "resources" (see resource/persistence/mongo.go) 465 )