summaryrefslogtreecommitdiff
path: root/src/mongo/db/indexkey.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/indexkey.h')
-rw-r--r--src/mongo/db/indexkey.h152
1 files changed, 10 insertions, 142 deletions
diff --git a/src/mongo/db/indexkey.h b/src/mongo/db/indexkey.h
index 2acd38e998d..7fed236db7e 100644
--- a/src/mongo/db/indexkey.h
+++ b/src/mongo/db/indexkey.h
@@ -22,6 +22,7 @@
#include "mongo/db/diskloc.h"
#include "mongo/db/index_names.h"
+#include "mongo/db/keypattern.h"
#include "mongo/db/jsobj.h"
namespace mongo {
@@ -32,126 +33,16 @@ namespace mongo {
class Cursor;
class IndexSpec;
- class IndexType; // TODO: this name sucks
- class IndexPlugin;
class IndexDetails;
class FieldRangeSet;
enum IndexSuitability { USELESS = 0 , HELPFUL = 1 , OPTIMAL = 2 };
- /**
- * this represents an instance of a index plugin
- * done this way so parsing, etc... can be cached
- * so if there is a FTS IndexPlugin, for each index using FTS
- * there will be 1 of these, and it can have things pre-parsed, etc...
- */
- class IndexType : boost::noncopyable {
- public:
- IndexType( const IndexPlugin * plugin , const IndexSpec * spec );
- virtual ~IndexType();
-
- virtual void getKeys( const BSONObj &obj, BSONObjSet &keys ) const = 0;
-
- /**
- * Returns the element placed in an index key when indexing a field absent from a document.
- * By default this is a null BSONElement.
- */
- virtual BSONElement missingField() const;
-
- /** optional op : changes query to match what's in the index */
- virtual BSONObj fixKey( const BSONObj& in ) { return in; }
-
- /** optional op : compare 2 objects with regards to this index */
- virtual int compare( const BSONObj& l , const BSONObj& r ) const;
-
- /** @return plugin */
- const IndexPlugin * getPlugin() const { return _plugin; }
-
- const BSONObj& keyPattern() const;
-
- virtual bool scanAndOrderRequired( const BSONObj& query , const BSONObj& order ) const ;
-
- protected:
- const IndexPlugin * _plugin;
- const IndexSpec * _spec;
- };
-
- /**
- * this represents a plugin
- * a plugin could be something like full text search, sparse index, etc...
- * 1 of these exists per type of index per server
- * 1 IndexType is created per index using this plugin
- */
- class IndexPlugin : boost::noncopyable {
- public:
- IndexPlugin( const string& name );
- virtual ~IndexPlugin() {}
-
- virtual IndexType* generate( const IndexSpec * spec ) const = 0;
-
- string getName() const { return _name; }
-
- /**
- * @return new keyPattern
- * if nothing changes, should return keyPattern
- */
- virtual BSONObj adjustIndexSpec( const BSONObj& spec ) const { return spec; }
-
- /**
- * Hook function to run after an index that uses this plugin is built.
- *
- * This will be called with an active write context (and lock) on the database.
- *
- * @param spec The IndexSpec of the newly built index.
- */
- virtual void postBuildHook( const IndexSpec& spec ) const { }
-
- // ------- static below -------
-
- static IndexPlugin* get( const string& name ) {
- if ( ! _plugins )
- return 0;
- map<string,IndexPlugin*>::iterator i = _plugins->find( name );
- if ( i == _plugins->end() )
- return 0;
- return i->second;
- }
-
- /**
- * @param keyPattern { x : "fts" }
- * @return "" or the name
- */
- static string findPluginName( const BSONObj& keyPattern );
-
- /**
- * True if is a regular (non-plugin) index or uses a plugin that existed before 2.4.
- * These plugins are grandfathered in and allowed to exist in DBs with
- * PDFILE_MINOR_VERSION_22_AND_OLDER
- */
- static bool existedBefore24(const string& name) {
- return name.empty()
- || name == IndexNames::GEO_2D
- || name == IndexNames::GEO_HAYSTACK
- || name == IndexNames::HASHED
- ;
- }
-
- private:
- string _name;
- static map<string,IndexPlugin*> * _plugins;
- };
-
/* precomputed details about an index, used for inserting keys on updates
stored/cached in NamespaceDetailsTransient, or can be used standalone
*/
class IndexSpec {
public:
- enum PluginRules {
- NoPlugins,
- RulesFor22, // if !IndexPlugin::existedBefore24() treat as ascending
- RulesFor24, // allow new plugins but error if unknown
- };
-
BSONObj keyPattern; // e.g., { name : 1 }
BSONObj info; // this is the same as IndexDetails::info.obj()
@@ -159,47 +50,26 @@ namespace mongo {
: _details(0) , _finishedInit(false) {
}
- explicit IndexSpec(const BSONObj& k, const BSONObj& m=BSONObj(),
- PluginRules rules=RulesFor24)
+ explicit IndexSpec(const BSONObj& k, const BSONObj& m=BSONObj())
: keyPattern(k) , info(m) , _details(0) , _finishedInit(false) {
- _init(rules);
+ _init();
}
/**
this is a DiscLoc of an IndexDetails info
should have a key field
*/
- explicit IndexSpec(const DiskLoc& loc, PluginRules rules=RulesFor24) {
- reset(loc, rules);
+ explicit IndexSpec(const DiskLoc& loc) {
+ reset(loc);
}
- void reset(const BSONObj& info, PluginRules rules=RulesFor24);
+ void reset(const BSONObj& info);
void reset(const IndexDetails * details); // determines rules based on pdfile version
- void reset(const DiskLoc& infoLoc, PluginRules rules=RulesFor24) {
- reset(infoLoc.obj(), rules);
+ void reset(const DiskLoc& infoLoc) {
+ reset(infoLoc.obj());
}
- void getKeys( const BSONObj &obj, BSONObjSet &keys ) const;
-
- /**
- * Returns the element placed in an index key when indexing a field absent from a document.
- * By default this is a null BSONElement.
- */
- BSONElement missingField() const {
- if ( _indexType.get() )
- return _indexType->missingField();
- return _nullElt;
- }
-
- string getTypeName() const {
- if ( _indexType.get() )
- return _indexType->getPlugin()->getName();
- return "";
- }
-
- IndexType* getType() const {
- return _indexType.get();
- }
+ string getTypeName() const;
const IndexDetails * getDetails() const {
return _details;
@@ -226,12 +96,10 @@ namespace mongo {
int _nFields; // number of fields in the index
bool _sparse; // if the index is sparse
- shared_ptr<IndexType> _indexType;
const IndexDetails * _details;
- void _init(PluginRules rules);
+ void _init();
- friend class IndexType;
friend class KeyGeneratorV0;
friend class KeyGeneratorV1;
public: