summaryrefslogtreecommitdiff
path: root/s
diff options
context:
space:
mode:
Diffstat (limited to 's')
-rw-r--r--s/chunk.cpp21
-rw-r--r--s/chunk.h5
-rw-r--r--s/d_logic.cpp4
-rw-r--r--s/d_logic.h2
-rw-r--r--s/d_migrate.cpp6
-rw-r--r--s/d_split.cpp16
-rw-r--r--s/d_state.cpp11
-rw-r--r--s/s_only.cpp5
-rw-r--r--s/shardconnection.cpp23
-rw-r--r--s/strategy_shard.cpp4
-rw-r--r--s/util.h3
11 files changed, 69 insertions, 31 deletions
diff --git a/s/chunk.cpp b/s/chunk.cpp
index 50d4e76..cf1f992 100644
--- a/s/chunk.cpp
+++ b/s/chunk.cpp
@@ -62,7 +62,7 @@ namespace mongo {
void Chunk::setShard( const Shard& s ){
_shard = s;
_manager->_migrationNotification(this);
- _markModified();
+ _modified = true;
}
bool Chunk::contains( const BSONObj& obj ) const{
@@ -224,7 +224,7 @@ namespace mongo {
vector<ChunkPtr> newChunks;
vector<BSONObj>::const_iterator i = m.begin();
BSONObj nextPoint = i->getOwned();
- _markModified();
+ _modified = true;
do {
BSONObj splitPoint = nextPoint;
log(4) << "splitPoint: " << splitPoint << endl;
@@ -238,9 +238,9 @@ namespace mongo {
uasserted( 13395, ss.str() );
}
- ChunkPtr s( new Chunk( _manager, splitPoint , nextPoint , _shard) );
- s->_markModified();
- newChunks.push_back(s);
+ ChunkPtr c( new Chunk( _manager, splitPoint , nextPoint , _shard) );
+ c->_modified = true;
+ newChunks.push_back( c );
} while ( i != m.end() );
// Have the chunk manager reflect the key change for the first chunk and create an entry for every
@@ -439,6 +439,7 @@ namespace mongo {
<< "min" << getMin()
<< "max" << getMax()
<< "maxSize" << ( MaxChunkSize + 1 )
+ << "estimate" << true
) , result ) );
conn.done();
@@ -549,10 +550,6 @@ namespace mongo {
return o["lastmod"];
}
- void Chunk::_markModified(){
- _modified = true;
- }
-
string Chunk::toString() const {
stringstream ss;
ss << "ns:" << _manager->getns() << " at: " << _shard.toString() << " lastmod: " << _lastmod.toString() << " min: " << _min << " max: " << _max;
@@ -577,7 +574,7 @@ namespace mongo {
if ( _chunkMap.empty() ){
ChunkPtr c( new Chunk(this, _key.globalMin(), _key.globalMax(), config->getPrimary()) );
- c->_markModified();
+ c->setModified( true );
_chunkMap[c->getMax()] = c;
_chunkRanges.reloadAll(_chunkMap);
@@ -902,7 +899,7 @@ namespace mongo {
int numOps = 0;
for ( ChunkMap::const_iterator i=_chunkMap.begin(); i!=_chunkMap.end(); ++i ){
ChunkPtr c = i->second;
- if ( ! c->_modified )
+ if ( ! c->getModified() )
continue;
numOps++;
@@ -966,6 +963,7 @@ namespace mongo {
for ( unsigned i=0; i<toFix.size(); i++ ){
toFix[i]->_lastmod = newVersions[i];
+ toFix[i]->setModified( false );
}
massert( 10417 , "how did version get smalled" , getVersion_inlock() >= a );
@@ -1240,5 +1238,4 @@ namespace mongo {
return conn.runCommand( "admin" , cmd , result );
}
-
} // namespace mongo
diff --git a/s/chunk.h b/s/chunk.h
index b81b788..82f2300 100644
--- a/s/chunk.h
+++ b/s/chunk.h
@@ -127,8 +127,6 @@ namespace mongo {
void appendShortVersion( const char * name , BSONObjBuilder& b );
- void _markModified();
-
static int MaxChunkSize;
string genID() const;
@@ -136,7 +134,8 @@ namespace mongo {
const ChunkManager* getManager() const { return _manager; }
- bool modified();
+ bool getModified() { return _modified; }
+ void setModified( bool modified ) { _modified = modified; }
ShardChunkVersion getVersionOnConfigServer() const;
private:
diff --git a/s/d_logic.cpp b/s/d_logic.cpp
index ddf83e8..62288ed 100644
--- a/s/d_logic.cpp
+++ b/s/d_logic.cpp
@@ -56,11 +56,11 @@ namespace mongo {
DbMessage d(m);
const char *ns = d.getns();
string errmsg;
- if ( shardVersionOk( ns , errmsg ) ){
+ if ( shardVersionOk( ns , opIsWrite( op ) , errmsg ) ){
return false;
}
- log() << "shardVersionOk failed ns:(" << ns << ") op:(" << opToString(op) << ") " << errmsg << endl;
+ log(1) << "connection meta data too old - will retry ns:(" << ns << ") op:(" << opToString(op) << ") " << errmsg << endl;
if ( doesOpGetAResponse( op ) ){
assert( dbresponse );
diff --git a/s/d_logic.h b/s/d_logic.h
index 0f7ba35..a000f6b 100644
--- a/s/d_logic.h
+++ b/s/d_logic.h
@@ -155,7 +155,7 @@ namespace mongo {
/**
* @return true if the current threads shard version is ok, or not in sharded version
*/
- bool shardVersionOk( const string& ns , string& errmsg );
+ bool shardVersionOk( const string& ns , bool write , string& errmsg );
/**
* @return true if we took care of the message and nothing else should be done
diff --git a/s/d_migrate.cpp b/s/d_migrate.cpp
index fac63af..b8ee78e 100644
--- a/s/d_migrate.cpp
+++ b/s/d_migrate.cpp
@@ -107,7 +107,8 @@ namespace mongo {
int loops = 0;
Timer t;
- while ( t.seconds() < 600 ){ // 10 minutes
+ while ( t.seconds() < 900 ){ // 15 minutes
+ assert( dbMutex.getState() == 0 );
sleepmillis( 20 );
set<CursorId> now;
@@ -519,6 +520,7 @@ namespace mongo {
// 4.
for ( int i=0; i<86400; i++ ){ // don't want a single chunk move to take more than a day
+ assert( dbMutex.getState() == 0 );
sleepsecs( 1 );
ScopedDbConnection conn( to );
BSONObj res;
@@ -537,6 +539,8 @@ namespace mongo {
if ( res["state"].String() == "steady" )
break;
+
+ killCurrentOp.checkForInterrupt();
}
timing.done(4);
diff --git a/s/d_split.cpp b/s/d_split.cpp
index 7ae8384..fdefc7e 100644
--- a/s/d_split.cpp
+++ b/s/d_split.cpp
@@ -66,8 +66,22 @@ namespace mongo {
int num = 0;
NamespaceDetails *d = nsdetails(ns);
int idxNo = d->idxNo(*id);
- for( BtreeCursor c( d, idxNo, *id, min, max, false, 1 ); c.ok(); c.advance(), ++num );
+
+ // only yielding on firt half for now
+ // after this it should be in ram, so 2nd should be fast
+ {
+ shared_ptr<Cursor> c( new BtreeCursor( d, idxNo, *id, min, max, false, 1 ) );
+ scoped_ptr<ClientCursor> cc( new ClientCursor( QueryOption_NoCursorTimeout , c , ns ) );
+ while ( c->ok() ){
+ num++;
+ c->advance();
+ if ( ! cc->yieldSometimes() )
+ break;
+ }
+ }
+
num /= 2;
+
BtreeCursor c( d, idxNo, *id, min, max, false, 1 );
for( ; num; c.advance(), --num );
diff --git a/s/d_state.cpp b/s/d_state.cpp
index 16f46cd..3f13b79 100644
--- a/s/d_state.cpp
+++ b/s/d_state.cpp
@@ -523,7 +523,7 @@ namespace mongo {
* @ return true if not in sharded mode
or if version for this client is ok
*/
- bool shardVersionOk( const string& ns , string& errmsg ){
+ bool shardVersionOk( const string& ns , bool isWriteOp , string& errmsg ){
if ( ! shardingState.enabled() )
return true;
@@ -549,7 +549,7 @@ namespace mongo {
if ( version == 0 && clientVersion > 0 ){
stringstream ss;
- ss << "version: " << version << " clientVersion: " << clientVersion;
+ ss << "collection was dropped or this shard no longer valied version: " << version << " clientVersion: " << clientVersion;
errmsg = ss.str();
return false;
}
@@ -565,6 +565,13 @@ namespace mongo {
return false;
}
+ if ( isWriteOp && version.majorVersion() == clientVersion.majorVersion() ){
+ // this means there was just a split
+ // since on a split w/o a migrate this server is ok
+ // going to accept write
+ return true;
+ }
+
stringstream ss;
ss << "your version is too old ns: " + ns << " global: " << version << " client: " << clientVersion;
errmsg = ss.str();
diff --git a/s/s_only.cpp b/s/s_only.cpp
index 74ee9c0..1f66e70 100644
--- a/s/s_only.cpp
+++ b/s/s_only.cpp
@@ -35,12 +35,13 @@ namespace mongo {
boost::thread_specific_ptr<Client> currentClient;
- Client::Client(const char *desc) :
+ Client::Client(const char *desc , MessagingPort *p) :
_context(0),
_shutdown(false),
_desc(desc),
_god(0),
- _lastOp(0)
+ _lastOp(0),
+ _mp(p)
{
}
Client::~Client(){}
diff --git a/s/shardconnection.cpp b/s/shardconnection.cpp
index 5d89b51..694693b 100644
--- a/s/shardconnection.cpp
+++ b/s/shardconnection.cpp
@@ -63,7 +63,12 @@ namespace mongo {
Status* ss = i->second;
assert( ss );
if ( ss->avail ){
- release( addr , ss->avail );
+ /* if we're shutting down, don't want to initiate release mechanism as it is slow,
+ and isn't needed since all connections will be closed anyway */
+ if ( inShutdown() )
+ delete ss->avail;
+ else
+ release( addr , ss->avail );
ss->avail = 0;
}
delete ss;
@@ -146,10 +151,18 @@ namespace mongo {
void release( const string& addr , DBClientBase * conn ){
resetShardVersion( conn );
BSONObj res;
- if ( conn->simpleCommand( "admin" , &res , "unsetSharding" ) )
- pool.release( addr , conn );
- else {
- log(LL_ERROR) << " couldn't unset sharding :( " << res << endl;
+
+ try {
+ if ( conn->simpleCommand( "admin" , &res , "unsetSharding" ) ){
+ pool.release( addr , conn );
+ }
+ else {
+ log(LL_ERROR) << " couldn't unset sharding :( " << res << endl;
+ delete conn;
+ }
+ }
+ catch ( std::exception& e ){
+ log(LL_ERROR) << "couldn't unsert sharding : " << e.what() << endl;
delete conn;
}
}
diff --git a/s/strategy_shard.cpp b/s/strategy_shard.cpp
index 91759fd..144bf79 100644
--- a/s/strategy_shard.cpp
+++ b/s/strategy_shard.cpp
@@ -196,7 +196,7 @@ namespace mongo {
if ( multi ){
}
else if ( strcmp( query.firstElement().fieldName() , "_id" ) || query.nFields() != 1 ){
- throw UserException( 8013 , "can't do update with query that doesn't have the shard key" );
+ throw UserException( 8013 , "can't do non-multi update with query that doesn't have the shard key" );
}
else {
save = true;
@@ -282,7 +282,7 @@ namespace mongo {
if ( left <= 0 )
throw e;
left--;
- log() << "update failed b/c of StaleConfigException, retrying "
+ log() << "delete failed b/c of StaleConfigException, retrying "
<< " left:" << left << " ns: " << r.getns() << " patt: " << pattern << endl;
r.reset( false );
shards.clear();
diff --git a/s/util.h b/s/util.h
index 8d78fe8..7695eda 100644
--- a/s/util.h
+++ b/s/util.h
@@ -87,6 +87,9 @@ namespace mongo {
ss << _major << "|" << _minor;
return ss.str();
}
+
+ int majorVersion() const { return _major; }
+ int minorVersion() const { return _minor; }
operator unsigned long long() const { return _combined; }