Summary:
Given a list of targeted shard ids, return the logical time to be used as the atClusterTime value that will be included in the commands sent to all the shards. This will be the max lastCommittedOpTimes of the given shards, found by looking up each shard in the shard registry and then calling getLastCommittedOpTime(). Since this logic will be shared by read commands, it should be put into a file of helper functions, like src/mongo/s/commands_helpers.cpp.
Details:
LogicalTime computeAtClusterTime(OperationContext* opCtx, std::set<ShardId> shardIds) { invariant(shardIds.size() > 0); auto shardRegistry = Grid::get(opCtx)->shardRegistry(); LogicalTime highestTime; for (const auto& shardId : shardIds) { auto lastCommittedOpTime = shardRegistry->getShardNoReload(shardId)->getLastCommittedOpTime(); if (lastCommittedOpTime > highestTime) { highestTime = lastCommittedOpTime; } } return highestTime; }
Open Questions:
- What to return if given an empty list of shard ids?
- it doesn't seem like this is possible, so invariant?
UnitTests
- Mock a shardRegistry with several shards, set lastCommittedOpTimes on each shard, and verify that computeAtClusterTime returns the highest time.
- is depended on by
-
SERVER-33029 Support snapshot in cluster aggregate command
- Closed
- is duplicated by
-
SERVER-34074 Make a helper function to compute atClusterTime for a set of shards
- Closed