From d01cc077cdf89d18e16718f4b2396efe2a8f3c65 Mon Sep 17 00:00:00 2001 From: Abdul Qadeer Date: Tue, 30 Apr 2024 17:45:51 +0300 Subject: [PATCH] SERVER-89913 Add retries on retryable errors (#21610) GitOrigin-RevId: 129bf89166920596d76c565894eb8e00f295ea20 --- .eslintrc.yml | 1 + .../sharding/retryable_upsert_single_write_shard.js | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 1c84d0b0245..83239134caa 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -237,3 +237,4 @@ globals: helloStatePrompt: true _validateMemberIndex: true help: true + retryOnRetryableError: true diff --git a/jstests/sharding/retryable_upsert_single_write_shard.js b/jstests/sharding/retryable_upsert_single_write_shard.js index bc9f54a2273..00d37354017 100644 --- a/jstests/sharding/retryable_upsert_single_write_shard.js +++ b/jstests/sharding/retryable_upsert_single_write_shard.js @@ -42,18 +42,16 @@ assert.commandWorked(db.runCommand(updateCmd)); assert.commandWorked(coll.insertOne({x: -50})); // Failover shard0 to cause it to forget the in memory txn state from being a txn participant. -const secondary = st.rs0.getSecondary(); -ShardingStateTest.failoverToMember(st.rs0, secondary); - -// Await until RS connection in shell is updated. -_awaitRSHostViaRSMonitor(secondary.name, {ok: true, ismaster: true}, st.rs0.name); +ShardingStateTest.failoverToMember(st.rs0, st.rs0.getSecondary()); // Retry the earlier retryable upsert. db = st.s.getDB(jsTestName()); coll = db.coll; // Insert a document matching the update query. -coll.insertOne({x: -50}); +// Add retries on retryable error as the connections in ShardingTest may be stale and can fail with +// NotWritablePrimary +retryOnRetryableError(() => coll.insertOne({x: -50}), 10, 30); // A retry of the update should fail. assert.commandFailedWithCode(db.runCommand(updateCmd), ErrorCodes.IncompleteTransactionHistory);