summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorAntonio Fuschetto <antonio.fuschetto@mongodb.com>2022-03-02 20:38:18 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-02 21:04:33 +0000
commit004c48e11d879257cbfbced5570597ccc0fbbd27 (patch)
treef95b8e6f72bde318f372048533d74718b6c624cc /src/mongo/s
parent99cbec2341c967585770c94b3004460702ba02c8 (diff)
downloadmongo-004c48e11d879257cbfbced5570597ccc0fbbd27.tar.gz
SERVER-63742 Default topology time in shard can lead to infinite refresh in shard registry
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/balancer_configuration_test.cpp5
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_test.cpp49
-rw-r--r--src/mongo/s/client/shard_remote_test.cpp5
-rw-r--r--src/mongo/s/commands/strategy.cpp4
-rw-r--r--src/mongo/s/grid.cpp4
-rw-r--r--src/mongo/s/grid.h4
-rw-r--r--src/mongo/s/sharding_router_test_fixture.cpp9
7 files changed, 58 insertions, 22 deletions
diff --git a/src/mongo/s/balancer_configuration_test.cpp b/src/mongo/s/balancer_configuration_test.cpp
index 546b7f67d4f..2f1d82ae7ee 100644
--- a/src/mongo/s/balancer_configuration_test.cpp
+++ b/src/mongo/s/balancer_configuration_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/client/remote_command_targeter_mock.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/query/query_request_helper.h"
+#include "mongo/db/vector_clock.h"
#include "mongo/executor/remote_command_request.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/rpc/metadata/tracking_metadata.h"
@@ -85,7 +86,9 @@ protected:
ASSERT_EQ(findCommand->getNamespaceOrUUID().nss()->ns(), "config.settings");
ASSERT_BSONOBJ_EQ(findCommand->getFilter(), BSON("_id" << key));
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
if (!result.isOK()) {
return StatusWith<vector<BSONObj>>(result.getStatus());
diff --git a/src/mongo/s/catalog/sharding_catalog_client_test.cpp b/src/mongo/s/catalog/sharding_catalog_client_test.cpp
index 3993dbb6937..fec79564dcf 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_test.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_test.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/query/query_request_helper.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/time_proof_service.h"
+#include "mongo/db/vector_clock.h"
#include "mongo/executor/task_executor.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
@@ -111,7 +112,9 @@ TEST_F(ShardingCatalogClientTest, GetCollectionExisting) {
ASSERT_BSONOBJ_EQ(query->getSort(), BSONObj());
ASSERT_EQ(query->getLimit().get(), 1);
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
ReplSetMetadata metadata(10,
{newOpTime, Date_t() + Seconds(newOpTime.getSecs())},
@@ -180,7 +183,9 @@ TEST_F(ShardingCatalogClientTest, GetDatabaseExisting) {
ASSERT_BSONOBJ_EQ(query->getSort(), BSONObj());
ASSERT(!query->getLimit());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
ReplSetMetadata metadata(10,
{newOpTime, Date_t() + Seconds(newOpTime.getSecs())},
@@ -310,7 +315,9 @@ TEST_F(ShardingCatalogClientTest, GetAllShardsValid) {
ASSERT_BSONOBJ_EQ(query->getSort(), BSONObj());
ASSERT_FALSE(query->getLimit().is_initialized());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{s1.toBSON(), s2.toBSON(), s3.toBSON()};
});
@@ -411,7 +418,9 @@ TEST_F(ShardingCatalogClientTest, GetChunksForNSWithSortAndLimit) {
ASSERT_BSONOBJ_EQ(query->getSort(), BSON(ChunkType::lastmod() << -1));
ASSERT_EQ(query->getLimit().get(), 1);
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
ReplSetMetadata metadata(10,
{newOpTime, Date_t() + Seconds(newOpTime.getSecs())},
@@ -474,7 +483,9 @@ TEST_F(ShardingCatalogClientTest, GetChunksForNSNoSortNoLimit) {
ASSERT_BSONOBJ_EQ(query->getSort(), BSONObj());
ASSERT_FALSE(query->getLimit().is_initialized());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{};
});
@@ -788,7 +799,9 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsNoDb) {
ASSERT_BSONOBJ_EQ(query->getFilter(), BSONObj());
ASSERT_BSONOBJ_EQ(query->getSort(), BSONObj());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
ReplSetMetadata metadata(10,
{newOpTime, Date_t() + Seconds(newOpTime.getSecs())},
@@ -839,7 +852,9 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsValidResultsWithDb) {
ASSERT_BSONOBJ_EQ(query->getFilter(), b.obj());
}
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{coll1.toBSON(), coll2.toBSON()};
});
@@ -877,7 +892,9 @@ TEST_F(ShardingCatalogClientTest, GetCollectionsInvalidCollectionType) {
ASSERT_BSONOBJ_EQ(query->getFilter(), b.obj());
}
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{
validColl.toBSON(),
@@ -912,7 +929,9 @@ TEST_F(ShardingCatalogClientTest, GetDatabasesForShardValid) {
BSON(DatabaseType::primary(dbt1.getPrimary().toString())));
ASSERT_BSONOBJ_EQ(query->getSort(), BSONObj());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{dbt1.toBSON(), dbt2.toBSON()};
});
@@ -980,7 +999,9 @@ TEST_F(ShardingCatalogClientTest, GetTagsForCollection) {
ASSERT_BSONOBJ_EQ(query->getFilter(), BSON(TagsType::ns("TestDB.TestColl")));
ASSERT_BSONOBJ_EQ(query->getSort(), BSON(TagsType::min() << 1));
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{tagA.toBSON(), tagB.toBSON()};
});
@@ -1337,7 +1358,9 @@ TEST_F(ShardingCatalogClientTest, GetNewKeys) {
ASSERT_BSONOBJ_EQ(BSON("expiresAt" << 1), query->getSort());
ASSERT_FALSE(query->getLimit().is_initialized());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{key1.toBSON(), key2.toBSON()};
});
@@ -1389,7 +1412,9 @@ TEST_F(ShardingCatalogClientTest, GetNewKeysWithEmptyCollection) {
ASSERT_BSONOBJ_EQ(BSON("expiresAt" << 1), query->getSort());
ASSERT_FALSE(query->getLimit().is_initialized());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
return vector<BSONObj>{};
});
diff --git a/src/mongo/s/client/shard_remote_test.cpp b/src/mongo/s/client/shard_remote_test.cpp
index 3c4cc4181ca..c7b9c1b7975 100644
--- a/src/mongo/s/client/shard_remote_test.cpp
+++ b/src/mongo/s/client/shard_remote_test.cpp
@@ -32,6 +32,7 @@
#include "mongo/client/connection_string.h"
#include "mongo/db/logical_time.h"
#include "mongo/db/query/cursor_response.h"
+#include "mongo/db/vector_clock.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/client/shard_factory.h"
#include "mongo/s/client/shard_registry.h"
@@ -134,8 +135,8 @@ TEST_F(ShardRemoteTest, NetworkReplyWithLastCommittedOpTime) {
// Verify shards that were not targeted were not affected.
for (auto shardId : kTestShardIds) {
if (shardId != targetedShard) {
- ASSERT_EQ(LogicalTime::kUninitialized,
- shardRegistry()->getShardNoReload(shardId)->getLastCommittedOpTime());
+ ASSERT(!VectorClock::isValidComponentTime(
+ shardRegistry()->getShardNoReload(shardId)->getLastCommittedOpTime()));
}
}
}
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index dee7de3a6c1..a1786d7fd17 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -152,14 +152,14 @@ void appendRequiredFieldsToResponse(OperationContext* opCtx, BSONObjBuilder* res
// Ensure that either both operationTime and $clusterTime are output, or neither.
if (clusterTimeWasOutput) {
auto operationTime = OperationTimeTracker::get(opCtx)->getMaxOperationTime();
- if (operationTime != LogicalTime::kUninitialized) {
+ if (VectorClock::isValidComponentTime(operationTime)) {
LOGV2_DEBUG(22764,
5,
"Appending operationTime: {operationTime}",
"Appending operationTime",
"operationTime"_attr = operationTime.asTimestamp());
operationTime.appendAsOperationTime(responseBuilder);
- } else if (clusterTime != LogicalTime::kUninitialized) {
+ } else if (VectorClock::isValidComponentTime(clusterTime)) {
// If we don't know the actual operation time, use the cluster time instead. This is
// safe but not optimal because we can always return a later operation time than
// actual.
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp
index c389eb90b65..63fb466ab5c 100644
--- a/src/mongo/s/grid.cpp
+++ b/src/mongo/s/grid.cpp
@@ -35,7 +35,6 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/server_options.h"
-#include "mongo/db/vector_clock.h"
#include "mongo/executor/task_executor.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/logv2/log.h"
@@ -199,7 +198,8 @@ void Grid::clearForUnitTests() {
_executorPool.reset();
_network = nullptr;
- _configOpTime = repl::OpTime();
+ _configOpTime = repl::OpTime{VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm};
}
} // namespace mongo
diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h
index c2cd6ec1c45..b971931e675 100644
--- a/src/mongo/s/grid.h
+++ b/src/mongo/s/grid.h
@@ -32,6 +32,7 @@
#include <functional>
#include "mongo/db/repl/optime.h"
+#include "mongo/db/vector_clock.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/platform/mutex.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
@@ -207,7 +208,8 @@ private:
// Last known highest opTime from the config server that should be used when doing reads.
// This value is updated any time a shard or mongos talks to a config server or a shard.
- repl::OpTime _configOpTime;
+ repl::OpTime _configOpTime{VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm};
/**
* Called to update what we've seen as the last config server optime.
diff --git a/src/mongo/s/sharding_router_test_fixture.cpp b/src/mongo/s/sharding_router_test_fixture.cpp
index 4c8b41f5266..cc9e584fdd2 100644
--- a/src/mongo/s/sharding_router_test_fixture.cpp
+++ b/src/mongo/s/sharding_router_test_fixture.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/query/collation/collator_factory_mock.h"
#include "mongo/db/query/query_request_helper.h"
#include "mongo/db/repl/read_concern_args.h"
+#include "mongo/db/vector_clock.h"
#include "mongo/db/vector_clock_metadata_hook.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
@@ -264,7 +265,9 @@ void ShardingTestFixture::expectGetShards(const std::vector<ShardType>& shards)
ASSERT_BSONOBJ_EQ(query->getSort(), BSONObj());
ASSERT_FALSE(query->getLimit().is_initialized());
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
std::vector<BSONObj> shardsToReturn;
@@ -360,7 +363,9 @@ void ShardingTestFixture::expectCount(const HostAndPort& configHost,
return BSON("ok" << 1 << "n" << response.getValue());
}
- checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ checkReadConcern(request.cmdObj,
+ VectorClock::kInitialComponentTime.asTimestamp(),
+ repl::OpTime::kUninitializedTerm);
BSONObjBuilder responseBuilder;
CommandHelpers::appendCommandStatusNoThrow(responseBuilder, response.getStatus());