From a23f4a3138dce2f71ca3f3f4529b64366e1cfce5 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 14 May 2009 11:30:13 -0400 Subject: [PATCH] don't do de duping for capped collections --- db/clientcursor.h | 2 +- db/cursor.h | 3 +++ db/query.cpp | 22 ++++++++++++---------- jstests/disk/norepeat.js | 13 +++++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/db/clientcursor.h b/db/clientcursor.h index 0e8d3f10c21..99eda2c0e6b 100644 --- a/db/clientcursor.h +++ b/db/clientcursor.h @@ -151,7 +151,7 @@ namespace mongo { void mayUpgradeStorage() { stringstream ss; - ss << cursorid; + ss << ns << "." << cursorid; ids_->mayUpgradeStorage( ss.str() ); } }; diff --git a/db/cursor.h b/db/cursor.h index 78cb389f509..68214cd251d 100644 --- a/db/cursor.h +++ b/db/cursor.h @@ -103,6 +103,7 @@ namespace mongo { virtual BSONObj prettyStartKey() const { return BSONObj(); } virtual BSONObj prettyEndKey() const { return BSONObj(); } + virtual bool capped() const { return false; } }; class AdvanceStrategy { @@ -197,6 +198,7 @@ namespace mongo { return "ForwardCappedCursor"; } virtual DiskLoc next( const DiskLoc &prev ) const; + virtual bool capped() const { return true; } private: NamespaceDetails *nsd; }; @@ -208,6 +210,7 @@ namespace mongo { return "ReverseCappedCursor"; } virtual DiskLoc next( const DiskLoc &prev ) const; + virtual bool capped() const { return true; } private: NamespaceDetails *nsd; }; diff --git a/db/query.cpp b/db/query.cpp index 0bccc0d244f..1547bd64c8d 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -822,16 +822,18 @@ namespace mongo { } else { BSONObj js = c->current(); - BSONElement idRef = js.getField( "_id" ); - if ( !idRef.eoo() ) { - BSONObjBuilder idBuilder; - idBuilder.append( idRef ); - BSONObj id = idBuilder.obj(); - if ( cc->ids_->get( id ) ) { - c->advance(); - continue; + if ( cc->ids_.get() ) { + BSONElement idRef = js.getField( "_id" ); + if ( !idRef.eoo() ) { + BSONObjBuilder idBuilder; + idBuilder.append( idRef ); + BSONObj id = idBuilder.obj(); + if ( cc->ids_->get( id ) ) { + c->advance(); + continue; + } + cc->ids_->put( id ); } - cc->ids_->put( id ); } bool ok = fillQueryResultFromObj(b, cc->filter.get(), js); if ( ok ) { @@ -1043,7 +1045,7 @@ namespace mongo { bool mayCreateCursor1 = wantMore_ && ntoreturn_ != 1 && useCursors; - if ( ( mayCreateCursor1 || mayCreateCursor2() ) && !ids_.get() ) { + if ( !ids_.get() && !c_->capped() && ( mayCreateCursor1 || mayCreateCursor2() ) ) { ids_.reset( new IdSet() ); } diff --git a/jstests/disk/norepeat.js b/jstests/disk/norepeat.js index be64106d7be..b636c3eaa91 100644 --- a/jstests/disk/norepeat.js +++ b/jstests/disk/norepeat.js @@ -43,4 +43,17 @@ assert.throws( function() { c.next() }, [], "unexpected: object found" ); m.getDB( "local" ).getCollectionNames().forEach( function( x ) { assert( !x.match( /^temp/ ), "temp collection found" ); } ); +t.drop(); +m.getDB( baseName ).createCollection( baseName, { capped:true, size:100000, autoIdIndex:false } ); +t = m.getDB( baseName ).getCollection( baseName ); +t.insert( {_id:"a"} ); +t.insert( {_id:"a"} ); +t.insert( {_id:"a"} ); + +c = t.find().limit( 2 ); +assert.eq( "a", c.next()._id ); +assert.eq( "a", c.next()._id ); +assert.eq( "a", c.next()._id ); +assert( !c.hasNext() ); + assert( t.validate().valid );