summaryrefslogtreecommitdiff
path: root/s
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2012-03-30 21:40:45 +0200
committerAntonin Kral <a.kral@bobek.cz>2012-03-30 21:40:45 +0200
commiteaaa7b30c99b89b5483e0a372bb73fe8c8695185 (patch)
tree6c08f243b00c0f6b7a4897a236774cf484e61314 /s
parentba59b00736b5b8dc0f0bd46397575aaf0cd4d44f (diff)
downloadmongodb-eaaa7b30c99b89b5483e0a372bb73fe8c8695185.tar.gz
Imported Upstream version 2.0.4
Diffstat (limited to 's')
-rw-r--r--s/d_chunk_manager.cpp2
-rw-r--r--s/d_logic.h3
-rw-r--r--s/d_state.cpp28
-rw-r--r--s/shardconnection.cpp2
4 files changed, 30 insertions, 5 deletions
diff --git a/s/d_chunk_manager.cpp b/s/d_chunk_manager.cpp
index 82a06f6..351df15 100644
--- a/s/d_chunk_manager.cpp
+++ b/s/d_chunk_manager.cpp
@@ -40,7 +40,7 @@ namespace mongo {
conn = direct.get();
}
else {
- scoped.reset( new ScopedDbConnection( configServer ) );
+ scoped.reset( new ScopedDbConnection( configServer, 30.0 ) );
conn = scoped->get();
}
diff --git a/s/d_logic.h b/s/d_logic.h
index d96f937..dca0ee1 100644
--- a/s/d_logic.h
+++ b/s/d_logic.h
@@ -147,6 +147,9 @@ namespace mongo {
// protects state below
mutable mongo::mutex _mutex;
+ // protects accessing the config server
+ // Using a ticket holder so we can have multiple redundant tries at any given time
+ mutable TicketHolder _configServerTickets;
// map from a namespace into the ensemble of chunk ranges that are stored in this mongod
// a ShardChunkManager carries all state we need for a collection at this shard, including its version information
diff --git a/s/d_state.cpp b/s/d_state.cpp
index 929d2a8..638d8c1 100644
--- a/s/d_state.cpp
+++ b/s/d_state.cpp
@@ -45,7 +45,8 @@ namespace mongo {
// -----ShardingState START ----
ShardingState::ShardingState()
- : _enabled(false) , _mutex( "ShardingState" ) {
+ : _enabled(false) , _mutex( "ShardingState" ),
+ _configServerTickets( 3 /* max number of concurrent config server refresh threads */ ) {
}
void ShardingState::enable( const string& server ) {
@@ -183,7 +184,23 @@ namespace mongo {
bool ShardingState::trySetVersion( const string& ns , ConfigVersion& version /* IN-OUT */ ) {
- // fast path - requested version is at the same version as this chunk manager
+ // Currently this function is called after a getVersion(), which is the first "check", and the assumption here
+ // is that we don't do anything nearly as long as a remote query in a thread between then and now.
+ // Otherwise it may be worth adding an additional check without the _configServerMutex below, since then it
+ // would be likely that the version may have changed in the meantime without waiting for or fetching config results.
+
+ // TODO: Mutex-per-namespace?
+
+ LOG( 2 ) << "trying to set shard version of " << version.toString() << " for '" << ns << "'" << endl;
+
+ _configServerTickets.waitForTicket();
+ TicketHolderReleaser needTicketFrom( &_configServerTickets );
+
+ // fast path - double-check if requested version is at the same version as this chunk manager before verifying
+ // against config server
+ //
+ // This path will short-circuit the version set if another thread already managed to update the version in the
+ // meantime. First check is from getVersion().
//
// cases:
// + this shard updated the version for a migrate's commit (FROM side)
@@ -191,12 +208,15 @@ namespace mongo {
// + two clients reloaded
// one triggered the 'slow path' (below)
// when the second's request gets here, the version is already current
+ ConfigVersion storedVersion;
{
scoped_lock lk( _mutex );
ChunkManagersMap::const_iterator it = _chunks.find( ns );
- if ( it != _chunks.end() && it->second->getVersion() == version )
+ if ( it != _chunks.end() && ( storedVersion = it->second->getVersion() ) == version )
return true;
}
+
+ LOG( 2 ) << "verifying cached version " << storedVersion.toString() << " and new version " << version.toString() << " for '" << ns << "'" << endl;
// slow path - requested version is different than the current chunk manager's, if one exists, so must check for
// newest version in the config server
@@ -209,8 +229,10 @@ namespace mongo {
// the secondary had no state (managers) at all, so every client request will fall here
// + a stale client request a version that's not current anymore
+ // Can't lock default mutex while creating ShardChunkManager, b/c may have to create a new connection to myself
const string c = (_configServer == _shardHost) ? "" /* local */ : _configServer;
ShardChunkManagerPtr p( new ShardChunkManager( c , ns , _shardName ) );
+
{
scoped_lock lk( _mutex );
diff --git a/s/shardconnection.cpp b/s/shardconnection.cpp
index 89b3839..471e37b 100644
--- a/s/shardconnection.cpp
+++ b/s/shardconnection.cpp
@@ -266,7 +266,7 @@ namespace mongo {
if ( _conn ) {
if ( ! _conn->isFailed() ) {
/* see done() comments above for why we log this line */
- log() << "~ScopedDBConnection: _conn != null" << endl;
+ log() << "sharded connection to " << _conn->getServerAddress() << " not being returned to the pool" << endl;
}
kill();
}