diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /jstests/sharding/libs/resharding_test_fixture.js | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'jstests/sharding/libs/resharding_test_fixture.js')
| -rw-r--r-- | jstests/sharding/libs/resharding_test_fixture.js | 100 |
1 files changed, 71 insertions, 29 deletions
diff --git a/jstests/sharding/libs/resharding_test_fixture.js b/jstests/sharding/libs/resharding_test_fixture.js index 13d39674f0f..cd658ae9508 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._pauseCoordinatorBeforeBlockingWrites = undefined; + this._pauseCoordinatorBeforeBlockingWritesFailpoints = []; /** @private */ - this._pauseCoordinatorBeforeDecisionPersistedFailpoint = undefined; + this._pauseCoordinatorBeforeDecisionPersistedFailpoints = []; /** @private */ - this._pauseCoordinatorBeforeCompletionFailpoint = undefined; + this._pauseCoordinatorBeforeCompletionFailpoints = []; /** @private */ this._reshardingThread = undefined; /** @private */ @@ -283,6 +283,11 @@ 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. * @@ -316,13 +321,19 @@ var ReshardingTest = class { this._newShardKey = Object.assign({}, newShardKeyPattern); - const configPrimary = this._st.configRS.getPrimary(); - this._pauseCoordinatorBeforeBlockingWrites = - configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeBlockingWrites"); - this._pauseCoordinatorBeforeDecisionPersistedFailpoint = - configureFailPoint(configPrimary, "reshardingPauseCoordinatorBeforeDecisionPersisted"); - this._pauseCoordinatorBeforeCompletionFailpoint = configureFailPoint( - configPrimary, "reshardingPauseCoordinatorBeforeCompletion", {}, {times: 1}); + 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})); + }); this._commandDoneSignal = new CountDownLatch(1); @@ -452,9 +463,9 @@ var ReshardingTest = class { try { fn(); } catch (duringReshardingError) { - for (const fp of [this._pauseCoordinatorBeforeBlockingWrites, - this._pauseCoordinatorBeforeDecisionPersistedFailpoint, - this._pauseCoordinatorBeforeCompletionFailpoint]) { + for (const fp of [...this._pauseCoordinatorBeforeBlockingWritesFailpoints, + ...this._pauseCoordinatorBeforeDecisionPersistedFailpoints, + ...this._pauseCoordinatorBeforeCompletionFailpoints]) { try { fp.off(); } catch (disableFailpointError) { @@ -503,7 +514,9 @@ 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. + * 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. * * 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. @@ -512,9 +525,20 @@ var ReshardingTest = class { * @private */ _waitForFailPoint(fp) { + const completionFailpoint = this._pauseCoordinatorBeforeCompletionFailpoints.find( + completionFailpoint => completionFailpoint.conn.host === fp.conn.host); + assert.soon( () => { - return this._commandDoneSignal.getCount() === 0 || fp.waitWithTimeout(1000); + if (this._commandDoneSignal.getCount() === 0 || fp.waitWithTimeout(1000)) { + return true; + } + + if (completionFailpoint !== fp && completionFailpoint.waitWithTimeout(1000)) { + completionFailpoint.off(); + } + + return false; }, "Timed out waiting for failpoint to be hit. Failpoint: " + fp.failPointName, undefined, @@ -529,6 +553,19 @@ 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(() => { @@ -539,17 +576,18 @@ 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._pauseCoordinatorBeforeBlockingWrites)) { + if (!this._waitForFailPoint( + this._pauseCoordinatorBeforeBlockingWritesFailpoints[primaryIdx])) { performCorrectnessChecks = false; } - this._pauseCoordinatorBeforeBlockingWrites.off(); + this._pauseCoordinatorBeforeBlockingWritesFailpoints.forEach(fp => fp.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._pauseCoordinatorBeforeDecisionPersistedFailpoint)) { + this._pauseCoordinatorBeforeDecisionPersistedFailpoints[primaryIdx])) { performCorrectnessChecks = false; } @@ -562,22 +600,21 @@ var ReshardingTest = class { postCheckConsistencyFn(); } - this._pauseCoordinatorBeforeDecisionPersistedFailpoint.off(); + this._pauseCoordinatorBeforeDecisionPersistedFailpoints.forEach(fp => fp.off()); postDecisionPersistedFn(); - this._pauseCoordinatorBeforeCompletionFailpoint.off(); + this._pauseCoordinatorBeforeCompletionFailpoints.forEach(fp => fp.off()); }); } else { this._callFunctionSafely(() => { - this.retryOnceOnNetworkError( // - () => this._pauseCoordinatorBeforeBlockingWrites.off()); - + this._pauseCoordinatorBeforeBlockingWritesFailpoints.forEach( + fp => this.retryOnceOnNetworkError(fp.off)); postCheckConsistencyFn(); - this.retryOnceOnNetworkError( - () => this._pauseCoordinatorBeforeDecisionPersistedFailpoint.off()); + this._pauseCoordinatorBeforeDecisionPersistedFailpoints.forEach( + fp => this.retryOnceOnNetworkError(fp.off)); postDecisionPersistedFn(); - this.retryOnceOnNetworkError( - () => this._pauseCoordinatorBeforeCompletionFailpoint.off()); + this._pauseCoordinatorBeforeCompletionFailpoints.forEach( + fp => this.retryOnceOnNetworkError(fp.off)); }); } @@ -600,7 +637,11 @@ var ReshardingTest = class { /** @private */ _checkConsistency() { - const nsCursor = this._st.s.getCollection(this._ns).find().sort({_id: 1}); + // 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 tempNsCursor = this._st.s.getCollection(this._tempNs).find().sort({_id: 1}); const diff = ((diff) => { @@ -618,7 +659,8 @@ var ReshardingTest = class { docsExtraAfterResharding: [], docsMissingAfterResharding: [], }, - "existing sharded collection and temporary resharding collection had different" + + "existing sharded collection " + this._ns + + " and temporary resharding collection " + this._tempNs + " had different" + " contents"); } |
