Skip to content

Commit 82719c4

Browse files
jmikolaalcaeus
andauthored
PHPLIB-1680: Remove pre-4.2 wire version checks and test code (#1801)
* Remove obsolete wire version checks for MongoDB 4.2 * Remove tests for pre-4.2 servers * Transactions are supported on 4.2+ sharded clusters This logic appears to date back to 8abb006 and was never updated when later server versions added support on mongos. * Don't check storageEngine on mongos --------- Co-authored-by: Andreas Braun <andreas.braun@mongodb.com>
1 parent 8eb0501 commit 82719c4

13 files changed

+16
-152
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,6 @@
813813
</PossiblyInvalidArgument>
814814
</file>
815815
<file src="src/Operation/Update.php">
816-
<MixedArgument>
817-
<code><![CDATA[$this->options['writeConcern']]]></code>
818-
</MixedArgument>
819816
<MixedAssignment>
820817
<code><![CDATA[$cmd['bypassDocumentValidation']]]></code>
821818
<code><![CDATA[$options[$option]]]></code>

src/Collection.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class Collection implements Stringable
8787
'root' => BSONDocument::class,
8888
];
8989

90-
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
91-
9290
/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
9391
private readonly Encoder $builderEncoder;
9492

@@ -236,24 +234,17 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
236234
$hasWriteStage = is_last_pipeline_operator_write($pipeline);
237235

238236
$options = $this->inheritReadPreference($options);
239-
240-
$server = $hasWriteStage
241-
? select_server_for_aggregate_write_stage($this->manager, $options)
242-
: select_server($this->manager, $options);
243-
244-
/* MongoDB 4.2 and later supports a read concern when an $out stage is
245-
* being used, but earlier versions do not.
246-
*/
247-
if (! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE)) {
248-
$options = $this->inheritReadConcern($options);
249-
}
250-
237+
$options = $this->inheritReadConcern($options);
251238
$options = $this->inheritCodecOrTypeMap($options);
252239

253240
if ($hasWriteStage) {
254241
$options = $this->inheritWriteOptions($options);
255242
}
256243

244+
$server = $hasWriteStage
245+
? select_server_for_aggregate_write_stage($this->manager, $options)
246+
: select_server($this->manager, $options);
247+
257248
$operation = new Aggregate($this->databaseName, $this->collectionName, $pipeline, $options);
258249

259250
return $operation->execute($server);

src/Database.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class Database implements Stringable
6666
'root' => BSONDocument::class,
6767
];
6868

69-
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
70-
7169
/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
7270
private readonly Encoder $builderEncoder;
7371

@@ -229,8 +227,7 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
229227
*/
230228
if (
231229
! isset($options['readConcern']) &&
232-
! is_in_transaction($options) &&
233-
( ! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE))
230+
! is_in_transaction($options)
234231
) {
235232
$options['readConcern'] = $this->readConcern;
236233
}

src/Operation/FindAndModify.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ final class FindAndModify implements Explainable
5555
{
5656
private const WIRE_VERSION_FOR_HINT = 9;
5757

58-
private const WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR = 8;
59-
6058
private array $options;
6159

6260
/**
@@ -227,12 +225,6 @@ public function __construct(private string $databaseName, private string $collec
227225
*/
228226
public function execute(Server $server): array|object|null
229227
{
230-
/* Server versions >= 4.2.0 raise errors for unsupported update options.
231-
* For previous versions, the CRUD spec requires a client-side error. */
232-
if (isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR)) {
233-
throw UnsupportedException::hintNotSupported();
234-
}
235-
236228
/* CRUD spec requires a client-side error when using "hint" with an
237229
* unacknowledged write concern on an unsupported server. */
238230
if (

src/Operation/Update.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
use function MongoDB\is_document;
3333
use function MongoDB\is_first_key_operator;
3434
use function MongoDB\is_pipeline;
35-
use function MongoDB\is_write_concern_acknowledged;
36-
use function MongoDB\server_supports_feature;
3735

3836
/**
3937
* Operation for the update command.
@@ -46,8 +44,6 @@
4644
*/
4745
final class Update implements Explainable
4846
{
49-
private const WIRE_VERSION_FOR_HINT = 8;
50-
5147
private array $options;
5248

5349
/**
@@ -176,15 +172,6 @@ public function __construct(private string $databaseName, private string $collec
176172
*/
177173
public function execute(Server $server): UpdateResult
178174
{
179-
/* CRUD spec requires a client-side error when using "hint" with an
180-
* unacknowledged write concern on an unsupported server. */
181-
if (
182-
isset($this->options['writeConcern']) && ! is_write_concern_acknowledged($this->options['writeConcern']) &&
183-
isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_HINT)
184-
) {
185-
throw UnsupportedException::hintNotSupported();
186-
}
187-
188175
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
189176
if ($inTransaction && isset($this->options['writeConcern'])) {
190177
throw UnsupportedException::writeConcernNotSupportedInTransaction();

tests/Collection/BuilderCollectionFunctionalTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ public function testUpdateOne(): void
231231

232232
public function testUpdateWithPipeline(): void
233233
{
234-
$this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported');
235-
236234
$result = $this->collection->updateOne(
237235
Query::query(x: Query::lt(2)),
238236
new Pipeline(
@@ -259,8 +257,6 @@ public function testUpdateMany(): void
259257

260258
public function testUpdateManyWithPipeline(): void
261259
{
262-
$this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported');
263-
264260
$result = $this->collection->updateMany(
265261
Query::query(x: Query::gt(1)),
266262
new Pipeline(

tests/FunctionalTestCase.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,6 @@ protected function skipIfCausalConsistencyIsNotSupported(): void
469469

470470
protected function skipIfClientSideEncryptionIsNotSupported(): void
471471
{
472-
if (version_compare($this->getFeatureCompatibilityVersion(), '4.2', '<')) {
473-
$this->markTestSkipped('Client Side Encryption only supported on FCV 4.2 or higher');
474-
}
475-
476472
if (static::getModuleInfo('libmongocrypt') === 'disabled') {
477473
$this->markTestSkipped('Client Side Encryption is not enabled in the MongoDB extension');
478474
}
@@ -491,16 +487,18 @@ protected function skipIfGeoHaystackIndexIsNotSupported(): void
491487

492488
protected function skipIfTransactionsAreNotSupported(): void
493489
{
494-
if ($this->getPrimaryServer()->getType() === Server::TYPE_STANDALONE) {
495-
$this->markTestSkipped('Transactions are not supported on standalone servers');
496-
}
490+
switch ($this->getPrimaryServer()->getType()) {
491+
case Server::TYPE_STANDALONE:
492+
$this->markTestSkipped('Transactions are not supported on standalone servers');
493+
break;
497494

498-
if ($this->isShardedCluster()) {
499-
$this->markTestSkipped('Transactions are only supported on FCV 4.2 or higher');
500-
}
495+
case Server::TYPE_RS_PRIMARY:
496+
// Note: mongos does not report storage engine information
497+
if ($this->getServerStorageEngine() !== 'wiredTiger') {
498+
$this->markTestSkipped('Transactions require WiredTiger storage engine');
499+
}
501500

502-
if ($this->getServerStorageEngine() !== 'wiredTiger') {
503-
$this->markTestSkipped('Transactions require WiredTiger storage engine');
501+
break;
504502
}
505503
}
506504

tests/Operation/BulkWriteFunctionalTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
use PHPUnit\Framework\Attributes\Depends;
1919
use stdClass;
2020

21-
use function is_array;
22-
2321
class BulkWriteFunctionalTest extends FunctionalTestCase
2422
{
2523
private Collection $collection;
@@ -198,10 +196,6 @@ function (array $event) use ($expectedReplacement): void {
198196
#[DataProvider('provideUpdatePipelines')]
199197
public function testUpdateDocuments($update, $expectedUpdate): void
200198
{
201-
if (is_array($expectedUpdate)) {
202-
$this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported');
203-
}
204-
205199
(new CommandObserver())->observe(
206200
function () use ($update): void {
207201
$operation = new BulkWrite(
@@ -423,8 +417,6 @@ function (array $event): void {
423417

424418
public function testBulkWriteWithPipelineUpdates(): void
425419
{
426-
$this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported');
427-
428420
$this->createFixtures(4);
429421

430422
$ops = [

tests/Operation/ExplainFunctionalTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,6 @@ public function testAggregate(): void
322322
#[DataProvider('provideVerbosityInformation')]
323323
public function testAggregateOptimizedToQuery($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void
324324
{
325-
$this->skipIfServerVersion('<', '4.2.0', 'MongoDB < 4.2 does not optimize simple aggregation pipelines');
326-
327325
$this->createFixtures(3);
328326

329327
$pipeline = [['$match' => ['_id' => ['$ne' => 2]]]];

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,6 @@ function (array $event): void {
126126
);
127127
}
128128

129-
public function testHintOptionUnsupportedClientSideError(): void
130-
{
131-
$this->skipIfServerVersion('>=', '4.2.0', 'server reports error for unsupported findAndModify options');
132-
133-
$operation = new FindAndModify(
134-
$this->getDatabaseName(),
135-
$this->getCollectionName(),
136-
['remove' => true, 'hint' => '_id_'],
137-
);
138-
139-
$this->expectException(UnsupportedException::class);
140-
$this->expectExceptionMessage('Hint is not supported by the server executing this operation');
141-
142-
$operation->execute($this->getPrimaryServer());
143-
}
144-
145129
public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void
146130
{
147131
$this->skipIfServerVersion('>=', '4.4.0', 'hint is supported');

0 commit comments

Comments
 (0)