mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-29 16:47:28 +01:00
clear index cache in c++ client on dropping collection / database
This commit is contained in:
parent
c4cbebd356
commit
ee6ef61ca4
@ -352,12 +352,12 @@ namespace mongo {
|
||||
bool resetError() { return simpleCommand("admin", 0, "reseterror"); }
|
||||
|
||||
/** Erase / drop an entire database */
|
||||
bool dropDatabase(const string &dbname, BSONObj *info = 0) {
|
||||
virtual bool dropDatabase(const string &dbname, BSONObj *info = 0) {
|
||||
return simpleCommand(dbname, info, "dropDatabase");
|
||||
}
|
||||
|
||||
/** Delete the specified collection. */
|
||||
bool dropCollection( const string &ns ){
|
||||
virtual bool dropCollection( const string &ns ){
|
||||
string db = nsGetDB( ns );
|
||||
string coll = nsGetCollection( ns );
|
||||
assert( coll.size() );
|
||||
@ -555,6 +555,20 @@ namespace mongo {
|
||||
virtual void resetIndexCache();
|
||||
|
||||
virtual string getServerAddress() const = 0;
|
||||
|
||||
/** Erase / drop an entire database */
|
||||
virtual bool dropDatabase(const string &dbname, BSONObj *info = 0) {
|
||||
bool ret = DBClientWithCommands::dropDatabase( dbname, info );
|
||||
resetIndexCache();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Delete the specified collection. */
|
||||
virtual bool dropCollection( const string &ns ){
|
||||
bool ret = DBClientWithCommands::dropCollection( ns );
|
||||
resetIndexCache();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
set<string> _seenIndexes;
|
||||
|
@ -389,6 +389,32 @@ namespace QueryTests {
|
||||
ASSERT( client().findOne( ns, fromjson( "{'a.b':{$ne:1}}" ) ).isEmpty() );
|
||||
}
|
||||
};
|
||||
|
||||
class AutoResetIndexCache : public ClientBase {
|
||||
public:
|
||||
~AutoResetIndexCache() {
|
||||
client().dropCollection( "querytests.AutoResetIndexCache" );
|
||||
}
|
||||
static const char *ns() { return "querytests.AutoResetIndexCache"; }
|
||||
static const char *idxNs() { return "querytests.system.indexes"; }
|
||||
void index() const { ASSERT( !client().findOne( idxNs(), BSONObj() ).isEmpty() ); }
|
||||
void noIndex() const { ASSERT( client().findOne( idxNs(), BSONObj() ).isEmpty() ); }
|
||||
void checkIndex() {
|
||||
client().ensureIndex( ns(), BSON( "a" << 1 ) );
|
||||
index();
|
||||
}
|
||||
void run() {
|
||||
client().dropDatabase( "querytests" );
|
||||
noIndex();
|
||||
checkIndex();
|
||||
client().dropCollection( ns() );
|
||||
noIndex();
|
||||
checkIndex();
|
||||
client().dropDatabase( "querytests" );
|
||||
noIndex();
|
||||
checkIndex();
|
||||
}
|
||||
};
|
||||
|
||||
class All : public UnitTest::Suite {
|
||||
public:
|
||||
@ -411,6 +437,7 @@ namespace QueryTests {
|
||||
add< EmptyFieldSpec >();
|
||||
add< MultiNe >();
|
||||
add< EmbeddedNe >();
|
||||
add< AutoResetIndexCache >();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user