-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2834 Direct read/write retries to another mongos if possible #1421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
8959b7e
590e82c
8eb6361
1e782f4
04789af
e257525
309f858
fcffe30
6aafc26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
OvertCommandListener, | ||
SpecTestCreator, | ||
rs_or_single_client, | ||
set_fail_point, | ||
) | ||
from test.utils_spec_runner import SpecRunner | ||
from test.version import Version | ||
|
@@ -40,6 +41,7 @@ | |
from bson.raw_bson import RawBSONDocument | ||
from bson.son import SON | ||
from pymongo.errors import ( | ||
AutoReconnect, | ||
ConnectionFailure, | ||
OperationFailure, | ||
ServerSelectionTimeoutError, | ||
|
@@ -469,6 +471,46 @@ def test_batch_splitting_retry_fails(self): | |
self.assertEqual(final_txn, expected_txn) | ||
self.assertEqual(coll.find_one(projection={"_id": True}), {"_id": 1}) | ||
|
||
@client_context.require_multiple_mongoses | ||
@client_context.require_failCommand_fail_point | ||
def test_retryable_writes_in_sharded_cluster_multiple_available(self): | ||
fail_command = { | ||
"configureFailPoint": "failCommand", | ||
"mode": {"times": 1}, | ||
"data": { | ||
"failCommands": ["insert"], | ||
"closeConnection": True, | ||
"appName": "retryableWriteTest", | ||
}, | ||
} | ||
|
||
mongos_clients = [] | ||
|
||
for mongos in client_context.mongos_seeds().split(","): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That change causes the following error:
|
||
client = rs_or_single_client(mongos) | ||
set_fail_point(client, fail_command) | ||
self.addCleanup(client.close) | ||
mongos_clients.append(client) | ||
|
||
listener = OvertCommandListener() | ||
client = rs_or_single_client( | ||
client_context.mongos_seeds(), | ||
appName="retryableWriteTest", | ||
event_listeners=[listener], | ||
retryWrites=True, | ||
) | ||
|
||
with self.assertRaises(AutoReconnect): | ||
client.t.t.insert_one({"x": 1}) | ||
|
||
# Disable failpoints on each mongos | ||
for client in mongos_clients: | ||
fail_command["mode"] = "off" | ||
set_fail_point(client, fail_command) | ||
|
||
self.assertEqual(len(listener.failed_events), 2) | ||
self.assertEqual(len(listener.succeeded_events), 0) | ||
|
||
|
||
class TestWriteConcernError(IntegrationTest): | ||
RUN_ON_LOAD_BALANCER = True | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1153,3 +1153,9 @@ def prepare_spec_arguments(spec, arguments, opname, entity_map, with_txn_callbac | |
raise AssertionError(f"Unsupported cursorType: {cursor_type}") | ||
else: | ||
arguments[c2s] = arguments.pop(arg_name) | ||
|
||
|
||
def set_fail_point(client, command_args): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the with self.fail_point() helper instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to set the fail point on each individual mongos to ensure the failure occurs on every node. |
||
cmd = SON([("configureFailPoint", "failCommand")]) | ||
cmd.update(command_args) | ||
client.admin.command(cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename filtered_servers->servers so the rest of this code doesn't have to change?