summaryrefslogtreecommitdiff
path: root/src/mongo/s/d_logic.h
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2013-07-16 14:43:05 -0400
committerGreg Studer <greg@10gen.com>2013-07-26 18:32:24 -0400
commit01296c1617fa8b003967c63dbbc1af911d6cd223 (patch)
tree3370e427ef7cfff4221f9d7fcf463c800267ef84 /src/mongo/s/d_logic.h
parent21431f5bc46c292bd2962d5bf9aa16dc6f43a121 (diff)
downloadmongo-01296c1617fa8b003967c63dbbc1af911d6cd223.tar.gz
SERVER-8598 replace trySetVersion with epoch-safe refresh behavior
Diffstat (limited to 'src/mongo/s/d_logic.h')
-rw-r--r--src/mongo/s/d_logic.h61
1 files changed, 52 insertions, 9 deletions
diff --git a/src/mongo/s/d_logic.h b/src/mongo/s/d_logic.h
index 8d027baaf1e..29697bc0290 100644
--- a/src/mongo/s/d_logic.h
+++ b/src/mongo/s/d_logic.h
@@ -80,17 +80,50 @@ namespace mongo {
void resetVersion( const string& ns );
/**
- * Requests to access a collection at a certain version. If the collection's metadata is not
- * at that version it will try to update itself to the newest version. The request is only
- * granted if the version is the current or the newest one.
+ * If the metadata for 'ns' at this shard is at or above the requested version,
+ * 'reqShardVersion', returns OK and fills in 'latestShardVersion' with the latest shard
+ * version. The latter is always greater or equal than 'reqShardVersion' if in the same
+ * epoch.
*
- * @param ns collection to be accessed
- * @param version (IN) the client believe this collection is on and (OUT) the version the
- * metadata is actually in
- * @param forceRefresh force contacting the config server to check version
- * @return true if the access can be allowed at the provided version
+ * Otherwise, falls back to refreshMetadataNow.
+ *
+ * This call blocks if there are more than N threads
+ * currently refreshing metadata. (N is the number of
+ * tickets in ShardingState::_configServerTickets,
+ * currently 3.)
+ *
+ * Locking Note:
+ * + Must NOT be called with the write lock because this call may go into the network,
+ * and deadlocks may occur with shard-as-a-config. Therefore, nothing here guarantees
+ * that 'latestShardVersion' is indeed the current one on return.
+ */
+ Status refreshMetadataIfNeeded( const string& ns,
+ const ChunkVersion& reqShardVersion,
+ ChunkVersion* latestShardVersion );
+
+ /**
+ * Refreshes collection metadata by asking the config server for the latest information.
+ * Starts a new config server request.
+ *
+ * Locking Notes:
+ * + Must NOT be called with the write lock because this call may go into the network,
+ * and deadlocks may occur with shard-as-a-config. Therefore, nothing here guarantees
+ * that 'latestShardVersion' is indeed the current one on return.
+ *
+ * + Because this call must not be issued with the DBLock held, by the time the config
+ * server sent us back the collection metadata information, someone else may have
+ * updated the previously stored collection metadata. There are cases when one can't
+ * tell which of updated or loaded metadata are the freshest. There are also cases where
+ * the data coming from configs do not correspond to a consistent snapshot.
+ * In these cases, return RemoteChangeDetected. (This usually means this call needs to
+ * be issued again, at caller discretion)
+ *
+ * @return OK if remote metadata successfully loaded (may or may not have been installed)
+ * @return RemoteChangeDetected if something changed while reloading and we may retry
+ * @return !OK if something else went wrong during reload
+ * @return latestShardVersion the version that is now stored for this collection
*/
- bool trySetVersion( const string& ns , ChunkVersion& version, bool forceRefresh );
+ Status refreshMetadataNow( const string& ns, ChunkVersion* latestShardVersion );
void appendInfo( BSONObjBuilder& b );
@@ -187,6 +220,16 @@ namespace mongo {
bool waitTillNotInCriticalSection( int maxSecondsToWait );
private:
+
+ /**
+ * Refreshes collection metadata by asking the config server for the latest information.
+ * May or may not be based on a requested version.
+ */
+ Status doRefreshMetadata( const string& ns,
+ const ChunkVersion& reqShardVersion,
+ bool useRequestedVersion,
+ ChunkVersion* latestShardVersion );
+
bool _enabled;
string _configServer;