Skip to content

Commit 201acd9

Browse files
committed
PHPC-1290: Update sharded test clusters to have multiple mongoses
This is necessary because session pinning doesn't work when connected to a single mongos node
1 parent 5ad804a commit 201acd9

15 files changed

+96
-38
lines changed

scripts/presets/travis/sharded_clusters/cluster.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@
6969
"logappend": true,
7070
"port": 4300,
7171
"bind_ip_all": true
72+
},
73+
{
74+
"logpath": "/tmp/MO/SHARDED/ROUTER/4301/mongod.log",
75+
"ipv6": true,
76+
"logappend": true,
77+
"port": 4301,
78+
"bind_ip_all": true
7279
}
7380
]
7481
}

scripts/presets/travis/sharded_clusters/cluster_replset.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@
9191
"logappend": true,
9292
"port": 4430,
9393
"bind_ip_all": true
94+
},
95+
{
96+
"logpath": "/tmp/MO/SHARDED-RS/ROUTER/4431/mongod.log",
97+
"ipv6": true,
98+
"logappend": true,
99+
"port": 4431,
100+
"bind_ip_all": true
94101
}
95102
]
96103
}

tests/cursor/cursor-destruct-001.phpt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ MongoDB\Driver\Cursor destruct should kill a live cursor
88
<?php
99
require_once __DIR__ . "/../utils/basic.inc";
1010

11-
function getNumOpenCursors(MongoDB\Driver\Manager $manager)
11+
function getNumOpenCursors(MongoDB\Driver\Server $server)
1212
{
13-
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(array('serverStatus' => 1)));
13+
$cursor = $server->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(array('serverStatus' => 1)));
1414
$result = current($cursor->toArray());
1515
if (isset($result->metrics->cursor->open->total)) {
1616
return $result->metrics->cursor->open->total;
@@ -25,22 +25,25 @@ function getNumOpenCursors(MongoDB\Driver\Manager $manager)
2525

2626
$manager = new MongoDB\Driver\Manager(URI);
2727

28+
// Select a specific server for future operations to avoid mongos switching in sharded clusters
29+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
30+
2831
$bulk = new MongoDB\Driver\BulkWrite();
2932
$bulk->insert(array('_id' => 1));
3033
$bulk->insert(array('_id' => 2));
3134
$bulk->insert(array('_id' => 3));
32-
$manager->executeBulkWrite(NS, $bulk);
35+
$server->executeBulkWrite(NS, $bulk);
3336

34-
$numOpenCursorsBeforeQuery = getNumOpenCursors($manager);
37+
$numOpenCursorsBeforeQuery = getNumOpenCursors($server);
3538

36-
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(array(), array('batchSize' => 2)));
39+
$cursor = $server->executeQuery(NS, new MongoDB\Driver\Query(array(), array('batchSize' => 2)));
3740

3841
var_dump($cursor->isDead());
39-
var_dump(getNumOpenCursors($manager) == $numOpenCursorsBeforeQuery + 1);
42+
var_dump(getNumOpenCursors($server) == $numOpenCursorsBeforeQuery + 1);
4043

4144
unset($cursor);
4245

43-
var_dump(getNumOpenCursors($manager) == $numOpenCursorsBeforeQuery);
46+
var_dump(getNumOpenCursors($server) == $numOpenCursorsBeforeQuery);
4447

4548
?>
4649
===DONE===

tests/cursor/cursor-tailable_error-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ echo throws(function() use ($manager) {
5656
}
5757

5858
if ($numAwaitAttempts === 5) {
59-
$manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command([
59+
$cursor->getServer()->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command([
6060
'killCursors' => COLLECTION_NAME,
6161
'cursors' => [ $cursor->getId() ],
6262
]));

tests/cursorid/cursorid-002.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ require_once __DIR__ . "/../utils/basic.inc";
1212

1313
$manager = new MongoDB\Driver\Manager(URI);
1414

15+
// Select a specific server for future operations to avoid mongos switching in sharded clusters
16+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
17+
1518
$bulk = new MongoDB\Driver\BulkWrite();
1619
$bulk->insert(['_id' => 1]);
1720
$bulk->insert(['_id' => 2]);
1821
$bulk->insert(['_id' => 3]);
19-
$manager->executeBulkWrite(NS, $bulk);
22+
$server->executeBulkWrite(NS, $bulk);
2023

21-
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2]));
24+
$cursor = $server->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2]));
2225
$cursorId = $cursor->getId();
2326

2427
$command = new MongoDB\Driver\Command([
@@ -28,7 +31,7 @@ $command = new MongoDB\Driver\Command([
2831

2932
/* Since the killCursors command result includes cursor IDs as 64-bit integers,
3033
* unserializing the result document requires a 64-bit platform. */
31-
$result = $manager->executeCommand(DATABASE_NAME, $command)->toArray()[0];
34+
$result = $server->executeCommand(DATABASE_NAME, $command)->toArray()[0];
3235
printf("Killed %d cursor(s)\n", count($result->cursorsKilled));
3336
printf("Killed expected cursor: %s\n", (string) $cursorId === (string) $result->cursorsKilled[0] ? 'yes' : 'no');
3437

tests/manager/manager-executeBulkWrite_error-005.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ MongoDB\Driver\Manager::executeBulkWrite() WriteResult accessible for network er
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_live(); ?>
66
<?php skip_if_no_failcommand_failpoint(); ?>
7-
<?php skip_if_multiple_mongos(); ?>
87
<?php skip_if_not_clean(); ?>
98
--FILE--
109
<?php
1110
require_once __DIR__ . "/../utils/basic.inc";
1211

1312
$manager = new MongoDB\Driver\Manager(URI);
1413

15-
configureFailPoint($manager, 'failCommand', [ 'times' => 1 ], [
14+
// Select a specific server for future operations to avoid mongos switching in sharded clusters
15+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
16+
17+
configureTargetedFailPoint($server, 'failCommand', [ 'times' => 1 ], [
1618
'failCommands' => ['delete'],
1719
'closeConnection' => true,
1820
]);
@@ -23,7 +25,7 @@ $bulk->update(['x' => 1], ['$set' => ['y' => 1]]);
2325
$bulk->delete(['x' => 1]);
2426

2527
try {
26-
$manager->executeBulkWrite(NS, $bulk);
28+
$server->executeBulkWrite(NS, $bulk);
2729
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
2830
printf("%s(%d): %s\n", get_class($e), $e->getCode(), $e->getMessage());
2931
$prev = $e->getPrevious();

tests/manager/manager-executeBulkWrite_error-011.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ require_once __DIR__ . "/../utils/basic.inc";
1313

1414
$manager = new MongoDB\Driver\Manager(URI);
1515

16+
// Select a specific server for future operations to avoid mongos switching in sharded clusters
17+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
18+
1619
// Create collection since it can't be (automatically) done within the transaction
1720
$majority = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY);
18-
$manager->executeWriteCommand(
21+
$server->executeWriteCommand(
1922
DATABASE_NAME,
2023
new MongoDB\Driver\Command(['create' => COLLECTION_NAME]),
2124
['writeConcern' => $majority]
2225
);
2326

24-
configureFailPoint($manager, 'failCommand', [ 'times' => 1 ], [
27+
configureTargetedFailPoint($server, 'failCommand', [ 'times' => 1 ], [
2528
'failCommands' => ['insert'],
2629
'closeConnection' => true,
2730
]);
@@ -33,7 +36,7 @@ $bulk = new MongoDB\Driver\BulkWrite;
3336
$bulk->insert(['x' => 1]);
3437

3538
try {
36-
$manager->executeBulkWrite(NS, $bulk, ['session' => $session]);
39+
$server->executeBulkWrite(NS, $bulk, ['session' => $session]);
3740
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
3841
printf("%s(%d): %s\n", get_class($e), $e->getCode(), $e->getMessage());
3942
var_dump($e->hasErrorLabel('TransientTransactionError'));

tests/retryable-reads/retryable-reads-001.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ class Observer implements MongoDB\Driver\Monitoring\CommandSubscriber
2727

2828
$manager = new MongoDB\Driver\Manager(URI, ['retryReads' => true]);
2929

30+
// Select a specific server for future operations to avoid mongos switching in sharded clusters
31+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
32+
3033
$bulk = new MongoDB\Driver\BulkWrite;
3134
$bulk->insert(['x' => 1]);
3235
$bulk->insert(['x' => 2]);
3336

34-
$manager->executeBulkWrite(NS, $bulk);
37+
$server->executeBulkWrite(NS, $bulk);
3538

36-
configureFailPoint($manager, 'failCommand', ['times' => 1], ['failCommands' => ['aggregate'], 'closeConnection' => true]);
39+
configureTargetedFailPoint($server, 'failCommand', ['times' => 1], ['failCommands' => ['aggregate'], 'closeConnection' => true]);
3740

3841
$observer = new Observer;
3942
MongoDB\Driver\Monitoring\addSubscriber($observer);
@@ -45,7 +48,7 @@ $command = new MongoDB\Driver\Command([
4548
],
4649
'cursor' => (object) [],
4750
]);
48-
$cursor = $manager->executeReadCommand(DATABASE_NAME, $command);
51+
$cursor = $server->executeReadCommand(DATABASE_NAME, $command);
4952
var_dump(iterator_to_array($cursor));
5053

5154
MongoDB\Driver\Monitoring\removeSubscriber($observer);

tests/retryable-reads/retryable-reads-002.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ class Observer implements MongoDB\Driver\Monitoring\CommandSubscriber
2727

2828
$manager = new MongoDB\Driver\Manager(URI, ['retryReads' => true]);
2929

30+
// Select a specific server for future operations to avoid mongos switching in sharded clusters
31+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
32+
3033
$bulk = new MongoDB\Driver\BulkWrite;
3134
$bulk->insert(['x' => 1]);
3235
$bulk->insert(['x' => 2]);
3336

34-
$manager->executeBulkWrite(NS, $bulk);
37+
$server->executeBulkWrite(NS, $bulk);
3538

36-
configureFailPoint($manager, 'failCommand', ['times' => 1], ['failCommands' => ['find'], 'closeConnection' => true]);
39+
configureTargetedFailPoint($server, 'failCommand', ['times' => 1], ['failCommands' => ['find'], 'closeConnection' => true]);
3740

3841
$observer = new Observer;
3942
MongoDB\Driver\Monitoring\addSubscriber($observer);
4043

41-
$cursor = $manager->executeQuery(NS, new \MongoDB\Driver\Query(['x' => 1]));
44+
$cursor = $server->executeQuery(NS, new \MongoDB\Driver\Query(['x' => 1]));
4245
var_dump(iterator_count($cursor));
4346

4447
MongoDB\Driver\Monitoring\removeSubscriber($observer);

tests/retryable-reads/retryable-reads_error-001.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,24 @@ class Observer implements MongoDB\Driver\Monitoring\CommandSubscriber
2626

2727
$manager = new MongoDB\Driver\Manager(URI, ['retryReads' => false]);
2828

29-
configureFailPoint($manager, 'failCommand', ['times' => 1], ['failCommands' => ['aggregate'], 'closeConnection' => true]);
29+
// Select a specific server for future operations to avoid mongos switching in sharded clusters
30+
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));
31+
32+
configureTargetedFailPoint($server, 'failCommand', ['times' => 1], ['failCommands' => ['aggregate'], 'closeConnection' => true]);
3033

3134
$observer = new Observer;
3235
MongoDB\Driver\Monitoring\addSubscriber($observer);
3336

3437
throws(
35-
function() use ($manager) {
38+
function() use ($server) {
3639
$command = new MongoDB\Driver\Command([
3740
'aggregate' => COLLECTION_NAME,
3841
'pipeline' => [
3942
['$group' => ['_id' => 1, 'n' => ['$sum' => 1]]],
4043
],
4144
'cursor' => (object) [],
4245
]);
43-
$manager->executeReadCommand(DATABASE_NAME, $command);
46+
$server->executeReadCommand(DATABASE_NAME, $command);
4447
},
4548
\MongoDB\Driver\Exception\ConnectionTimeoutException::class
4649
);

0 commit comments

Comments
 (0)