summaryrefslogtreecommitdiff
path: root/src/mongo/db/server_options.h
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2017-10-10 12:52:19 -0400
committerLouis Williams <louis.williams@mongodb.com>2017-10-16 12:39:30 -0400
commit203ff7c010d1d4fcbe291852f70fb9d967a171cc (patch)
tree2783eb259f18ee18356575e8b7b03ae370c62c28 /src/mongo/db/server_options.h
parent51386591ed96fc3070bdaa2652974dadebeaccaf (diff)
downloadmongo-203ff7c010d1d4fcbe291852f70fb9d967a171cc.tar.gz
SERVER-30242 SERVER-31513 SERVER-31235 Make method to determine if fCV has been initialized in memory. Make fCV state one atomic variable. Initialize fCV on arbiters once a primary is elected.
Diffstat (limited to 'src/mongo/db/server_options.h')
-rw-r--r--src/mongo/db/server_options.h60
1 files changed, 36 insertions, 24 deletions
diff --git a/src/mongo/db/server_options.h b/src/mongo/db/server_options.h
index 12d8018c180..8e77dc8fd41 100644
--- a/src/mongo/db/server_options.h
+++ b/src/mongo/db/server_options.h
@@ -147,61 +147,76 @@ struct ServerGlobalParams {
struct FeatureCompatibility {
/**
- * The combination of the version and targetVersion determine this node's behavior.
+ * The combination of the fields in the admin.system.version document in the format
+ * (version, targetVersion) are represented by this enum and determine this node's behavior.
*
- * The legal (version, targetVersion) states are:
+ * The legal enum (and featureCompatiblityVersion document) states are:
*
- * (3.4, Unset) aka fully 3.4: only 3.4 features are available, and new and existing storage
+ * k34
+ * (3.4, Unset) aka fully 3.4: Only 3.4 features are available, and new and existing storage
* engine entries use the 3.4 format
*
- * (3.4, 3.6) aka upgrading: only 3.4 features are available, but new storage engine entries
+ * kUpgradingTo36
+ * (3.4, 3.6) aka upgrading: Only 3.4 features are available, but new storage engine entries
* use the 3.6 format, and existing entries may have either the
* 3.4 or 3.6 format
*
+ * k36
* (3.6, Unset) aka fully 3.6: 3.6 features are available, and new and existing storage
* engine entries use the 3.6 format
*
- * (3.4, 3.4) aka downgrading: only 3.4 features are available and new storage engine
+ * kDowngradingTo34
+ * (3.4, 3.4) aka downgrading: Only 3.4 features are available and new storage engine
* entries use the 3.4 format, but existing entries may have
* either the 3.4 or 3.6 format
+ *
+ * kUnset
+ * (Unset, Unset) aka uninitialized: This is the case on startup before the fCV document is
+ * loaded into memory. isVersionInitialized() will return
+ * false, and getVersion() will return the default (k34).
+ *
*/
- enum class Version { k34, k36, kUnset };
+ enum class Version { k34, kUpgradingTo36, k36, kDowngradingTo34, kUnset };
+ /**
+ * On startup, the featureCompatibilityVersion may not have been explicitly set yet. This
+ * exposes the actual state of the featureCompatibilityVersion if it is uninitialized.
+ */
+ const bool isVersionInitialized() const {
+ return _version.load() != Version::kUnset;
+ }
+
+ /**
+ * This safe getter for the featureCompatibilityVersion returns a default value when the
+ * version has not yet been set.
+ */
const Version getVersion() const {
- return _version.load();
+ Version v = _version.load();
+ return (v == Version::kUnset) ? Version::k34 : v;
}
void reset() {
_version.store(Version::k34);
- _targetVersion.store(Version::kUnset);
}
void setVersion(Version version) {
return _version.store(version);
}
- const Version getTargetVersion() const {
- return _targetVersion.load();
- }
-
- void setTargetVersion(Version version) {
- return _targetVersion.store(version);
- }
-
const bool isFullyUpgradedTo36() {
- return (_version.load() == Version::k36 && _targetVersion.load() == Version::kUnset);
+ return (getVersion() == Version::k36);
}
const bool isUpgradingTo36() {
- return (_version.load() == Version::k34 && _targetVersion.load() == Version::k36);
+ return (getVersion() == Version::kUpgradingTo36);
}
const bool isFullyDowngradedTo34() {
- return (_version.load() == Version::k34 && _targetVersion.load() == Version::kUnset);
+ return (getVersion() == Version::k34);
}
const bool isDowngradingTo34() {
- return (_version.load() == Version::k34 && _targetVersion.load() == Version::k34);
+ return (getVersion() == Version::kDowngradingTo34);
}
// This determines whether to give Collections UUIDs upon creation.
@@ -217,10 +232,7 @@ struct ServerGlobalParams {
AtomicWord<bool> validateFeaturesAsMaster{true};
private:
- AtomicWord<Version> _version{Version::k34};
-
- // If set, an upgrade or downgrade is in progress to the set version.
- AtomicWord<Version> _targetVersion{Version::kUnset};
+ AtomicWord<Version> _version{Version::kUnset};
} featureCompatibility;