Unverified Commit 382cb96d authored by Andreas Braun's avatar Andreas Braun

PHPLIB-413: Add support for read concerns in aggregations with an $out stage

Merged from #643

https://jira.mongodb.org/browse/PHPLIB-413
parents aca250a2 ac5c1a72
......@@ -69,6 +69,7 @@ class Collection
private static $wireVersionForFindAndModifyWriteConcern = 4;
private static $wireVersionForReadConcern = 4;
private static $wireVersionForWritableCommandWriteConcern = 5;
private static $wireVersionForReadConcernWithOutStage = 8;
private $collectionName;
private $databaseName;
......@@ -201,15 +202,16 @@ class Collection
$server = $this->manager->selectServer($options['readPreference']);
/* A "majority" read concern is not compatible with the $out stage, so
* avoid providing the Collection's read concern if it would conflict.
/* MongoDB 4.2 and later supports a read concern when an $out stage is
* being used, but earlier versions do not.
*
* A read concern is also not compatible with transactions.
*/
if ( ! isset($options['readConcern']) &&
! ($hasOutStage && $this->readConcern->getLevel() === ReadConcern::MAJORITY) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) &&
! \MongoDB\is_in_transaction($options)) {
! \MongoDB\is_in_transaction($options) &&
( ! $hasOutStage || \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcernWithOutStage))
) {
$options['readConcern'] = $this->readConcern;
}
......
......@@ -48,6 +48,7 @@ class Database
];
private static $wireVersionForReadConcern = 4;
private static $wireVersionForWritableCommandWriteConcern = 5;
private static $wireVersionForReadConcernWithOutStage = 8;
private $databaseName;
private $manager;
......@@ -186,15 +187,16 @@ class Database
$server = $this->manager->selectServer($options['readPreference']);
/* A "majority" read concern is not compatible with the $out stage, so
* avoid providing the Collection's read concern if it would conflict.
/* MongoDB 4.2 and later supports a read concern when an $out stage is
* being used, but earlier versions do not.
*
* A read concern is also not compatible with transactions.
*/
if ( ! isset($options['readConcern']) &&
! ($hasOutStage && $this->readConcern->getLevel() === ReadConcern::MAJORITY) &&
\MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern) &&
! \MongoDB\is_in_transaction($options)) {
! \MongoDB\is_in_transaction($options) &&
( ! $hasOutStage || \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcernWithOutStage))
) {
$options['readConcern'] = $this->readConcern;
}
......
......@@ -59,6 +59,10 @@ final class Context
$clientOptions = isset($test->clientOptions) ? (array) $test->clientOptions : [];
if (isset($test->outcome->collection->name)) {
$o->outcomeCollectionName = $test->outcome->collection->name;
}
$o->client = new Client(FunctionalTestCase::getUri(), $clientOptions);
return $o;
......
......@@ -19,11 +19,6 @@ class CrudSpecTest extends FunctionalTestCase
'aggregate-merge: Aggregate with $merge and majority readConcern' => 'PHPLIB-438',
'aggregate-merge: Aggregate with $merge and local readConcern' => 'PHPLIB-438',
'aggregate-merge: Aggregate with $merge and available readConcern' => 'PHPLIB-438',
'aggregate-out-readConcern: readConcern majority with out stage' => 'PHPLIB-431',
'aggregate-out-readConcern: readConcern local with out stage' => 'PHPLIB-431',
'aggregate-out-readConcern: readConcern available with out stage' => 'PHPLIB-431',
'aggregate-out-readConcern: readConcern linearizable with out stage' => 'PHPLIB-431',
'aggregate-out-readConcern: invalid readConcern with out stage' => 'PHPLIB-431',
'bulkWrite-arrayFilters: BulkWrite with arrayFilters' => 'Fails due to command assertions',
'updateWithPipelines: UpdateOne using pipelines' => 'PHPLIB-418',
'updateWithPipelines: UpdateMany using pipelines' => 'PHPLIB-418',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment