summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-04-29 21:04:54 -0400
committerEliot Horowitz <eliot@10gen.com>2010-04-29 21:04:54 -0400
commit1721270c5b43e9bb1e7fb6bfdd201c9e38ad3695 (patch)
treea4920fc8e57b8e3bfae160d7461c947c7499d620
parent4147810106a47aedcea32fccc5e7ae4891bae43f (diff)
downloadmongo-1721270c5b43e9bb1e7fb6bfdd201c9e38ad3695.tar.gz
hack invalid config case
-rw-r--r--s/chunk.cpp88
-rw-r--r--s/chunk.h6
2 files changed, 61 insertions, 33 deletions
diff --git a/s/chunk.cpp b/s/chunk.cpp
index 83b682c0a12..aa535f1a6df 100644
--- a/s/chunk.cpp
+++ b/s/chunk.cpp
@@ -470,23 +470,8 @@ namespace mongo {
_config( config ) , _ns( ns ) ,
_key( pattern ) , _unique( unique ) ,
_sequenceNumber( ++NextSequenceNumber ) {
- Chunk temp(0);
- ShardConnection conn( temp.modelServer() );
- auto_ptr<DBClientCursor> cursor = conn->query( temp.getNS() , BSON( "ns" << ns ) );
- while ( cursor->more() ){
- BSONObj d = cursor->next();
- if ( d["isMaxMarker"].trueValue() ){
- continue;
- }
-
- Chunk * c = new Chunk( this );
- c->unserialize( d );
- _chunks.push_back( c );
- _chunkMap[c->getMax()] = c;
- c->_id = d["_id"].wrap().getOwned();
- }
- conn.done();
+ _load();
if ( _chunks.size() == 0 ){
Chunk * c = new Chunk( this );
@@ -511,31 +496,70 @@ namespace mongo {
_chunks.clear();
_chunkMap.clear();
}
+
+ void ChunkManager::_reload(){
+ rwlock lk( _lock , true );
+ _chunks.clear();
+ _chunkMap.clear();
+ _load();
+ }
+
+ void ChunkManager::_load(){
+ Chunk temp(0);
+
+ ShardConnection conn( temp.modelServer() );
+
+ auto_ptr<DBClientCursor> cursor = conn->query( temp.getNS() , BSON( "ns" << _ns ) );
+ while ( cursor->more() ){
+ BSONObj d = cursor->next();
+ if ( d["isMaxMarker"].trueValue() ){
+ continue;
+ }
+
+ Chunk * c = new Chunk( this );
+ c->unserialize( d );
+ _chunks.push_back( c );
+ _chunkMap[c->getMax()] = c;
+ c->_id = d["_id"].wrap().getOwned();
+ }
+ conn.done();
+ }
+
bool ChunkManager::hasShardKey( const BSONObj& obj ){
return _key.hasShardKey( obj );
}
- Chunk& ChunkManager::findChunk( const BSONObj & obj ){
- rwlock lk( _lock , false );
-
+ Chunk& ChunkManager::findChunk( const BSONObj & obj , bool retry ){
BSONObj key = _key.extractKey(obj);
- ChunkMap::iterator it = _chunkMap.upper_bound(key);
- if (it != _chunkMap.end()){
- Chunk* c = it->second;
- if ( c->contains( obj ) ){
- return *c;
- }else{
- PRINT(it->first);
- PRINT(*c);
- PRINT(key);
- massert(13141, "Chunk map pointed to incorrect chunk", false);
+
+ {
+ rwlock lk( _lock , false );
+
+ ChunkMap::iterator it = _chunkMap.upper_bound(key);
+ if (it != _chunkMap.end()){
+ Chunk* c = it->second;
+ if ( c->contains( obj ) ){
+ return *c;
+ }
+ else{
+ PRINT(it->first);
+ PRINT(*c);
+ PRINT(key);
+ massert(13141, "Chunk map pointed to incorrect chunk", false);
+ }
}
}
- stringstream ss;
- ss << "couldn't find a chunk which should be impossible extracted: " << key;
- throw UserException( 8070 , ss.str() );
+ if ( retry ){
+ stringstream ss;
+ ss << "couldn't find a chunk aftry retry which should be impossible extracted: " << key;
+ throw UserException( 8070 , ss.str() );
+ }
+
+ log() << "ChunkManager: couldn't find chunk for: " << key << " going to retry" << endl;
+ _reload();
+ return findChunk( obj , true );
}
Chunk* ChunkManager::findChunkOnServer( const Shard& shard ) const {
diff --git a/s/chunk.h b/s/chunk.h
index 79cfa64df46..d2282ca3528 100644
--- a/s/chunk.h
+++ b/s/chunk.h
@@ -172,7 +172,7 @@ namespace mongo {
Chunk* getChunk( int i ){ rwlock lk( _lock , false ); return _chunks[i]; }
bool hasShardKey( const BSONObj& obj );
- Chunk& findChunk( const BSONObj& obj );
+ Chunk& findChunk( const BSONObj& obj , bool retry = false );
Chunk* findChunkOnServer( const Shard& shard ) const;
ShardKeyPattern& getShardKey(){ return _key; }
@@ -213,6 +213,10 @@ namespace mongo {
void drop();
private:
+
+ void _reload();
+ void _load();
+
DBConfig * _config;
string _ns;
ShardKeyPattern _key;