summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-03-13 11:26:10 -0400
committerGreg Studer <greg@10gen.com>2014-03-20 14:48:42 -0400
commitd949d2f1c378a8230a2c24da4f1c431cca78a80c (patch)
tree5852264ecf90630f72ac7537b0634ba1f9c20ab5
parent967120643015068ca8f60cde4bfbc2984da7bef1 (diff)
downloadmongo-d949d2f1c378a8230a2c24da4f1c431cca78a80c.tar.gz
SERVER-12548 add indexes to distlock collections backport
-rw-r--r--src/mongo/client/distlock.cpp35
-rw-r--r--src/mongo/s/config.cpp12
2 files changed, 36 insertions, 11 deletions
diff --git a/src/mongo/client/distlock.cpp b/src/mongo/client/distlock.cpp
index 0e38a64f953..a2f56e564bf 100644
--- a/src/mongo/client/distlock.cpp
+++ b/src/mongo/client/distlock.cpp
@@ -131,19 +131,32 @@ namespace mongo {
continue;
}
- // remove really old entries from the lockpings collection if they're not holding a lock
- // (this may happen if an instance of a process was taken down and no new instance came up to
- // replace it for a quite a while)
- // if the lock is taken, the take-over mechanism should handle the situation
- auto_ptr<DBClientCursor> c = conn->query( LocksType::ConfigNS , BSONObj() );
- // TODO: Would be good to make clear whether query throws or returns empty on errors
- uassert( 16060, str::stream() << "cannot query locks collection on config server " << conn.getHost(), c.get() );
+ // Remove really old entries from the lockpings collection if they're not
+ // holding a lock. This may happen if an instance of a process was taken down
+ // and no new instance came up to replace it for a quite a while.
+ // NOTE this is NOT the same as the standard take-over mechanism, which forces
+ // the lock entry.
+ BSONObj fieldsToReturn = BSON( LocksType::state() << 1 <<
+ LocksType::process() << 1 );
+ auto_ptr<DBClientCursor> activeLocks =
+ conn->query( LocksType::ConfigNS,
+ BSON( LocksType::state() << GT << 0 ) );
+
+ uassert( 16060,
+ str::stream() << "cannot query locks collection on config server "
+ << conn.getHost(),
+ activeLocks.get() );
set<string> pids;
- while ( c->more() ) {
- BSONObj lock = c->next();
- if ( ! lock[LocksType::process()].eoo() ) {
- pids.insert( lock[LocksType::process()].valuestrsafe() );
+ while ( activeLocks->more() ) {
+ BSONObj lock = activeLocks->nextSafe();
+
+ if ( !lock[LocksType::process()].eoo() ) {
+ pids.insert( lock[LocksType::process()].str() );
+ }
+ else {
+ warning() << "found incorrect lock document during lock ping cleanup: "
+ << lock.toString() << endl;
}
}
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp
index b8698a10687..9e042938607 100644
--- a/src/mongo/s/config.cpp
+++ b/src/mongo/s/config.cpp
@@ -34,6 +34,8 @@
#include "mongo/s/type_chunk.h"
#include "mongo/s/type_collection.h"
#include "mongo/s/type_database.h"
+#include "mongo/s/type_locks.h"
+#include "mongo/s/type_lockpings.h"
#include "mongo/s/type_settings.h"
#include "mongo/s/type_shard.h"
#include "mongo/util/net/message.h"
@@ -985,6 +987,16 @@ namespace mongo {
conn->get()->ensureIndex(ShardType::ConfigNS, BSON(ShardType::host() << 1), true);
+ conn->get()->ensureIndex(LocksType::ConfigNS,
+ BSON( LocksType::lockID() << 1 ), true);
+
+ conn->get()->ensureIndex(LockpingsType::ConfigNS,
+ BSON( LockpingsType::ping() << 1 ), false);
+
+ conn->get()->ensureIndex(LocksType::ConfigNS,
+ BSON( LocksType::state() << 1 <<
+ LocksType::process() << 1 ), false);
+
conn->done();
}
catch ( DBException& e ) {