diff options
author | Antonio Fuschetto <antonio.fuschetto@mongodb.com> | 2022-02-24 23:35:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-25 00:34:26 +0000 |
commit | 74280e7af5405e41d2f128d9a261e4d139cc8e71 (patch) | |
tree | d5638092ff0fcd1a3db818178d0674de411b838d | |
parent | 1c31d7055ebb875775cd987c14cc82fb40a19b2e (diff) | |
download | mongo-74280e7af5405e41d2f128d9a261e4d139cc8e71.tar.gz |
SERVER-62907 Vector clock components must survive CSRS non-rolling restart
-rw-r--r-- | src/mongo/db/vector_clock_mongod.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/db/vector_clock_mongod.cpp b/src/mongo/db/vector_clock_mongod.cpp index 5afbb1946d9..f5d7513a543 100644 --- a/src/mongo/db/vector_clock_mongod.cpp +++ b/src/mongo/db/vector_clock_mongod.cpp @@ -184,6 +184,30 @@ VectorClockMongoD::~VectorClockMongoD() = default; void VectorClockMongoD::onStepUpBegin(OperationContext* opCtx, long long term) { stdx::lock_guard lg(_mutex); _durableTime.reset(); + + // Initialize the config server's topology time to the maximum topology time from + // `config.shards` collection instead of using `Timestamp(0 ,0)`. + if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { + const auto maxTopologyTime{[&opCtx]() -> boost::optional<Timestamp> { + DBDirectClient client{opCtx}; + FindCommandRequest findRequest{ShardType::ConfigNS}; + findRequest.setSort(BSON(ShardType::topologyTime << -1)); + findRequest.setLimit(1); + auto cursor{client.find(std::move(findRequest))}; + invariant(cursor); + if (!cursor->more()) { + // No shards are available yet. + return boost::none; + } + + const auto shardEntry{uassertStatusOK(ShardType::fromBSON(cursor->nextSafe()))}; + return shardEntry.getTopologyTime(); + }()}; + + if (maxTopologyTime) { + _advanceComponentTimeTo(Component::TopologyTime, LogicalTime(*maxTopologyTime)); + } + } } void VectorClockMongoD::onStepDown() { |