Storage Engine API
bson_collection_catalog_entry.h
Go to the documentation of this file.
1 // bson_collection_catalog_entry.h
2 
31 #pragma once
32 
33 #include <string>
34 #include <vector>
35 
37 #include "mongo/db/index/multikey_paths.h"
39 
40 namespace mongo {
41 
47 public:
48  BSONCollectionCatalogEntry(StringData ns);
49 
51 
52  virtual CollectionOptions getCollectionOptions(OperationContext* opCtx) const;
53 
54  virtual int getTotalIndexCount(OperationContext* opCtx) const;
55 
56  virtual int getCompletedIndexCount(OperationContext* opCtx) const;
57 
58  virtual BSONObj getIndexSpec(OperationContext* opCtx, StringData idxName) const;
59 
60  virtual void getAllIndexes(OperationContext* opCtx, std::vector<std::string>* names) const;
61 
62  virtual void getReadyIndexes(OperationContext* opCtx, std::vector<std::string>* names) const;
63 
64  virtual void getAllUniqueIndexes(OperationContext* opCtx,
65  std::vector<std::string>* names) const;
66 
67  virtual bool isIndexMultikey(OperationContext* opCtx,
68  StringData indexName,
69  MultikeyPaths* multikeyPaths) const;
70 
71  virtual RecordId getIndexHead(OperationContext* opCtx, StringData indexName) const;
72 
73  virtual bool isIndexReady(OperationContext* opCtx, StringData indexName) const;
74 
75  virtual KVPrefix getIndexPrefix(OperationContext* opCtx, StringData indexName) const;
76 
77  // ------ for implementors
78 
79  struct IndexMetaData {
82  BSONObj s, bool r, RecordId h, bool m, KVPrefix prefix, bool isBackgroundSecondaryBuild)
83  : spec(s),
84  ready(r),
85  head(h),
86  multikey(m),
87  prefix(prefix),
88  isBackgroundSecondaryBuild(isBackgroundSecondaryBuild) {}
89 
90  void updateTTLSetting(long long newExpireSeconds);
91 
92  std::string name() const {
93  return spec["name"].String();
94  }
95 
96  BSONObj spec;
97  bool ready;
98  RecordId head;
99  bool multikey;
102 
103  // If non-empty, 'multikeyPaths' is a vector with size equal to the number of elements in
104  // the index key pattern. Each element in the vector is an ordered set of positions
105  // (starting at 0) into the corresponding indexed field that represent what prefixes of the
106  // indexed field cause the index to be multikey.
107  MultikeyPaths multikeyPaths;
108  };
109 
110  struct MetaData {
111  void parse(const BSONObj& obj);
112  BSONObj toBSON() const;
113 
114  int findIndexOffset(StringData name) const;
115 
120  bool eraseIndex(StringData name);
121 
122  void rename(StringData toNS);
123 
124  KVPrefix getMaxPrefix() const;
125 
126  std::string ns;
128  std::vector<IndexMetaData> indexes;
130  };
131 
132 protected:
133  virtual MetaData _getMetaData(OperationContext* opCtx) const = 0;
134 };
135 }
std::string ns
Definition: bson_collection_catalog_entry.h:126
std::vector< IndexMetaData > indexes
Definition: bson_collection_catalog_entry.h:128
virtual void getAllIndexes(OperationContext *opCtx, std::vector< std::string > *names) const
Definition: bson_collection_catalog_entry.cpp:138
RecordId head
Definition: bson_collection_catalog_entry.h:98
virtual CollectionOptions getCollectionOptions(OperationContext *opCtx) const
Definition: bson_collection_catalog_entry.cpp:106
KVPrefix prefix
Definition: bson_collection_catalog_entry.h:100
virtual ~BSONCollectionCatalogEntry()
Definition: bson_collection_catalog_entry.h:50
virtual bool isIndexMultikey(OperationContext *opCtx, StringData indexName, MultikeyPaths *multikeyPaths) const
Returns true if the index identified by &#39;indexName&#39; is multikey, and returns false otherwise...
Definition: bson_collection_catalog_entry.cpp:169
Definition: collection_options.h:57
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
std::string name() const
Definition: bson_collection_catalog_entry.h:92
Definition: collection_catalog_entry.h:47
MultikeyPaths multikeyPaths
Definition: bson_collection_catalog_entry.h:107
CollectionOptions options
Definition: bson_collection_catalog_entry.h:127
bool isBackgroundSecondaryBuild
Definition: bson_collection_catalog_entry.h:101
virtual RecordId getIndexHead(OperationContext *opCtx, StringData indexName) const
Definition: bson_collection_catalog_entry.cpp:184
IndexMetaData(BSONObj s, bool r, RecordId h, bool m, KVPrefix prefix, bool isBackgroundSecondaryBuild)
Definition: bson_collection_catalog_entry.h:81
virtual bool isIndexReady(OperationContext *opCtx, StringData indexName) const
Definition: bson_collection_catalog_entry.cpp:193
virtual KVPrefix getIndexPrefix(OperationContext *opCtx, StringData indexName) const
Definition: bson_collection_catalog_entry.cpp:201
static const KVPrefix kNotPrefixed
Definition: kv_prefix.h:47
virtual MetaData _getMetaData(OperationContext *opCtx) const =0
BSONCollectionCatalogEntry(StringData ns)
Definition: bson_collection_catalog_entry.cpp:103
void updateTTLSetting(long long newExpireSeconds)
Definition: bson_collection_catalog_entry.cpp:211
A KVPrefix may be prepended to the keys of entries in an underlying KV store.
Definition: kv_prefix.h:44
Definition: bson_collection_catalog_entry.h:79
virtual int getCompletedIndexCount(OperationContext *opCtx) const
Definition: bson_collection_catalog_entry.cpp:117
virtual BSONObj getIndexSpec(OperationContext *opCtx, StringData idxName) const
Definition: bson_collection_catalog_entry.cpp:128
bool ready
Definition: bson_collection_catalog_entry.h:97
virtual void getAllUniqueIndexes(OperationContext *opCtx, std::vector< std::string > *names) const
Definition: bson_collection_catalog_entry.cpp:157
BSONObj spec
Definition: bson_collection_catalog_entry.h:96
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
bool multikey
Definition: bson_collection_catalog_entry.h:99
Definition: bson_collection_catalog_entry.h:110
This is a helper class for any storage engine that wants to store catalog information as BSON...
Definition: bson_collection_catalog_entry.h:46
virtual int getTotalIndexCount(OperationContext *opCtx) const
Definition: bson_collection_catalog_entry.cpp:111
const NamespaceString & ns() const
Definition: collection_catalog_entry.h:52
IndexMetaData()
Definition: bson_collection_catalog_entry.h:80
virtual void getReadyIndexes(OperationContext *opCtx, std::vector< std::string > *names) const
Definition: bson_collection_catalog_entry.cpp:147