summaryrefslogtreecommitdiff
path: root/s/strategy.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-07-01 17:44:13 -0400
committerEliot Horowitz <eliot@10gen.com>2010-07-01 17:44:13 -0400
commit2498228f417371da7c18d7bed38be4b3a300a29f (patch)
tree5a13990597d100f8c8fddb9d1c96ddfa8c4d19e7 /s/strategy.cpp
parent30d3a841f2af1a3e8bdf10a0e8d9ed41994a10dc (diff)
downloadmongo-2498228f417371da7c18d7bed38be4b3a300a29f.tar.gz
workong on moving migrate to mongod, cleaning, and version fixing
SERVER-1319 SERVER-933
Diffstat (limited to 's/strategy.cpp')
-rw-r--r--s/strategy.cpp53
1 files changed, 13 insertions, 40 deletions
diff --git a/s/strategy.cpp b/s/strategy.cpp
index 2a55fca0945..112c9d94412 100644
--- a/s/strategy.cpp
+++ b/s/strategy.cpp
@@ -68,6 +68,8 @@ namespace mongo {
void Strategy::insert( const Shard& shard , const char * ns , const BSONObj& obj ){
ShardConnection dbcon( shard , ns );
+ if ( dbcon.setVersion() )
+ throw StaleConfigException( ns , "for insert" );
dbcon->insert( ns , obj );
dbcon.done();
}
@@ -162,15 +164,18 @@ namespace mongo {
map<string,WriteBackListener*> WriteBackListener::_cache;
mongo::mutex WriteBackListener::_lock("WriteBackListener");
-
- void checkShardVersion( DBClientBase& conn , const string& ns , bool authoritative ){
+
+ /**
+ * @return true if had to do something
+ */
+ bool checkShardVersion( DBClientBase& conn , const string& ns , bool authoritative ){
// TODO: cache, optimize, etc...
WriteBackListener::init( conn );
DBConfigPtr conf = grid.getDBConfig( ns );
if ( ! conf )
- return;
+ return false;
ShardChunkVersion version = 0;
unsigned long long officialSequenceNumber = 0;
@@ -184,7 +189,7 @@ namespace mongo {
unsigned long long & sequenceNumber = checkShardVersionLastSequence[ make_pair(&conn,ns) ];
if ( sequenceNumber == officialSequenceNumber )
- return;
+ return false;
if ( isSharded ){
version = manager->getVersion( Shard::make( conn.getServerAddress() ) );
@@ -201,9 +206,9 @@ namespace mongo {
log(1) << " setShardVersion success!" << endl;
sequenceNumber = officialSequenceNumber;
dassert( sequenceNumber == checkShardVersionLastSequence[ make_pair(&conn,ns) ] );
- return;
+ return true;
}
-
+
log(1) << " setShardVersion failed!\n" << result << endl;
if ( result.getBoolField( "need_authoritative" ) )
@@ -211,45 +216,13 @@ namespace mongo {
if ( ! authoritative ){
checkShardVersion( conn , ns , 1 );
- return;
+ return true;
}
log() << " setShardVersion failed: " << result << endl;
massert( 10429 , (string)"setShardVersion failed! " + result.jsonString() , 0 );
- }
-
- bool setShardVersion( DBClientBase & conn , const string& ns , ShardChunkVersion version , bool authoritative , BSONObj& result ){
- BSONObjBuilder cmdBuilder;
- cmdBuilder.append( "setShardVersion" , ns.c_str() );
- cmdBuilder.append( "configdb" , configServer.modelServer() );
- cmdBuilder.appendTimestamp( "version" , version.toLong() );
- cmdBuilder.appendOID( "serverID" , &serverID );
- if ( authoritative )
- cmdBuilder.appendBool( "authoritative" , 1 );
-
- Shard s = Shard::make( conn.getServerAddress() );
- cmdBuilder.append( "shard" , s.getName() );
- cmdBuilder.append( "shardHost" , s.getConnString() );
- BSONObj cmd = cmdBuilder.obj();
-
- log(1) << " setShardVersion " << s.getName() << " " << conn.getServerAddress() << " " << ns << " " << cmd << " " << &conn << endl;
-
- return conn.runCommand( "admin" , cmd , result );
- }
-
- bool lockNamespaceOnServer( const Shard& shard, const string& ns ){
- ScopedDbConnection conn( shard.getConnString() );
- bool res = lockNamespaceOnServer( conn.conn() , ns );
- conn.done();
- return res;
- }
-
- bool lockNamespaceOnServer( DBClientBase& conn , const string& ns ){
- // TODO: replace this
- //BSONObj lockResult;
- //return setShardVersion( conn , ns , grid.getNextOpTime() , true , lockResult );
return true;
}
-
+
}