Storage Engine API
collection_options.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <string>
32 
33 #include <boost/optional.hpp>
34 
35 #include "mongo/base/status.h"
36 #include "mongo/db/jsobj.h"
37 #include "mongo/util/uuid.h"
38 
39 namespace mongo {
40 
41 // TODO(SERVER-34489) Remove when upgrade/downgrade is ready.
43 
44 class CollatorFactoryInterface;
45 
53 using CollectionUUID = UUID;
54 
55 using OptionalCollectionUUID = boost::optional<CollectionUUID>;
56 
61  bool isView() const;
62 
69 
73  Status validateForStorage() const;
74 
78  Status parse(const BSONObj& obj, ParseKind kind = parseForCommand);
79 
80  void appendBSON(BSONObjBuilder* builder) const;
81  BSONObj toBSON() const;
82 
87  static bool validMaxCappedDocs(long long* max);
88 
96  bool matchesStorageOptions(const CollectionOptions& other,
97  CollatorFactoryInterface* collatorFactory) const;
98 
99  // ----
100 
101  // Collection UUID. Present for all CollectionOptions parsed for storage, except for those
102  // corresponding to the system.namespaces and system.indexes collections on MMAP (see
103  // SERVER-29926, SERVER-30095).
105 
106  bool capped = false;
107  long long cappedSize = 0;
108  long long cappedMaxDocs = 0;
109 
110  // (MMAPv1) The following 2 are mutually exclusive, can only have one set.
111  long long initialNumExtents = 0;
112  std::vector<long long> initialExtentSizes;
113 
114  // The behavior of _id index creation when collection created
115  void setNoIdIndex() {
116  autoIndexId = NO;
117  }
118  enum {
119  DEFAULT, // currently yes for most collections, NO for some system ones
120  YES, // create _id index
121  NO // do not create _id index
122  } autoIndexId = DEFAULT;
123 
124  // user flags
125  enum UserFlags {
127  Flag_NoPadding = 1 << 1,
128  };
129  int flags = Flag_UsePowerOf2Sizes; // a bitvector of UserFlags
130  bool flagsSet = false;
131 
132  bool temp = false;
133 
134  // Storage engine collection options. Always owned or empty.
135  BSONObj storageEngine;
136 
137  // Default options for indexes created on the collection. Always owned or empty.
139 
140  // Index specs for the _id index.
141  BSONObj idIndex;
142 
143  // Always owned or empty.
144  BSONObj validator;
145  std::string validationAction;
146  std::string validationLevel;
147 
148  // The namespace's default collation.
149  BSONObj collation;
150 
151  // View-related options.
152  // The namespace of the view or collection that "backs" this view, or the empty string if this
153  // collection is not a view.
154  std::string viewOn;
155  // The aggregation pipeline that defines this view.
156  BSONObj pipeline;
157 };
158 }
bool createTimestampSafeUniqueIndex
Definition: collection_options.cpp:46
BSONObj collation
Definition: collection_options.h:149
std::string validationAction
Definition: collection_options.h:145
Definition: collection_options.h:120
Definition: collection_options.h:127
Definition: collection_options.h:121
Definition: collection_options.h:57
long long initialNumExtents
Definition: collection_options.h:111
void setNoIdIndex()
Definition: collection_options.h:115
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
BSONObj pipeline
Definition: collection_options.h:156
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
BSONObj validator
Definition: collection_options.h:144
Definition: collection_options.h:68
BSONObj storageEngine
Definition: collection_options.h:135
bool matchesStorageOptions(const CollectionOptions &other, CollatorFactoryInterface *collatorFactory) const
Returns true if given options matches to this.
Definition: collection_options.cpp:349
long long cappedMaxDocs
Definition: collection_options.h:108
Definition: collection_options.h:126
UUID CollectionUUID
A CollectionUUID is a 128-bit unique identifier, per RFC 4122, v4.
Definition: collection_options.h:53
BSONObj idIndex
Definition: collection_options.h:141
Status validateForStorage() const
Confirms that collection options can be converted to BSON and back without errors.
Definition: collection_options.cpp:109
void appendBSON(BSONObjBuilder *builder) const
Definition: collection_options.cpp:285
Status parse(const BSONObj &obj, ParseKind kind=parseForCommand)
Parses the "options" subfield of the collection info object.
Definition: collection_options.cpp:113
Definition: collection_options.h:68
long long cappedSize
Definition: collection_options.h:107
boost::optional< CollectionUUID > OptionalCollectionUUID
Definition: collection_options.h:55
ParseKind
The &#39;uuid&#39; member is a collection property stored in the catalog with user-settable options...
Definition: collection_options.h:68
std::vector< long long > initialExtentSizes
Definition: collection_options.h:112
std::string viewOn
Definition: collection_options.h:154
bool capped
Definition: collection_options.h:106
static bool validMaxCappedDocs(long long *max)
Definition: collection_options.cpp:53
bool temp
Definition: collection_options.h:132
int flags
Definition: collection_options.h:129
Definition: collection_options.h:119
std::string validationLevel
Definition: collection_options.h:146
UserFlags
Definition: collection_options.h:125
BSONObj indexOptionDefaults
Definition: collection_options.h:138
enum mongo::CollectionOptions::@19 autoIndexId
BSONObj toBSON() const
Definition: collection_options.cpp:279
bool flagsSet
Definition: collection_options.h:130
bool isView() const
Returns true if the options indicate the namespace is a view.
Definition: collection_options.cpp:105
OptionalCollectionUUID uuid
Definition: collection_options.h:104