Skip to content

Commit 0ec1769

Browse files
author
Alberto Lerner
committed
force explicit change of version
1 parent 57b800c commit 0ec1769

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

s/d_logic.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace mongo {
4747

4848
bool hasVersion( const string& ns );
4949
bool hasVersion( const string& ns , ConfigVersion& version );
50-
ConfigVersion& getVersion( const string& ns ); // TODO: this is dangeroues
50+
const ConfigVersion getVersion( const string& ns ) const;
5151
void setVersion( const string& ns , const ConfigVersion& version );
5252

5353
void appendInfo( BSONObjBuilder& b );
@@ -65,7 +65,7 @@ namespace mongo {
6565
string _shardHost;
6666

6767
// protects state below
68-
mongo::mutex _mutex;
68+
mutable mongo::mutex _mutex;
6969

7070
// map from a namespace into the highest ShardChunkVersion for that collection
7171
NSVersionMap _versions;
@@ -88,7 +88,7 @@ namespace mongo {
8888
bool hasID() const { return _id.isSet(); }
8989
void setID( const OID& id );
9090

91-
ConfigVersion& getVersion( const string& ns ); // TODO: this is dangeroues
91+
const ConfigVersion getVersion( const string& ns ) const;
9292
void setVersion( const string& ns , const ConfigVersion& version );
9393

9494
static ShardedConnectionInfo* get( bool create );

s/d_state.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,15 @@ namespace mongo {
113113
return true;
114114
}
115115

116-
ConfigVersion& ShardingState::getVersion( const string& ns ){
116+
const ConfigVersion ShardingState::getVersion( const string& ns ) const {
117117
scoped_lock lk(_mutex);
118-
return _versions[ns];
118+
119+
NSVersionMap::const_iterator it = _versions.find( ns );
120+
if ( it != _versions.end() ) {
121+
return it->second;
122+
} else {
123+
return 0;
124+
}
119125
}
120126

121127
void ShardingState::setVersion( const string& ns , const ConfigVersion& version ){
@@ -273,8 +279,13 @@ namespace mongo {
273279
_tl.reset();
274280
}
275281

276-
ConfigVersion& ShardedConnectionInfo::getVersion( const string& ns ){
277-
return _versions[ns];
282+
const ConfigVersion ShardedConnectionInfo::getVersion( const string& ns ) const {
283+
NSVersionMap::const_iterator it = _versions.find( ns );
284+
if ( it != _versions.end() ) {
285+
return it->second;
286+
} else {
287+
return 0;
288+
}
278289
}
279290

280291
void ShardedConnectionInfo::setVersion( const string& ns , const ConfigVersion& version ){
@@ -421,18 +432,18 @@ namespace mongo {
421432
return false;
422433
}
423434

424-
ConfigVersion& oldVersion = info->getVersion(ns);
425-
ConfigVersion& globalVersion = shardingState.getVersion(ns);
435+
const ConfigVersion oldVersion = info->getVersion(ns);
436+
const ConfigVersion globalVersion = shardingState.getVersion(ns);
426437

427438
if ( oldVersion > 0 && globalVersion == 0 ){
428439
// this had been reset
429-
oldVersion = 0;
440+
info->setVersion( ns , 0 );
430441
}
431442

432443
if ( version == 0 && globalVersion == 0 ){
433444
// this connection is cleaning itself
434-
oldVersion = 0;
435-
return 1;
445+
info->setVersion( ns , 0 );
446+
return true;
436447
}
437448

438449
if ( version == 0 && globalVersion > 0 ){
@@ -441,15 +452,15 @@ namespace mongo {
441452
result.appendTimestamp( "globalVersion" , globalVersion );
442453
result.appendTimestamp( "oldVersion" , oldVersion );
443454
errmsg = "dropping needs to be authoritative";
444-
return 0;
455+
return false;
445456
}
446457
log() << "wiping data for: " << ns << endl;
447458
result.appendTimestamp( "beforeDrop" , globalVersion );
448459
// only setting global version on purpose
449460
// need clients to re-find meta-data
450-
globalVersion = 0;
451-
oldVersion = 0;
452-
return 1;
461+
shardingState.setVersion( ns , 0 );
462+
info->setVersion( ns , 0 );
463+
return true;
453464
}
454465

455466
if ( version < oldVersion ){
@@ -480,17 +491,18 @@ namespace mongo {
480491
return false;
481492
}
482493

494+
result.appendTimestamp( "oldVersion" , oldVersion );
495+
result.append( "ok" , 1 );
496+
497+
info->setVersion( ns , version );
498+
shardingState.setVersion( ns , version );
499+
483500
{
484501
dbtemprelease unlock;
485502
shardingState.getChunkMatcher( ns );
486503
}
487504

488-
result.appendTimestamp( "oldVersion" , oldVersion );
489-
oldVersion = version;
490-
globalVersion = version;
491-
492-
result.append( "ok" , 1 );
493-
return 1;
505+
return true;
494506
}
495507

496508
} setShardVersionCmd;

0 commit comments

Comments
 (0)