summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/database_sharding_state.cpp
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2018-03-07 14:08:41 -0500
committerEsha Maharishi <esha.maharishi@mongodb.com>2018-03-12 16:24:39 -0400
commit7a799697e4024e6cca11dbd99bfe51da69a673b4 (patch)
tree2662bf768f149b03a541145e4fd5d35ae6837dc0 /src/mongo/db/s/database_sharding_state.cpp
parente372a6848385ec26aeeed4688d472348f87bc88f (diff)
downloadmongo-7a799697e4024e6cca11dbd99bfe51da69a673b4.tar.gz
SERVER-33098 Make shards check the client's databaseVersion and throw StaleDbVersion on mismatch
Diffstat (limited to 'src/mongo/db/s/database_sharding_state.cpp')
-rw-r--r--src/mongo/db/s/database_sharding_state.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/mongo/db/s/database_sharding_state.cpp b/src/mongo/db/s/database_sharding_state.cpp
index 952fd1c3695..a08d5dbcca6 100644
--- a/src/mongo/db/s/database_sharding_state.cpp
+++ b/src/mongo/db/s/database_sharding_state.cpp
@@ -31,8 +31,15 @@
#include "mongo/db/s/database_sharding_state.h"
#include "mongo/db/operation_context.h"
+#include "mongo/db/s/operation_sharding_state.h"
+#include "mongo/s/stale_exception.h"
+#include "mongo/util/fail_point_service.h"
+#include "mongo/util/stacktrace.h"
namespace mongo {
+
+MONGO_FP_DECLARE(checkForDbVersionMismatch);
+
const Database::Decoration<DatabaseShardingState> DatabaseShardingState::get =
Database::declareDecoration<DatabaseShardingState>();
@@ -68,18 +75,34 @@ void DatabaseShardingState::setDbVersion(OperationContext* opCtx,
void DatabaseShardingState::checkDbVersion(OperationContext* opCtx) const {
invariant(opCtx->lockState()->isLocked());
+ const auto dbName = get.owner(this)->name();
+
+ const auto clientDbVersion = OperationShardingState::get(opCtx).getDbVersion(dbName);
+ if (!clientDbVersion) {
+ return;
+ }
+
+ if (!MONGO_FAIL_POINT(checkForDbVersionMismatch)) {
+ // While checking the dbVersion and triggering a cache refresh on StaleDbVersion is under
+ // development, only check for dbVersion mismatch if explicitly asked to.
+ return;
+ }
if (_critSecSignal) {
- // TODO (SERVER-33097): Set movePrimary critical section signal on the
+ // TODO (SERVER-33773): Set movePrimary critical section signal on the
// OperationShardingState (so that the operation can wait outside the DBLock for the
// movePrimary critical section to end before returning to the client).
- // TODO (SERVER-33098): throw StaleDbVersion.
+ uasserted(StaleDbRoutingVersion(dbName, *clientDbVersion, boost::none),
+ "migration critical section active");
}
- // TODO (SERVER-33098): check the client's dbVersion (from the OperationShardingState) against
- // _dbVersion, and throw StaleDbVersion if they don't match.
- return;
+ uassert(StaleDbRoutingVersion(dbName, *clientDbVersion, boost::none),
+ "don't know dbVersion",
+ _dbVersion);
+ uassert(StaleDbRoutingVersion(dbName, *clientDbVersion, *_dbVersion),
+ "dbVersion mismatch",
+ *clientDbVersion == *_dbVersion);
}
} // namespace mongo