Skip to content

Commit d353a82

Browse files
committed
PHPLIB-463: Prevent driver from retrying MapReduce operations
Running mapReduce commands through the executeReadCommand helper will cause the driver to retry the operation, as it should not inspect the command to catch mapReduce commands. To avoid this, we run mapReduce commands through the generic command helper which generally doesn't retry reads.
1 parent 0dcdfba commit d353a82

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Operation/MapReduce.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,15 @@ public function execute(Server $server)
271271
$command = $this->createCommand($server);
272272
$options = $this->createOptions($hasOutputCollection);
273273

274+
/* If the mapReduce operation results in a write, use
275+
* executeReadWriteCommand to ensure we're handling the writeConcern
276+
* option.
277+
* In other cases, we use executeCommand as this will prevent the
278+
* mapReduce operation from being retried when retryReads is enabled.
279+
* See https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst#unsupported-read-operations. */
274280
$cursor = $hasOutputCollection
275281
? $server->executeReadWriteCommand($this->databaseName, $command, $options)
276-
: $server->executeReadCommand($this->databaseName, $command, $options);
282+
: $server->executeCommand($this->databaseName, $command, $options);
277283

278284
if (isset($this->options['typeMap']) && ! $hasOutputCollection) {
279285
$cursor->setTypeMap(create_field_path_type_map($this->options['typeMap'], 'results.$'));

0 commit comments

Comments
 (0)