summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-04-03 14:21:00 -0400
committerEliot Horowitz <eliot@10gen.com>2009-04-03 14:21:00 -0400
commit7b8881ffab8905f6f5ee46bea7d05b1ea09d8615 (patch)
tree150a39cd407449eb72b614d52d1ffbc464a4d47c
parent5d81abc69044aa62241524fa3e7ee3c9aed2fbb1 (diff)
downloadmongo-7b8881ffab8905f6f5ee46bea7d05b1ea09d8615.tar.gz
refactor locking
-rw-r--r--s/commands.cpp9
-rw-r--r--s/shard.cpp3
-rw-r--r--s/strategy.cpp13
-rw-r--r--s/strategy.h7
4 files changed, 22 insertions, 10 deletions
diff --git a/s/commands.cpp b/s/commands.cpp
index 3b58628606d..af053754546 100644
--- a/s/commands.cpp
+++ b/s/commands.cpp
@@ -339,15 +339,10 @@ namespace mongo {
log() << "splitting: " << ns << " shard: " << old << endl;
- unsigned long long nextTS = grid.getNextOpTime();
- ScopedDbConnection conn( old.getServer() );
- BSONObj lockResult;
- if ( ! setShardVersion( conn.conn() , ns , nextTS , true , lockResult ) ){
- log() << "setShardVersion for split failed!" << endl;
- errmsg = "setShardVersion failed to lock server. is someone else doing something?";
+ if ( ! lockNamespaceOnServer( old.getServer() , ns ) ){
+ log() << errmsg << endl;
return false;
}
- conn.done();
if ( middle.isEmpty() )
old.split();
diff --git a/s/shard.cpp b/s/shard.cpp
index 27c44f3727c..99e64ed3d1a 100644
--- a/s/shard.cpp
+++ b/s/shard.cpp
@@ -21,6 +21,7 @@
#include "config.h"
#include "../util/unittest.h"
#include "../client/connpool.h"
+#include "strategy.h"
namespace mongo {
@@ -126,6 +127,8 @@ namespace mongo {
string from = _server;
+ lockNamespaceOnServer( from , _ns );
+
// copyCollection
ScopedDbConnection toconn( to );
BSONObj cloneRes;
diff --git a/s/strategy.cpp b/s/strategy.cpp
index dc644cb86e7..6a252f68d30 100644
--- a/s/strategy.cpp
+++ b/s/strategy.cpp
@@ -106,5 +106,16 @@ namespace mongo {
return conn.runCommand( "admin" , cmd , result );
}
-
+
+ bool lockNamespaceOnServer( const string& server , const string& ns ){
+ ScopedDbConnection conn( server );
+ bool res = lockNamespaceOnServer( conn.conn() , ns );
+ conn.done();
+ return res;
+ }
+
+ bool lockNamespaceOnServer( DBClientBase& conn , const string& ns ){
+ BSONObj lockResult;
+ return setShardVersion( conn , ns , grid.getNextOpTime() , true , lockResult );
+ }
}
diff --git a/s/strategy.h b/s/strategy.h
index fbe0d50d058..88540fac4e0 100644
--- a/s/strategy.h
+++ b/s/strategy.h
@@ -24,11 +24,14 @@ namespace mongo {
};
+ extern Strategy * SINGLE;
+ extern Strategy * SHARDED;
+
void checkShardVersion( DBClientBase & conn , const string& ns , bool authoritative = false );
bool setShardVersion( DBClientBase & conn , const string& ns , ServerShardVersion version , bool authoritative , BSONObj& result );
- extern Strategy * SINGLE;
- extern Strategy * SHARDED;
+ bool lockNamespaceOnServer( const string& server , const string& ns );
+ bool lockNamespaceOnServer( DBClientBase& conn , const string& ns );
}