diff --git a/db/repl.h b/db/repl.h index f1a48a6eeeb..942e8e1f894 100644 --- a/db/repl.h +++ b/db/repl.h @@ -158,6 +158,15 @@ namespace mongo { else imp_[ ns ].erase( id ); } + long long roughSize() const { + long long size = 0; + for( map< string, BSONObjSetDefaultOrder >::const_iterator i = imp_.begin(); + i != imp_.end(); ++i ) + for( BSONObjSetDefaultOrder::const_iterator j = i->second.begin(); + j != i->second.end(); ++j ) + size += sizeof( BSONObj ); + return size; + } private: typedef map< string, BSONObjSetDefaultOrder > IdSets; IdSets imp_; diff --git a/dbtests/repltests.cpp b/dbtests/repltests.cpp index 277093546b3..86756bbc373 100644 --- a/dbtests/repltests.cpp +++ b/dbtests/repltests.cpp @@ -735,14 +735,25 @@ namespace ReplTests { public: MemIdsTest() : s_( "MemIdsTest" ) {} void run() { + int n = sizeof( BSONObj ); + s_.reset(); + ASSERT_EQUALS( 0, s_.roughSize() ); ASSERT( !s_.get( "a", BSON( "_id" << 4 ) ) ); ASSERT( !s_.get( "b", BSON( "_id" << 4 ) ) ); s_.set( "a", BSON( "_id" << 4 ), true ); + ASSERT_EQUALS( n, s_.roughSize() ); ASSERT( s_.get( "a", BSON( "_id" << 4 ) ) ); ASSERT( !s_.get( "b", BSON( "_id" << 4 ) ) ); s_.set( "a", BSON( "_id" << 4 ), false ); + ASSERT_EQUALS( 0, s_.roughSize() ); ASSERT( !s_.get( "a", BSON( "_id" << 4 ) ) ); + + s_.set( "a", BSON( "_id" << 4 ), true ); + s_.set( "b", BSON( "_id" << 4 ), true ); + s_.set( "b", BSON( "_id" << 100 ), true ); + s_.set( "b", BSON( "_id" << 101 ), true ); + ASSERT_EQUALS( n * 4, s_.roughSize() ); } private: MemIds s_; @@ -782,6 +793,7 @@ namespace ReplTests { add< Idempotence::EmptyPush >(); add< DeleteOpIsIdBased >(); add< DbIdsTest >(); + add< MemIdsTest >(); } };