void onDbVersionMismatch(OperationContext* opCtx, const StringData dbName, const DatabaseVersion& clientDbVersion, const boost::optional<DatabaseVersion>& serverDbVersion) noexcept { invariant(!opCtx->lockState()->isLocked()); invariant(!opCtx->getClient()->isInDirectClient()); auto const shardingState = ShardingState::get(opCtx); invariant(shardingState->canAcceptShardedCommands()); if (serverDbVersion && serverDbVersion->getUuid() == clientDbVersion.getUuid() && serverDbVersion->getLastMod() >= clientDbVersion.getLastMod()) { // The client was stale; do not trigger server-side refresh. return; } try { // TODO SERVER-33773 if the 'waitForMovePrimaryCriticalSection' flag is set on the // OperationShardingState, wait for the movePrimary critical section to complete before // attempting a refresh. } catch (const DBException& ex) { log() << "Failed to wait for movePrimary critical section to complete " << causedBy(redact(ex)); return; } try { forceDatabaseRefresh(opCtx, dbName); } catch (const DBException& ex) { log() << "Failed to refresh databaseVersion for database " << dbName << causedBy(redact(ex)); } }
bool isFixed(const DatabaseVersion& dbv) { return dbv.getLastMod() == 0; }
bool equal(const DatabaseVersion& dbv1, const DatabaseVersion& dbv2) { return dbv1.getUuid() == dbv2.getUuid() && dbv1.getLastMod() == dbv2.getLastMod(); }
DatabaseVersion makeFixed() { DatabaseVersion dbv; dbv.setLastMod(0); dbv.setUuid(UUID::gen()); return dbv; }
DatabaseVersion makeIncremented(const DatabaseVersion& v) { DatabaseVersion dbv; dbv.setLastMod(v.getLastMod() + 1); dbv.setUuid(v.getUuid()); return dbv; }
DatabaseVersion makeNew() { DatabaseVersion dbv; dbv.setLastMod(1); dbv.setUuid(UUID::gen()); return dbv; }