diff options
-rw-r--r-- | jstests/fts1.js | 5 | ||||
-rw-r--r-- | src/mongo/db/fts/fts_index.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/fts/fts_index.h | 2 | ||||
-rw-r--r-- | src/mongo/db/indexkey.h | 9 | ||||
-rw-r--r-- | src/mongo/db/pdfile.cpp | 6 |
5 files changed, 30 insertions, 0 deletions
diff --git a/jstests/fts1.js b/jstests/fts1.js index bd464eb4b41..bc8c7581909 100644 --- a/jstests/fts1.js +++ b/jstests/fts1.js @@ -9,7 +9,12 @@ t.save( { _id : 2 , x : "az b" } ); t.save( { _id : 3 , x : "b c" } ); t.save( { _id : 4 , x : "b c d" } ); +assert.eq(t.stats().userFlags, 0, + "A new collection should not have power-of-2 storage allocation strategy"); t.ensureIndex( { x : "text" } ); +assert.eq(t.stats().userFlags, 1, + "Creating a text index on a collection should change the allocation strategy " + + "to power-of-2."); assert.eq( [1,2,3,4] , queryIDS( t , "c az" ) , "A1" ); assert.eq( [4] , queryIDS( t , "d" ) , "A2" ); diff --git a/src/mongo/db/fts/fts_index.cpp b/src/mongo/db/fts/fts_index.cpp index 04fafe12a83..2e667d0d1f7 100644 --- a/src/mongo/db/fts/fts_index.cpp +++ b/src/mongo/db/fts/fts_index.cpp @@ -26,6 +26,7 @@ #include "mongo/util/mongoutils/str.h" #include "mongo/util/stringutils.h" #include "mongo/util/timer.h" +#include "mongo/db/pdfile.h" namespace mongo { @@ -84,6 +85,13 @@ namespace mongo { return new FTSIndex( this, spec ); } + void FTSIndexPlugin::postBuildHook( const IndexSpec& spec ) const { + string ns = spec.getDetails()->parentNS(); + NamespaceDetails* nsd = nsdetails( ns ); + if ( nsd->setUserFlag( NamespaceDetails::Flag_UsePowerOf2Sizes ) ) { + nsd->syncUserFlags( ns ); + } + } FTSIndexPlugin* ftsPlugin; MONGO_INITIALIZER(FTSIndexPlugin)(InitializerContext* context) { diff --git a/src/mongo/db/fts/fts_index.h b/src/mongo/db/fts/fts_index.h index d9bf8a61b16..2eff9207ab1 100644 --- a/src/mongo/db/fts/fts_index.h +++ b/src/mongo/db/fts/fts_index.h @@ -61,6 +61,8 @@ namespace mongo { BSONObj adjustIndexSpec( const BSONObj& spec ) const; + void postBuildHook( const IndexSpec& spec ) const; + }; } //namespace fts diff --git a/src/mongo/db/indexkey.h b/src/mongo/db/indexkey.h index 85cba345897..6753ee3bc60 100644 --- a/src/mongo/db/indexkey.h +++ b/src/mongo/db/indexkey.h @@ -109,6 +109,15 @@ namespace mongo { */ 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 ) { diff --git a/src/mongo/db/pdfile.cpp b/src/mongo/db/pdfile.cpp index 8b90b6c7363..948d7c392cb 100644 --- a/src/mongo/db/pdfile.cpp +++ b/src/mongo/db/pdfile.cpp @@ -1538,6 +1538,12 @@ namespace mongo { // clear transient info caches so they refresh; increments nIndexes tableToIndex->addIndex(tabletoidxns.c_str()); getDur().writingInt(tableToIndex->indexBuildsInProgress) -= 1; + + const IndexPlugin *plugin = idx.getSpec().getType()->getPlugin(); + if (plugin) { + plugin->postBuildHook( idx.getSpec() ); + } + } catch (...) { // Generally, this will be called as an exception from building the index bubbles up. |