diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /jstests/sharding/libs | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'jstests/sharding/libs')
| -rw-r--r-- | jstests/sharding/libs/defragmentation_util.js | 26 | ||||
| -rw-r--r-- | jstests/sharding/libs/last_lts_mongod_commands.js | 4 | ||||
| -rw-r--r-- | jstests/sharding/libs/last_lts_mongos_commands.js | 6 | ||||
| -rw-r--r-- | jstests/sharding/libs/mongos_api_params_util.js | 15 | ||||
| -rw-r--r-- | jstests/sharding/libs/remove_shard_util.js | 34 | ||||
| -rw-r--r-- | jstests/sharding/libs/resharding_test_fixture.js | 100 | ||||
| -rw-r--r-- | jstests/sharding/libs/with_partial_shard_key_util.js | 28 |
7 files changed, 44 insertions, 169 deletions
diff --git a/jstests/sharding/libs/defragmentation_util.js b/jstests/sharding/libs/defragmentation_util.js index 943f2eb462d..52ac1333ef7 100644 --- a/jstests/sharding/libs/defragmentation_util.js +++ b/jstests/sharding/libs/defragmentation_util.js @@ -21,9 +21,7 @@ var defragmentationUtil = (function() { } createAndDistributeChunks(mongos, ns, numChunks, chunkSpacing); - // Created zones will line up exactly with existing chunks so as not to trigger zone - // violations in the balancer. - createRandomZones(mongos, ns, numZones); + createRandomZones(mongos, ns, numZones, chunkSpacing); fillChunksToRandomSize(mongos, ns, docSizeBytes, maxChunkFillMB); const beginningNumberChunks = findChunksUtil.countChunksForNs(mongos.getDB('config'), ns); @@ -51,18 +49,19 @@ var defragmentationUtil = (function() { } }; - let createRandomZones = function(mongos, ns, numZones) { - let existingChunks = findChunksUtil.findChunksByNs(mongos.getDB('config'), ns); - existingChunks = Array.shuffle(existingChunks.toArray()); - for (let i = 0; i < numZones; i++) { + let createRandomZones = function(mongos, ns, numZones, chunkSpacing) { + for (let i = -Math.floor(numZones / 2); i < Math.ceil(numZones / 2); i++) { let zoneName = "Zone" + i; - let shardForZone = existingChunks[i].shard; + let shardForZone = + findChunksUtil + .findOneChunkByNs(mongos.getDB('config'), ns, {min: {key: i * chunkSpacing}}) + .shard; assert.commandWorked( mongos.adminCommand({addShardToZone: shardForZone, zone: zoneName})); assert.commandWorked(mongos.adminCommand({ updateZoneKeyRange: ns, - min: existingChunks[i].min, - max: existingChunks[i].max, + min: {key: i * chunkSpacing}, + max: {key: i * chunkSpacing + chunkSpacing}, zone: zoneName })); } @@ -203,13 +202,6 @@ var defragmentationUtil = (function() { assert.soon(function() { let balancerStatus = assert.commandWorked(mongos.adminCommand({balancerCollectionStatus: ns})); - - if (balancerStatus.balancerCompliant) { - // As we can't rely on `balancerCompliant` due to orphan counter non atomic update, - // we need to ensure the collection is balanced by some extra checks - sh.awaitCollectionBalance(mongos.getCollection(ns)); - } - return balancerStatus.balancerCompliant || balancerStatus.firstComplianceViolation !== 'defragmentingChunks'; }); diff --git a/jstests/sharding/libs/last_lts_mongod_commands.js b/jstests/sharding/libs/last_lts_mongod_commands.js index f8c0802af04..c25af3a8275 100644 --- a/jstests/sharding/libs/last_lts_mongod_commands.js +++ b/jstests/sharding/libs/last_lts_mongod_commands.js @@ -20,12 +20,8 @@ const commandsAddedToMongodSinceLastLTS = [ "clusterGetMore", "clusterInsert", "clusterUpdate", - "createSearchIndexes", - "dropSearchIndex", "getClusterParameter", - "listSearchIndexes", "rotateCertificates", "setClusterParameter", "setUserWriteBlockMode", - "updateSearchIndex", ]; diff --git a/jstests/sharding/libs/last_lts_mongos_commands.js b/jstests/sharding/libs/last_lts_mongos_commands.js index 6acf8dba820..f7a72743e6b 100644 --- a/jstests/sharding/libs/last_lts_mongos_commands.js +++ b/jstests/sharding/libs/last_lts_mongos_commands.js @@ -18,17 +18,12 @@ const commandsAddedToMongosSinceLastLTS = [ "commitReshardCollection", "compactStructuredEncryptionData", "configureCollectionBalancing", - "createSearchIndexes", - "dropSearchIndex", - "fsyncUnlock", "getClusterParameter", - "listSearchIndexes", "moveRange", "reshardCollection", "rotateCertificates", "setAllowMigrations", "setClusterParameter", - "setProfilingFilterGlobally", // TODO SERVER-73305 "setUserWriteBlockMode", "testDeprecation", "testDeprecationInVersion2", @@ -36,5 +31,4 @@ const commandsAddedToMongosSinceLastLTS = [ "testRemoval", "testVersions1And2", "testVersion2", - "updateSearchIndex", ]; diff --git a/jstests/sharding/libs/mongos_api_params_util.js b/jstests/sharding/libs/mongos_api_params_util.js index 7de6a36dcda..e1ca18df3e6 100644 --- a/jstests/sharding/libs/mongos_api_params_util.js +++ b/jstests/sharding/libs/mongos_api_params_util.js @@ -75,7 +75,7 @@ let MongosAPIParametersUtil = (function() { function awaitRemoveShard(shardName) { assert.commandWorked(st.startBalancer()); - st.awaitBalancerRound(); + st.waitForBalancer(true, 60000); assert.soon(() => { const res = st.s.adminCommand({removeShard: shardName}); jsTestLog(`removeShard result: ${tojson(res)}`); @@ -789,11 +789,7 @@ let MongosAPIParametersUtil = (function() { jsTestLog(`Waiting for "find" on "${st.rs0.name}" ` + `with comment ${uuidStr} in currentOp`); assert.soon(() => { - const filter = { - "command.find": "collection", - "command.comment": uuidStr, - shard: st.rs0.name - }; + const filter = {"command.comment": uuidStr, shard: st.rs0.name}; const inprog = adminDb.currentOp(filter).inprog; if (inprog.length === 1) { jsTestLog(`Found it! findOpId ${inprog[0].opid}`); @@ -1219,8 +1215,9 @@ let MongosAPIParametersUtil = (function() { } }, { - commandName: "setProfilingFilterGlobally", - skip: "executes locally on mongos (not sent to any remote node)", + commandName: "setFreeMonitoring", + skip: "explicitly fails for mongos, primary mongod only", + conditional: true }, { commandName: "setParameter", @@ -1412,7 +1409,7 @@ let MongosAPIParametersUtil = (function() { }; }); - const st = new ShardingTest({mongos: 1, shards: 2, config: 1, rs: {nodes: 1}}); + const st = new ShardingTest({mongos: 1, shards: 2, rs: {nodes: 1}}); const listCommandsRes = st.s0.adminCommand({listCommands: 1}); assert.commandWorked(listCommandsRes); diff --git a/jstests/sharding/libs/remove_shard_util.js b/jstests/sharding/libs/remove_shard_util.js deleted file mode 100644 index 4de2c17a461..00000000000 --- a/jstests/sharding/libs/remove_shard_util.js +++ /dev/null @@ -1,34 +0,0 @@ -function removeShard(shardingTestOrConn, shardName, timeout) { - if (timeout == undefined) { - timeout = 10 * 60 * 1000; // 10 minutes - } - - var s; - if (shardingTestOrConn instanceof ShardingTest) { - s = shardingTestOrConn.s; - } else { - s = shardingTestOrConn; - } - - assert.soon(function() { - let res; - if (TestData.configShard && shardName == "config") { - // Need to use transitionToDedicatedConfigServer if trying - // to remove config server as a shard - res = s.adminCommand({transitionToDedicatedConfigServer: shardName}); - } else { - res = s.adminCommand({removeShard: shardName}); - } - if (!res.ok && res.code === ErrorCodes.ShardNotFound) { - // If the config server primary steps down right after removing the config.shards doc - // for the shard but before responding with "state": "completed", the mongos would retry - // the _configsvrRemoveShard command against the new config server primary, which would - // not find the removed shard in its ShardRegistry if it has done a ShardRegistry reload - // after the config.shards doc for the shard was removed. This would cause the command - // to fail with ShardNotFound. - return true; - } - assert.commandWorked(res); - return res.state == 'completed'; - }, "failed to remove shard " + shardName + " within " + timeout + "ms", timeout); -} diff --git a/jstests/sharding/libs/resharding_test_fixture.js b/jstests/sharding/libs/resharding_test_fixture.js index cd658ae9508..13d39674f0f 100644 --- a/jstests/sharding/libs/resharding_test_fixture.js +++ b/jstests/sharding/libs/resharding_test_fixture.js @@ -85,11 +85,11 @@ var ReshardingTest = class { /** @private */ this._newShardKey = undefined; /** @private */ - this._pauseCoordinatorBeforeBlockingWritesFailpoints = []; + this._pauseCoordinatorBeforeBlockingWrites = undefined; /** @private */ - this._pauseCoordinatorBeforeDecisionPersistedFailpoints = []; + this._pauseCoordinatorBeforeDecisionPersistedFailpoint = undefined; /** @private */ - this._pauseCoordinatorBeforeCompletionFailpoints = []; + this._pauseCoordinatorBeforeCompletionFailpoint = undefined; /** @private */ this._reshardingThread = undefined; /** @private */ @@ -283,11 +283,6 @@ var ReshardingTest = class { return sourceCollection; } - get tempNs() { - assert.neq(undefined, this._tempNs, "createShardedCollection must be called first"); - return this._tempNs; - } - /** * Reshards an existing collection using the specified new shard key and new chunk ranges. * @@ -321,19 +316,13 @@ var ReshardingTest = class { this._newShardKey = Object.assign({}, newShardKeyPattern); - this._pauseCoordinatorBeforeBlockingWritesFailpoints = []; - this._pauseCoordinatorBeforeDecisionPersistedFailpoints = []; - this._pauseCoordinatorBeforeCompletionFailpoints = []; - this._st.forEachConfigServer((configServer) => { - this._pauseCoordinatorBeforeBlockingWritesFailpoints.push( - configureFailPoint(configServer, "reshardingPauseCoordinatorBeforeBlockingWrites")); - this._pauseCoordinatorBeforeDecisionPersistedFailpoints.push(configureFailPoint( - configServer, "reshardingPauseCoordinatorBeforeDecisionPersisted")); - this._pauseCoordinatorBeforeCompletionFailpoints.push( - configureFailPoint(configServer, - "reshardingPauseCoordinatorBeforeCompletion", - {"sourceNamespace": this._ns})); - }); + const configPrimary = this._st.configRS.getPrimary(); + this._pauseCoordinatorBeforeBlockingWrites = + configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeBlockingWrites"); + this._pauseCoordinatorBeforeDecisionPersistedFailpoint = + configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeDecisionPersisted"); + this._pauseCoordinatorBeforeCompletionFailpoint = configureFailPoint( + configPrimary, "reshardingPauseCoordinatorBeforeCompletion", {}, {times: 1}); this._commandDoneSignal = new CountDownLatch(1); @@ -463,9 +452,9 @@ var ReshardingTest = class { try { fn(); } catch (duringReshardingError) { - for (const fp of [...this._pauseCoordinatorBeforeBlockingWritesFailpoints, - ...this._pauseCoordinatorBeforeDecisionPersistedFailpoints, - ...this._pauseCoordinatorBeforeCompletionFailpoints]) { + for (const fp of [this._pauseCoordinatorBeforeBlockingWrites, + this._pauseCoordinatorBeforeDecisionPersistedFailpoint, + this._pauseCoordinatorBeforeCompletionFailpoint]) { try { fp.off(); } catch (disableFailpointError) { @@ -514,9 +503,7 @@ var ReshardingTest = class { * proceeding to the next stage. This helper returns after either: * * 1) The node's waitForFailPoint returns successfully or - * 2) The `reshardCollection` command has returned a response or - * 3) The ReshardingCoordinator is blocked on the reshardingPauseCoordinatorBeforeCompletion - * failpoint and won't ever satisfy the supplied failpoint. + * 2) The `reshardCollection` command has returned a response. * * The function returns true when we returned because the server reached the failpoint. The * function returns false when the `reshardCollection` command is no longer running. @@ -525,20 +512,9 @@ var ReshardingTest = class { * @private */ _waitForFailPoint(fp) { - const completionFailpoint = this._pauseCoordinatorBeforeCompletionFailpoints.find( - completionFailpoint => completionFailpoint.conn.host === fp.conn.host); - assert.soon( () => { - if (this._commandDoneSignal.getCount() === 0 || fp.waitWithTimeout(1000)) { - return true; - } - - if (completionFailpoint !== fp && completionFailpoint.waitWithTimeout(1000)) { - completionFailpoint.off(); - } - - return false; + return this._commandDoneSignal.getCount() === 0 || fp.waitWithTimeout(1000); }, "Timed out waiting for failpoint to be hit. Failpoint: " + fp.failPointName, undefined, @@ -553,19 +529,6 @@ var ReshardingTest = class { postCheckConsistencyFn = () => {}, postDecisionPersistedFn = () => {}, afterReshardingFn = () => {}) { - // The CSRS primary may have changed as a result of running the duringReshardingFn() - // callback function. The failpoints will only be triggered on the new CSRS primary so we - // detect which node that is here. - const configPrimary = this._st.configRS.getPrimary(); - const primaryIdx = this._pauseCoordinatorBeforeBlockingWritesFailpoints.findIndex( - fp => fp.conn.host === configPrimary.host); - // The CSRS secondaries may be going through replication rollback which closes their - // connections to the test client. We wait for any replication rollbacks to complete and for - // the test client to have reconnected so the failpoints can be turned off on all of the - // nodes later on. - this._st.configRS.awaitSecondaryNodes(); - this._st.configRS.awaitReplication(); - let performCorrectnessChecks = true; if (expectedErrorCode === ErrorCodes.OK) { this._callFunctionSafely(() => { @@ -576,18 +539,17 @@ var ReshardingTest = class { // reshardingPauseCoordinatorBeforeDecisionPersisted failpoint to wait for all of // the recipient shards to have applied through all of the oplog entries from all of // the donor shards. - if (!this._waitForFailPoint( - this._pauseCoordinatorBeforeBlockingWritesFailpoints[primaryIdx])) { + if (!this._waitForFailPoint(this._pauseCoordinatorBeforeBlockingWrites)) { performCorrectnessChecks = false; } - this._pauseCoordinatorBeforeBlockingWritesFailpoints.forEach(fp => fp.off()); + this._pauseCoordinatorBeforeBlockingWrites.off(); // A resharding command that returned a failure will not hit the "Decision // Persisted" failpoint. If the command has returned, don't require that the // failpoint was entered. This ensures that following up by joining the // `_reshardingThread` will succeed. if (!this._waitForFailPoint( - this._pauseCoordinatorBeforeDecisionPersistedFailpoints[primaryIdx])) { + this._pauseCoordinatorBeforeDecisionPersistedFailpoint)) { performCorrectnessChecks = false; } @@ -600,21 +562,22 @@ var ReshardingTest = class { postCheckConsistencyFn(); } - this._pauseCoordinatorBeforeDecisionPersistedFailpoints.forEach(fp => fp.off()); + this._pauseCoordinatorBeforeDecisionPersistedFailpoint.off(); postDecisionPersistedFn(); - this._pauseCoordinatorBeforeCompletionFailpoints.forEach(fp => fp.off()); + this._pauseCoordinatorBeforeCompletionFailpoint.off(); }); } else { this._callFunctionSafely(() => { - this._pauseCoordinatorBeforeBlockingWritesFailpoints.forEach( - fp => this.retryOnceOnNetworkError(fp.off)); + this.retryOnceOnNetworkError( // + () => this._pauseCoordinatorBeforeBlockingWrites.off()); + postCheckConsistencyFn(); - this._pauseCoordinatorBeforeDecisionPersistedFailpoints.forEach( - fp => this.retryOnceOnNetworkError(fp.off)); + this.retryOnceOnNetworkError( + () => this._pauseCoordinatorBeforeDecisionPersistedFailpoint.off()); postDecisionPersistedFn(); - this._pauseCoordinatorBeforeCompletionFailpoints.forEach( - fp => this.retryOnceOnNetworkError(fp.off)); + this.retryOnceOnNetworkError( + () => this._pauseCoordinatorBeforeCompletionFailpoint.off()); }); } @@ -637,11 +600,7 @@ var ReshardingTest = class { /** @private */ _checkConsistency() { - // The "available" read concern level won't block this find cmd behind the critical section. - // Tests for resharding are not expected to have unowned documents in the collection being - // resharded. - const nsCursor = - this._st.s.getCollection(this._ns).find().readConcern("available").sort({_id: 1}); + const nsCursor = this._st.s.getCollection(this._ns).find().sort({_id: 1}); const tempNsCursor = this._st.s.getCollection(this._tempNs).find().sort({_id: 1}); const diff = ((diff) => { @@ -659,8 +618,7 @@ var ReshardingTest = class { docsExtraAfterResharding: [], docsMissingAfterResharding: [], }, - "existing sharded collection " + this._ns + - " and temporary resharding collection " + this._tempNs + " had different" + + "existing sharded collection and temporary resharding collection had different" + " contents"); } diff --git a/jstests/sharding/libs/with_partial_shard_key_util.js b/jstests/sharding/libs/with_partial_shard_key_util.js deleted file mode 100644 index bcfeae08926..00000000000 --- a/jstests/sharding/libs/with_partial_shard_key_util.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Utilities for the find_and_modify_with_partial_shard_key.js and delete_with_partial_shard_key.js - * tests. - */ -"use strict"; - -/** - * Runs an explain on the `cmdObj` and checks that the explain targets the shard given be - * `expectedShardName`. - */ -function assertExplainTargetsCorrectShard(db, cmdObj, expectedShardName) { - var res = db.runCommand({explain: cmdObj}); - assert.eq(res.queryPlanner.winningPlan.shards.length, 1); - assert.eq(res.queryPlanner.winningPlan.shards[0].shardName, expectedShardName); -} - -/** - * Performs a split given by the `splitDoc`, and then moves the chunk containg `moveShard0Doc` to - * shard0 and the chunk containing `moveShard1Doc` to shard1. - */ -function splitAndMoveChunks(st, splitDoc, moveShard0Doc, moveShard1Doc) { - assert.commandWorked(st.s0.adminCommand({split: "test.sharded_coll", middle: splitDoc})); - - assert.commandWorked(st.s0.adminCommand( - {moveChunk: "test.sharded_coll", find: moveShard0Doc, to: st.shard0.shardName})); - assert.commandWorked(st.s0.adminCommand( - {moveChunk: "test.sharded_coll", find: moveShard1Doc, to: st.shard1.shardName})); -} |
