summaryrefslogtreecommitdiff
path: root/src/mongo/db/index_names.h
diff options
context:
space:
mode:
authorHari Khalsa <hkhalsa@10gen.com>2014-02-14 14:22:52 -0500
committerHari Khalsa <hkhalsa@10gen.com>2014-02-19 12:45:44 -0500
commitcfdf055eee1b1d0eed3d13c0c2d4d66a27dff662 (patch)
tree08fafe5cf887b3c12e3e07a36a4468db96b8d703 /src/mongo/db/index_names.h
parent00c7183b1a79b795f3d39c9079bb2f795c1cabb6 (diff)
downloadmongo-cfdf055eee1b1d0eed3d13c0c2d4d66a27dff662.tar.gz
SERVER-10026 push access method name into index descriptor, pay attention to it in planning
Diffstat (limited to 'src/mongo/db/index_names.h')
-rw-r--r--src/mongo/db/index_names.h45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/mongo/db/index_names.h b/src/mongo/db/index_names.h
index 03f7786c879..fd7af42675b 100644
--- a/src/mongo/db/index_names.h
+++ b/src/mongo/db/index_names.h
@@ -37,6 +37,26 @@ namespace mongo {
class BSONObj;
/**
+ * We need to know what 'type' an index is in order to plan correctly. We can't entirely rely
+ * on the key pattern to tell us what kind of index we have.
+ *
+ * An example of the Bad Thing That We Must Avoid:
+ * 1. Create a 2dsphere index in 2.4, insert some docs.
+ * 2. Downgrade to 2.2. Insert some more docs into the collection w/the 2dsphere
+ * index. 2.2 treats the index as a normal btree index and creates keys accordingly.
+ * 3. Using the 2dsphere index in 2.4 gives wrong results or assert-fails or crashes as
+ * the data isn't what we expect.
+ */
+ enum IndexType {
+ INDEX_BTREE,
+ INDEX_2D,
+ INDEX_HAYSTACK,
+ INDEX_2DSPHERE,
+ INDEX_TEXT,
+ INDEX_HASHED,
+ };
+
+ /**
* We use the string representation of index names all over the place, so we declare them all
* once here.
*/
@@ -47,18 +67,14 @@ namespace mongo {
static const string GEO_2DSPHERE;
static const string TEXT;
static const string HASHED;
+ static const string BTREE;
/**
* 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;
- }
+ static bool existedBefore24(const string& name);
/**
* Return the first string value in the provided object. For an index key pattern,
@@ -66,14 +82,15 @@ namespace mongo {
*/
static string findPluginName(const BSONObj& keyPattern);
- static bool isKnownName(const string& name) {
- return name.empty()
- || name == IndexNames::GEO_2D
- || name == IndexNames::GEO_2DSPHERE
- || name == IndexNames::GEO_HAYSTACK
- || name == IndexNames::TEXT
- || name == IndexNames::HASHED;
- }
+ /**
+ * Is the provided access method name one we recognize?
+ */
+ static bool isKnownName(const string& name);
+
+ /**
+ * Convert an index name to an IndexType.
+ */
+ static IndexType nameToType(const string& accessMethod);
};
} // namespace mongo