summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2013-12-21 17:59:41 -0500
committerJason Rassi <rassi@10gen.com>2013-12-21 19:29:46 -0500
commit859858cc6159b973ee7ea547bb9a149e18ea5c48 (patch)
treef2ae6268ca8a956036b16b25ae60e6e1f3074083
parenta8481e8f75464e5e570d415a00a98b6607d4cf54 (diff)
downloadmongo-859858cc6159b973ee7ea547bb9a149e18ea5c48.tar.gz
SERVER-11494 Run text index version check at time of text index use
-rw-r--r--src/mongo/db/fts/fts_spec.cpp21
-rw-r--r--src/mongo/db/fts/fts_spec_test.cpp30
2 files changed, 48 insertions, 3 deletions
diff --git a/src/mongo/db/fts/fts_spec.cpp b/src/mongo/db/fts/fts_spec.cpp
index eb534f10a3e..f1829104796 100644
--- a/src/mongo/db/fts/fts_spec.cpp
+++ b/src/mongo/db/fts/fts_spec.cpp
@@ -30,10 +30,25 @@ namespace mongo {
const double MAX_WEIGHT = 1000000000.0;
const double MAX_WORD_WEIGHT = MAX_WEIGHT / 10000;
+ const int TEXT_INDEX_VERSION = 1;
FTSSpec::FTSSpec( const BSONObj& indexInfo ) {
- massert( 16739, "found invalid spec for text index",
+ // indexInfo is a text index spec. Text index specs pass through fixSpec() before
+ // being saved to the system.indexes collection. fixSpec() enforces a schema, such that
+ // required fields must exist and be of the correct type (e.g. weights,
+ // textIndexVersion).
+ massert( 16739,
+ "found invalid spec for text index, expected object for weights",
indexInfo["weights"].isABSONObj() );
+ BSONElement textIndexVersionElt = indexInfo["textIndexVersion"];
+ massert( 17287,
+ "found invalid spec for text index, expected number for textIndexVersion",
+ textIndexVersionElt.isNumber() );
+ massert( 17288,
+ str::stream() << "attempt to use unsupported textIndexVersion " <<
+ textIndexVersionElt.numberInt() << ", only textIndexVersion " <<
+ TEXT_INDEX_VERSION << " supported",
+ textIndexVersionElt.numberInt() == TEXT_INDEX_VERSION );
_defaultLanguage = indexInfo["default_language"].valuestrsafe();
_languageOverrideField = indexInfo["language_override"].valuestrsafe();
@@ -357,7 +372,7 @@ namespace mongo {
language_override = "language";
int version = -1;
- int textIndexVersion = 1;
+ int textIndexVersion = TEXT_INDEX_VERSION;
BSONObjBuilder b;
BSONObjIterator i( spec );
@@ -385,7 +400,7 @@ namespace mongo {
textIndexVersion = e.numberInt();
uassert( 16730,
str::stream() << "bad textIndexVersion: " << textIndexVersion,
- textIndexVersion == 1 );
+ textIndexVersion == TEXT_INDEX_VERSION );
}
else {
b.append( e );
diff --git a/src/mongo/db/fts/fts_spec_test.cpp b/src/mongo/db/fts/fts_spec_test.cpp
index df4ff719f02..c93536013be 100644
--- a/src/mongo/db/fts/fts_spec_test.cpp
+++ b/src/mongo/db/fts/fts_spec_test.cpp
@@ -24,6 +24,36 @@
namespace mongo {
namespace fts {
+ const BSONObj makeFixedSpec( int textIndexVersion ) {
+ return BSON( "v" << 1 <<
+ "key" << BSON( "_fts" << "text" <<
+ "_ftsx" << 1 ) <<
+ "name" << "a_text" <<
+ "ns" << "test.foo" <<
+ "weights" << BSON( "a" << 1 ) <<
+ "default_language" << "english" <<
+ "language_override" << "language" <<
+ "textIndexVersion" << textIndexVersion );
+ }
+
+ TEST( FTSSpec, TextIndexVersionCheck1 ) {
+ const int currentVersion = 1;
+ const int unsupportedVersion = 2;
+
+ // Constructing an FTSSpec with the current textIndexVersion should succeed.
+ BSONObj validTextSpec = makeFixedSpec( currentVersion );
+ try {
+ FTSSpec spec( validTextSpec );
+ }
+ catch ( UserException& e ) {
+ ASSERT( false );
+ }
+
+ // Constructing an FTSSpec with an unsupported textIndexVersion should fail.
+ BSONObj invalidTextSpec = makeFixedSpec( unsupportedVersion );
+ ASSERT_THROWS( FTSSpec spec( invalidTextSpec ), UserException );
+ }
+
TEST( FTSSpec, Fix1 ) {
BSONObj user = BSON( "key" << BSON( "title" << "fts" <<
"text" << "fts" ) <<