If mongos doesn’t see a namespace in its cache, it will discover whether the namespace is a view or collection from the primary shard.
It will discover if the primary shard has changed through database versioning.
Routing logic for a namespace not in mongos’s cache:
- Mongos forwards the request to the node it believes to be the primary shard for “test”, with both
- shardVersion “UNSHARDED”
- databaseVersion <mongos’s cached databaseVersion>
- Since the request contains a databaseVersion, the shard verifies it
- If the databaseVersion doesn't match, the shard returns StaleDbVersion
- If it does match, the shard tries to resolve the namespace
- If it’s a view, returns the viewDefinition
- Else processes the request normally
- This can return StaleShardVersion or actual data
- Mongos receives the response. If the response is
- StaleDbVersion, refreshes its cache entry for db “test” and retries
- StaleShardVersion, refreshes cache entry for “test.foo” and retries
- viewDefinition, rewrites the request as an aggregation and retries
- actual data, returns the data
- depends on
-
SERVER-32607 Implement a DatabaseVersion class and add it to the DatabaseType
- Closed