Skip to content

Commit 123a8b0

Browse files
committed
SERVER-31315 expose the four distinct upgrade/downgrade states in serverGlobalParams.featureCompatibility
1 parent 316a341 commit 123a8b0

File tree

3 files changed

+46
-40
lines changed

3 files changed

+46
-40
lines changed

src/mongo/db/commands/feature_compatibility_version.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,14 @@ void FeatureCompatibilityVersion::onInsertOrUpdate(OperationContext* opCtx, cons
249249
opCtx->recoveryUnit()->onCommit([opCtx, versionInfo]() {
250250
serverGlobalParams.featureCompatibility.version.store(versionInfo.version);
251251
serverGlobalParams.featureCompatibility.targetVersion.store(versionInfo.targetVersion);
252-
_closeConnectionsBelowVersion(opCtx, versionInfo);
252+
253+
// Close all connections from internal clients with binary versions lower than 3.6.
254+
if (versionInfo.version == ServerGlobalParams::FeatureCompatibility::Version::k36 ||
255+
versionInfo.targetVersion == ServerGlobalParams::FeatureCompatibility::Version::k36) {
256+
opCtx->getServiceContext()->getServiceEntryPoint()->endAllSessions(
257+
transport::Session::kLatestVersionInternalClientKeepOpen |
258+
transport::Session::kExternalClientKeepOpen);
259+
}
253260
});
254261
}
255262

@@ -293,18 +300,6 @@ void FeatureCompatibilityVersion::_validateVersion(StringData version) {
293300
version == FeatureCompatibilityVersionCommandParser::kVersion34);
294301
}
295302

296-
void FeatureCompatibilityVersion::_closeConnectionsBelowVersion(
297-
OperationContext* opCtx, FeatureCompatibilityVersionInfo versionInfo) {
298-
299-
// Close all internal connections to versions lower than 3.6.
300-
if (versionInfo.version == ServerGlobalParams::FeatureCompatibility::Version::k36 ||
301-
versionInfo.targetVersion == ServerGlobalParams::FeatureCompatibility::Version::k36) {
302-
opCtx->getServiceContext()->getServiceEntryPoint()->endAllSessions(
303-
transport::Session::kLatestVersionInternalClientKeepOpen |
304-
transport::Session::kExternalClientKeepOpen);
305-
}
306-
}
307-
308303
void FeatureCompatibilityVersion::_runUpdateCommand(OperationContext* opCtx,
309304
StringData version,
310305
UpdateBuilder builder) {

src/mongo/db/commands/feature_compatibility_version.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,6 @@ class FeatureCompatibilityVersion {
147147
*/
148148
static void _validateVersion(StringData version);
149149

150-
/**
151-
* Close incoming connections from interal clients who cannot speak our highest wire protocol
152-
* version.
153-
*/
154-
static void _closeConnectionsBelowVersion(OperationContext* opCtx,
155-
FeatureCompatibilityVersionInfo versionInfo);
156-
157150
/**
158151
* Build update command.
159152
*/

src/mongo/db/server_options.h

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,33 +146,51 @@ struct ServerGlobalParams {
146146
BSONObj overrideShardIdentity;
147147

148148
struct FeatureCompatibility {
149-
enum class Version {
150-
/**
151-
* In this mode, the cluster will expose a 3.4-like API. Attempts by a client to use new
152-
* features in 3.6 will be rejected.
153-
*/
154-
k34,
155-
156-
/**
157-
* In this mode, new features in 3.6 are allowed. The system should guarantee that no
158-
* 3.4 node can participate in a cluster whose feature compatibility version is 3.6.
159-
*/
160-
k36,
161-
/**
162-
* This is only used for targetVersion to indicate that no upgrade is in progress.
163-
*/
164-
kUnset
165-
};
149+
/**
150+
* The combination of the version and targetVersion determine this node's behavior.
151+
*
152+
* The legal (version, targetVersion) states are:
153+
*
154+
* (3.4, Unset) aka fully 3.4: only 3.4 features are available, and new and existing storage
155+
* engine entries use the 3.4 format
156+
*
157+
* (3.4, 3.6) aka upgrading: only 3.4 features are available, but new storage engine entries
158+
* use the 3.6 format, and existing entries may have either the
159+
* 3.4 or 3.6 format
160+
*
161+
* (3.6, Unset) aka fully 3.6: 3.6 features are available, and new and existing storage
162+
* engine entries use the 3.6 format
163+
*
164+
* (3.4, 3.4) aka downgrading: only 3.4 features are available and new storage engine
165+
* entries use the 3.4 format, but existing entries may have
166+
* either the 3.4 or 3.6 format
167+
*/
168+
enum class Version { k34, k36, kUnset };
166169

167-
// Read-only parameter featureCompatibilityVersion.
168170
AtomicWord<Version> version{Version::k34};
169171

170172
// If set, an upgrade or downgrade is in progress to the set version.
171173
AtomicWord<Version> targetVersion{Version::kUnset};
172174

175+
const bool isFullyUpgradedTo36() {
176+
return (version.load() == Version::k36 && targetVersion.load() == Version::kUnset);
177+
}
178+
179+
const bool isUpgradingTo36() {
180+
return (version.load() == Version::k34 && targetVersion.load() == Version::k36);
181+
}
182+
183+
const bool isFullyDowngradedTo34() {
184+
return (version.load() == Version::k34 && targetVersion.load() == Version::kUnset);
185+
}
186+
187+
const bool isDowngradingTo34() {
188+
return (version.load() == Version::k34 && targetVersion.load() == Version::k34);
189+
}
190+
173191
// This determines whether to give Collections UUIDs upon creation.
174-
bool isSchemaVersion36() {
175-
return (version.load() == Version::k36 || targetVersion.load() == Version::k36);
192+
const bool isSchemaVersion36() {
193+
return (isFullyUpgradedTo36() || isUpgradingTo36());
176194
}
177195

178196
// Feature validation differs depending on the role of a mongod in a replica set or

0 commit comments

Comments
 (0)