@@ -980,76 +980,92 @@ var ShardingTest = function(params) {
980
980
} ;
981
981
982
982
/**
983
- * Returns whether any settings to ShardingTest or jsTestOptions indicate this is a multiversion
984
- * cluster.
983
+ * Returns a document {isMixedVersion: <bool>, oldestBinVersion: <string>}.
984
+ * The 'isMixedVersion' field is true if any settings to ShardingTest or jsTestOptions indicate
985
+ * this is a multiversion cluster.
986
+ * The 'oldestBinVersion' field is set to the oldest binary version used in this cluster, one of
987
+ * 'latest', 'last-continuous' and 'last-lts'.
988
+ * Note: Mixed version cluster with binary versions older than 'last-lts' is not supported. If
989
+ * such binary exists in the cluster, this function assumes this is not a mixed version cluster
990
+ * and returns 'oldestBinVersion' as 'latest'.
985
991
*
986
- * Checks for 'last-lts' bin versions via:
992
+ * Checks for bin versions via:
987
993
* jsTestOptions().shardMixedBinVersions, jsTestOptions().mongosBinVersion,
988
994
* otherParams.configOptions.binVersion, otherParams.shardOptions.binVersion,
989
995
* otherParams.mongosOptions.binVersion
990
996
*/
991
- this . isMixedVersionCluster = function ( ) {
992
- var lastLTSBinVersion = MongoRunner . getBinVersionFor ( 'last-lts' ) ;
993
-
994
- // Must check shardMixedBinVersion because it causes shardOptions.binVersion to be an object
995
- // (versionIterator) rather than a version string. Must check mongosBinVersion, as well,
996
- // because it does not update mongosOptions.binVersion.
997
- if ( jsTestOptions ( ) . shardMixedBinVersions ||
998
- ( jsTestOptions ( ) . mongosBinVersion &&
999
- MongoRunner . areBinVersionsTheSame ( lastLTSBinVersion ,
1000
- jsTestOptions ( ) . mongosBinVersion ) ) ) {
1001
- return true ;
1002
- }
997
+ this . getClusterVersionInfo = function ( ) {
998
+ function clusterHasBinVersion ( version ) {
999
+ const binVersion = MongoRunner . getBinVersionFor ( version ) ;
1000
+ const hasBinVersionInParams = ( params ) => {
1001
+ return params && params . binVersion &&
1002
+ MongoRunner . areBinVersionsTheSame (
1003
+ binVersion , MongoRunner . getBinVersionFor ( params . binVersion ) ) ;
1004
+ } ;
1003
1005
1004
- // Check for 'last-lts' config servers.
1005
- if ( otherParams . configOptions && otherParams . configOptions . binVersion &&
1006
- MongoRunner . areBinVersionsTheSame (
1007
- lastLTSBinVersion ,
1008
- MongoRunner . getBinVersionFor ( otherParams . configOptions . binVersion ) ) ) {
1009
- return true ;
1010
- }
1011
- for ( var i = 0 ; i < numConfigs ; ++ i ) {
1012
- if ( otherParams [ 'c' + i ] && otherParams [ 'c' + i ] . binVersion &&
1013
- MongoRunner . areBinVersionsTheSame (
1014
- lastLTSBinVersion ,
1015
- MongoRunner . getBinVersionFor ( otherParams [ 'c' + i ] . binVersion ) ) ) {
1006
+ // Must check shardMixedBinVersion because it causes shardOptions.binVersion to be an
1007
+ // object (versionIterator) rather than a version string. Must check mongosBinVersion,
1008
+ // as well, because it does not update mongosOptions.binVersion.
1009
+ // TODO SERVER-50389: Differentiate between 'last-lts' and 'last-continuous' when
1010
+ // last-continuous is supported with shardMixedBinVersions.
1011
+ if ( jsTestOptions ( ) . shardMixedBinVersions ||
1012
+ ( jsTestOptions ( ) . mongosBinVersion &&
1013
+ MongoRunner . areBinVersionsTheSame ( binVersion , jsTestOptions ( ) . mongosBinVersion ) ) ) {
1016
1014
return true ;
1017
1015
}
1018
- }
1019
1016
1020
- // Check for 'last-lts' mongod servers.
1021
- if ( otherParams . shardOptions && otherParams . shardOptions . binVersion &&
1022
- MongoRunner . areBinVersionsTheSame (
1023
- lastLTSBinVersion ,
1024
- MongoRunner . getBinVersionFor ( otherParams . shardOptions . binVersion ) ) ) {
1025
- return true ;
1026
- }
1027
- for ( var i = 0 ; i < numShards ; ++ i ) {
1028
- if ( otherParams [ 'd' + i ] && otherParams [ 'd' + i ] . binVersion &&
1029
- MongoRunner . areBinVersionsTheSame (
1030
- lastLTSBinVersion ,
1031
- MongoRunner . getBinVersionFor ( otherParams [ 'd' + i ] . binVersion ) ) ) {
1017
+ // Check for config servers.
1018
+ if ( hasBinVersionInParams ( otherParams . configOptions ) ) {
1032
1019
return true ;
1033
1020
}
1034
- }
1021
+ for ( let i = 0 ; i < numConfigs ; ++ i ) {
1022
+ if ( hasBinVersionInParams ( otherParams [ 'c' + i ] ) ) {
1023
+ return true ;
1024
+ }
1025
+ }
1035
1026
1036
- // Check for 'last-lts' mongos servers.
1037
- if ( otherParams . mongosOptions && otherParams . mongosOptions . binVersion &&
1038
- MongoRunner . areBinVersionsTheSame (
1039
- lastLTSBinVersion ,
1040
- MongoRunner . getBinVersionFor ( otherParams . mongosOptions . binVersion ) ) ) {
1041
- return true ;
1042
- }
1043
- for ( var i = 0 ; i < numMongos ; ++ i ) {
1044
- if ( otherParams [ 's' + i ] && otherParams [ 's' + i ] . binVersion &&
1045
- MongoRunner . areBinVersionsTheSame (
1046
- lastLTSBinVersion ,
1047
- MongoRunner . getBinVersionFor ( otherParams [ 's' + i ] . binVersion ) ) ) {
1027
+ // Check for mongod servers.
1028
+ if ( hasBinVersionInParams ( otherParams . shardOptions ) ) {
1029
+ return true ;
1030
+ }
1031
+ if ( hasBinVersionInParams ( otherParams . rs ) ) {
1048
1032
return true ;
1049
1033
}
1034
+ for ( let i = 0 ; i < numShards ; ++ i ) {
1035
+ if ( hasBinVersionInParams ( otherParams [ 'd' + i ] ) ) {
1036
+ return true ;
1037
+ }
1038
+ if ( hasBinVersionInParams ( otherParams [ 'rs' + i ] ) ) {
1039
+ return true ;
1040
+ }
1041
+ }
1042
+
1043
+ // Check for mongos servers.
1044
+ if ( hasBinVersionInParams ( otherParams . mongosOptions ) ) {
1045
+ return true ;
1046
+ }
1047
+ for ( let i = 0 ; i < numMongos ; ++ i ) {
1048
+ if ( hasBinVersionInParams ( otherParams [ 's' + i ] ) ) {
1049
+ return true ;
1050
+ }
1051
+ }
1052
+
1053
+ return false ;
1050
1054
}
1051
1055
1052
- return false ;
1056
+ let hasLastLTS = clusterHasBinVersion ( "last-lts" ) ;
1057
+ let hasLastContinuous = clusterHasBinVersion ( "last-continuous" ) ;
1058
+ if ( ( lastLTSFCV !== lastContinuousFCV ) && hasLastLTS && hasLastContinuous ) {
1059
+ throw new Error ( "Can only specify one of 'last-lts' and 'last-continuous' " +
1060
+ "in binVersion, not both." ) ;
1061
+ }
1062
+ if ( hasLastLTS ) {
1063
+ return { isMixedVersion : true , oldestBinVersion : "last-lts" } ;
1064
+ } else if ( hasLastContinuous ) {
1065
+ return { isMixedVersion : true , oldestBinVersion : "last-continuous" } ;
1066
+ } else {
1067
+ return { isMixedVersion : false , oldestBinVersion : "latest" } ;
1068
+ }
1053
1069
} ;
1054
1070
1055
1071
/**
@@ -1279,6 +1295,8 @@ var ShardingTest = function(params) {
1279
1295
// version
1280
1296
// shard cluster that randomly assigns shard binVersions, half "latest" and half
1281
1297
// "last-lts".
1298
+ // TODO SERVER-50389: Support last-continuous binary version with
1299
+ // shardMixedBinVersions.
1282
1300
if ( ! otherParams . shardOptions . binVersion ) {
1283
1301
Random . setRandomSeed ( ) ;
1284
1302
otherParams . shardOptions . binVersion =
@@ -1354,6 +1372,8 @@ var ShardingTest = function(params) {
1354
1372
// If the test doesn't depend on specific shard binVersions, create a mixed version
1355
1373
// shard cluster that randomly assigns shard binVersions, half "latest" and half
1356
1374
// "last-lts".
1375
+ // TODO SERVER-50389: Support last-continuous binary version with
1376
+ // shardMixedBinVersions.
1357
1377
if ( ! otherParams . shardOptions . binVersion ) {
1358
1378
Random . setRandomSeed ( ) ;
1359
1379
otherParams . shardOptions . binVersion =
@@ -1646,10 +1666,11 @@ var ShardingTest = function(params) {
1646
1666
}
1647
1667
1648
1668
const configRS = this . configRS ;
1649
- if ( _hasNewFeatureCompatibilityVersion ( ) && this . isMixedVersionCluster ( ) ) {
1669
+ const clusterVersionInfo = this . getClusterVersionInfo ( ) ;
1670
+ if ( _hasNewFeatureCompatibilityVersion ( ) && clusterVersionInfo . isMixedVersion ) {
1671
+ const fcv = binVersionToFCV ( clusterVersionInfo . oldestBinVersion ) ;
1650
1672
function setFeatureCompatibilityVersion ( ) {
1651
- assert . commandWorked (
1652
- csrsPrimary . adminCommand ( { setFeatureCompatibilityVersion : lastLTSFCV } ) ) ;
1673
+ assert . commandWorked ( csrsPrimary . adminCommand ( { setFeatureCompatibilityVersion : fcv } ) ) ;
1653
1674
1654
1675
// Wait for the new featureCompatibilityVersion to propagate to all nodes in the CSRS
1655
1676
// to ensure that older versions of mongos can successfully connect.
@@ -1798,50 +1819,42 @@ var ShardingTest = function(params) {
1798
1819
// Ensure that the sessions collection exists so jstests can run things with
1799
1820
// logical sessions and test them. We do this by forcing an immediate cache refresh
1800
1821
// on the config server, which auto-shards the collection for the cluster.
1801
- var lastLTSBinVersion = MongoRunner . getBinVersionFor ( 'last-lts' ) ;
1802
- if ( ( ! otherParams . configOptions ) ||
1803
- ( otherParams . configOptions && ! otherParams . configOptions . binVersion ) ||
1804
- ( otherParams . configOptions && otherParams . configOptions . binVersion &&
1805
- MongoRunner . areBinVersionsTheSame (
1806
- lastLTSBinVersion ,
1807
- MongoRunner . getBinVersionFor ( otherParams . configOptions . binVersion ) ) ) ) {
1808
- this . configRS . getPrimary ( ) . getDB ( "admin" ) . runCommand ( { refreshLogicalSessionCacheNow : 1 } ) ;
1809
-
1810
- const x509AuthRequired = ( mongosOptions [ 0 ] && mongosOptions [ 0 ] . clusterAuthMode &&
1811
- mongosOptions [ 0 ] . clusterAuthMode === "x509" ) ;
1812
-
1813
- // Flushes the routing table cache on connection 'conn'. If 'keyFileLocal' is defined,
1814
- // authenticates the keyfile user on 'authConn' - a connection or set of connections for
1815
- // the shard - before executing the flush.
1816
- const flushRT = function flushRoutingTableAndHandleAuth ( conn , authConn , keyFileLocal ) {
1817
- // Invokes the actual execution of cache refresh.
1818
- const execFlushRT = ( conn ) => {
1819
- assert . commandWorked ( conn . getDB ( "admin" ) . runCommand (
1820
- { _flushRoutingTableCacheUpdates : "config.system.sessions" } ) ) ;
1821
- } ;
1822
-
1823
- if ( keyFileLocal ) {
1824
- authutil . asCluster ( authConn , keyFileLocal , ( ) => execFlushRT ( conn ) ) ;
1825
- } else {
1826
- execFlushRT ( conn ) ;
1827
- }
1822
+ this . configRS . getPrimary ( ) . getDB ( "admin" ) . runCommand ( { refreshLogicalSessionCacheNow : 1 } ) ;
1823
+
1824
+ const x509AuthRequired = ( mongosOptions [ 0 ] && mongosOptions [ 0 ] . clusterAuthMode &&
1825
+ mongosOptions [ 0 ] . clusterAuthMode === "x509" ) ;
1826
+
1827
+ // Flushes the routing table cache on connection 'conn'. If 'keyFileLocal' is defined,
1828
+ // authenticates the keyfile user on 'authConn' - a connection or set of connections for
1829
+ // the shard - before executing the flush.
1830
+ const flushRT = function flushRoutingTableAndHandleAuth ( conn , authConn , keyFileLocal ) {
1831
+ // Invokes the actual execution of cache refresh.
1832
+ const execFlushRT = ( conn ) => {
1833
+ assert . commandWorked ( conn . getDB ( "admin" ) . runCommand (
1834
+ { _flushRoutingTableCacheUpdates : "config.system.sessions" } ) ) ;
1828
1835
} ;
1829
1836
1830
- // TODO SERVER-45108: Enable support for x509 auth for _flushRoutingTableCacheUpdates.
1831
- if ( ! otherParams . manualAddShard && ! x509AuthRequired ) {
1832
- for ( let i = 0 ; i < numShards ; i ++ ) {
1833
- const keyFileLocal =
1834
- ( otherParams . shards && otherParams . shards [ i ] && otherParams . shards [ i ] . keyFile )
1835
- ? otherParams . shards [ i ] . keyFile
1836
- : this . keyFile ;
1837
-
1838
- if ( otherParams . rs || otherParams [ "rs" + i ] || startShardsAsRS ) {
1839
- const rs = this . _rs [ i ] . test ;
1840
- flushRT ( rs . getPrimary ( ) , rs . nodes , keyFileLocal ) ;
1841
- } else {
1842
- // If specified, use the keyFile for the standalone shard.
1843
- flushRT ( this [ "shard" + i ] , this [ "shard" + i ] , keyFileLocal ) ;
1844
- }
1837
+ if ( keyFileLocal ) {
1838
+ authutil . asCluster ( authConn , keyFileLocal , ( ) => execFlushRT ( conn ) ) ;
1839
+ } else {
1840
+ execFlushRT ( conn ) ;
1841
+ }
1842
+ } ;
1843
+
1844
+ // TODO SERVER-45108: Enable support for x509 auth for _flushRoutingTableCacheUpdates.
1845
+ if ( ! otherParams . manualAddShard && ! x509AuthRequired ) {
1846
+ for ( let i = 0 ; i < numShards ; i ++ ) {
1847
+ const keyFileLocal =
1848
+ ( otherParams . shards && otherParams . shards [ i ] && otherParams . shards [ i ] . keyFile )
1849
+ ? otherParams . shards [ i ] . keyFile
1850
+ : this . keyFile ;
1851
+
1852
+ if ( otherParams . rs || otherParams [ "rs" + i ] || startShardsAsRS ) {
1853
+ const rs = this . _rs [ i ] . test ;
1854
+ flushRT ( rs . getPrimary ( ) , rs . nodes , keyFileLocal ) ;
1855
+ } else {
1856
+ // If specified, use the keyFile for the standalone shard.
1857
+ flushRT ( this [ "shard" + i ] , this [ "shard" + i ] , keyFileLocal ) ;
1845
1858
}
1846
1859
}
1847
1860
}
0 commit comments