summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/s/sharded_connection_info.cpp4
-rw-r--r--src/mongo/db/s/sharded_connection_info.h13
-rw-r--r--src/mongo/s/d_state.cpp13
3 files changed, 22 insertions, 8 deletions
diff --git a/src/mongo/db/s/sharded_connection_info.cpp b/src/mongo/db/s/sharded_connection_info.cpp
index 13b60b08bae..24108490b01 100644
--- a/src/mongo/db/s/sharded_connection_info.cpp
+++ b/src/mongo/db/s/sharded_connection_info.cpp
@@ -73,12 +73,12 @@ void ShardedConnectionInfo::reset(Client* client) {
clientSCI(client) = boost::none;
}
-const ChunkVersion ShardedConnectionInfo::getVersion(const std::string& ns) const {
+ChunkVersion ShardedConnectionInfo::getVersion(const std::string& ns) const {
NSVersionMap::const_iterator it = _versions.find(ns);
if (it != _versions.end()) {
return it->second;
} else {
- return ChunkVersion(0, 0, OID());
+ return ChunkVersion::UNSHARDED();
}
}
diff --git a/src/mongo/db/s/sharded_connection_info.h b/src/mongo/db/s/sharded_connection_info.h
index 4cc22fa3963..4cfae41c263 100644
--- a/src/mongo/db/s/sharded_connection_info.h
+++ b/src/mongo/db/s/sharded_connection_info.h
@@ -49,10 +49,19 @@ public:
ShardedConnectionInfo();
~ShardedConnectionInfo();
- const ChunkVersion getVersion(const std::string& ns) const;
+ static ShardedConnectionInfo* get(Client* client, bool create);
+
+ /**
+ * Returns the shard version associated with the specified namespace on this connection. If no
+ * version is associated with the namespace returns ChunkVersion::UNSHARDED.
+ */
+ ChunkVersion getVersion(const std::string& ns) const;
+
+ /**
+ * Assigns a new version on the connection to the specified namespace.
+ */
void setVersion(const std::string& ns, const ChunkVersion& version);
- static ShardedConnectionInfo* get(Client* client, bool create);
static void reset(Client* client);
static void addHook();
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index 9e1a413690a..5f9cfff51bf 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -218,12 +218,17 @@ bool haveLocalShardingInfo(OperationContext* txn, const string& ns) {
return false;
}
- auto css = CollectionShardingState::get(txn, ns);
- if (!css->getMetadata()) {
- return false;
+ const auto& oss = OperationShardingState::get(txn);
+ if (oss.hasShardVersion()) {
+ return true;
+ }
+
+ const auto& sci = ShardedConnectionInfo::get(txn->getClient(), false);
+ if (sci && !sci->getVersion(ns).isStrictlyEqualTo(ChunkVersion::UNSHARDED())) {
+ return true;
}
- return ShardedConnectionInfo::get(txn->getClient(), false) != nullptr;
+ return false;
}
void usingAShardConnection(const string& addr) {}