Skip to content

PHPLIB-500: Support for allowDiskUse on find operations #721

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

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ cache:

env:
global:
- DRIVER_VERSION=1.7.0
- DRIVER_VERSION=1.8.0
# Todo: Remove when v1.8 has been branched
- DRIVER_BRANCH="master"
- SERVER_DISTRO=enterprise-ubuntu1604
- SERVER_VERSION=4.2.0
- DEPLOYMENT=STANDALONE
Expand Down Expand Up @@ -125,16 +127,18 @@ jobs:
- DEPLOYMENT=SHARDED_CLUSTER_RS

# Test next patch release for driver
- stage: Test
php: "7.3"
env:
- DRIVER_BRANCH="v1.7"
# Todo: enable when v1.8 has been branched
# - stage: Test
# php: "7.3"
# env:
# - DRIVER_BRANCH="v1.8"

# Test next minor release for driver
- stage: Test
php: "7.3"
env:
- DRIVER_BRANCH="master"
# Todo: enable when v1.8 has been branched
# - stage: Test
# php: "7.3"
# env:
# - DRIVER_BRANCH="master"

before_install:
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^7.0",
"ext-hash": "*",
"ext-json": "*",
"ext-mongodb": "^1.7"
"ext-mongodb": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "^6.4 || ^8.3",
Expand Down
11 changes: 11 additions & 0 deletions docs/includes/apiargs-MongoDBCollection-method-find-option.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ operation: ~
optional: true
---
arg_name: option
name: allowDiskUse
type: boolean
description: |
Enables writing to temporary files. When set to ``true``, queries can write
data to the ``_tmp`` sub-directory in the ``dbPath`` directory. The default is
``false``.
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: batchSize
type: integer
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: skip
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: allowDiskUse
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: limit
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: allowDiskUse
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: batchSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: skip
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: allowDiskUse
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
Expand Down
10 changes: 9 additions & 1 deletion src/Operation/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class Find implements Executable, Explainable
*
* Supported options:
*
* * allowDiskUse (boolean): Enables writing to temporary files. When set
* to true, queries can write data to the _tmp sub-directory in the
* dbPath directory. The default is false.
*
* * allowPartialResults (boolean): Get partial results from a mongos if
* some shards are inaccessible (instead of throwing an error).
*
Expand Down Expand Up @@ -169,6 +173,10 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}

if (isset($options['allowDiskUse']) && ! is_bool($options['allowDiskUse'])) {
throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
}

if (isset($options['allowPartialResults']) && ! is_bool($options['allowPartialResults'])) {
throw InvalidArgumentException::invalidType('"allowPartialResults" option', $options['allowPartialResults'], 'boolean');
}
Expand Down Expand Up @@ -416,7 +424,7 @@ private function createQueryOptions()
}
}

foreach (['allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) {
foreach (['allowDiskUse', 'allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) {
if (isset($this->options[$option])) {
$options[$option] = $this->options[$option];
}
Expand Down
13 changes: 8 additions & 5 deletions tests/SpecTests/CrudSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
class CrudSpecTest extends FunctionalTestCase
{
/** @var array */
private static $incompleteTests = [
'find-allowdiskuse: Find does not send allowDiskuse when value is not specified' => 'PHPLIB-500',
'find-allowdiskuse: Find sends allowDiskuse false when false is specified' => 'PHPLIB-500',
'find-allowdiskuse: Find sends allowDiskUse true when true is specified' => 'PHPLIB-500',
];
private static $incompleteTests = [];

/**
* Assert that the expected and actual command documents match.
Expand All @@ -29,6 +25,13 @@ class CrudSpecTest extends FunctionalTestCase
*/
public static function assertCommandMatches(stdClass $expected, stdClass $actual)
{
foreach ($expected as $key => $value) {
if ($value === null) {
static::assertObjectNotHasAttribute($key, $actual);
unset($expected->{$key});
}
}

static::assertDocumentsMatch($expected, $actual);
}

Expand Down