summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/capped.js2
-rw-r--r--jstests/capped5.js11
-rw-r--r--jstests/queryoptimizera.js8
-rw-r--r--jstests/replsets/capped_id.js4
-rw-r--r--jstests/tool/dumprestore8.js8
-rw-r--r--src/mongo/db/oplog.cpp18
-rw-r--r--src/mongo/db/pdfile.cpp20
-rw-r--r--src/mongo/dbtests/queryoptimizercursortests.cpp15
-rw-r--r--src/mongo/dbtests/replsettests.cpp2
9 files changed, 40 insertions, 48 deletions
diff --git a/jstests/capped.js b/jstests/capped.js
index 6fdc4df9e60..421132b6f75 100644
--- a/jstests/capped.js
+++ b/jstests/capped.js
@@ -1,7 +1,7 @@
db.jstests_capped.drop();
db.createCollection("jstests_capped", {capped:true, size:30000});
-assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_capped"} ).count(), "expected a count of zero indexes for new capped collection" );
+assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_capped"} ).count(), "expected a count of one index for new capped collection" );
t = db.jstests_capped;
t.save({x:1});
diff --git a/jstests/capped5.js b/jstests/capped5.js
index be6c27d7256..9af06f84063 100644
--- a/jstests/capped5.js
+++ b/jstests/capped5.js
@@ -7,7 +7,7 @@ t.drop();
db.createCollection( tn , {capped: true, size: 1024 * 1024 * 1 } );
t.insert( { _id : 5 , x : 11 , z : 52 } );
-assert.eq( 0 , t.getIndexKeys().length , "A0" )
+assert.eq( 1 , t.getIndexKeys().length , "A0" ) //now we assume _id index even on capped coll
assert.eq( 52 , t.findOne( { x : 11 } ).z , "A1" );
t.ensureIndex( { _id : 1 } )
@@ -21,23 +21,22 @@ db.createCollection( tn , {capped: true, size: 1024 * 1024 * 1 } );
t.insert( { _id : 5 , x : 11 } );
t.insert( { _id : 6 , x : 11 } );
t.ensureIndex( { x:1 }, {unique:true, dropDups:true } );
-assert.eq( 0, db.system.indexes.count( {ns:"test."+tn} ) );
+assert.eq( 1, db.system.indexes.count( {ns:"test."+tn} ) ); //now we assume _id index
assert.eq( 2, t.find().toArray().length );
t.drop();
db.createCollection( tn , {capped: true, size: 1024 * 1024 * 1 } );
t.insert( { _id : 5 , x : 11 } );
t.insert( { _id : 5 , x : 12 } );
-t.ensureIndex( { _id:1 } );
-assert.eq( 0, db.system.indexes.count( {ns:"test."+tn} ) );
-assert.eq( 2, t.find().toArray().length );
+assert.eq( 1, db.system.indexes.count( {ns:"test."+tn} ) ); //now we assume _id index
+assert.eq( 1, t.find().toArray().length ); //_id index unique, so second insert fails
t.drop();
db.createCollection( tn , {capped: true, size: 1024 * 1024 * 1 } );
t.insert( { _id : 5 , x : 11 } );
t.insert( { _id : 6 , x : 12 } );
t.ensureIndex( { x:1 }, {unique:true, dropDups:true } );
-assert.eq( 1, db.system.indexes.count( {ns:"test."+tn} ) );
+assert.eq( 2, db.system.indexes.count( {ns:"test."+tn} ) ); //now we assume _id index
assert.eq( 2, t.find().hint( {x:1} ).toArray().length );
// SERVER-525 (closed) unique indexes in capped collection
diff --git a/jstests/queryoptimizera.js b/jstests/queryoptimizera.js
index a7d520c15d8..f26c2b0978c 100644
--- a/jstests/queryoptimizera.js
+++ b/jstests/queryoptimizera.js
@@ -52,9 +52,9 @@ function assertNewWarning() {
oldNumWarnings = newNumWarnings;
}
-// Simple _id query without an _id index.
+// Simple _id query
t.find( { _id:0 } ).itcount();
-assertNewWarning();
+assertNoNewWarnings();
// Simple _id query without an _id index, on a non capped collection.
notCapped.find( { _id:0 } ).itcount();
@@ -62,7 +62,7 @@ assertNoNewWarnings();
// A multi field query, including _id.
t.find( { _id:0, a:0 } ).itcount();
-assertNewWarning();
+assertNoNewWarnings();
// An unsatisfiable query.
t.find( { _id:0, a:{$in:[]} } ).itcount();
@@ -74,7 +74,7 @@ assertNoNewWarnings();
// Retry a multi field query.
t.find( { _id:0, a:0 } ).itcount();
-assertNewWarning();
+assertNoNewWarnings();
// Warnings should not be printed when an index is added on _id.
t.ensureIndex( { _id:1 } );
diff --git a/jstests/replsets/capped_id.js b/jstests/replsets/capped_id.js
index 3cd51a617b4..ef700e48959 100644
--- a/jstests/replsets/capped_id.js
+++ b/jstests/replsets/capped_id.js
@@ -101,8 +101,8 @@ for( testnum=0; testnum < numtests; testnum++ ){
slave2db.system.indexes.find().forEach(printjson);
print("");
- // insure each slave has _id index, but not master
- assert.eq( 0 ,
+ // insure all nodes have _id index
+ assert.eq( 1 ,
masterdb.system.indexes.find( { key:{"_id" : 1}, ns: dbname + "." + coll } ).count() ,
"master has an _id index on capped collection");
assert.eq( 1 ,
diff --git a/jstests/tool/dumprestore8.js b/jstests/tool/dumprestore8.js
index d3d2ef590c7..4e6591738d6 100644
--- a/jstests/tool/dumprestore8.js
+++ b/jstests/tool/dumprestore8.js
@@ -31,7 +31,7 @@ db.bar.ensureIndex({x:1});
barDocCount = db.bar.count();
assert.gt( barDocCount, 0 , "No documents inserted" );
assert.lt( db.bar.count(), 1000 , "Capped collection didn't evict documents" );
-assert.eq( 4 , db.system.indexes.count() , "Indexes weren't created right" );
+assert.eq( 5 , db.system.indexes.count() , "Indexes weren't created right" );
// Full dump/restore
@@ -52,7 +52,7 @@ for (var i = 0; i < 10; i++) {
db.bar.save({x:i});
}
assert.eq( barDocCount, db.bar.count(), "Capped collection didn't evict documents after restore." );
-assert.eq( 4 , db.system.indexes.count() , "Indexes weren't created correctly by restore" );
+assert.eq( 5 , db.system.indexes.count() , "Indexes weren't created correctly by restore" );
// Dump/restore single DB
@@ -77,7 +77,7 @@ for (var i = 0; i < 10; i++) {
db.bar.save({x:i});
}
assert.eq( barDocCount, db.bar.count(), "Capped collection didn't evict documents after restore 2." );
-assert.eq( 4 , db.system.indexes.count() , "Indexes weren't created correctly by restore 2" );
+assert.eq( 5 , db.system.indexes.count() , "Indexes weren't created correctly by restore 2" );
// Dump/restore single collection
@@ -100,6 +100,6 @@ for (var i = 0; i < 10; i++) {
db.baz.save({x:i});
}
assert.eq( barDocCount, db.baz.count(), "Capped collection didn't evict documents after restore 3." );
-assert.eq( 1 , db.system.indexes.count() , "Indexes weren't created correctly by restore 3" );
+assert.eq( 2 , db.system.indexes.count() , "Indexes weren't created correctly by restore 3" );
t.stop();
diff --git a/src/mongo/db/oplog.cpp b/src/mongo/db/oplog.cpp
index 2e7153b7bea..fb6c302e722 100644
--- a/src/mongo/db/oplog.cpp
+++ b/src/mongo/db/oplog.cpp
@@ -766,14 +766,9 @@ namespace mongo {
}
}
else {
- /* erh 10/16/2009 - this is probably not relevant any more since its auto-created, but not worth removing */
-
- // this is the old version that doesn't create _id indexes on capped collections
- //RARELY if (nsd && !nsd->isCapped()) { ensureHaveIdIndex(ns); } // otherwise updates will be slow
-
- // this version creates indexes on all collections, including capped
- // as long we apply inserts as updates, this is needed for performance
- RARELY if ( nsd ) { ensureHaveIdIndex(ns); } // otherwise updates will be slow
+ // probably don't need this since all replicated colls have _id indexes now
+ // but keep it just in case
+ RARELY if ( nsd && !nsd->isCapped() ) { ensureHaveIdIndex(ns); }
/* todo : it may be better to do an insert here, and then catch the dup key exception and do update
then. very few upserts will not be inserts...
@@ -787,8 +782,11 @@ namespace mongo {
}
else if ( *opType == 'u' ) {
opCounters->gotUpdate();
- // ensure all collections, including capped, have an _id index.
- RARELY if ( nsd ) { ensureHaveIdIndex(ns); } // otherwise updates will be super slow
+
+ // probably don't need this since all replicated colls have _id indexes now
+ // but keep it just in case
+ RARELY if ( nsd && !nsd->isCapped() ) { ensureHaveIdIndex(ns); }
+
OpDebug debug;
BSONObj updateCriteria = op.getObjectField("o2");
bool upsert = fields[3].booleanSafe();
diff --git a/src/mongo/db/pdfile.cpp b/src/mongo/db/pdfile.cpp
index 4a7e952e076..1f0f0ffeb5c 100644
--- a/src/mongo/db/pdfile.cpp
+++ b/src/mongo/db/pdfile.cpp
@@ -313,16 +313,11 @@ namespace mongo {
NamespaceDetails *d = nsdetails(ns);
verify(d);
- bool ensure = false;
- if ( options.getField( "autoIndexId" ).type() ) {
- if ( options["autoIndexId"].trueValue() ) {
- ensure = true;
- }
- }
- else {
- if ( !newCapped ) {
- ensure=true;
- }
+ // make an _id index for all colls, except capped ones in local w/o autoIndexID
+ // (reason for the exception is for the oplog and non-replicated capped colls)
+ bool ensure = true;
+ if( newCapped && str::equals( nsToDatabase( ns ).c_str() , "local" ) ) {
+ ensure = options.getField( "autoIndexId" ).trueValue();
}
if( ensure ) {
if( deferIdIndex )
@@ -1435,8 +1430,9 @@ namespace mongo {
BSONObj io((const char *) obuf);
BSONElement idField = io.getField( "_id" );
uassert( 10099 , "_id cannot be an array", idField.type() != Array );
- // we don't add _id for capped collections as they don't have an _id index
- if( idField.eoo() && !wouldAddIndex && strstr(ns, ".local.") == 0 && d->haveIdIndex() ) {
+ // we don't add _id for capped collections in local as they don't have an _id index
+ if( idField.eoo() && !wouldAddIndex &&
+ !str::equals( nsToDatabase( ns ).c_str() , "local" ) && d->haveIdIndex() ) {
if( addedID )
*addedID = true;
addID = len;
diff --git a/src/mongo/dbtests/queryoptimizercursortests.cpp b/src/mongo/dbtests/queryoptimizercursortests.cpp
index 2ffa03c3ac9..d8094e04a9f 100644
--- a/src/mongo/dbtests/queryoptimizercursortests.cpp
+++ b/src/mongo/dbtests/queryoptimizercursortests.cpp
@@ -3751,14 +3751,14 @@ namespace QueryOptimizerCursorTests {
void check( const shared_ptr<Cursor> &c ) {}
};
- class SnapshotWithoutIdIndex : public Base {
+ class SnapshotCappedColl : public Base {
public:
- SnapshotWithoutIdIndex() {
+ SnapshotCappedColl() {
_cli.dropCollection( ns() );
_cli.createCollection( ns(), 1000, true );
_cli.ensureIndex( ns(), BSON( "a" << 1 ) );
}
- string expectedType() const { return "BtreeCursor a_1"; }
+ string expectedType() const { return "BtreeCursor _id_"; }
BSONObj query() const {
return BSON( "$query" << BSON( "a" << 1 ) << "$snapshot" << true );
}
@@ -4837,7 +4837,7 @@ namespace QueryOptimizerCursorTests {
add<GetCursor::MultiIndex>();
add<GetCursor::Hint>();
add<GetCursor::Snapshot>();
- add<GetCursor::SnapshotWithoutIdIndex>();
+ add<GetCursor::SnapshotCappedColl>();
add<GetCursor::Min>();
add<GetCursor::Max>();
add<GetCursor::RequireIndex::NoConstraints>();
@@ -4854,9 +4854,10 @@ namespace QueryOptimizerCursorTests {
add<GetCursor::IdElseNatural::HintedIdForQuery>( BSON( "a" << 1 ) );
add<GetCursor::IdElseNatural::HintedIdForQuery>( BSON( "_id" << 1 << "a" << 1 ) );
add<GetCursor::IdElseNatural::HintedNaturalForQuery>( BSONObj() );
- add<GetCursor::IdElseNatural::HintedNaturalForQuery>( BSON( "_id" << 1 ) );
- add<GetCursor::IdElseNatural::HintedNaturalForQuery>( BSON( "a" << 1 ) );
- add<GetCursor::IdElseNatural::HintedNaturalForQuery>( BSON( "_id" << 1 << "a" << 1 ) );
+ // now capped collections have _id index by default, so skip these
+ //add<GetCursor::IdElseNatural::HintedNaturalForQuery>( BSON( "_id" << 1 ) );
+ //add<GetCursor::IdElseNatural::HintedNaturalForQuery>( BSON( "a" << 1 ) );
+ //add<GetCursor::IdElseNatural::HintedNaturalForQuery>( BSON( "_id" << 1 << "a" << 1 ) );
add<GetCursor::MatcherValidation>();
add<Explain::ClearRecordedIndex>();
add<Explain::Initial>();
diff --git a/src/mongo/dbtests/replsettests.cpp b/src/mongo/dbtests/replsettests.cpp
index f790196f924..baf269389cd 100644
--- a/src/mongo/dbtests/replsettests.cpp
+++ b/src/mongo/dbtests/replsettests.cpp
@@ -336,8 +336,6 @@ namespace ReplSetTests {
}
};
- // check that applying ops doesn't cause _id index to be created
-
class CappedUpdate : public CappedInitialSync {
void updateSucceed() {
BSONObjBuilder b;